diff mbox

[U-Boot,v6,15/27] dm: eth: Pass the packet pointer as a parameter to recv

Message ID 1426117465-16072-16-git-send-email-joe.hershberger@ni.com
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Joe Hershberger March 11, 2015, 11:44 p.m. UTC
Stop forcing drivers to call net_process_received_packet() - formerly
called NetReceive(). Now the uclass will handle calling the driver for
each packet until the driver errors or has nothing to return. The uclass
will then pass the good packets off to the network stack by calling
net_process_received_packet().

Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>

---

Changes in v6:
-Swallow -EAGAIN error in eth_rx()
-Updated function documentation

Changes in v5:
-New to v5

Changes in v4: None
Changes in v3: None
Changes in v2: None

 include/net.h |  6 ++++--
 net/eth.c     | 15 ++++++++++++++-
 2 files changed, 18 insertions(+), 3 deletions(-)

Comments

Simon Glass March 20, 2015, 12:10 p.m. UTC | #1
On 11 March 2015 at 17:44, Joe Hershberger <joe.hershberger@ni.com> wrote:
> Stop forcing drivers to call net_process_received_packet() - formerly
> called NetReceive(). Now the uclass will handle calling the driver for
> each packet until the driver errors or has nothing to return. The uclass
> will then pass the good packets off to the network stack by calling
> net_process_received_packet().
>
> Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
>

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox

Patch

diff --git a/include/net.h b/include/net.h
index 31ef1ff..241a096 100644
--- a/include/net.h
+++ b/include/net.h
@@ -95,7 +95,9 @@  struct eth_pdata {
  *
  * start: Prepare the hardware to send and receive packets
  * send: Send the bytes passed in "packet" as a packet on the wire
- * recv: Check if the hardware received a packet. Call the network stack if so
+ * recv: Check if the hardware received a packet. If so, set the pointer to the
+ *	 packet buffer in the packetp parameter. If not, return an error or 0 to
+ *	 indicate that the hardware receive FIFO is empty
  * stop: Stop the hardware from looking for packets - may be called even if
  *	 state == PASSIVE
  * mcast: Join or leave a multicast group (for TFTP) - optional
@@ -110,7 +112,7 @@  struct eth_pdata {
 struct eth_ops {
 	int (*start)(struct udevice *dev);
 	int (*send)(struct udevice *dev, void *packet, int length);
-	int (*recv)(struct udevice *dev);
+	int (*recv)(struct udevice *dev, uchar **packetp);
 	void (*stop)(struct udevice *dev);
 #ifdef CONFIG_MCAST_TFTP
 	int (*mcast)(struct udevice *dev, const u8 *enetaddr, int join);
diff --git a/net/eth.c b/net/eth.c
index 1abf027..058c55a 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -259,6 +259,9 @@  int eth_send(void *packet, int length)
 int eth_rx(void)
 {
 	struct udevice *current;
+	uchar *packet;
+	int ret;
+	int i;
 
 	current = eth_get_dev();
 	if (!current)
@@ -267,7 +270,17 @@  int eth_rx(void)
 	if (!device_active(current))
 		return -EINVAL;
 
-	return eth_get_ops(current)->recv(current);
+	/* Process up to 32 packets at one time */
+	for (i = 0; i < 32; i++) {
+		ret = eth_get_ops(current)->recv(current, &packet);
+		if (ret > 0)
+			net_process_received_packet(packet, ret);
+		else
+			break;
+	}
+	if (ret == -EAGAIN)
+		ret = 0;
+	return ret;
 }
 
 static int eth_write_hwaddr(struct udevice *dev)