2 * (C) Copyright 2007 Semihalf
4 * Written by: Rafal Jaworowski <raj@semihalf.com>
6 * See file CREDITS for list of people who contributed to this
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.
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.
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,
29 #include <linux/types.h>
30 #include <api_public.h>
32 DECLARE_GLOBAL_DATA_PTR;
38 #define debugf(fmt, args...) do { printf("%s(): ", __func__); printf(fmt, ##args); } while (0)
40 #define debugf(fmt, args...)
43 #define errf(fmt, args...) do { printf("ERROR @ %s(): ", __func__); printf(fmt, ##args); } while (0)
46 static int dev_valid_net(void *cookie)
48 return ((void *)eth_get_dev() == cookie) ? 1 : 0;
51 int dev_open_net(void *cookie)
53 if (!dev_valid_net(cookie))
56 if (eth_init(gd->bd) < 0)
62 int dev_close_net(void *cookie)
64 if (!dev_valid_net(cookie))
72 * There can only be one active eth interface at a time - use what is
73 * currently set to eth_current
75 int dev_enum_net(struct device_info *di)
77 struct eth_device *eth_current = eth_get_dev();
79 di->type = DEV_TYP_NET;
80 di->cookie = (void *)eth_current;
81 if (di->cookie == NULL)
84 memcpy(di->di_net.hwaddr, eth_current->enetaddr, 6);
86 debugf("device found, returning cookie 0x%08x\n",
87 (u_int32_t)di->cookie);
92 int dev_write_net(void *cookie, void *buf, int len)
94 /* XXX verify that cookie points to a valid net device??? */
96 return eth_send(buf, len);
99 int dev_read_net(void *cookie, void *buf, int len)
101 /* XXX verify that cookie points to a valid net device??? */
103 return eth_receive(buf, len);