All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] can: sun4i: fix overrun
       [not found] <5511583c-37ac-c6b7-f88d-1fd740fae3f5 () pengutronix ! de>
@ 2017-10-27 12:46 ` GBert
  2017-11-06 15:03   ` Marc Kleine-Budde
  0 siblings, 1 reply; 6+ messages in thread
From: GBert @ 2017-10-27 12:46 UTC (permalink / raw)
  To: linux-can; +Cc: Gerhard Bertelsmann

From: Gerhard Bertelsmann <info@gerhard-bertelsmann.de>

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(-)

diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c
index 68ef0a4..bcec511 100644
--- a/drivers/net/can/sun4i_can.c
+++ b/drivers/net/can/sun4i_can.c
@@ -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);
-- 
1.7.9.5


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

* Re: [PATCH v2] can: sun4i: fix overrun
  2017-10-27 12:46 ` [PATCH v2] can: sun4i: fix overrun GBert
@ 2017-11-06 15:03   ` Marc Kleine-Budde
  2017-11-06 15:57     ` [PATCH v4] " GBert
  0 siblings, 1 reply; 6+ messages in thread
From: Marc Kleine-Budde @ 2017-11-06 15:03 UTC (permalink / raw)
  To: GBert, linux-can


[-- Attachment #1.1: Type: text/plain, Size: 1280 bytes --]

On 10/27/2017 02:46 PM, GBert wrote:
> From: Gerhard Bertelsmann <info@gerhard-bertelsmann.de>
> 
> 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.

> ---
>  drivers/net/can/sun4i_can.c |   10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c
> index 68ef0a4..bcec511 100644
> --- a/drivers/net/can/sun4i_can.c
> +++ b/drivers/net/can/sun4i_can.c
> @@ -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

-- 
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: 488 bytes --]

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

* [PATCH v4] can: sun4i: fix overrun
  2017-11-06 15:03   ` Marc Kleine-Budde
@ 2017-11-06 15:57     ` GBert
  2017-11-06 16:09       ` Marc Kleine-Budde
  2017-11-06 17:16       ` [PATCH v5] " GBert
  0 siblings, 2 replies; 6+ messages in thread
From: GBert @ 2017-11-06 15:57 UTC (permalink / raw)
  To: linux-can; +Cc: cb2begq

From: cb2begq <info@gerhard-bertelsmann.de>

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


Signed-off-by: Gerhard Bertelsmann <info@gerhard-bertelsmann.de>

---
 drivers/net/can/sun4i_can.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c
index b0c8085..1d2d12e 100644
--- a/drivers/net/can/sun4i_can.c
+++ b/drivers/net/can/sun4i_can.c
@@ -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);
-- 
1.7.9.5


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

* Re: [PATCH v4] can: sun4i: fix overrun
  2017-11-06 15:57     ` [PATCH v4] " GBert
@ 2017-11-06 16:09       ` Marc Kleine-Budde
  2017-11-06 17:16       ` [PATCH v5] " GBert
  1 sibling, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2017-11-06 16:09 UTC (permalink / raw)
  To: GBert, linux-can


[-- Attachment #1.1: Type: text/plain, Size: 2388 bytes --]

On 11/06/2017 04:57 PM, GBert wrote:
> From: cb2begq <info@gerhard-bertelsmann.de>
> 
> 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
> 
> 
> Signed-off-by: Gerhard Bertelsmann <info@gerhard-bertelsmann.de>
> 
> ---
>  drivers/net/can/sun4i_can.c |   15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c
> index b0c8085..1d2d12e 100644
> --- a/drivers/net/can/sun4i_can.c
> +++ b/drivers/net/can/sun4i_can.c
> @@ -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;

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.

> +
>  		/* 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);
> 

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: 488 bytes --]

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

* [PATCH v5] can: sun4i: fix overrun
  2017-11-06 15:57     ` [PATCH v4] " GBert
  2017-11-06 16:09       ` Marc Kleine-Budde
@ 2017-11-06 17:16       ` GBert
  2017-11-07  8:22         ` Marc Kleine-Budde
  1 sibling, 1 reply; 6+ messages in thread
From: GBert @ 2017-11-06 17:16 UTC (permalink / raw)
  To: linux-can; +Cc: cb2begq

From: cb2begq <info@gerhard-bertelsmann.de>

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


Signed-off-by: Gerhard Bertelsmann <info@gerhard-bertelsmann.de>

---
 drivers/net/can/sun4i_can.c |   12 ++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/sun4i_can.c b/drivers/net/can/sun4i_can.c
index b0c8085..1d2d12e 100644
--- a/drivers/net/can/sun4i_can.c
+++ b/drivers/net/can/sun4i_can.c
@@ -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);
-- 
1.7.9.5


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

* Re: [PATCH v5] can: sun4i: fix overrun
  2017-11-06 17:16       ` [PATCH v5] " GBert
@ 2017-11-07  8:22         ` Marc Kleine-Budde
  0 siblings, 0 replies; 6+ messages in thread
From: Marc Kleine-Budde @ 2017-11-07  8:22 UTC (permalink / raw)
  To: GBert, linux-can


[-- Attachment #1.1: Type: text/plain, Size: 804 bytes --]

On 11/06/2017 06:16 PM, GBert wrote:
> From: cb2begq <info@gerhard-bertelsmann.de>
> 
> 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
> 
> 
> Signed-off-by: Gerhard Bertelsmann <info@gerhard-bertelsmann.de>

Applied to can.

tnx,
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: 488 bytes --]

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

end of thread, other threads:[~2017-11-07  8:22 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <5511583c-37ac-c6b7-f88d-1fd740fae3f5 () pengutronix ! de>
2017-10-27 12:46 ` [PATCH v2] can: sun4i: fix overrun GBert
2017-11-06 15:03   ` Marc Kleine-Budde
2017-11-06 15:57     ` [PATCH v4] " GBert
2017-11-06 16:09       ` Marc Kleine-Budde
2017-11-06 17:16       ` [PATCH v5] " GBert
2017-11-07  8:22         ` Marc Kleine-Budde

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.