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] Pull request: u-boot-freebsd
Date: Thu, 27 Dec 2007 18:19:02 +0100	[thread overview]
Message-ID: <20071227171900.GA15367@semihalf.com> (raw)
In-Reply-To: <4773D286.8080405@qstreams.com>

Hi Ben,

On Thu, Dec 27, 2007 at 11:27:50AM -0500, Ben Warren wrote:
> >>    
> >>>      [Net] Introduce standalone eth_receive() routine
> >>>      
> >>This adds a lot of code to the networking code which is not neede dby
> >>most of the boards. Please make this an optional feature that get's
> >>only compiled in for boards that explicitely request it. Then run this
> >>patch separately through the network custodian.
> >>
> >>    
> >
> >I already sent this patch to Ben and the list some time ago and got an 
> >initial
> >ACK, but I'll re-spin with.
> >
> >  
> When you send the re-spun patch I'll be sure to pull it in.
> 

The patch is included below. I'm only wondering if it makes sense to run this patch through you and the rest of my changes separately, while they all belong to the same changeset and kind of depend on this one...

kind regards,
Rafal


[PATCH] [Net] Introduce standalone 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>
---
 include/net.h |    3 ++
 net/eth.c     |   58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/net.c     |   10 +++++++++
 3 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/include/net.h b/include/net.h
index 603452a..f6decdc 100644
--- a/include/net.h
+++ b/include/net.h
@@ -122,6 +122,9 @@ extern void eth_set_enetaddr(int num, char* a);	/* Set new MAC address		*/
 
 extern int eth_init(bd_t *bis);			/* Initialize the device	*/
 extern int eth_send(volatile void *packet, int length);	   /* Send a packet	*/
+#ifdef CONFIG_API
+extern int eth_receive(volatile void *packet, int length); /* Receive a packet	*/
+#endif
 extern int eth_rx(void);			/* Check for received packets	*/
 extern void eth_halt(void);			/* stop SCC			*/
 extern char *eth_get_name(void);		/* get name of current device	*/
diff --git a/net/eth.c b/net/eth.c
index 1b56a35..4657f79 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -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;
diff --git a/net/net.c b/net/net.c
index c719bc4..cac3e09 100644
--- a/net/net.c
+++ b/net/net.c
@@ -137,6 +137,9 @@ uchar		NetBcastAddr[6] =	/* Ethernet bcast address		*/
 			{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 uchar		NetEtherNullAddr[6] =
 			{ 0, 0, 0, 0, 0, 0 };
+#ifdef CONFIG_API
+void		(*push_packet)(volatile void *, int len) = 0;
+#endif
 #if defined(CONFIG_CMD_CDP)
 uchar		NetCDPAddr[6] =		/* Ethernet bcast address		*/
 			{ 0x01, 0x00, 0x0c, 0xcc, 0xcc, 0xcc };
@@ -1161,6 +1164,13 @@ NetReceive(volatile uchar * inpkt, int len)
 	if (len < ETHER_HDR_SIZE)
 		return;
 
+#ifdef CONFIG_API
+	if (push_packet) {
+		(*push_packet)(inpkt, len);
+		return;
+	}
+#endif
+
 #if defined(CONFIG_CMD_CDP)
 	/* keep track if packet is CDP */
 	iscdp = memcmp(et->et_dest, NetCDPAddr, 6) == 0;
-- 
1.5.2.2

  reply	other threads:[~2007-12-27 17:19 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-17 12:06 [U-Boot-Users] Pull request: u-boot-freebsd Rafal Jaworowski
2007-12-17 12:39 ` Haavard Skinnemoen
2007-12-17 17:17   ` Rafal Jaworowski
2007-12-17 18:03     ` Haavard Skinnemoen
2007-12-18 22:40       ` Rafal Jaworowski
2007-12-18 23:08         ` Wolfgang Denk
2007-12-19  9:32         ` Haavard Skinnemoen
2007-12-17 18:06     ` Marcel Moolenaar
2007-12-17 18:19       ` Haavard Skinnemoen
2007-12-17 19:10         ` Marcel Moolenaar
2007-12-19  9:08           ` Haavard Skinnemoen
2007-12-18 23:00         ` Rafal Jaworowski
2007-12-19  9:15           ` Haavard Skinnemoen
2007-12-27  0:05 ` Wolfgang Denk
2007-12-27 11:56   ` Rafal Jaworowski
2007-12-27 16:27     ` Ben Warren
2007-12-27 17:19       ` Rafal Jaworowski [this message]
2007-12-27 17:06     ` Wolfgang Denk
2007-12-27 17:29       ` Rafal Jaworowski
2007-12-27 19:59         ` Ben Warren
2007-12-27 20:06         ` Wolfgang Denk
  -- strict thread matches above, loose matches on Subject: below --
2008-02-21 11:06 Rafal Jaworowski
2008-02-22 12:01 ` Wolfgang Denk
2008-01-29 16:28 Rafal Jaworowski
2008-02-11 23:51 ` Wolfgang Denk
2008-01-09 19:04 Rafal Jaworowski
2008-01-09 22:08 ` Wolfgang Denk
2007-10-14 10:51 Rafal Jaworowski
2007-10-14 12:50 ` Wolfgang Denk

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=20071227171900.GA15367@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