diff options
author | Rafal Jaworowski <raj@semihalf.com> | 2007-12-27 18:19:02 +0100 |
---|---|---|
committer | Ben Warren <biggerbadderben@gmail.com> | 2008-01-03 21:36:50 -0500 |
commit | f85b60710571b37293d2233933b76e2aa3db5635 (patch) | |
tree | ab517f6280b1d126b0f9dfe53a5496623d63a26f /net/eth.c | |
parent | 5c740711f0ea5b51414b341b71597c4a0751be74 (diff) | |
download | u-boot-imx-f85b60710571b37293d2233933b76e2aa3db5635.zip u-boot-imx-f85b60710571b37293d2233933b76e2aa3db5635.tar.gz u-boot-imx-f85b60710571b37293d2233933b76e2aa3db5635.tar.bz2 |
Introduce new eth_receive routine
The purpose of this routine is receiving a single network frame, outside of
U-Boot's NetLoop(). Exporting it to standalone programs that run on top of
U-Boot will let them utilise networking facilities. For sending a raw frame
the already existing eth_send() can be used.
The direct consumer of this routine is the newly introduced API layer for
external applications (enabled with CONFIG_API).
Signed-off-by: Rafal Jaworowski <raj@semihalf.com>
Signed-off-by: Piotr Kruszynski <ppk@semihalf.com>
Signed-off-by: Ben Warren <biggerbadderben@gmail.com>
Diffstat (limited to 'net/eth.c')
-rw-r--r-- | net/eth.c | 58 |
1 files changed, 58 insertions, 0 deletions
@@ -62,6 +62,17 @@ extern int bfin_EMAC_initialize(bd_t *); extern int atstk1000_eth_initialize(bd_t *); extern int mcffec_initialize(bd_t*); +#ifdef CONFIG_API +extern void (*push_packet)(volatile void *, int); + +static struct { + uchar data[PKTSIZE]; + int length; +} eth_rcv_bufs[PKTBUFSRX]; + +static unsigned int eth_rcv_current = 0, eth_rcv_last = 0; +#endif + static struct eth_device *eth_devices, *eth_current; struct eth_device *eth_get_dev(void) @@ -457,6 +468,53 @@ int eth_rx(void) return eth_current->recv(eth_current); } +#ifdef CONFIG_API +static void eth_save_packet(volatile void *packet, int length) +{ + volatile char *p = packet; + int i; + + if ((eth_rcv_last+1) % PKTBUFSRX == eth_rcv_current) + return; + + if (PKTSIZE < length) + return; + + for (i = 0; i < length; i++) + eth_rcv_bufs[eth_rcv_last].data[i] = p[i]; + + eth_rcv_bufs[eth_rcv_last].length = length; + eth_rcv_last = (eth_rcv_last + 1) % PKTBUFSRX; +} + +int eth_receive(volatile void *packet, int length) +{ + volatile char *p = packet; + void *pp = push_packet; + int i; + + if (eth_rcv_current == eth_rcv_last) { + push_packet = eth_save_packet; + eth_rx(); + push_packet = pp; + + if (eth_rcv_current == eth_rcv_last) + return -1; + } + + if (length < eth_rcv_bufs[eth_rcv_current].length) + return -1; + + length = eth_rcv_bufs[eth_rcv_current].length; + + for (i = 0; i < length; i++) + p[i] = eth_rcv_bufs[eth_rcv_current].data[i]; + + eth_rcv_current = (eth_rcv_current + 1) % PKTBUFSRX; + return length; +} +#endif /* CONFIG_API */ + void eth_try_another(int first_restart) { static struct eth_device *first_failed = NULL; |