1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2007 Semihalf
5 * Written by: Rafal Jaworowski <raj@semihalf.com>
11 #include <linux/types.h>
12 #include <api_public.h>
18 #define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0)
20 #define debugf(fmt, args...)
23 #define errf(fmt, args...) do { printf("ERROR @ %s(): ", __func__); printf(fmt, ##args); } while (0)
25 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH)
27 static int dev_valid_net(void *cookie)
29 return ((void *)eth_get_dev() == cookie) ? 1 : 0;
32 int dev_open_net(void *cookie)
34 if (!dev_valid_net(cookie))
43 int dev_close_net(void *cookie)
45 if (!dev_valid_net(cookie))
53 * There can only be one active eth interface at a time - use what is
54 * currently set to eth_current
56 int dev_enum_net(struct device_info *di)
58 struct eth_device *eth_current = eth_get_dev();
60 di->type = DEV_TYP_NET;
61 di->cookie = (void *)eth_current;
62 if (di->cookie == NULL)
65 memcpy(di->di_net.hwaddr, eth_current->enetaddr, 6);
67 debugf("device found, returning cookie 0x%08x\n",
68 (u_int32_t)di->cookie);
73 int dev_write_net(void *cookie, void *buf, int len)
75 /* XXX verify that cookie points to a valid net device??? */
77 return eth_send(buf, len);
80 int dev_read_net(void *cookie, void *buf, int len)
82 /* XXX verify that cookie points to a valid net device??? */
84 return eth_receive(buf, len);
89 int dev_open_net(void *cookie)
94 int dev_close_net(void *cookie)
99 int dev_enum_net(struct device_info *di)
104 int dev_write_net(void *cookie, void *buf, int len)
109 int dev_read_net(void *cookie, void *buf, int len)