mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] net: designware: drop bad RX frames
@ 2019-02-01 12:59 Ian Abbott
  2019-02-05 11:44 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ian Abbott @ 2019-02-01 12:59 UTC (permalink / raw)
  To: barebox; +Cc: Ian Abbott

In dwc_ether_rx(), check the RX descriptor status for various error
conditions.  On error, issue a warning with the error status bits and
drop the received frame.

Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
---
 drivers/net/designware.c | 42 +++++++++++++++++++++++++++++++---------
 1 file changed, 33 insertions(+), 9 deletions(-)

diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index ad70967e8..21134cd5a 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -326,24 +326,48 @@ static int dwc_ether_rx(struct eth_device *dev)
 
 	u32 status = desc_p->txrx_status;
 	int length = 0;
+	int ret = 0;
 
 	/* Check  if the owner is the CPU */
 	if (status & DESC_RXSTS_OWNBYDMA)
 		return 0;
 
-	length = (status & DESC_RXSTS_FRMLENMSK) >>
-		 DESC_RXSTS_FRMLENSHFT;
+	if ((status & (DESC_RXSTS_ERROR | DESC_RXSTS_DAFILTERFAIL |
+		       DESC_RXSTS_SAFILTERFAIL)) ||
+	    (status & (DESC_RXSTS_RXIPC_GIANTFRAME |
+		       DESC_RXSTS_RXFRAMEETHER)) ==
+	    DESC_RXSTS_RXIPC_GIANTFRAME) {
+		/* Error in packet - discard it */
+		dev_warn(&dev->dev, "Rx error status (%x)\n",
+			 status & (DESC_RXSTS_DAFILTERFAIL |
+				   DESC_RXSTS_ERROR |
+				   DESC_RXSTS_RXTRUNCATED |
+				   DESC_RXSTS_SAFILTERFAIL |
+				   DESC_RXSTS_RXIPC_GIANTFRAME |
+				   DESC_RXSTS_RXDAMAGED |
+				   DESC_RXSTS_RXIPC_GIANT |
+				   DESC_RXSTS_RXCOLLISION |
+				   DESC_RXSTS_RXFRAMEETHER |
+				   DESC_RXSTS_RXWATCHDOG |
+				   DESC_RXSTS_RXMIIERROR |
+				   DESC_RXSTS_RXCRC));
+		ret = -EIO;
+	} else {
+		length = (status & DESC_RXSTS_FRMLENMSK) >>
+			 DESC_RXSTS_FRMLENSHFT;
+
+		dma_sync_single_for_cpu((unsigned long)desc_p->dmamac_addr,
+					length, DMA_FROM_DEVICE);
+		net_receive(dev, desc_p->dmamac_addr, length);
+		dma_sync_single_for_device((unsigned long)desc_p->dmamac_addr,
+					   length, DMA_FROM_DEVICE);
+		ret = length;
+	}
 
 	/*
 	 * Make the current descriptor valid again and go to
 	 * the next one
 	 */
-	dma_sync_single_for_cpu((unsigned long)desc_p->dmamac_addr, length,
-				DMA_FROM_DEVICE);
-	net_receive(dev, desc_p->dmamac_addr, length);
-	dma_sync_single_for_device((unsigned long)desc_p->dmamac_addr, length,
-				   DMA_FROM_DEVICE);
-
 	desc_p->txrx_status |= DESC_RXSTS_OWNBYDMA;
 
 	/* Test the wrap-around condition. */
@@ -352,7 +376,7 @@ static int dwc_ether_rx(struct eth_device *dev)
 
 	priv->rx_currdescnum = desc_num;
 
-	return length;
+	return ret;
 }
 
 static void dwc_ether_halt (struct eth_device *dev)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] net: designware: drop bad RX frames
  2019-02-01 12:59 [PATCH] net: designware: drop bad RX frames Ian Abbott
@ 2019-02-05 11:44 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2019-02-05 11:44 UTC (permalink / raw)
  To: Ian Abbott; +Cc: barebox

On Fri, Feb 01, 2019 at 12:59:48PM +0000, Ian Abbott wrote:
> In dwc_ether_rx(), check the RX descriptor status for various error
> conditions.  On error, issue a warning with the error status bits and
> drop the received frame.
> 
> Signed-off-by: Ian Abbott <abbotti@mev.co.uk>
> ---
>  drivers/net/designware.c | 42 +++++++++++++++++++++++++++++++---------
>  1 file changed, 33 insertions(+), 9 deletions(-)

Applied, thanks

Sascha

> 
> diff --git a/drivers/net/designware.c b/drivers/net/designware.c
> index ad70967e8..21134cd5a 100644
> --- a/drivers/net/designware.c
> +++ b/drivers/net/designware.c
> @@ -326,24 +326,48 @@ static int dwc_ether_rx(struct eth_device *dev)
>  
>  	u32 status = desc_p->txrx_status;
>  	int length = 0;
> +	int ret = 0;
>  
>  	/* Check  if the owner is the CPU */
>  	if (status & DESC_RXSTS_OWNBYDMA)
>  		return 0;
>  
> -	length = (status & DESC_RXSTS_FRMLENMSK) >>
> -		 DESC_RXSTS_FRMLENSHFT;
> +	if ((status & (DESC_RXSTS_ERROR | DESC_RXSTS_DAFILTERFAIL |
> +		       DESC_RXSTS_SAFILTERFAIL)) ||
> +	    (status & (DESC_RXSTS_RXIPC_GIANTFRAME |
> +		       DESC_RXSTS_RXFRAMEETHER)) ==
> +	    DESC_RXSTS_RXIPC_GIANTFRAME) {
> +		/* Error in packet - discard it */
> +		dev_warn(&dev->dev, "Rx error status (%x)\n",
> +			 status & (DESC_RXSTS_DAFILTERFAIL |
> +				   DESC_RXSTS_ERROR |
> +				   DESC_RXSTS_RXTRUNCATED |
> +				   DESC_RXSTS_SAFILTERFAIL |
> +				   DESC_RXSTS_RXIPC_GIANTFRAME |
> +				   DESC_RXSTS_RXDAMAGED |
> +				   DESC_RXSTS_RXIPC_GIANT |
> +				   DESC_RXSTS_RXCOLLISION |
> +				   DESC_RXSTS_RXFRAMEETHER |
> +				   DESC_RXSTS_RXWATCHDOG |
> +				   DESC_RXSTS_RXMIIERROR |
> +				   DESC_RXSTS_RXCRC));
> +		ret = -EIO;
> +	} else {
> +		length = (status & DESC_RXSTS_FRMLENMSK) >>
> +			 DESC_RXSTS_FRMLENSHFT;
> +
> +		dma_sync_single_for_cpu((unsigned long)desc_p->dmamac_addr,
> +					length, DMA_FROM_DEVICE);
> +		net_receive(dev, desc_p->dmamac_addr, length);
> +		dma_sync_single_for_device((unsigned long)desc_p->dmamac_addr,
> +					   length, DMA_FROM_DEVICE);
> +		ret = length;
> +	}
>  
>  	/*
>  	 * Make the current descriptor valid again and go to
>  	 * the next one
>  	 */
> -	dma_sync_single_for_cpu((unsigned long)desc_p->dmamac_addr, length,
> -				DMA_FROM_DEVICE);
> -	net_receive(dev, desc_p->dmamac_addr, length);
> -	dma_sync_single_for_device((unsigned long)desc_p->dmamac_addr, length,
> -				   DMA_FROM_DEVICE);
> -
>  	desc_p->txrx_status |= DESC_RXSTS_OWNBYDMA;
>  
>  	/* Test the wrap-around condition. */
> @@ -352,7 +376,7 @@ static int dwc_ether_rx(struct eth_device *dev)
>  
>  	priv->rx_currdescnum = desc_num;
>  
> -	return length;
> +	return ret;
>  }
>  
>  static void dwc_ether_halt (struct eth_device *dev)
> -- 
> 2.20.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2019-02-05 11:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-01 12:59 [PATCH] net: designware: drop bad RX frames Ian Abbott
2019-02-05 11:44 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox