diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2016-08-03 08:08:23 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-08-03 08:08:23 +0200 |
commit | 7a51da5ff1e2b2c9397d781d04d0165371e80c6c (patch) | |
tree | 8b22cfc0db8b3b8c90876017e08d834442851b44 | |
parent | b927df0329a97dcfe9ba22b45375be2dc416dcd6 (diff) | |
parent | a622565d06b0747458b59240c71f92b6925f562c (diff) | |
download | barebox-7a51da5ff1e2b2c9397d781d04d0165371e80c6c.tar.gz barebox-7a51da5ff1e2b2c9397d781d04d0165371e80c6c.tar.xz |
Merge branch 'for-next/net'
-rw-r--r-- | drivers/net/usb/usbnet.c | 2 | ||||
-rw-r--r-- | include/net.h | 10 | ||||
-rw-r--r-- | net/eth.c | 28 | ||||
-rw-r--r-- | net/net.c | 5 |
4 files changed, 28 insertions, 17 deletions
diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index a51cfda328..33d900b706 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c @@ -125,7 +125,7 @@ static int usbnet_recv(struct eth_device *edev) len = dev->rx_urb_size; - ret = usb_bulk_msg(dev->udev, dev->in, rx_buf, len, &alen, 1000); + ret = usb_bulk_msg(dev->udev, dev->in, rx_buf, len, &alen, 1); if (ret) return ret; diff --git a/include/net.h b/include/net.h index 13e335aac2..8f857c8f85 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); @@ -466,4 +472,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__ */ @@ -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,8 +163,8 @@ struct eth_device *eth_get_byname(const char *ethname) { struct eth_device *edev; - list_for_each_entry(edev, &netdev_list, list) { - if (!strcmp(ethname, dev_name(&edev->dev))) + for_each_netdev(edev) { + 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); - list_for_each_entry(edev, &netdev_list, list) { - devname = dev_name(&edev->dev); - if (strncmp(instr, devname, len)) + for_each_netdev(edev) { + 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; } @@ -228,7 +226,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; @@ -273,7 +271,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 +335,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; @@ -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); } @@ -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; |