summaryrefslogtreecommitdiffstats
path: root/net/eth.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2007-07-05 18:01:31 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-07-05 18:01:31 +0200
commit69eab860c2a4f72c7c882652f3c248e575d32f4e (patch)
treee8701c5dcc42ad15a8bb2bf7ec0dd296c7c0ec87 /net/eth.c
parent144592aacd88c0752cbdcefa889db50a14c2450a (diff)
downloadbarebox-69eab860c2a4f72c7c882652f3c248e575d32f4e.tar.gz
barebox-69eab860c2a4f72c7c882652f3c248e575d32f4e.tar.xz
svn_rev_196
WIP
Diffstat (limited to 'net/eth.c')
-rw-r--r--net/eth.c96
1 files changed, 45 insertions, 51 deletions
diff --git a/net/eth.c b/net/eth.c
index bcfbe6fa25..e2db385e9d 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -28,6 +28,7 @@
#include <net.h>
#include <miiphy.h>
#include <malloc.h>
+#include <asm-generic/errno.h>
typedef enum eth_cookies {
PARAM_IP,
@@ -36,25 +37,42 @@ typedef enum eth_cookies {
PARAM_NM,
} eth_cookies_t;
-static char *eth_get(struct device_d* dev, ulong cookie)
+static char *eth_get(struct device_d* dev, struct param_d *param)
{
- struct eth_device *ndev = dev->driver->type_data;
-
- if (cookie >= 4)
- return 0;
+ struct eth_device *edev = dev->priv;
+ char *buf;
+
+ switch (param->cookie) {
+ case PARAM_MAC:
+ buf = malloc(18);
+ enet_addr_to_string(edev->enetaddr, buf);
+ break;
+ default:
+ buf = strdup((char *)param->val);
+ }
- return ndev->param[cookie];
+ return buf;
}
-static int eth_set(struct device_d* dev, ulong cookie, char *newval)
+static int eth_set(struct device_d* dev, struct param_d *param, char *newval)
{
- struct eth_device *ndev = dev->driver->type_data;
- char **val = &ndev->param[cookie];
-
- if (*val)
- free(*val);
+ struct eth_device *edev = dev->priv;
+ int ret;
+
+ switch (param->cookie) {
+ case PARAM_MAC:
+ if (string_to_enet_addr(newval, edev->enetaddr))
+ return -EINVAL;
+
+ if ((ret = edev->set_mac_address(edev, newval)))
+ return ret;
+ /* Fall through */
+ default:
+ if (param->val)
+ free(param->val);
+ param->val = strdup(newval);
+ }
- *val = newval;
return 0;
}
@@ -114,15 +132,17 @@ int eth_rx(void)
return eth_current->recv(eth_current);
}
-static int eth_handle(struct device_d *dev)
+int eth_register(struct eth_device *edev)
{
- unsigned char ethaddr_tmp[20];
- unsigned char *ethaddr;
- struct eth_device *ndev = dev->driver->type_data;
- char *e = NULL;
+ struct device_d *dev = edev->dev;
+ unsigned char ethaddr_str[20];
+ unsigned char ethaddr[6];
int i;
- if (!ndev->get_mac_address) {
+
+ printf("%s\n",__FUNCTION__);
+
+ if (!edev->get_mac_address) {
printf("no get_mac_address found for current eth device\n");
return -1;
}
@@ -130,42 +150,16 @@ static int eth_handle(struct device_d *dev)
for (i = 0; i < 4; i++)
dev_add_parameter(dev, &eth_params[i]);
- ethaddr = ndev->enetaddr;
-
- /* Try to get a MAC address from the eeprom set 'ethaddr' to it.
- * If this fails we rely on 'ethaddr' being set by the user.
- */
- if (ndev->get_mac_address(ndev, ethaddr) == 0) {
- sprintf (ethaddr_tmp, "%02X:%02X:%02X:%02X:%02X:%02X",
+ if (edev->get_mac_address(edev, ethaddr) == 0) {
+ sprintf (ethaddr_str, "%02X:%02X:%02X:%02X:%02X:%02X",
ethaddr[0], ethaddr[1], ethaddr[2], ethaddr[3], ethaddr[4], ethaddr[5]);
- printf("got MAC address from EEPROM: %s\n",ethaddr_tmp);
- setenv ("ethaddr", ethaddr_tmp);
- } else {
- ethaddr = getenv ("ethaddr");
- if (!ethaddr){
- printf("could not get MAC address from device and ethaddr not set\n");
- return -1;
- }
-
- printf("got MAC address from Environment: %s\n",ethaddr);
- for(i = 0; i < 6; i++) {
- ndev->enetaddr[i] = ethaddr ? simple_strtoul (ethaddr, &e, 16) : 0;
- if (ethaddr) {
- ethaddr = (*e) ? e + 1 : e;
- }
- ndev->set_mac_address(eth_current, ndev->enetaddr);
- }
+ printf("got MAC address from EEPROM: %s\n",ethaddr_str);
+ dev_set_param(dev, "mac", ethaddr);
+ memcpy(edev->enetaddr, ethaddr, 6);
}
- eth_current = ndev;
- return 0;
-}
-
-int eth_initialize(void)
-{
- register_device_type_handler(&eth_handle, DEVICE_TYPE_ETHER);
+ eth_current = edev;
return 0;
}
-core_initcall(eth_initialize);