1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <config.h>
27#include <common.h>
28#include <net.h>
29#include <linux/types.h>
30#include <api_public.h>
31
32DECLARE_GLOBAL_DATA_PTR;
33
34#define DEBUG
35#undef DEBUG
36
37#ifdef DEBUG
38#define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0)
39#else
40#define debugf(fmt, args...)
41#endif
42
43#define errf(fmt, args...) do { printf("ERROR @ %s(): ", __func__); printf(fmt, ##args); } while (0)
44
45
46static int dev_valid_net(void *cookie)
47{
48 return ((void *)eth_get_dev() == cookie) ? 1 : 0;
49}
50
51int dev_open_net(void *cookie)
52{
53 if (!dev_valid_net(cookie))
54 return API_ENODEV;
55
56 if (eth_init(gd->bd) < 0)
57 return API_EIO;
58
59 return 0;
60}
61
62int dev_close_net(void *cookie)
63{
64 if (!dev_valid_net(cookie))
65 return API_ENODEV;
66
67 eth_halt();
68 return 0;
69}
70
71
72
73
74
75int dev_enum_net(struct device_info *di)
76{
77 struct eth_device *eth_current = eth_get_dev();
78
79 di->type = DEV_TYP_NET;
80 di->cookie = (void *)eth_current;
81 if (di->cookie == NULL)
82 return 0;
83
84 memcpy(di->di_net.hwaddr, eth_current->enetaddr, 6);
85
86 debugf("device found, returning cookie 0x%08x\n",
87 (u_int32_t)di->cookie);
88
89 return 1;
90}
91
92int dev_write_net(void *cookie, void *buf, int len)
93{
94
95
96 return eth_send(buf, len);
97}
98
99int dev_read_net(void *cookie, void *buf, int len)
100{
101
102
103 return eth_receive(buf, len);
104}
105