blob: 72ce91c9d0bbb546c7d8b50098b161ca8cf124ea [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
Joe Hershberger05c3e682015-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 Hershberger05c3e682015-03-22 17:09:10 -05004 * Joe Hershberger, National Instruments
wdenkc6097192002-11-03 00:24:07 +00005 *
Wolfgang Denk1a459662013-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 Hershberger05c3e682015-03-22 17:09:10 -050011#include <dm.h>
Joe Hershberger6e0d26c2015-05-20 14:27:26 -050012#include <environment.h>
wdenkc6097192002-11-03 00:24:07 +000013#include <net.h>
Marian Balakowiczd9785c12005-11-30 18:06:04 +010014#include <miiphy.h>
Andy Fleming5f184712011-04-08 02:10:27 -050015#include <phy.h>
Pavel Machek75d9a452014-07-13 10:27:02 +020016#include <asm/errno.h>
Joe Hershberger05c3e682015-03-22 17:09:10 -050017#include <dm/device-internal.h>
Joe Hershberger6e0d26c2015-05-20 14:27:26 -050018#include <dm/uclass-internal.h>
wdenkc6097192002-11-03 00:24:07 +000019
Joe Hershbergerd2eaec62015-03-22 17:09:06 -050020DECLARE_GLOBAL_DATA_PTR;
21
Mike Frysinger3f6e6992009-01-29 19:43:44 -050022void eth_parse_enetaddr(const char *addr, uchar *enetaddr)
23{
24 char *end;
25 int i;
26
27 for (i = 0; i < 6; ++i) {
28 enetaddr[i] = addr ? simple_strtoul(addr, &end, 16) : 0;
29 if (addr)
30 addr = (*end) ? end + 1 : end;
31 }
32}
33
34int eth_getenv_enetaddr(char *name, uchar *enetaddr)
35{
36 eth_parse_enetaddr(getenv(name), enetaddr);
Joe Hershberger0adb5b72015-04-08 01:41:04 -050037 return is_valid_ethaddr(enetaddr);
Mike Frysinger3f6e6992009-01-29 19:43:44 -050038}
39
40int eth_setenv_enetaddr(char *name, const uchar *enetaddr)
41{
42 char buf[20];
43
44 sprintf(buf, "%pM", enetaddr);
45
46 return setenv(name, buf);
47}
Mike Frysinger86848a72009-07-15 21:31:28 -040048
Simon Glass7616e782011-06-13 16:13:10 -070049int eth_getenv_enetaddr_by_index(const char *base_name, int index,
50 uchar *enetaddr)
Mike Frysinger86848a72009-07-15 21:31:28 -040051{
52 char enetvar[32];
Simon Glass7616e782011-06-13 16:13:10 -070053 sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
Mike Frysinger86848a72009-07-15 21:31:28 -040054 return eth_getenv_enetaddr(enetvar, enetaddr);
55}
Mike Frysinger3f6e6992009-01-29 19:43:44 -050056
Joe Hershberger154177e2012-07-10 16:23:22 -050057static inline int eth_setenv_enetaddr_by_index(const char *base_name, int index,
Rob Herringc88ef3c2012-04-14 18:06:49 +000058 uchar *enetaddr)
59{
60 char enetvar[32];
61 sprintf(enetvar, index ? "%s%daddr" : "%saddr", base_name, index);
62 return eth_setenv_enetaddr(enetvar, enetaddr);
63}
64
Ben Warrenecee9322010-04-26 11:11:46 -070065static int eth_mac_skip(int index)
66{
67 char enetvar[15];
68 char *skip_state;
Joe Hershbergerff819a32015-04-08 01:41:19 -050069
Ben Warrenecee9322010-04-26 11:11:46 -070070 sprintf(enetvar, index ? "eth%dmacskip" : "ethmacskip", index);
Joe Hershbergerff819a32015-04-08 01:41:19 -050071 skip_state = getenv(enetvar);
72 return skip_state != NULL;
Ben Warrenecee9322010-04-26 11:11:46 -070073}
74
Joe Hershberger84eb1fb2015-03-22 17:09:03 -050075static void eth_current_changed(void);
76
Simon Glass3bc42702015-04-05 16:07:37 -060077/*
78 * CPU and board-specific Ethernet initializations. Aliased function
79 * signals caller to move on
80 */
81static int __def_eth_init(bd_t *bis)
82{
83 return -1;
84}
85int cpu_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
86int board_eth_init(bd_t *bis) __attribute__((weak, alias("__def_eth_init")));
87
88static void eth_common_init(void)
89{
90 bootstage_mark(BOOTSTAGE_ID_NET_ETH_START);
91#if defined(CONFIG_MII) || defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB)
92 miiphy_init();
93#endif
94
95#ifdef CONFIG_PHYLIB
96 phy_init();
97#endif
98
Simon Glass3bc42702015-04-05 16:07:37 -060099 /*
100 * If board-specific initialization exists, call it.
101 * If not, call a CPU-specific one
102 */
103 if (board_eth_init != __def_eth_init) {
104 if (board_eth_init(gd->bd) < 0)
105 printf("Board Net Initialization Failed\n");
106 } else if (cpu_eth_init != __def_eth_init) {
107 if (cpu_eth_init(gd->bd) < 0)
108 printf("CPU Net Initialization Failed\n");
109 } else {
110 printf("Net Initialization Skipped\n");
111 }
112}
113
Joe Hershberger05c3e682015-03-22 17:09:10 -0500114#ifdef CONFIG_DM_ETH
115/**
116 * struct eth_device_priv - private structure for each Ethernet device
117 *
118 * @state: The state of the Ethernet MAC driver (defined by enum eth_state_t)
119 */
120struct eth_device_priv {
121 enum eth_state_t state;
122};
123
124/**
125 * struct eth_uclass_priv - The structure attached to the uclass itself
126 *
127 * @current: The Ethernet device that the network functions are using
128 */
129struct eth_uclass_priv {
130 struct udevice *current;
131};
132
Joe Hershberger60304592015-03-22 17:09:24 -0500133/* eth_errno - This stores the most recent failure code from DM functions */
134static int eth_errno;
135
Joe Hershberger05c3e682015-03-22 17:09:10 -0500136static struct eth_uclass_priv *eth_get_uclass_priv(void)
137{
138 struct uclass *uc;
139
140 uclass_get(UCLASS_ETH, &uc);
141 assert(uc);
142 return uc->priv;
143}
144
145static void eth_set_current_to_next(void)
146{
147 struct eth_uclass_priv *uc_priv;
148
149 uc_priv = eth_get_uclass_priv();
150 if (uc_priv->current)
151 uclass_next_device(&uc_priv->current);
152 if (!uc_priv->current)
153 uclass_first_device(UCLASS_ETH, &uc_priv->current);
154}
155
Joe Hershberger60304592015-03-22 17:09:24 -0500156/*
157 * Typically this will simply return the active device.
158 * In the case where the most recent active device was unset, this will attempt
159 * to return the first device. If that device doesn't exist or fails to probe,
160 * this function will return NULL.
161 */
Joe Hershberger05c3e682015-03-22 17:09:10 -0500162struct udevice *eth_get_dev(void)
163{
164 struct eth_uclass_priv *uc_priv;
165
166 uc_priv = eth_get_uclass_priv();
167 if (!uc_priv->current)
Joe Hershberger60304592015-03-22 17:09:24 -0500168 eth_errno = uclass_first_device(UCLASS_ETH,
Joe Hershberger05c3e682015-03-22 17:09:10 -0500169 &uc_priv->current);
170 return uc_priv->current;
171}
172
Joe Hershberger60304592015-03-22 17:09:24 -0500173/*
174 * Typically this will just store a device pointer.
175 * In case it was not probed, we will attempt to do so.
176 * dev may be NULL to unset the active device.
177 */
Joe Hershberger05c3e682015-03-22 17:09:10 -0500178static void eth_set_dev(struct udevice *dev)
179{
Joe Hershberger60304592015-03-22 17:09:24 -0500180 if (dev && !device_active(dev))
181 eth_errno = device_probe(dev);
Joe Hershberger05c3e682015-03-22 17:09:10 -0500182 eth_get_uclass_priv()->current = dev;
183}
184
Joe Hershbergere58780d2015-03-22 17:09:16 -0500185/*
186 * Find the udevice that either has the name passed in as devname or has an
187 * alias named devname.
188 */
189struct udevice *eth_get_dev_by_name(const char *devname)
190{
191 int seq = -1;
192 char *endp = NULL;
193 const char *startp = NULL;
194 struct udevice *it;
195 struct uclass *uc;
196
197 /* Must be longer than 3 to be an alias */
198 if (strlen(devname) > strlen("eth")) {
199 startp = devname + strlen("eth");
200 seq = simple_strtoul(startp, &endp, 10);
201 }
202
203 uclass_get(UCLASS_ETH, &uc);
204 uclass_foreach_dev(it, uc) {
Joe Hershberger60304592015-03-22 17:09:24 -0500205 /*
206 * We need the seq to be valid, so try to probe it.
207 * If the probe fails, the seq will not match since it will be
208 * -1 instead of what we are looking for.
209 * We don't care about errors from probe here. Either they won't
210 * match an alias or it will match a literal name and we'll pick
211 * up the error when we try to probe again in eth_set_dev().
212 */
Joe Hershbergere58780d2015-03-22 17:09:16 -0500213 device_probe(it);
214 /*
215 * Check for the name or the sequence number to match
216 */
217 if (strcmp(it->name, devname) == 0 ||
218 (endp > startp && it->seq == seq))
219 return it;
220 }
221
222 return NULL;
223}
224
Joe Hershberger05c3e682015-03-22 17:09:10 -0500225unsigned char *eth_get_ethaddr(void)
226{
227 struct eth_pdata *pdata;
228
229 if (eth_get_dev()) {
230 pdata = eth_get_dev()->platdata;
231 return pdata->enetaddr;
232 }
233
234 return NULL;
235}
236
237/* Set active state without calling start on the driver */
238int eth_init_state_only(void)
239{
240 struct udevice *current;
241 struct eth_device_priv *priv;
242
243 current = eth_get_dev();
244 if (!current || !device_active(current))
245 return -EINVAL;
246
247 priv = current->uclass_priv;
248 priv->state = ETH_STATE_ACTIVE;
249
250 return 0;
251}
252
253/* Set passive state without calling stop on the driver */
254void eth_halt_state_only(void)
255{
256 struct udevice *current;
257 struct eth_device_priv *priv;
258
259 current = eth_get_dev();
260 if (!current || !device_active(current))
261 return;
262
263 priv = current->uclass_priv;
264 priv->state = ETH_STATE_PASSIVE;
265}
266
267int eth_get_dev_index(void)
268{
269 if (eth_get_dev())
270 return eth_get_dev()->seq;
271 return -1;
272}
273
Joe Hershbergerf566c992015-03-24 02:41:49 -0500274static int eth_write_hwaddr(struct udevice *dev)
275{
276 struct eth_pdata *pdata = dev->platdata;
277 int ret = 0;
278
279 if (!dev || !device_active(dev))
280 return -EINVAL;
281
282 /* seq is valid since the device is active */
283 if (eth_get_ops(dev)->write_hwaddr && !eth_mac_skip(dev->seq)) {
284 if (!is_valid_ethaddr(pdata->enetaddr)) {
285 printf("\nError: %s address %pM illegal value\n",
286 dev->name, pdata->enetaddr);
287 return -EINVAL;
288 }
289
290 ret = eth_get_ops(dev)->write_hwaddr(dev);
291 if (ret)
292 printf("\nWarning: %s failed to set MAC address\n",
293 dev->name);
294 }
295
296 return ret;
297}
298
Joe Hershberger6e0d26c2015-05-20 14:27:26 -0500299static int on_ethaddr(const char *name, const char *value, enum env_op op,
300 int flags)
301{
302 int index;
303 int retval;
304 struct udevice *dev;
305
306 /* look for an index after "eth" */
307 index = simple_strtoul(name + 3, NULL, 10);
308
309 retval = uclass_find_device_by_seq(UCLASS_ETH, index, false, &dev);
310 if (!retval) {
311 struct eth_pdata *pdata = dev->platdata;
312 switch (op) {
313 case env_op_create:
314 case env_op_overwrite:
315 eth_parse_enetaddr(value, pdata->enetaddr);
316 break;
317 case env_op_delete:
318 memset(pdata->enetaddr, 0, 6);
319 }
320 }
321
322 return 0;
323}
324U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr);
325
Joe Hershberger05c3e682015-03-22 17:09:10 -0500326int eth_init(void)
327{
328 struct udevice *current;
329 struct udevice *old_current;
Joe Hershberger60304592015-03-22 17:09:24 -0500330 int ret = -ENODEV;
Joe Hershberger05c3e682015-03-22 17:09:10 -0500331
332 current = eth_get_dev();
333 if (!current) {
334 printf("No ethernet found.\n");
335 return -ENODEV;
336 }
337
338 old_current = current;
339 do {
340 debug("Trying %s\n", current->name);
341
342 if (device_active(current)) {
Joe Hershberger60304592015-03-22 17:09:24 -0500343 ret = eth_get_ops(current)->start(current);
344 if (ret >= 0) {
Joe Hershberger05c3e682015-03-22 17:09:10 -0500345 struct eth_device_priv *priv =
346 current->uclass_priv;
347
348 priv->state = ETH_STATE_ACTIVE;
349 return 0;
350 }
Joe Hershbergerff819a32015-04-08 01:41:19 -0500351 } else {
Joe Hershberger60304592015-03-22 17:09:24 -0500352 ret = eth_errno;
Joe Hershbergerff819a32015-04-08 01:41:19 -0500353 }
Joe Hershberger60304592015-03-22 17:09:24 -0500354
Joe Hershberger05c3e682015-03-22 17:09:10 -0500355 debug("FAIL\n");
356
Joe Hershberger60304592015-03-22 17:09:24 -0500357 /*
358 * If ethrotate is enabled, this will change "current",
359 * otherwise we will drop out of this while loop immediately
360 */
Joe Hershberger05c3e682015-03-22 17:09:10 -0500361 eth_try_another(0);
Joe Hershberger60304592015-03-22 17:09:24 -0500362 /* This will ensure the new "current" attempted to probe */
Joe Hershberger05c3e682015-03-22 17:09:10 -0500363 current = eth_get_dev();
364 } while (old_current != current);
365
Joe Hershberger60304592015-03-22 17:09:24 -0500366 return ret;
Joe Hershberger05c3e682015-03-22 17:09:10 -0500367}
368
369void eth_halt(void)
370{
371 struct udevice *current;
372 struct eth_device_priv *priv;
373
374 current = eth_get_dev();
375 if (!current || !device_active(current))
376 return;
377
378 eth_get_ops(current)->stop(current);
379 priv = current->uclass_priv;
380 priv->state = ETH_STATE_PASSIVE;
381}
382
383int eth_send(void *packet, int length)
384{
385 struct udevice *current;
Joe Hershberger60304592015-03-22 17:09:24 -0500386 int ret;
Joe Hershberger05c3e682015-03-22 17:09:10 -0500387
388 current = eth_get_dev();
389 if (!current)
390 return -ENODEV;
391
392 if (!device_active(current))
393 return -EINVAL;
394
Joe Hershberger60304592015-03-22 17:09:24 -0500395 ret = eth_get_ops(current)->send(current, packet, length);
396 if (ret < 0) {
397 /* We cannot completely return the error at present */
398 debug("%s: send() returned error %d\n", __func__, ret);
399 }
400 return ret;
Joe Hershberger05c3e682015-03-22 17:09:10 -0500401}
402
403int eth_rx(void)
404{
405 struct udevice *current;
Joe Hershberger17591402015-03-22 17:09:12 -0500406 uchar *packet;
Simon Glassa1ca92e2015-07-06 16:47:49 -0600407 int flags;
Joe Hershberger17591402015-03-22 17:09:12 -0500408 int ret;
409 int i;
Joe Hershberger05c3e682015-03-22 17:09:10 -0500410
411 current = eth_get_dev();
412 if (!current)
413 return -ENODEV;
414
415 if (!device_active(current))
416 return -EINVAL;
417
Joe Hershberger17591402015-03-22 17:09:12 -0500418 /* Process up to 32 packets at one time */
Simon Glassa1ca92e2015-07-06 16:47:49 -0600419 flags = ETH_RECV_CHECK_DEVICE;
Joe Hershberger17591402015-03-22 17:09:12 -0500420 for (i = 0; i < 32; i++) {
Simon Glassa1ca92e2015-07-06 16:47:49 -0600421 ret = eth_get_ops(current)->recv(current, flags, &packet);
422 flags = 0;
Joe Hershberger17591402015-03-22 17:09:12 -0500423 if (ret > 0)
424 net_process_received_packet(packet, ret);
Joe Hershberger63c97292015-04-03 20:09:46 -0500425 if (ret >= 0 && eth_get_ops(current)->free_pkt)
426 eth_get_ops(current)->free_pkt(current, packet, ret);
427 if (ret <= 0)
Joe Hershberger17591402015-03-22 17:09:12 -0500428 break;
429 }
430 if (ret == -EAGAIN)
431 ret = 0;
Joe Hershberger60304592015-03-22 17:09:24 -0500432 if (ret < 0) {
433 /* We cannot completely return the error at present */
434 debug("%s: recv() returned error %d\n", __func__, ret);
435 }
Joe Hershberger17591402015-03-22 17:09:12 -0500436 return ret;
Joe Hershberger05c3e682015-03-22 17:09:10 -0500437}
438
Joe Hershberger05c3e682015-03-22 17:09:10 -0500439int eth_initialize(void)
440{
441 int num_devices = 0;
442 struct udevice *dev;
443
Simon Glass3bc42702015-04-05 16:07:37 -0600444 eth_common_init();
Joe Hershberger05c3e682015-03-22 17:09:10 -0500445
446 /*
447 * Devices need to write the hwaddr even if not started so that Linux
448 * will have access to the hwaddr that u-boot stored for the device.
449 * This is accomplished by attempting to probe each device and calling
450 * their write_hwaddr() operation.
451 */
452 uclass_first_device(UCLASS_ETH, &dev);
453 if (!dev) {
454 printf("No ethernet found.\n");
455 bootstage_error(BOOTSTAGE_ID_NET_ETH_START);
456 } else {
Joe Hershberger6536b9b2015-03-22 17:09:17 -0500457 char *ethprime = getenv("ethprime");
458 struct udevice *prime_dev = NULL;
459
460 if (ethprime)
461 prime_dev = eth_get_dev_by_name(ethprime);
462 if (prime_dev) {
463 eth_set_dev(prime_dev);
464 eth_current_changed();
465 } else {
466 eth_set_dev(NULL);
467 }
468
Joe Hershberger05c3e682015-03-22 17:09:10 -0500469 bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT);
470 do {
471 if (num_devices)
472 printf(", ");
473
474 printf("eth%d: %s", dev->seq, dev->name);
475
Joe Hershberger6536b9b2015-03-22 17:09:17 -0500476 if (ethprime && dev == prime_dev)
477 printf(" [PRIME]");
478
Joe Hershberger05c3e682015-03-22 17:09:10 -0500479 eth_write_hwaddr(dev);
480
481 uclass_next_device(&dev);
482 num_devices++;
483 } while (dev);
484
485 putc('\n');
486 }
487
488 return num_devices;
489}
490
491static int eth_post_bind(struct udevice *dev)
492{
493 if (strchr(dev->name, ' ')) {
494 printf("\nError: eth device name \"%s\" has a space!\n",
495 dev->name);
496 return -EINVAL;
497 }
498
499 return 0;
500}
501
502static int eth_pre_unbind(struct udevice *dev)
503{
504 /* Don't hang onto a pointer that is going away */
505 if (dev == eth_get_uclass_priv()->current)
506 eth_set_dev(NULL);
507
508 return 0;
509}
510
511static int eth_post_probe(struct udevice *dev)
512{
513 struct eth_device_priv *priv = dev->uclass_priv;
514 struct eth_pdata *pdata = dev->platdata;
515 unsigned char env_enetaddr[6];
516
517 priv->state = ETH_STATE_INIT;
518
519 /* Check if the device has a MAC address in ROM */
520 if (eth_get_ops(dev)->read_rom_hwaddr)
521 eth_get_ops(dev)->read_rom_hwaddr(dev);
522
523 eth_getenv_enetaddr_by_index("eth", dev->seq, env_enetaddr);
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500524 if (!is_zero_ethaddr(env_enetaddr)) {
525 if (!is_zero_ethaddr(pdata->enetaddr) &&
Joe Hershberger05c3e682015-03-22 17:09:10 -0500526 memcmp(pdata->enetaddr, env_enetaddr, 6)) {
527 printf("\nWarning: %s MAC addresses don't match:\n",
528 dev->name);
529 printf("Address in SROM is %pM\n",
530 pdata->enetaddr);
531 printf("Address in environment is %pM\n",
532 env_enetaddr);
533 }
534
535 /* Override the ROM MAC address */
536 memcpy(pdata->enetaddr, env_enetaddr, 6);
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500537 } else if (is_valid_ethaddr(pdata->enetaddr)) {
Joe Hershberger05c3e682015-03-22 17:09:10 -0500538 eth_setenv_enetaddr_by_index("eth", dev->seq, pdata->enetaddr);
539 printf("\nWarning: %s using MAC address from ROM\n",
540 dev->name);
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500541 } else if (is_zero_ethaddr(pdata->enetaddr)) {
Joe Hershbergerbef10142015-05-04 14:55:13 -0500542#ifdef CONFIG_NET_RANDOM_ETHADDR
543 net_random_ethaddr(pdata->enetaddr);
544 printf("\nWarning: %s (eth%d) using random MAC address - %pM\n",
545 dev->name, dev->seq, pdata->enetaddr);
546#else
Joe Hershberger05c3e682015-03-22 17:09:10 -0500547 printf("\nError: %s address not set.\n",
548 dev->name);
549 return -EINVAL;
Joe Hershbergerbef10142015-05-04 14:55:13 -0500550#endif
Joe Hershberger05c3e682015-03-22 17:09:10 -0500551 }
552
553 return 0;
554}
555
556static int eth_pre_remove(struct udevice *dev)
557{
558 eth_get_ops(dev)->stop(dev);
559
560 return 0;
561}
562
563UCLASS_DRIVER(eth) = {
564 .name = "eth",
565 .id = UCLASS_ETH,
566 .post_bind = eth_post_bind,
567 .pre_unbind = eth_pre_unbind,
568 .post_probe = eth_post_probe,
569 .pre_remove = eth_pre_remove,
570 .priv_auto_alloc_size = sizeof(struct eth_uclass_priv),
571 .per_device_auto_alloc_size = sizeof(struct eth_device_priv),
Joe Hershbergere58780d2015-03-22 17:09:16 -0500572 .flags = DM_UC_FLAG_SEQ_ALIAS,
Joe Hershberger05c3e682015-03-22 17:09:10 -0500573};
574#endif
575
576#ifndef CONFIG_DM_ETH
Ben Warrendd354792008-06-23 22:57:27 -0700577
Rafal Jaworowskif85b6072007-12-27 18:19:02 +0100578#ifdef CONFIG_API
Rafal Jaworowskif85b6072007-12-27 18:19:02 +0100579static struct {
580 uchar data[PKTSIZE];
581 int length;
582} eth_rcv_bufs[PKTBUFSRX];
583
Joe Hershberger66c73852012-05-15 08:59:07 +0000584static unsigned int eth_rcv_current, eth_rcv_last;
Rafal Jaworowskif85b6072007-12-27 18:19:02 +0100585#endif
586
Joe Hershbergerf8be7d62012-08-03 10:59:08 +0000587static struct eth_device *eth_devices;
588struct eth_device *eth_current;
wdenkc6097192002-11-03 00:24:07 +0000589
Joe Hershberger84eb1fb2015-03-22 17:09:03 -0500590static void eth_set_current_to_next(void)
591{
592 eth_current = eth_current->next;
593}
594
Joe Hershbergere58780d2015-03-22 17:09:16 -0500595static void eth_set_dev(struct eth_device *dev)
596{
597 eth_current = dev;
598}
599
Ben Warrend7fb9bc2010-07-29 12:56:11 -0700600struct eth_device *eth_get_dev_by_name(const char *devname)
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200601{
602 struct eth_device *dev, *target_dev;
603
Helmut Raiger7e7f9032011-08-22 00:17:17 +0000604 BUG_ON(devname == NULL);
605
Marian Balakowicz63ff0042005-10-28 22:30:33 +0200606 if (!eth_devices)
607 return NULL;
608
609 dev = eth_devices;
610 target_dev = NULL;
611 do {
612 if (strcmp(devname, dev->name) == 0) {
613 target_dev = dev;
614 break;
615 }
616 dev = dev->next;
617 } while (dev != eth_devices);
618
619 return target_dev;
620}
621
Andy Fleming9e569862009-02-11 15:07:24 -0600622struct eth_device *eth_get_dev_by_index(int index)
623{
624 struct eth_device *dev, *target_dev;
Andy Fleming9e569862009-02-11 15:07:24 -0600625
626 if (!eth_devices)
627 return NULL;
628
629 dev = eth_devices;
630 target_dev = NULL;
631 do {
Michael Wallefea7dca2011-10-27 11:31:35 +0000632 if (dev->index == index) {
Andy Fleming9e569862009-02-11 15:07:24 -0600633 target_dev = dev;
634 break;
635 }
636 dev = dev->next;
Andy Fleming9e569862009-02-11 15:07:24 -0600637 } while (dev != eth_devices);
638
639 return target_dev;
640}
641
Joe Hershberger66c73852012-05-15 08:59:07 +0000642int eth_get_dev_index(void)
wdenkc6097192002-11-03 00:24:07 +0000643{
Joe Hershberger66c73852012-05-15 08:59:07 +0000644 if (!eth_current)
Michael Wallefea7dca2011-10-27 11:31:35 +0000645 return -1;
wdenkc6097192002-11-03 00:24:07 +0000646
Michael Wallefea7dca2011-10-27 11:31:35 +0000647 return eth_current->index;
wdenkc6097192002-11-03 00:24:07 +0000648}
649
Joe Hershberger6e0d26c2015-05-20 14:27:26 -0500650static int on_ethaddr(const char *name, const char *value, enum env_op op,
651 int flags)
652{
653 int index;
654 struct eth_device *dev;
655
656 if (!eth_devices)
657 return 0;
658
659 /* look for an index after "eth" */
660 index = simple_strtoul(name + 3, NULL, 10);
661
662 dev = eth_devices;
663 do {
664 if (dev->index == index) {
665 switch (op) {
666 case env_op_create:
667 case env_op_overwrite:
668 eth_parse_enetaddr(value, dev->enetaddr);
669 break;
670 case env_op_delete:
671 memset(dev->enetaddr, 0, 6);
672 }
673 }
674 } while (dev != eth_devices);
675
676 return 0;
677}
678U_BOOT_ENV_CALLBACK(ethaddr, on_ethaddr);
679
Simon Glass7616e782011-06-13 16:13:10 -0700680int eth_write_hwaddr(struct eth_device *dev, const char *base_name,
681 int eth_number)
682{
683 unsigned char env_enetaddr[6];
684 int ret = 0;
685
Eric Miao69376642012-01-18 22:56:33 +0000686 eth_getenv_enetaddr_by_index(base_name, eth_number, env_enetaddr);
Simon Glass7616e782011-06-13 16:13:10 -0700687
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500688 if (!is_zero_ethaddr(env_enetaddr)) {
689 if (!is_zero_ethaddr(dev->enetaddr) &&
Joe Hershberger4c7c65a2015-03-22 17:09:01 -0500690 memcmp(dev->enetaddr, env_enetaddr, 6)) {
Simon Glass7616e782011-06-13 16:13:10 -0700691 printf("\nWarning: %s MAC addresses don't match:\n",
Joe Hershbergerff819a32015-04-08 01:41:19 -0500692 dev->name);
Simon Glass7616e782011-06-13 16:13:10 -0700693 printf("Address in SROM is %pM\n",
Joe Hershbergerff819a32015-04-08 01:41:19 -0500694 dev->enetaddr);
Simon Glass7616e782011-06-13 16:13:10 -0700695 printf("Address in environment is %pM\n",
Joe Hershbergerff819a32015-04-08 01:41:19 -0500696 env_enetaddr);
Simon Glass7616e782011-06-13 16:13:10 -0700697 }
698
699 memcpy(dev->enetaddr, env_enetaddr, 6);
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500700 } else if (is_valid_ethaddr(dev->enetaddr)) {
Rob Herringc88ef3c2012-04-14 18:06:49 +0000701 eth_setenv_enetaddr_by_index(base_name, eth_number,
702 dev->enetaddr);
703 printf("\nWarning: %s using MAC address from net device\n",
Joe Hershbergerff819a32015-04-08 01:41:19 -0500704 dev->name);
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500705 } else if (is_zero_ethaddr(dev->enetaddr)) {
Joe Hershbergerbef10142015-05-04 14:55:13 -0500706#ifdef CONFIG_NET_RANDOM_ETHADDR
707 net_random_ethaddr(dev->enetaddr);
708 printf("\nWarning: %s (eth%d) using random MAC address - %pM\n",
709 dev->name, eth_number, dev->enetaddr);
710#else
Pavel Machek75d9a452014-07-13 10:27:02 +0200711 printf("\nError: %s address not set.\n",
712 dev->name);
713 return -EINVAL;
Joe Hershbergerbef10142015-05-04 14:55:13 -0500714#endif
Simon Glass7616e782011-06-13 16:13:10 -0700715 }
716
Pavel Machek75d9a452014-07-13 10:27:02 +0200717 if (dev->write_hwaddr && !eth_mac_skip(eth_number)) {
Joe Hershberger0adb5b72015-04-08 01:41:04 -0500718 if (!is_valid_ethaddr(dev->enetaddr)) {
Pavel Machek75d9a452014-07-13 10:27:02 +0200719 printf("\nError: %s address %pM illegal value\n",
Joe Hershbergerff819a32015-04-08 01:41:19 -0500720 dev->name, dev->enetaddr);
Pavel Machek75d9a452014-07-13 10:27:02 +0200721 return -EINVAL;
722 }
Benoît Thébaudeau460f9492012-08-10 07:56:21 +0000723
Simon Glass7616e782011-06-13 16:13:10 -0700724 ret = dev->write_hwaddr(dev);
Pavel Machek75d9a452014-07-13 10:27:02 +0200725 if (ret)
Joe Hershbergerff819a32015-04-08 01:41:19 -0500726 printf("\nWarning: %s failed to set MAC address\n",
727 dev->name);
Benoît Thébaudeau460f9492012-08-10 07:56:21 +0000728 }
Simon Glass7616e782011-06-13 16:13:10 -0700729
730 return ret;
731}
732
Simon Glass89d48362011-02-16 11:14:33 -0800733int eth_register(struct eth_device *dev)
734{
735 struct eth_device *d;
Joe Hershberger66c73852012-05-15 08:59:07 +0000736 static int index;
Michal Simek58c583b2011-08-29 23:30:13 +0000737
Mike Frysingerf6add132011-11-10 14:11:04 +0000738 assert(strlen(dev->name) < sizeof(dev->name));
Michal Simek58c583b2011-08-29 23:30:13 +0000739
Simon Glass89d48362011-02-16 11:14:33 -0800740 if (!eth_devices) {
Joe Hershbergerff819a32015-04-08 01:41:19 -0500741 eth_devices = dev;
742 eth_current = dev;
Simon Glass89d48362011-02-16 11:14:33 -0800743 eth_current_changed();
wdenkc6097192002-11-03 00:24:07 +0000744 } else {
Joe Hershberger66c73852012-05-15 08:59:07 +0000745 for (d = eth_devices; d->next != eth_devices; d = d->next)
Detlev Zundelaba4b692010-03-31 17:56:08 +0200746 ;
wdenkc6097192002-11-03 00:24:07 +0000747 d->next = dev;
748 }
749
750 dev->state = ETH_STATE_INIT;
751 dev->next = eth_devices;
Michael Wallefea7dca2011-10-27 11:31:35 +0000752 dev->index = index++;
wdenkc6097192002-11-03 00:24:07 +0000753
754 return 0;
755}
756
Vincent Palatine7e982d2012-01-09 08:32:36 +0000757int eth_unregister(struct eth_device *dev)
758{
759 struct eth_device *cur;
760
761 /* No device */
762 if (!eth_devices)
Joe Hershberger05324a42015-03-22 17:09:04 -0500763 return -ENODEV;
Vincent Palatine7e982d2012-01-09 08:32:36 +0000764
765 for (cur = eth_devices; cur->next != eth_devices && cur->next != dev;
766 cur = cur->next)
767 ;
768
769 /* Device not found */
770 if (cur->next != dev)
Joe Hershberger05324a42015-03-22 17:09:04 -0500771 return -ENODEV;
Vincent Palatine7e982d2012-01-09 08:32:36 +0000772
773 cur->next = dev->next;
774
775 if (eth_devices == dev)
776 eth_devices = dev->next == eth_devices ? NULL : dev->next;
777
778 if (eth_current == dev) {
779 eth_current = eth_devices;
780 eth_current_changed();
781 }
782
783 return 0;
784}
785
Joe Hershbergerd2eaec62015-03-22 17:09:06 -0500786int eth_initialize(void)
wdenkc6097192002-11-03 00:24:07 +0000787{
Michael Wallefea7dca2011-10-27 11:31:35 +0000788 int num_devices = 0;
Simon Glass3bc42702015-04-05 16:07:37 -0600789
wdenkc6097192002-11-03 00:24:07 +0000790 eth_devices = NULL;
791 eth_current = NULL;
Simon Glass3bc42702015-04-05 16:07:37 -0600792 eth_common_init();
Marian Balakowiczd9785c12005-11-30 18:06:04 +0100793
wdenkc6097192002-11-03 00:24:07 +0000794 if (!eth_devices) {
Joe Hershberger66c73852012-05-15 08:59:07 +0000795 puts("No ethernet found.\n");
Simon Glass770605e2012-02-13 13:51:18 +0000796 bootstage_error(BOOTSTAGE_ID_NET_ETH_START);
wdenkc6097192002-11-03 00:24:07 +0000797 } else {
798 struct eth_device *dev = eth_devices;
Joe Hershberger66c73852012-05-15 08:59:07 +0000799 char *ethprime = getenv("ethprime");
wdenkc6097192002-11-03 00:24:07 +0000800
Simon Glass770605e2012-02-13 13:51:18 +0000801 bootstage_mark(BOOTSTAGE_ID_NET_ETH_INIT);
wdenkc6097192002-11-03 00:24:07 +0000802 do {
Michael Wallefea7dca2011-10-27 11:31:35 +0000803 if (dev->index)
Joe Hershberger66c73852012-05-15 08:59:07 +0000804 puts(", ");
wdenkc6097192002-11-03 00:24:07 +0000805
806 printf("%s", dev->name);
807
Joe Hershberger66c73852012-05-15 08:59:07 +0000808 if (ethprime && strcmp(dev->name, ethprime) == 0) {
wdenkc6097192002-11-03 00:24:07 +0000809 eth_current = dev;
Joe Hershberger66c73852012-05-15 08:59:07 +0000810 puts(" [PRIME]");
wdenkc6097192002-11-03 00:24:07 +0000811 }
812
Mike Frysinger1384f3b2010-06-09 22:10:48 -0400813 if (strchr(dev->name, ' '))
Joe Hershberger66c73852012-05-15 08:59:07 +0000814 puts("\nWarning: eth device name has a space!"
815 "\n");
Mike Frysinger1384f3b2010-06-09 22:10:48 -0400816
Pavel Machek75d9a452014-07-13 10:27:02 +0200817 eth_write_hwaddr(dev, "eth", dev->index);
wdenkc6097192002-11-03 00:24:07 +0000818
wdenkc6097192002-11-03 00:24:07 +0000819 dev = dev->next;
Michael Wallefea7dca2011-10-27 11:31:35 +0000820 num_devices++;
Joe Hershberger66c73852012-05-15 08:59:07 +0000821 } while (dev != eth_devices);
wdenkc6097192002-11-03 00:24:07 +0000822
Simon Glass89d48362011-02-16 11:14:33 -0800823 eth_current_changed();
Joe Hershberger66c73852012-05-15 08:59:07 +0000824 putc('\n');
wdenkc6097192002-11-03 00:24:07 +0000825 }
826
Michael Wallefea7dca2011-10-27 11:31:35 +0000827 return num_devices;
wdenkc6097192002-11-03 00:24:07 +0000828}
829
David Updegraff53a5c422007-06-11 10:41:07 -0500830#ifdef CONFIG_MCAST_TFTP
831/* Multicast.
832 * mcast_addr: multicast ipaddr from which multicast Mac is made
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200833 * join: 1=join, 0=leave.
David Updegraff53a5c422007-06-11 10:41:07 -0500834 */
Joe Hershberger049a95a2015-04-08 01:41:01 -0500835int eth_mcast_join(struct in_addr mcast_ip, int join)
David Updegraff53a5c422007-06-11 10:41:07 -0500836{
Joe Hershberger66c73852012-05-15 08:59:07 +0000837 u8 mcast_mac[6];
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200838 if (!eth_current || !eth_current->mcast)
David Updegraff53a5c422007-06-11 10:41:07 -0500839 return -1;
Joe Hershberger049a95a2015-04-08 01:41:01 -0500840 mcast_mac[5] = htonl(mcast_ip.s_addr) & 0xff;
841 mcast_mac[4] = (htonl(mcast_ip.s_addr)>>8) & 0xff;
842 mcast_mac[3] = (htonl(mcast_ip.s_addr)>>16) & 0x7f;
David Updegraff53a5c422007-06-11 10:41:07 -0500843 mcast_mac[2] = 0x5e;
844 mcast_mac[1] = 0x0;
845 mcast_mac[0] = 0x1;
846 return eth_current->mcast(eth_current, mcast_mac, join);
847}
848
Wolfgang Denk85eb5ca2007-08-14 09:47:27 +0200849/* the 'way' for ethernet-CRC-32. Spliced in from Linux lib/crc32.c
850 * and this is the ethernet-crc method needed for TSEC -- and perhaps
David Updegraff53a5c422007-06-11 10:41:07 -0500851 * some other adapter -- hash tables
852 */
853#define CRCPOLY_LE 0xedb88320
Joe Hershberger66c73852012-05-15 08:59:07 +0000854u32 ether_crc(size_t len, unsigned char const *p)
David Updegraff53a5c422007-06-11 10:41:07 -0500855{
856 int i;
857 u32 crc;
858 crc = ~0;
859 while (len--) {
860 crc ^= *p++;
861 for (i = 0; i < 8; i++)
862 crc = (crc >> 1) ^ ((crc & 1) ? CRCPOLY_LE : 0);
863 }
864 /* an reverse the bits, cuz of way they arrive -- last-first */
865 crc = (crc >> 16) | (crc << 16);
866 crc = (crc >> 8 & 0x00ff00ff) | (crc << 8 & 0xff00ff00);
867 crc = (crc >> 4 & 0x0f0f0f0f) | (crc << 4 & 0xf0f0f0f0);
868 crc = (crc >> 2 & 0x33333333) | (crc << 2 & 0xcccccccc);
869 crc = (crc >> 1 & 0x55555555) | (crc << 1 & 0xaaaaaaaa);
870 return crc;
871}
872
873#endif
874
wdenkc6097192002-11-03 00:24:07 +0000875
Joe Hershbergerd2eaec62015-03-22 17:09:06 -0500876int eth_init(void)
wdenkc6097192002-11-03 00:24:07 +0000877{
Joe Hershberger6e0d26c2015-05-20 14:27:26 -0500878 struct eth_device *old_current;
wdenkc6097192002-11-03 00:24:07 +0000879
Stefan Roese6bc11382008-03-04 17:40:41 +0100880 if (!eth_current) {
Joe Hershberger66c73852012-05-15 08:59:07 +0000881 puts("No ethernet found.\n");
Joe Hershberger05324a42015-03-22 17:09:04 -0500882 return -ENODEV;
Stefan Roese6bc11382008-03-04 17:40:41 +0100883 }
wdenkc6097192002-11-03 00:24:07 +0000884
885 old_current = eth_current;
886 do {
Robin Getz0ebf04c2009-07-23 03:01:03 -0400887 debug("Trying %s\n", eth_current->name);
wdenkc6097192002-11-03 00:24:07 +0000888
Joe Hershbergerd2eaec62015-03-22 17:09:06 -0500889 if (eth_current->init(eth_current, gd->bd) >= 0) {
wdenkc6097192002-11-03 00:24:07 +0000890 eth_current->state = ETH_STATE_ACTIVE;
891
Upakul Barkakaty505be872007-11-29 12:16:13 +0530892 return 0;
wdenkc6097192002-11-03 00:24:07 +0000893 }
Robin Getz0ebf04c2009-07-23 03:01:03 -0400894 debug("FAIL\n");
wdenkc6097192002-11-03 00:24:07 +0000895
896 eth_try_another(0);
897 } while (old_current != eth_current);
898
Joe Hershberger05324a42015-03-22 17:09:04 -0500899 return -ETIMEDOUT;
wdenkc6097192002-11-03 00:24:07 +0000900}
901
902void eth_halt(void)
903{
904 if (!eth_current)
905 return;
906
907 eth_current->halt(eth_current);
908
909 eth_current->state = ETH_STATE_PASSIVE;
910}
911
Joe Hershbergerdb288a92012-05-15 08:59:04 +0000912int eth_send(void *packet, int length)
wdenkc6097192002-11-03 00:24:07 +0000913{
914 if (!eth_current)
Joe Hershberger05324a42015-03-22 17:09:04 -0500915 return -ENODEV;
wdenkc6097192002-11-03 00:24:07 +0000916
917 return eth_current->send(eth_current, packet, length);
918}
919
920int eth_rx(void)
921{
922 if (!eth_current)
Joe Hershberger05324a42015-03-22 17:09:04 -0500923 return -ENODEV;
wdenkc6097192002-11-03 00:24:07 +0000924
925 return eth_current->recv(eth_current);
926}
Joe Hershberger05c3e682015-03-22 17:09:10 -0500927#endif /* ifndef CONFIG_DM_ETH */
wdenkc6097192002-11-03 00:24:07 +0000928
Rafal Jaworowskif85b6072007-12-27 18:19:02 +0100929#ifdef CONFIG_API
Joe Hershbergerdb288a92012-05-15 08:59:04 +0000930static void eth_save_packet(void *packet, int length)
Rafal Jaworowskif85b6072007-12-27 18:19:02 +0100931{
Joe Hershbergerdb288a92012-05-15 08:59:04 +0000932 char *p = packet;
Rafal Jaworowskif85b6072007-12-27 18:19:02 +0100933 int i;
934
935 if ((eth_rcv_last+1) % PKTBUFSRX == eth_rcv_current)
936 return;
937
938 if (PKTSIZE < length)
939 return;
940
941 for (i = 0; i < length; i++)
942 eth_rcv_bufs[eth_rcv_last].data[i] = p[i];
943
944 eth_rcv_bufs[eth_rcv_last].length = length;
945 eth_rcv_last = (eth_rcv_last + 1) % PKTBUFSRX;
946}
947
Joe Hershbergerdb288a92012-05-15 08:59:04 +0000948int eth_receive(void *packet, int length)
Rafal Jaworowskif85b6072007-12-27 18:19:02 +0100949{
Joe Hershbergerdb288a92012-05-15 08:59:04 +0000950 char *p = packet;
Rafal Jaworowskif85b6072007-12-27 18:19:02 +0100951 void *pp = push_packet;
952 int i;
953
954 if (eth_rcv_current == eth_rcv_last) {
955 push_packet = eth_save_packet;
956 eth_rx();
957 push_packet = pp;
958
959 if (eth_rcv_current == eth_rcv_last)
960 return -1;
961 }
962
Michael Walle46c07bc2012-06-22 11:24:28 +0000963 length = min(eth_rcv_bufs[eth_rcv_current].length, length);
Rafal Jaworowskif85b6072007-12-27 18:19:02 +0100964
965 for (i = 0; i < length; i++)
966 p[i] = eth_rcv_bufs[eth_rcv_current].data[i];
967
968 eth_rcv_current = (eth_rcv_current + 1) % PKTBUFSRX;
969 return length;
970}
971#endif /* CONFIG_API */
972
Joe Hershberger84eb1fb2015-03-22 17:09:03 -0500973static void eth_current_changed(void)
974{
975 char *act = getenv("ethact");
976 /* update current ethernet name */
977 if (eth_get_dev()) {
978 if (act == NULL || strcmp(act, eth_get_name()) != 0)
979 setenv("ethact", eth_get_name());
980 }
981 /*
982 * remove the variable completely if there is no active
983 * interface
984 */
985 else if (act != NULL)
986 setenv("ethact", NULL);
987}
988
wdenkc6097192002-11-03 00:24:07 +0000989void eth_try_another(int first_restart)
990{
Joe Hershberger05c3e682015-03-22 17:09:10 -0500991 static void *first_failed;
Remy Bohmerc650e1b2011-02-19 20:15:14 +0100992 char *ethrotate;
Matthias Fuchse1692572008-01-17 07:45:05 +0100993
994 /*
995 * Do not rotate between network interfaces when
996 * 'ethrotate' variable is set to 'no'.
997 */
Joe Hershberger66c73852012-05-15 08:59:07 +0000998 ethrotate = getenv("ethrotate");
999 if ((ethrotate != NULL) && (strcmp(ethrotate, "no") == 0))
Matthias Fuchse1692572008-01-17 07:45:05 +01001000 return;
wdenkc6097192002-11-03 00:24:07 +00001001
Joe Hershberger84eb1fb2015-03-22 17:09:03 -05001002 if (!eth_get_dev())
wdenkc6097192002-11-03 00:24:07 +00001003 return;
1004
Joe Hershberger66c73852012-05-15 08:59:07 +00001005 if (first_restart)
Joe Hershberger84eb1fb2015-03-22 17:09:03 -05001006 first_failed = eth_get_dev();
wdenkc6097192002-11-03 00:24:07 +00001007
Joe Hershberger84eb1fb2015-03-22 17:09:03 -05001008 eth_set_current_to_next();
wdenkc6097192002-11-03 00:24:07 +00001009
Simon Glass89d48362011-02-16 11:14:33 -08001010 eth_current_changed();
wdenka3d991b2004-04-15 21:48:45 +00001011
Joe Hershberger84eb1fb2015-03-22 17:09:03 -05001012 if (first_failed == eth_get_dev())
Joe Hershbergerbc0571f2015-04-08 01:41:21 -05001013 net_restart_wrap = 1;
wdenkc6097192002-11-03 00:24:07 +00001014}
1015
wdenka3d991b2004-04-15 21:48:45 +00001016void eth_set_current(void)
1017{
Joe Hershberger66c73852012-05-15 08:59:07 +00001018 static char *act;
1019 static int env_changed_id;
Heiko Schocher2f70c492009-02-10 09:38:52 +01001020 int env_id;
wdenka3d991b2004-04-15 21:48:45 +00001021
Heiko Schocher2f70c492009-02-10 09:38:52 +01001022 env_id = get_env_id();
1023 if ((act == NULL) || (env_changed_id != env_id)) {
1024 act = getenv("ethact");
1025 env_changed_id = env_id;
1026 }
Joe Hershberger6536b9b2015-03-22 17:09:17 -05001027
1028 if (act == NULL) {
1029 char *ethprime = getenv("ethprime");
1030 void *dev = NULL;
1031
1032 if (ethprime)
1033 dev = eth_get_dev_by_name(ethprime);
1034 if (dev)
1035 eth_set_dev(dev);
1036 else
1037 eth_set_dev(NULL);
1038 } else {
Joe Hershbergere58780d2015-03-22 17:09:16 -05001039 eth_set_dev(eth_get_dev_by_name(act));
Joe Hershberger6536b9b2015-03-22 17:09:17 -05001040 }
wdenka3d991b2004-04-15 21:48:45 +00001041
Simon Glass89d48362011-02-16 11:14:33 -08001042 eth_current_changed();
wdenka3d991b2004-04-15 21:48:45 +00001043}
wdenka3d991b2004-04-15 21:48:45 +00001044
Joe Hershberger84eb1fb2015-03-22 17:09:03 -05001045const char *eth_get_name(void)
wdenk5bb226e2003-11-17 21:14:37 +00001046{
Joe Hershberger84eb1fb2015-03-22 17:09:03 -05001047 return eth_get_dev() ? eth_get_dev()->name : "unknown";
wdenk5bb226e2003-11-17 21:14:37 +00001048}