net: sh_eth: Split sh_eth_recv

Split sh_eth_recv into two functions, one which checks whether
a packet was received and one which handles the received packet.
This is done in preparation for DM support, which handles these
two parts separately.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Cc: Joe Hershberger <joe.hershberger@ni.com>
This commit is contained in:
Marek Vasut 2018-01-21 15:39:50 +01:00 committed by Marek Vasut
parent dca221bd92
commit 52c15e220b

View file

@ -118,23 +118,28 @@ static int sh_eth_send_legacy(struct eth_device *dev, void *packet, int len)
return sh_eth_send_common(eth, packet, len); return sh_eth_send_common(eth, packet, len);
} }
static int sh_eth_recv_common(struct sh_eth_dev *eth) static int sh_eth_recv_start(struct sh_eth_dev *eth)
{ {
int port = eth->port, len = 0; int port = eth->port, len = 0;
struct sh_eth_info *port_info = &eth->port_info[port]; struct sh_eth_info *port_info = &eth->port_info[port];
uchar *packet;
/* Check if the rx descriptor is ready */ /* Check if the rx descriptor is ready */
invalidate_cache(port_info->rx_desc_cur, sizeof(struct rx_desc_s)); invalidate_cache(port_info->rx_desc_cur, sizeof(struct rx_desc_s));
if (!(port_info->rx_desc_cur->rd0 & RD_RACT)) { if (port_info->rx_desc_cur->rd0 & RD_RACT)
return -EINVAL;
/* Check for errors */ /* Check for errors */
if (!(port_info->rx_desc_cur->rd0 & RD_RFE)) { if (port_info->rx_desc_cur->rd0 & RD_RFE)
return -EINVAL;
len = port_info->rx_desc_cur->rd1 & 0xffff; len = port_info->rx_desc_cur->rd1 & 0xffff;
packet = (uchar *)
ADDR_TO_P2(port_info->rx_desc_cur->rd2); return len;
invalidate_cache(packet, len); }
net_process_received_packet(packet, len);
} static void sh_eth_recv_finish(struct sh_eth_dev *eth)
{
struct sh_eth_info *port_info = &eth->port_info[eth->port];
/* Make current descriptor available again */ /* Make current descriptor available again */
if (port_info->rx_desc_cur->rd0 & RD_RDLE) if (port_info->rx_desc_cur->rd0 & RD_RDLE)
@ -150,7 +155,21 @@ static int sh_eth_recv_common(struct sh_eth_dev *eth)
if (port_info->rx_desc_cur >= if (port_info->rx_desc_cur >=
port_info->rx_desc_base + NUM_RX_DESC) port_info->rx_desc_base + NUM_RX_DESC)
port_info->rx_desc_cur = port_info->rx_desc_base; port_info->rx_desc_cur = port_info->rx_desc_base;
} }
static int sh_eth_recv_common(struct sh_eth_dev *eth)
{
int port = eth->port, len = 0;
struct sh_eth_info *port_info = &eth->port_info[port];
uchar *packet = (uchar *)ADDR_TO_P2(port_info->rx_desc_cur->rd2);
len = sh_eth_recv_start(eth);
if (len > 0) {
invalidate_cache(packet, len);
net_process_received_packet(packet, len);
sh_eth_recv_finish(eth);
} else
len = 0;
/* Restart the receiver if disabled */ /* Restart the receiver if disabled */
if (!(sh_eth_read(port_info, EDRRR) & EDRRR_R)) if (!(sh_eth_read(port_info, EDRRR) & EDRRR_R))