9
0
Fork 0

svn_rev_196

WIP
This commit is contained in:
Sascha Hauer 2007-07-05 18:01:31 +02:00 committed by Sascha Hauer
parent 144592aacd
commit 69eab860c2
1 changed files with 43 additions and 49 deletions

View File

@ -28,6 +28,7 @@
#include <net.h> #include <net.h>
#include <miiphy.h> #include <miiphy.h>
#include <malloc.h> #include <malloc.h>
#include <asm-generic/errno.h>
typedef enum eth_cookies { typedef enum eth_cookies {
PARAM_IP, PARAM_IP,
@ -36,25 +37,42 @@ typedef enum eth_cookies {
PARAM_NM, PARAM_NM,
} eth_cookies_t; } 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; struct eth_device *edev = dev->priv;
char *buf;
if (cookie >= 4) switch (param->cookie) {
return 0; 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; struct eth_device *edev = dev->priv;
char **val = &ndev->param[cookie]; int ret;
if (*val) switch (param->cookie) {
free(*val); 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; return 0;
} }
@ -114,15 +132,17 @@ int eth_rx(void)
return eth_current->recv(eth_current); 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]; struct device_d *dev = edev->dev;
unsigned char *ethaddr; unsigned char ethaddr_str[20];
struct eth_device *ndev = dev->driver->type_data; unsigned char ethaddr[6];
char *e = NULL;
int i; 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"); printf("no get_mac_address found for current eth device\n");
return -1; return -1;
} }
@ -130,42 +150,16 @@ static int eth_handle(struct device_d *dev)
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
dev_add_parameter(dev, &eth_params[i]); dev_add_parameter(dev, &eth_params[i]);
ethaddr = ndev->enetaddr; if (edev->get_mac_address(edev, ethaddr) == 0) {
sprintf (ethaddr_str, "%02X:%02X:%02X:%02X:%02X:%02X",
/* 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",
ethaddr[0], ethaddr[1], ethaddr[2], ethaddr[3], ethaddr[4], ethaddr[5]); ethaddr[0], ethaddr[1], ethaddr[2], ethaddr[3], ethaddr[4], ethaddr[5]);
printf("got MAC address from EEPROM: %s\n",ethaddr_tmp); printf("got MAC address from EEPROM: %s\n",ethaddr_str);
setenv ("ethaddr", ethaddr_tmp); dev_set_param(dev, "mac", ethaddr);
} else { memcpy(edev->enetaddr, ethaddr, 6);
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);
}
} }
eth_current = ndev; eth_current = edev;
return 0;
}
int eth_initialize(void)
{
register_device_type_handler(&eth_handle, DEVICE_TYPE_ETHER);
return 0; return 0;
} }
core_initcall(eth_initialize);