Re: [PATCH 14/14] net: sh_eth: Fix RX error handling

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> From: Valentine Barshak 
>
> In case RX error occurs, and the RD_RFE bit is set, the descriptor
> is never returned back to the queue. Make sh_eth_recv_start return
> zero length in this case so that the descriptor can be released
> and pushed back to the list. Also return the more appropriate
> -EAGAIN instead of -EINVAL if the descriptor is not ready yet.
>
> Signed-off-by: Valentine Barshak 
> Reviewed-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/sh_eth.c | 16 +++-
>  1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
> index 7314caadfdc..7b1f59dc498 100644
> --- a/drivers/net/sh_eth.c
> +++ b/drivers/net/sh_eth.c
> @@ -129,11 +129,11 @@ static int sh_eth_recv_start(struct sh_eth_dev *eth)
> /* Check if the rx descriptor is ready */
> invalidate_cache(port_info->rx_desc_cur, sizeof(struct rx_desc_s));
> if (port_info->rx_desc_cur->rd0 & RD_RACT)
> -   return -EINVAL;
> +   return -EAGAIN;
>
> /* Check for errors */
> if (port_info->rx_desc_cur->rd0 & RD_RFE)
> -   return -EINVAL;
> +   return 0;
>
> return port_info->rx_desc_cur->rd1 & 0x;
>  }
> @@ -556,15 +556,13 @@ static int sh_ether_recv(struct udevice *dev, int 
> flags, uchar **packetp)
> *packetp = packet;
>
> return len;
> -   } else {
> -   len = 0;
> +   }
>
> -   /* Restart the receiver if disabled */
> -   if (!(sh_eth_read(port_info, EDRRR) & EDRRR_R))
> -   sh_eth_write(port_info, EDRRR_R, EDRRR);
> +   /* Restart the receiver if disabled */
> +   if (!(sh_eth_read(port_info, EDRRR) & EDRRR_R))
> +   sh_eth_write(port_info, EDRRR_R, EDRRR);
>
> -   return -EAGAIN;
> -   }
> +   return len;
>  }
>
>  static int sh_ether_free_pkt(struct udevice *dev, uchar *packet, int length)
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


[PATCH 14/14] net: sh_eth: Fix RX error handling

2023-05-30 Thread Marek Vasut
From: Valentine Barshak 

In case RX error occurs, and the RD_RFE bit is set, the descriptor
is never returned back to the queue. Make sh_eth_recv_start return
zero length in this case so that the descriptor can be released
and pushed back to the list. Also return the more appropriate
-EAGAIN instead of -EINVAL if the descriptor is not ready yet.

Signed-off-by: Valentine Barshak 
Reviewed-by: Marek Vasut 
---
Cc: Geert Uytterhoeven 
Cc: Joe Hershberger 
Cc: Michal Simek 
Cc: Nishanth Menon 
Cc: Ramon Fried 
---
 drivers/net/sh_eth.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
index 7314caadfdc..7b1f59dc498 100644
--- a/drivers/net/sh_eth.c
+++ b/drivers/net/sh_eth.c
@@ -129,11 +129,11 @@ static int sh_eth_recv_start(struct sh_eth_dev *eth)
/* Check if the rx descriptor is ready */
invalidate_cache(port_info->rx_desc_cur, sizeof(struct rx_desc_s));
if (port_info->rx_desc_cur->rd0 & RD_RACT)
-   return -EINVAL;
+   return -EAGAIN;
 
/* Check for errors */
if (port_info->rx_desc_cur->rd0 & RD_RFE)
-   return -EINVAL;
+   return 0;
 
return port_info->rx_desc_cur->rd1 & 0x;
 }
@@ -556,15 +556,13 @@ static int sh_ether_recv(struct udevice *dev, int flags, 
uchar **packetp)
*packetp = packet;
 
return len;
-   } else {
-   len = 0;
+   }
 
-   /* Restart the receiver if disabled */
-   if (!(sh_eth_read(port_info, EDRRR) & EDRRR_R))
-   sh_eth_write(port_info, EDRRR_R, EDRRR);
+   /* Restart the receiver if disabled */
+   if (!(sh_eth_read(port_info, EDRRR) & EDRRR_R))
+   sh_eth_write(port_info, EDRRR_R, EDRRR);
 
-   return -EAGAIN;
-   }
+   return len;
 }
 
 static int sh_ether_free_pkt(struct udevice *dev, uchar *packet, int length)
-- 
2.39.2