]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
500856eb RJ |
2 | /* |
3 | * (C) Copyright 2007 Semihalf | |
4 | * | |
5 | * Written by: Rafal Jaworowski <[email protected]> | |
500856eb RJ |
6 | */ |
7 | ||
8 | #include <config.h> | |
500856eb RJ |
9 | #include <net.h> |
10 | #include <linux/types.h> | |
11 | #include <api_public.h> | |
12 | ||
500856eb RJ |
13 | #define DEBUG |
14 | #undef DEBUG | |
15 | ||
500856eb RJ |
16 | #ifdef DEBUG |
17 | #define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0) | |
18 | #else | |
19 | #define debugf(fmt, args...) | |
20 | #endif | |
21 | ||
22 | #define errf(fmt, args...) do { printf("ERROR @ %s(): ", __func__); printf(fmt, ##args); } while (0) | |
23 | ||
21181578 | 24 | #if defined(CONFIG_CMD_NET) && !defined(CONFIG_DM_ETH) |
500856eb RJ |
25 | |
26 | static int dev_valid_net(void *cookie) | |
27 | { | |
28 | return ((void *)eth_get_dev() == cookie) ? 1 : 0; | |
29 | } | |
30 | ||
31 | int dev_open_net(void *cookie) | |
32 | { | |
33 | if (!dev_valid_net(cookie)) | |
34 | return API_ENODEV; | |
35 | ||
d2eaec60 | 36 | if (eth_init() < 0) |
500856eb RJ |
37 | return API_EIO; |
38 | ||
39 | return 0; | |
40 | } | |
41 | ||
42 | int dev_close_net(void *cookie) | |
43 | { | |
44 | if (!dev_valid_net(cookie)) | |
45 | return API_ENODEV; | |
46 | ||
47 | eth_halt(); | |
48 | return 0; | |
49 | } | |
50 | ||
d3a6532c | 51 | /* |
500856eb RJ |
52 | * There can only be one active eth interface at a time - use what is |
53 | * currently set to eth_current | |
54 | */ | |
55 | int dev_enum_net(struct device_info *di) | |
56 | { | |
57 | struct eth_device *eth_current = eth_get_dev(); | |
58 | ||
59 | di->type = DEV_TYP_NET; | |
60 | di->cookie = (void *)eth_current; | |
61 | if (di->cookie == NULL) | |
62 | return 0; | |
63 | ||
64 | memcpy(di->di_net.hwaddr, eth_current->enetaddr, 6); | |
65 | ||
66 | debugf("device found, returning cookie 0x%08x\n", | |
67 | (u_int32_t)di->cookie); | |
68 | ||
69 | return 1; | |
70 | } | |
71 | ||
72 | int dev_write_net(void *cookie, void *buf, int len) | |
73 | { | |
74 | /* XXX verify that cookie points to a valid net device??? */ | |
75 | ||
76 | return eth_send(buf, len); | |
77 | } | |
78 | ||
79 | int dev_read_net(void *cookie, void *buf, int len) | |
80 | { | |
81 | /* XXX verify that cookie points to a valid net device??? */ | |
82 | ||
83 | return eth_receive(buf, len); | |
84 | } | |
11db3abe JH |
85 | |
86 | #else | |
87 | ||
88 | int dev_open_net(void *cookie) | |
89 | { | |
90 | return API_ENODEV; | |
91 | } | |
92 | ||
93 | int dev_close_net(void *cookie) | |
94 | { | |
95 | return API_ENODEV; | |
96 | } | |
97 | ||
98 | int dev_enum_net(struct device_info *di) | |
99 | { | |
100 | return 0; | |
101 | } | |
102 | ||
103 | int dev_write_net(void *cookie, void *buf, int len) | |
104 | { | |
105 | return API_ENODEV; | |
106 | } | |
107 | ||
108 | int dev_read_net(void *cookie, void *buf, int len) | |
109 | { | |
110 | return API_ENODEV; | |
111 | } | |
112 | ||
113 | #endif |