]> git.ipfire.org Git - people/ms/u-boot.git/blame - api/api_net.c
Merge branch 'next'
[people/ms/u-boot.git] / api / api_net.c
CommitLineData
500856eb
RJ
1/*
2 * (C) Copyright 2007 Semihalf
3 *
4 * Written by: Rafal Jaworowski <raj@semihalf.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 *
24 */
25
26#include <config.h>
27
28#if defined(CONFIG_API)
29
30#include <common.h>
31#include <net.h>
32#include <linux/types.h>
33#include <api_public.h>
34
35DECLARE_GLOBAL_DATA_PTR;
36
37#define DEBUG
38#undef DEBUG
39
40#if !defined(CONFIG_NET_MULTI)
41#error "API/net is currently only available for platforms with CONFIG_NET_MULTI"
42#endif
43
44#ifdef DEBUG
45#define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0)
46#else
47#define debugf(fmt, args...)
48#endif
49
50#define errf(fmt, args...) do { printf("ERROR @ %s(): ", __func__); printf(fmt, ##args); } while (0)
51
52
53static int dev_valid_net(void *cookie)
54{
55 return ((void *)eth_get_dev() == cookie) ? 1 : 0;
56}
57
58int dev_open_net(void *cookie)
59{
60 if (!dev_valid_net(cookie))
61 return API_ENODEV;
62
63 if (eth_init(gd->bd) < 0)
64 return API_EIO;
65
66 return 0;
67}
68
69int dev_close_net(void *cookie)
70{
71 if (!dev_valid_net(cookie))
72 return API_ENODEV;
73
74 eth_halt();
75 return 0;
76}
77
d3a6532c 78/*
500856eb
RJ
79 * There can only be one active eth interface at a time - use what is
80 * currently set to eth_current
81 */
82int dev_enum_net(struct device_info *di)
83{
84 struct eth_device *eth_current = eth_get_dev();
85
86 di->type = DEV_TYP_NET;
87 di->cookie = (void *)eth_current;
88 if (di->cookie == NULL)
89 return 0;
90
91 memcpy(di->di_net.hwaddr, eth_current->enetaddr, 6);
92
93 debugf("device found, returning cookie 0x%08x\n",
94 (u_int32_t)di->cookie);
95
96 return 1;
97}
98
99int dev_write_net(void *cookie, void *buf, int len)
100{
101 /* XXX verify that cookie points to a valid net device??? */
102
103 return eth_send(buf, len);
104}
105
106int dev_read_net(void *cookie, void *buf, int len)
107{
108 /* XXX verify that cookie points to a valid net device??? */
109
110 return eth_receive(buf, len);
111}
112
113#endif /* CONFIG_API */