summaryrefslogtreecommitdiffstats
path: root/net/eth.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2010-05-27 11:37:46 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2010-06-17 08:28:16 +0200
commit994f95c073caf4df62d1271aef4112ce8aaa8add (patch)
treec0167dbdedb5c3ebc68f374c3f3df7d0b0b8bfdb /net/eth.c
parentc21a7fb9f15ee1fb213e22c0e7a9d0f53b274cb2 (diff)
downloadbarebox-994f95c073caf4df62d1271aef4112ce8aaa8add.tar.gz
barebox-994f95c073caf4df62d1271aef4112ce8aaa8add.tar.xz
net: remove need for eth_halt/eth_open
We used to eth_open/eth_halt the network devices during NetLoopInit which is called whenever the user enters a network command. Change this behaviour so that the current network device gets opened when making it the current one. With this change it's always possible to send packages and we are able to implement a new network stack in the next step. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net/eth.c')
-rw-r--r--net/eth.c56
1 files changed, 36 insertions, 20 deletions
diff --git a/net/eth.c b/net/eth.c
index 7570198a17..fc16233be3 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -36,7 +36,13 @@ static LIST_HEAD(netdev_list);
void eth_set_current(struct eth_device *eth)
{
+ if (eth_current && eth_current->active) {
+ eth_current->halt(eth_current);
+ eth_current->active = 0;
+ }
+
eth_current = eth;
+ net_update_env();
}
struct eth_device * eth_get_current(void)
@@ -57,37 +63,37 @@ struct eth_device *eth_get_byname(char *ethname)
return NULL;
}
-int eth_open(void)
-{
- if (!eth_current)
- return -ENODEV;
-
- return eth_current->open(eth_current);
-}
-
-void eth_halt(void)
-{
- if (!eth_current)
- return;
-
- eth_current->halt(eth_current);
-
- eth_current->state = ETH_STATE_PASSIVE;
-}
-
int eth_send(void *packet, int length)
{
+ int ret;
+
if (!eth_current)
return -ENODEV;
+ if (!eth_current->active) {
+ ret = eth_current->open(eth_current);
+ if (ret)
+ return ret;
+ eth_current->active = 1;
+ }
+
return eth_current->send(eth_current, packet, length);
}
int eth_rx(void)
{
+ int ret;
+
if (!eth_current)
return -ENODEV;
+ if (!eth_current->active) {
+ ret = eth_current->open(eth_current);
+ if (ret)
+ return ret;
+ eth_current->active = 1;
+ }
+
return eth_current->recv(eth_current);
}
@@ -104,11 +110,15 @@ static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const ch
edev->set_ethaddr(edev, ethaddr);
+ if (edev == eth_current)
+ net_update_env();
+
return 0;
}
static int eth_set_ipaddr(struct device_d *dev, struct param_d *param, const char *val)
{
+ struct eth_device *edev = dev->type_data;
IPaddr_t ip;
if (string_to_ip(val, &ip))
@@ -117,6 +127,9 @@ static int eth_set_ipaddr(struct device_d *dev, struct param_d *param, const cha
free(param->value);
param->value = strdup(val);
+ if (edev == eth_current)
+ net_update_env();
+
return 0;
}
@@ -157,7 +170,7 @@ int eth_register(struct eth_device *edev)
if (edev->get_ethaddr(edev, ethaddr) == 0) {
ethaddr_to_string(ethaddr, ethaddr_str);
- printf("got MAC address from EEPROM: %s\n",ethaddr_str);
+ printf("got MAC address from EEPROM: %s\n",&ethaddr_str);
dev_set_param(dev, "ethaddr", ethaddr_str);
}
@@ -180,9 +193,12 @@ void eth_unregister(struct eth_device *edev)
if (edev->param_serverip.value)
free(edev->param_serverip.value);
- if (eth_current == edev)
+ if (eth_current == edev) {
+ eth_current->halt(eth_current);
eth_current = NULL;
+ }
list_del(&edev->list);
}
+