public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Rafal Jaworowski <raj@semihalf.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] [PATCH 1/7] eth_receive() for standalone receiving Ethernet frame
Date: Wed, 3 Oct 2007 12:03:29 +0200	[thread overview]
Message-ID: <20071003100327.GB1854@semihalf.com> (raw)
In-Reply-To: <20071003100126.GA1854@semihalf.com>

diff --git a/net/eth.c b/net/eth.c
index c8f92a5..032c926 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -59,8 +59,15 @@ extern int npe_initialize(bd_t *);
 extern int uec_initialize(int);
 extern int bfin_EMAC_initialize(bd_t *);
 extern int atstk1000_eth_initialize(bd_t *);
+extern void (*push_packet)(volatile void *, int);
+
+static struct {
+	uchar data[PKTSIZE];
+	int length;
+} eth_rcv_bufs[PKTBUFSRX];
 
 static struct eth_device *eth_devices, *eth_current;
+static unsigned int eth_rcv_current = 0, eth_rcv_last = 0;
 
 struct eth_device *eth_get_dev(void)
 {
@@ -404,6 +411,51 @@ int eth_rx(void)
 	return eth_current->recv(eth_current);
 }
 
+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;
+}
+
 void eth_try_another(int first_restart)
 {
 	static struct eth_device *first_failed = NULL;
diff --git a/net/net.c b/net/net.c
index e9d7757..ae7c372 100644
--- a/net/net.c
+++ b/net/net.c
@@ -133,6 +133,7 @@ uchar		NetBcastAddr[6] =	/* Ethernet bcast address		*/
 			{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 uchar		NetEtherNullAddr[6] =
 			{ 0, 0, 0, 0, 0, 0 };
+void		(*push_packet)(volatile void *, int len) = 0;
 #if defined(CONFIG_CMD_CDP)
 uchar		NetCDPAddr[6] =		/* Ethernet bcast address		*/
 			{ 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
@@ -1157,6 +1158,11 @@ NetReceive(volatile uchar * inpkt, int len)
 	if (len < ETHER_HDR_SIZE)
 		return;
 
+	if (push_packet) {
+		(*push_packet)(inpkt, len);
+		return;
+	}
+
 #if defined(CONFIG_CMD_CDP)
 	/* keep track if packet is CDP */
 	iscdp = memcmp(et->et_dest, NetCDPAddr, 6) == 0;

  reply	other threads:[~2007-10-03 10:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-03 10:01 [U-Boot-Users] [PATCH 0/7] API for external applications Rafal Jaworowski
2007-10-03 10:03 ` Rafal Jaworowski [this message]
2007-10-03 10:04 ` [U-Boot-Users] [PATCH 2/7] Simplify base address handling in bd_info Rafal Jaworowski
2007-10-03 10:05 ` [U-Boot-Users] [PATCH 3/7] Globalize envmatch() Rafal Jaworowski
2007-10-03 10:06 ` [U-Boot-Users] [PATCH 4/7] API header file Rafal Jaworowski
2007-10-03 10:07 ` [U-Boot-Users] [PATCH 5/7] Core API (U-Boot side) Rafal Jaworowski
2007-10-03 10:07 ` [U-Boot-Users] [PATCH 6/7] External application demo Rafal Jaworowski
2007-10-03 10:08 ` [U-Boot-Users] [PATCH 7/7] Enable API_CONFIG for MPC8555CDS Rafal Jaworowski
2007-10-03 12:35 ` [U-Boot-Users] [PATCH 1/7] eth_receive() for standalone receiving Ethernet frame Rafal Jaworowski
2007-10-03 14:45 ` [U-Boot-Users] [PATCH 0/7] API for external applications Marcel Moolenaar
2007-10-04 15:52 ` Haavard Skinnemoen
2007-10-04 16:33   ` Marcel Moolenaar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071003100327.GB1854@semihalf.com \
    --to=raj@semihalf.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox