summaryrefslogtreecommitdiffstats
path: root/net
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
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')
-rw-r--r--net/eth.c56
-rw-r--r--net/net.c21
-rw-r--r--net/ping.c1
3 files changed, 49 insertions, 29 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);
}
+
diff --git a/net/net.c b/net/net.c
index 4554d49e36..28943a039e 100644
--- a/net/net.c
+++ b/net/net.c
@@ -228,9 +228,6 @@ int NetLoopInit(proto_t protocol)
NetArpWaitTxPacket -= (ulong)NetArpWaitTxPacket % PKTALIGN;
NetArpWaitTxPacketSize = 0;
- if (eth_open() < 0)
- return -1;
-
string_to_ethaddr(dev_get_param(&eth_get_current()->dev, "ethaddr"),
NetOurEther);
@@ -243,8 +240,6 @@ int NetLoopInit(proto_t protocol)
NetServerIP = dev_get_param_ip(&eth_current->dev, "serverip");
ret = net_check_prereq(protocol);
- if (ret)
- eth_halt();
return ret;
}
@@ -281,7 +276,6 @@ int NetLoop(void)
* Abort if ctrl-c was pressed.
*/
if (ctrlc()) {
- eth_halt();
puts ("\nAbort\n");
return -1;
}
@@ -315,11 +309,9 @@ int NetLoop(void)
sprintf(buf, "0x%lx", NetBootFileXferSize);
setenv("filesize", buf);
}
- eth_halt();
return NetBootFileXferSize;
case NETLOOP_FAIL:
- eth_halt();
return -1;
}
}
@@ -959,3 +951,16 @@ void ethaddr_to_string(const unsigned char *enetaddr, char *str)
enetaddr[4], enetaddr[5]);
}
+void net_update_env(void)
+{
+ struct eth_device *edev = eth_get_current();
+
+ NetOurIP = dev_get_param_ip(&edev->dev, "ipaddr");
+ NetServerIP = dev_get_param_ip(&edev->dev, "serverip");
+ NetOurGatewayIP = dev_get_param_ip(&edev->dev, "gateway");
+ NetOurSubnetMask = dev_get_param_ip(&edev->dev, "netmask");
+
+ string_to_ethaddr(dev_get_param(&edev->dev, "ethaddr"),
+ NetOurEther);
+}
+
diff --git a/net/ping.c b/net/ping.c
index 1bc481af44..7e21fe4ccf 100644
--- a/net/ping.c
+++ b/net/ping.c
@@ -62,7 +62,6 @@ static int PingSend(void)
static void
PingTimeout (void)
{
- eth_halt();
NetState = NETLOOP_FAIL; /* we did not get the reply */
}