blob: 2608302648f8d4e9eaa9cd992bbf8948e74a1fd0 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
Joe Hershbergerc7eceaf2015-03-22 17:09:10 -05002 * (C) Copyright 2001-2015
wdenkc6097192002-11-03 00:24:07 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
Joe Hershbergerc7eceaf2015-03-22 17:09:10 -05004 * Joe Hershberger, National Instruments
wdenkc6097192002-11-03 00:24:07 +00005 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00007 */
8
9#include <common.h>
10#include <command.h>
Joe Hershberger7e0b0152015-05-20 14:27:26 -050011#include <environment.h>
wdenkc6097192002-11-03 00:24:07 +000012#include <net.h>
Andy Flemingaecf6fc2011-04-08 02:10:27 -050013#include <phy.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090014#include <linux/errno.h>
Simon Glass0a9bde12016-01-17 14:51:57 -070015#include "eth_internal.h"
wdenkc6097192002-11-03 00:24:07 +000016
Joe Hershberger3dbe17e2015-03-22 17:09:06 -050017DECLARE_GLOBAL_DATA_PTR;
18
Simon Glassb6121f22015-04-05 16:07:37 -060019/*
20 * CPU and board-specific Ethernet initializations. Aliased function
21 * signals caller to move on
22 */
23static int __def_eth_init(bd_t *bis)
24{
25 return -1;
26}
27int cpu_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
28int board_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
29
Rafal Jaworowski1f2c9a42007-12-27 18:19:02 +010030#ifdef CONFIG_API
Rafal Jaworowski1f2c9a42007-12-27 18:19:02 +010031static struct {
32 uchar data[PKTSIZE];
33 int length;
34} eth_rcv_bufs[PKTBUFSRX];
35
Joe Hershberger5956ded2012-05-15 08:59:07 +000036static unsigned int eth_rcv_current, eth_rcv_last;
Rafal Jaworowski1f2c9a42007-12-27 18:19:02 +010037#endif
38
Joe Hershberger9f374062012-08-03 10:59:08 +000039static struct eth_device *eth_devices;
40struct eth_device *eth_current;
wdenkc6097192002-11-03 00:24:07 +000041
Simon Glassd9582c32016-01-17 14:51:59 -070042void eth_set_current_to_next(void)
Joe Hershbergere1e8a8c2015-03-22 17:09:03 -050043{
44 eth_current = eth_current->next;
45}
46
Simon Glassd9582c32016-01-17 14:51:59 -070047void eth_set_dev(struct eth_device *dev)
Joe Hershberger279d2f62015-03-22 17:09:16 -050048{
49 eth_current = dev;
50}
51
Ben Warren97824d62010-07-29 12:56:11 -070052struct eth_device *eth_get_dev_by_name(const char *devname)
Marian Balakowiczaab8c492005-10-28 22:30:33 +020053{
54 struct eth_device *dev, *target_dev;
55
Helmut Raiger153bf3a2011-08-22 00:17:17 +000056 BUG_ON(devname == NULL);
57
Marian Balakowiczaab8c492005-10-28 22:30:33 +020058 if (!eth_devices)
59 return NULL;
60
61 dev = eth_devices;
62 target_dev = NULL;
63 do {
64 if (strcmp(devname, dev->name) == 0) {
65 target_dev = dev;
66 break;
67 }
68 dev = dev->next;
69 } while (dev != eth_devices);
70
71 return target_dev;
72}
73
Andy Fleminge7fd34b2009-02-11 15:07:24 -060074struct eth_device *eth_get_dev_by_index(int index)
75{
76 struct eth_device *dev, *target_dev;
Andy Fleminge7fd34b2009-02-11 15:07:24 -060077
78 if (!eth_devices)
79 return NULL;
80
81 dev = eth_devices;
82 target_dev = NULL;
83 do {
Michael Walle391da4c2011-10-27 11:31:35 +000084 if (dev->index == index) {
Andy Fleminge7fd34b2009-02-11 15:07:24 -060085 target_dev = dev;
86 break;
87 }
88 dev = dev->next;
Andy Fleminge7fd34b2009-02-11 15:07:24 -060089 } while (dev != eth_devices);
90
91 return target_dev;
92}
93
Joe Hershberger5956ded2012-05-15 08:59:07 +000094int eth_get_dev_index(void)
wdenkc6097192002-11-03 00:24:07 +000095{
Joe Hershberger5956ded2012-05-15 08:59:07 +000096 if (!eth_current)
Michael Walle391da4c2011-10-27 11:31:35 +000097 return -1;
wdenkc6097192002-11-03 00:24:07 +000098
Michael Walle391da4c2011-10-27 11:31:35 +000099 return eth_current->index;
wdenkc6097192002-11-03 00:24:07 +0000100}
101
Joe Hershberger7e0b0152015-05-20 14:27:26 -0500102static int on_ethaddr(const char *name, const char *value, enum env_op op,
103 int flags)
104{
105 int index;
106 struct eth_device *dev;
107
108 if (!eth_devices)
109 return 0;
110
111 /* look for an index after "eth" */
112 index = simple_strtoul(name + 3, NULL, 10);
113
114 dev = eth_devices;
115 do {
116 if (dev->index == index) {
117 switch (op) {
118 case env_op_create:
119 case env_op_overwrite:
120 eth_parse_enetaddr(value, dev->enetaddr);
Marek Vasut0ef21482016-11-12 16:28:40 +0100121 eth_write_hwaddr(dev, "eth", dev->index);
Joe Hershberger7e0b0152015-05-20 14:27:26 -0500122 break;
123 case env_op_delete:
oliver@schinagl.nl496904b2016-11-25 16:30:19 +0100124 memset(dev->enetaddr, 0, ARP_HLEN);
Joe Hershberger7e0b0152015-05-20 14:27:26 -0500125 }
126 }
Gong Qianyua4f23972015-08-31 11:34:43 +0800127 dev = dev->next;
Joe Hershberger7e0b0152015-05-20 14:27:26 -0500128 } while (dev != eth_devices);
129
130 return 0;
131}
132U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr);
133
Simon Glass62b36c92011-06-13 16:13:10 -0700134int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
135 int eth_number)
136{
oliver@schinagl.nl496904b2016-11-25 16:30:19 +0100137 unsigned char env_enetaddr[ARP_HLEN];
Simon Glass62b36c92011-06-13 16:13:10 -0700138 int ret = 0;
139
Eric Miaoae97ef62012-01-18 22:56:33 +0000140 eth_getenv_enetaddr_by_index(base_name, eth_number, env_enetaddr);
Simon Glass62b36c92011-06-13 16:13:10 -0700141
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500142 if (!is_zero_ethaddr(env_enetaddr)) {
143 if (!is_zero_ethaddr(dev->enetaddr) &&
oliver@schinagl.nl496904b2016-11-25 16:30:19 +0100144 memcmp(dev->enetaddr, env_enetaddr, ARP_HLEN)) {
Simon Glass62b36c92011-06-13 16:13:10 -0700145 printf("\nWarning: %s MAC addresses don't match:\n",
Joe Hershbergerc10c0b12015-04-08 01:41:19 -0500146 dev->name);
Simon Glass62b36c92011-06-13 16:13:10 -0700147 printf("Address in SROM is %pM\n",
Joe Hershbergerc10c0b12015-04-08 01:41:19 -0500148 dev->enetaddr);
Simon Glass62b36c92011-06-13 16:13:10 -0700149 printf("Address in environment is %pM\n",
Joe Hershbergerc10c0b12015-04-08 01:41:19 -0500150 env_enetaddr);
Simon Glass62b36c92011-06-13 16:13:10 -0700151 }
152
oliver@schinagl.nl496904b2016-11-25 16:30:19 +0100153 memcpy(dev->enetaddr, env_enetaddr, ARP_HLEN);
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500154 } else if (is_valid_ethaddr(dev->enetaddr)) {
Simon Glass8551d552017-08-03 12:22:11 -0600155 eth_env_set_enetaddr_by_index(base_name, eth_number,
156 dev->enetaddr);
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500157 } else if (is_zero_ethaddr(dev->enetaddr)) {
Joe Hershberger2dc2b5d2015-05-04 14:55:13 -0500158#ifdef CONFIG_NET_RANDOM_ETHADDR
159 net_random_ethaddr(dev->enetaddr);
160 printf("\nWarning: %s (eth%d) using random MAC address - %pM\n",
161 dev->name, eth_number, dev->enetaddr);
162#else
Pavel Machek222981f2014-07-13 10:27:02 +0200163 printf("\nError: %s address not set.\n",
164 dev->name);
165 return -EINVAL;
Joe Hershberger2dc2b5d2015-05-04 14:55:13 -0500166#endif
Simon Glass62b36c92011-06-13 16:13:10 -0700167 }
168
Pavel Machek222981f2014-07-13 10:27:02 +0200169 if (dev->write_hwaddr && !eth_mac_skip(eth_number)) {
Joe Hershberger8ecdbed2015-04-08 01:41:04 -0500170 if (!is_valid_ethaddr(dev->enetaddr)) {
Pavel Machek222981f2014-07-13 10:27:02 +0200171 printf("\nError: %s address %pM illegal value\n",
Joe Hershbergerc10c0b12015-04-08 01:41:19 -0500172 dev->name, dev->enetaddr);
Pavel Machek222981f2014-07-13 10:27:02 +0200173 return -EINVAL;
174 }
Benoît Thébaudeau050219e2012-08-10 07:56:21 +0000175
Simon Glass62b36c92011-06-13 16:13:10 -0700176 ret = dev->write_hwaddr(dev);
Pavel Machek222981f2014-07-13 10:27:02 +0200177 if (ret)
Joe Hershbergerc10c0b12015-04-08 01:41:19 -0500178 printf("\nWarning: %s failed to set MAC address\n",
179 dev->name);
Benoît Thébaudeau050219e2012-08-10 07:56:21 +0000180 }
Simon Glass62b36c92011-06-13 16:13:10 -0700181
182 return ret;
183}
184
Simon Glass1e9961d2011-02-16 11:14:33 -0800185int eth_register(struct eth_device *dev)
186{
187 struct eth_device *d;
Joe Hershberger5956ded2012-05-15 08:59:07 +0000188 static int index;
Michal Simek5b4945b2011-08-29 23:30:13 +0000189
Mike Frysinger6b300dc2011-11-10 14:11:04 +0000190 assert(strlen(dev->name) < sizeof(dev->name));
Michal Simek5b4945b2011-08-29 23:30:13 +0000191
Simon Glass1e9961d2011-02-16 11:14:33 -0800192 if (!eth_devices) {
Joe Hershbergerc10c0b12015-04-08 01:41:19 -0500193 eth_devices = dev;
194 eth_current = dev;
Simon Glass1e9961d2011-02-16 11:14:33 -0800195 eth_current_changed();
wdenkc6097192002-11-03 00:24:07 +0000196 } else {
Joe Hershberger5956ded2012-05-15 08:59:07 +0000197 for (d = eth_devices; d->next != eth_devices; d = d->next)
Detlev Zundeld46bcd32010-03-31 17:56:08 +0200198 ;
wdenkc6097192002-11-03 00:24:07 +0000199 d->next = dev;
200 }
201
202 dev->state = ETH_STATE_INIT;
203 dev->next = eth_devices;
Michael Walle391da4c2011-10-27 11:31:35 +0000204 dev->index = index++;
wdenkc6097192002-11-03 00:24:07 +0000205
206 return 0;
207}
208
Vincent Palatin451be502012-01-09 08:32:36 +0000209int eth_unregister(struct eth_device *dev)
210{
211 struct eth_device *cur;
212
213 /* No device */
214 if (!eth_devices)
Joe Hershbergerd0ce3412015-03-22 17:09:04 -0500215 return -ENODEV;
Vincent Palatin451be502012-01-09 08:32:36 +0000216
217 for (cur = eth_devices; cur->next != eth_devices && cur->next != dev;
218 cur = cur->next)
219 ;
220
221 /* Device not found */
222 if (cur->next != dev)
Joe Hershbergerd0ce3412015-03-22 17:09:04 -0500223 return -ENODEV;
Vincent Palatin451be502012-01-09 08:32:36 +0000224
225 cur->next = dev->next;
226
227 if (eth_devices == dev)
228 eth_devices = dev->next == eth_devices ? NULL : dev->next;
229
230 if (eth_current == dev) {
231 eth_current = eth_devices;
232 eth_current_changed();
233 }
234
235 return 0;
236}
237
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500238int eth_initialize(void)
wdenkc6097192002-11-03 00:24:07 +0000239{
Michael Walle391da4c2011-10-27 11:31:35 +0000240 int num_devices = 0;
Simon Glassb6121f22015-04-05 16:07:37 -0600241
wdenkc6097192002-11-03 00:24:07 +0000242 eth_devices = NULL;
243 eth_current = NULL;
Simon Glassb6121f22015-04-05 16:07:37 -0600244 eth_common_init();
Simon Glass0a9bde12016-01-17 14:51:57 -0700245 /*
246 * If board-specific initialization exists, call it.
247 * If not, call a CPU-specific one
248 */
249 if (board_eth_init != __def_eth_init) {
250 if (board_eth_init(gd->bd) < 0)
251 printf("Board Net Initialization Failed\n");
252 } else if (cpu_eth_init != __def_eth_init) {
253 if (cpu_eth_init(gd->bd) < 0)
254 printf("CPU Net Initialization Failed\n");
255 } else {
256 printf("Net Initialization Skipped\n");
257 }
Marian Balakowiczcbdd1c82005-11-30 18:06:04 +0100258
wdenkc6097192002-11-03 00:24:07 +0000259 if (!eth_devices) {
Joe Hershberger5956ded2012-05-15 08:59:07 +0000260 puts("No ethernet found.\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000261 bootstage_error(BOOTSTAGE_ID_NET_ETH_START);
wdenkc6097192002-11-03 00:24:07 +0000262 } else {
263 struct eth_device *dev = eth_devices;
Joe Hershberger5956ded2012-05-15 08:59:07 +0000264 char *ethprime = getenv("ethprime");
wdenkc6097192002-11-03 00:24:07 +0000265
Simon Glass0169e6b2012-02-13 13:51:18 +0000266 bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT);
wdenkc6097192002-11-03 00:24:07 +0000267 do {
Michael Walle391da4c2011-10-27 11:31:35 +0000268 if (dev->index)
Joe Hershberger5956ded2012-05-15 08:59:07 +0000269 puts(", ");
wdenkc6097192002-11-03 00:24:07 +0000270
271 printf("%s", dev->name);
272
Joe Hershberger5956ded2012-05-15 08:59:07 +0000273 if (ethprime && strcmp(dev->name, ethprime) == 0) {
wdenkc6097192002-11-03 00:24:07 +0000274 eth_current = dev;
Joe Hershberger5956ded2012-05-15 08:59:07 +0000275 puts(" [PRIME]");
wdenkc6097192002-11-03 00:24:07 +0000276 }
277
Mike Frysinger2843ed92010-06-09 22:10:48 -0400278 if (strchr(dev->name, ' '))
Joe Hershberger5956ded2012-05-15 08:59:07 +0000279 puts("\nWarning: eth device name has a space!"
280 "\n");
Mike Frysinger2843ed92010-06-09 22:10:48 -0400281
Pavel Machek222981f2014-07-13 10:27:02 +0200282 eth_write_hwaddr(dev, "eth", dev->index);
wdenkc6097192002-11-03 00:24:07 +0000283
wdenkc6097192002-11-03 00:24:07 +0000284 dev = dev->next;
Michael Walle391da4c2011-10-27 11:31:35 +0000285 num_devices++;
Joe Hershberger5956ded2012-05-15 08:59:07 +0000286 } while (dev != eth_devices);
wdenkc6097192002-11-03 00:24:07 +0000287
Simon Glass1e9961d2011-02-16 11:14:33 -0800288 eth_current_changed();
Joe Hershberger5956ded2012-05-15 08:59:07 +0000289 putc('\n');
wdenkc6097192002-11-03 00:24:07 +0000290 }
291
Michael Walle391da4c2011-10-27 11:31:35 +0000292 return num_devices;
wdenkc6097192002-11-03 00:24:07 +0000293}
294
David Updegraff7280da72007-06-11 10:41:07 -0500295#ifdef CONFIG_MCAST_TFTP
296/* Multicast.
297 * mcast_addr: multicast ipaddr from which multicast Mac is made
Wolfgang Denk627f5c32007-08-14 09:47:27 +0200298 * join: 1=join, 0=leave.
David Updegraff7280da72007-06-11 10:41:07 -0500299 */
Joe Hershberger5874dec2015-04-08 01:41:01 -0500300int eth_mcast_join(struct in_addr mcast_ip, int join)
David Updegraff7280da72007-06-11 10:41:07 -0500301{
oliver@schinagl.nl496904b2016-11-25 16:30:19 +0100302 u8 mcast_mac[ARP_HLEN];
Wolfgang Denk627f5c32007-08-14 09:47:27 +0200303 if (!eth_current || !eth_current->mcast)
David Updegraff7280da72007-06-11 10:41:07 -0500304 return -1;
Joe Hershberger5874dec2015-04-08 01:41:01 -0500305 mcast_mac[5] = htonl(mcast_ip.s_addr) & 0xff;
306 mcast_mac[4] = (htonl(mcast_ip.s_addr)>>8) & 0xff;
307 mcast_mac[3] = (htonl(mcast_ip.s_addr)>>16) & 0x7f;
David Updegraff7280da72007-06-11 10:41:07 -0500308 mcast_mac[2] = 0x5e;
309 mcast_mac[1] = 0x0;
310 mcast_mac[0] = 0x1;
311 return eth_current->mcast(eth_current, mcast_mac, join);
312}
313
Wolfgang Denk627f5c32007-08-14 09:47:27 +0200314/* the 'way' for ethernet-CRC-32. Spliced in from Linux lib/crc32.c
315 * and this is the ethernet-crc method needed for TSEC -- and perhaps
David Updegraff7280da72007-06-11 10:41:07 -0500316 * some other adapter -- hash tables
317 */
318#define CRCPOLY_LE 0xedb88320
Joe Hershberger5956ded2012-05-15 08:59:07 +0000319u32 ether_crc(size_t len, unsigned char const *p)
David Updegraff7280da72007-06-11 10:41:07 -0500320{
321 int i;
322 u32 crc;
323 crc = ~0;
324 while (len--) {
325 crc ^= *p++;
326 for (i = 0; i < 8; i++)
327 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
328 }
329 /* an reverse the bits, cuz of way they arrive -- last-first */
330 crc = (crc >> 16) | (crc << 16);
331 crc = (crc >> 8 & 0x00ff00ff) | (crc << 8 & 0xff00ff00);
332 crc = (crc >> 4 & 0x0f0f0f0f) | (crc << 4 & 0xf0f0f0f0);
333 crc = (crc >> 2 & 0x33333333) | (crc << 2 & 0xcccccccc);
334 crc = (crc >> 1 & 0x55555555) | (crc << 1 & 0xaaaaaaaa);
335 return crc;
336}
wdenkc6097192002-11-03 00:24:07 +0000337
David Updegraff7280da72007-06-11 10:41:07 -0500338#endif
339
wdenkc6097192002-11-03 00:24:07 +0000340
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500341int eth_init(void)
wdenkc6097192002-11-03 00:24:07 +0000342{
Joe Hershberger7e0b0152015-05-20 14:27:26 -0500343 struct eth_device *old_current;
wdenkc6097192002-11-03 00:24:07 +0000344
Stefan Roese11da2be2008-03-04 17:40:41 +0100345 if (!eth_current) {
Joe Hershberger5956ded2012-05-15 08:59:07 +0000346 puts("No ethernet found.\n");
Joe Hershbergerd0ce3412015-03-22 17:09:04 -0500347 return -ENODEV;
Stefan Roese11da2be2008-03-04 17:40:41 +0100348 }
wdenkc6097192002-11-03 00:24:07 +0000349
350 old_current = eth_current;
351 do {
Robin Getz9e0a4d62009-07-23 03:01:03 -0400352 debug("Trying %s\n", eth_current->name);
wdenkc6097192002-11-03 00:24:07 +0000353
Joe Hershberger3dbe17e2015-03-22 17:09:06 -0500354 if (eth_current->init(eth_current, gd->bd) >= 0) {
wdenkc6097192002-11-03 00:24:07 +0000355 eth_current->state = ETH_STATE_ACTIVE;
356
Upakul Barkakatyaed33582007-11-29 12:16:13 +0530357 return 0;
wdenkc6097192002-11-03 00:24:07 +0000358 }
Robin Getz9e0a4d62009-07-23 03:01:03 -0400359 debug("FAIL\n");
wdenkc6097192002-11-03 00:24:07 +0000360
361 eth_try_another(0);
362 } while (old_current != eth_current);
363
Joe Hershbergerd0ce3412015-03-22 17:09:04 -0500364 return -ETIMEDOUT;
wdenkc6097192002-11-03 00:24:07 +0000365}
366
367void eth_halt(void)
368{
369 if (!eth_current)
370 return;
371
372 eth_current->halt(eth_current);
373
374 eth_current->state = ETH_STATE_PASSIVE;
375}
376
Bernhard Nortmann8de9d122015-09-14 15:29:43 +0200377int eth_is_active(struct eth_device *dev)
378{
379 return dev && dev->state == ETH_STATE_ACTIVE;
380}
381
Joe Hershberger4b7747e2012-05-15 08:59:04 +0000382int eth_send(void *packet, int length)
wdenkc6097192002-11-03 00:24:07 +0000383{
384 if (!eth_current)
Joe Hershbergerd0ce3412015-03-22 17:09:04 -0500385 return -ENODEV;
wdenkc6097192002-11-03 00:24:07 +0000386
387 return eth_current->send(eth_current, packet, length);
388}
389
390int eth_rx(void)
391{
392 if (!eth_current)
Joe Hershbergerd0ce3412015-03-22 17:09:04 -0500393 return -ENODEV;
wdenkc6097192002-11-03 00:24:07 +0000394
395 return eth_current->recv(eth_current);
396}
Rafal Jaworowski1f2c9a42007-12-27 18:19:02 +0100397
398#ifdef CONFIG_API
Joe Hershberger4b7747e2012-05-15 08:59:04 +0000399static void eth_save_packet(void *packet, int length)
Rafal Jaworowski1f2c9a42007-12-27 18:19:02 +0100400{
Joe Hershberger4b7747e2012-05-15 08:59:04 +0000401 char *p = packet;
Rafal Jaworowski1f2c9a42007-12-27 18:19:02 +0100402 int i;
403
404 if ((eth_rcv_last+1) % PKTBUFSRX == eth_rcv_current)
405 return;
406
407 if (PKTSIZE < length)
408 return;
409
410 for (i = 0; i < length; i++)
411 eth_rcv_bufs[eth_rcv_last].data[i] = p[i];
412
413 eth_rcv_bufs[eth_rcv_last].length = length;
414 eth_rcv_last = (eth_rcv_last + 1) % PKTBUFSRX;
415}
416
Joe Hershberger4b7747e2012-05-15 08:59:04 +0000417int eth_receive(void *packet, int length)
Rafal Jaworowski1f2c9a42007-12-27 18:19:02 +0100418{
Joe Hershberger4b7747e2012-05-15 08:59:04 +0000419 char *p = packet;
Rafal Jaworowski1f2c9a42007-12-27 18:19:02 +0100420 void *pp = push_packet;
421 int i;
422
423 if (eth_rcv_current == eth_rcv_last) {
424 push_packet = eth_save_packet;
425 eth_rx();
426 push_packet = pp;
427
428 if (eth_rcv_current == eth_rcv_last)
429 return -1;
430 }
431
Michael Walledf7c98a2012-06-22 11:24:28 +0000432 length = min(eth_rcv_bufs[eth_rcv_current].length, length);
Rafal Jaworowski1f2c9a42007-12-27 18:19:02 +0100433
434 for (i = 0; i < length; i++)
435 p[i] = eth_rcv_bufs[eth_rcv_current].data[i];
436
437 eth_rcv_current = (eth_rcv_current + 1) % PKTBUFSRX;
438 return length;
439}
440#endif /* CONFIG_API */