* [PATCH 2/5] net: eth: open correct edev in eth_check_open
2016-07-15 7:23 [PATCH 1/5] net: usb: use minimum timeout when polling for new packets Sascha Hauer
@ 2016-07-15 7:23 ` Sascha Hauer
2016-07-15 7:23 ` [PATCH 3/5] net: introduce for_each_netdev iterator Sascha Hauer
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2016-07-15 7:23 UTC (permalink / raw)
To: Barebox List
eth_check_open gets the network device to check as parameter, so
use it rather than using eth_current. Currently both are the same,
so this currently does not fix anything.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
net/eth.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/eth.c b/net/eth.c
index fb3f22f..6bec154 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -228,7 +228,7 @@ static int eth_check_open(struct eth_device *edev)
if (edev->active)
return 0;
- ret = edev->open(eth_current);
+ ret = edev->open(edev);
if (ret)
return ret;
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/5] net: introduce for_each_netdev iterator
2016-07-15 7:23 [PATCH 1/5] net: usb: use minimum timeout when polling for new packets Sascha Hauer
2016-07-15 7:23 ` [PATCH 2/5] net: eth: open correct edev in eth_check_open Sascha Hauer
@ 2016-07-15 7:23 ` Sascha Hauer
2016-07-15 7:23 ` [PATCH 4/5] net: eth: add name to struct eth_device Sascha Hauer
2016-07-15 7:23 ` [PATCH 5/5] net: Pass network device to net_answer_arp() Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2016-07-15 7:23 UTC (permalink / raw)
To: Barebox List
for_each_netdev is nicer to read. Also export the list of network
devices since it will be used by code outside of net/eth.c in later
patches.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/net.h | 4 ++++
net/eth.c | 14 +++++++-------
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/include/net.h b/include/net.h
index 13e335a..81118d2 100644
--- a/include/net.h
+++ b/include/net.h
@@ -466,4 +466,8 @@ void led_trigger_network(enum led_trigger trigger);
int ifup(const char *name, unsigned flags);
int ifup_all(unsigned flags);
+extern struct list_head netdev_list;
+
+#define for_each_netdev(netdev) list_for_each_entry(netdev, &netdev_list, list)
+
#endif /* __NET_H__ */
diff --git a/net/eth.c b/net/eth.c
index 6bec154..499f4b0 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -31,7 +31,7 @@
static struct eth_device *eth_current;
static uint64_t last_link_check;
-static LIST_HEAD(netdev_list);
+LIST_HEAD(netdev_list);
struct eth_ethaddr {
struct list_head list;
@@ -104,7 +104,7 @@ void eth_register_ethaddr(int ethid, const char *ethaddr)
eth_drop_ethaddr(ethid);
- list_for_each_entry(edev, &netdev_list, list) {
+ for_each_netdev(edev) {
if (edev->dev.id == ethid) {
register_preset_mac_address(edev, ethaddr);
return;
@@ -121,7 +121,7 @@ static struct eth_device *eth_get_by_node(struct device_node *node)
{
struct eth_device *edev;
- list_for_each_entry(edev, &netdev_list, list) {
+ for_each_netdev(edev) {
if (!edev->parent)
continue;
if (!edev->parent->device_node)
@@ -163,7 +163,7 @@ struct eth_device *eth_get_byname(const char *ethname)
{
struct eth_device *edev;
- list_for_each_entry(edev, &netdev_list, list) {
+ for_each_netdev(edev) {
if (!strcmp(ethname, dev_name(&edev->dev)))
return edev;
}
@@ -179,7 +179,7 @@ int eth_complete(struct string_list *sl, char *instr)
len = strlen(instr);
- list_for_each_entry(edev, &netdev_list, list) {
+ for_each_netdev(edev) {
devname = dev_name(&edev->dev);
if (strncmp(instr, devname, len))
continue;
@@ -273,7 +273,7 @@ int eth_rx(void)
{
struct eth_device *edev;
- list_for_each_entry(edev, &netdev_list, list) {
+ for_each_netdev(edev) {
if (edev->active)
__eth_rx(edev);
}
@@ -337,7 +337,7 @@ static int eth_of_fixup(struct device_node *root, void *unused)
eth_of_fixup_node(root, addr->node ? addr->node->full_name : NULL,
addr->ethid, addr->ethaddr);
- list_for_each_entry(edev, &netdev_list, list)
+ for_each_netdev(edev)
eth_of_fixup_node(root, edev->nodepath, edev->dev.id, edev->ethaddr);
return 0;
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 4/5] net: eth: add name to struct eth_device
2016-07-15 7:23 [PATCH 1/5] net: usb: use minimum timeout when polling for new packets Sascha Hauer
2016-07-15 7:23 ` [PATCH 2/5] net: eth: open correct edev in eth_check_open Sascha Hauer
2016-07-15 7:23 ` [PATCH 3/5] net: introduce for_each_netdev iterator Sascha Hauer
@ 2016-07-15 7:23 ` Sascha Hauer
2016-07-15 7:23 ` [PATCH 5/5] net: Pass network device to net_answer_arp() Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2016-07-15 7:23 UTC (permalink / raw)
To: Barebox List
Using dev_name often is not a good idea since it's a statically
allocated string which gets overwritten by later calls to dev_name.
Add a devname string to struct eth_device to have the name available
for later use.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/net.h | 6 ++++++
net/eth.c | 12 +++++++-----
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/include/net.h b/include/net.h
index 81118d2..8f857c8 100644
--- a/include/net.h
+++ b/include/net.h
@@ -51,6 +51,7 @@ struct eth_device {
struct phy_device *phydev;
struct device_d dev;
+ char *devname;
struct device_d *parent;
char *nodepath;
@@ -65,6 +66,11 @@ struct eth_device {
#define dev_to_edev(d) container_of(d, struct eth_device, dev)
+static inline const char *eth_name(struct eth_device *edev)
+{
+ return edev->devname;
+}
+
int eth_register(struct eth_device* dev); /* Register network device */
void eth_unregister(struct eth_device* dev); /* Unregister network device */
int eth_set_ethaddr(struct eth_device *edev, const char *ethaddr);
diff --git a/net/eth.c b/net/eth.c
index 499f4b0..6f8e78d 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -164,7 +164,7 @@ struct eth_device *eth_get_byname(const char *ethname)
struct eth_device *edev;
for_each_netdev(edev) {
- if (!strcmp(ethname, dev_name(&edev->dev)))
+ if (!strcmp(ethname, eth_name(edev)))
return edev;
}
return NULL;
@@ -174,17 +174,15 @@ struct eth_device *eth_get_byname(const char *ethname)
int eth_complete(struct string_list *sl, char *instr)
{
struct eth_device *edev;
- const char *devname;
int len;
len = strlen(instr);
for_each_netdev(edev) {
- devname = dev_name(&edev->dev);
- if (strncmp(instr, devname, len))
+ if (strncmp(instr, eth_name(edev), len))
continue;
- string_list_add_asprintf(sl, "%s ", devname);
+ string_list_add_asprintf(sl, "%s ", eth_name(edev));
}
return COMPLETE_CONTINUE;
}
@@ -378,6 +376,8 @@ int eth_register(struct eth_device *edev)
if (ret)
return ret;
+ edev->devname = xstrdup(dev_name(&edev->dev));
+
dev_add_param_ip(dev, "ipaddr", NULL, NULL, &edev->ipaddr, edev);
dev_add_param_ip(dev, "serverip", NULL, NULL, &edev->serverip, edev);
dev_add_param_ip(dev, "gateway", NULL, NULL, &edev->gateway, edev);
@@ -424,6 +424,8 @@ void eth_unregister(struct eth_device *edev)
if (IS_ENABLED(CONFIG_OFDEVICE))
free(edev->nodepath);
+ free(edev->devname);
+
unregister_device(&edev->dev);
list_del(&edev->list);
}
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 5/5] net: Pass network device to net_answer_arp()
2016-07-15 7:23 [PATCH 1/5] net: usb: use minimum timeout when polling for new packets Sascha Hauer
` (2 preceding siblings ...)
2016-07-15 7:23 ` [PATCH 4/5] net: eth: add name to struct eth_device Sascha Hauer
@ 2016-07-15 7:23 ` Sascha Hauer
3 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2016-07-15 7:23 UTC (permalink / raw)
To: Barebox List
The caller already has the correct network device, so pass it
to net_answer_arp() rather than using eth_get_current() there.
This is a step towards making a global current network device
unnecessary.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
net/net.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/net/net.c b/net/net.c
index e5bd9bb..df1d677 100644
--- a/net/net.c
+++ b/net/net.c
@@ -379,11 +379,10 @@ int net_icmp_send(struct net_connection *con, int len)
return net_ip_send(con, sizeof(struct icmphdr) + len);
}
-static int net_answer_arp(unsigned char *pkt, int len)
+static int net_answer_arp(struct eth_device *edev, unsigned char *pkt, int len)
{
struct arprequest *arp = (struct arprequest *)(pkt + ETHER_HDR_SIZE);
struct ethernet *et = (struct ethernet *)pkt;
- struct eth_device *edev = eth_get_current();
unsigned char *packet;
int ret;
@@ -453,7 +452,7 @@ static int net_handle_arp(struct eth_device *edev, unsigned char *pkt, int len)
switch (ntohs(arp->ar_op)) {
case ARPOP_REQUEST:
- return net_answer_arp(pkt, len);
+ return net_answer_arp(edev, pkt, len);
case ARPOP_REPLY:
arp_handler(arp);
return 1;
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread