summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2011-07-28 11:36:49 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2011-07-29 12:05:26 +0200
commitc46b04542f57ad4d0429ae72f47775d027b12ac6 (patch)
tree72cdcaff814bb42113dad91e0fcfb9af17e866ab /net
parentfee474a22e0f6cb287f2aba5333334b71e27b942 (diff)
downloadbarebox-c46b04542f57ad4d0429ae72f47775d027b12ac6.tar.gz
barebox-c46b04542f57ad4d0429ae72f47775d027b12ac6.tar.xz
net: Add a possibility for boards to give network devices a MAC address
MAC addresses are sometimes stored at unusual places. This patch makes it possible to give a MAC address to a ethernet device id. This is independent of the device actually being present. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net')
-rw-r--r--net/eth.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/net/eth.c b/net/eth.c
index c5b346c28e..2a801f5ce4 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -34,6 +34,52 @@ static struct eth_device *eth_current;
static LIST_HEAD(netdev_list);
+struct eth_ethaddr {
+ struct list_head list;
+ u8 ethaddr[6];
+ int ethid;
+};
+
+static LIST_HEAD(ethaddr_list);
+
+static int eth_get_registered_ethaddr(int ethid, void *buf)
+{
+ struct eth_ethaddr *addr;
+
+ list_for_each_entry(addr, &ethaddr_list, list) {
+ if (addr->ethid == ethid) {
+ memcpy(buf, addr->ethaddr, 6);
+ return 0;
+ }
+ }
+ return -EINVAL;
+}
+
+static void eth_drop_ethaddr(int ethid)
+{
+ struct eth_ethaddr *addr, *tmp;
+
+ list_for_each_entry_safe(addr, tmp, &ethaddr_list, list) {
+ if (addr->ethid == ethid) {
+ list_del(&addr->list);
+ free(addr);
+ return;
+ }
+ }
+}
+
+void eth_register_ethaddr(int ethid, const char *ethaddr)
+{
+ struct eth_ethaddr *addr;
+
+ eth_drop_ethaddr(ethid);
+
+ addr = xzalloc(sizeof(*addr));
+ addr->ethid = ethid;
+ memcpy(addr->ethaddr, ethaddr, 6);
+ list_add_tail(&addr->list, &ethaddr_list);
+}
+
void eth_set_current(struct eth_device *eth)
{
if (eth_current && eth_current->active) {
@@ -144,6 +190,7 @@ int eth_register(struct eth_device *edev)
struct device_d *dev = &edev->dev;
unsigned char ethaddr_str[20];
unsigned char ethaddr[6];
+ int ret, found = 0;
if (!edev->get_ethaddr) {
dev_err(dev, "no get_mac_address found for current eth device\n");
@@ -165,7 +212,17 @@ int eth_register(struct eth_device *edev)
list_add_tail(&edev->list, &netdev_list);
- if (edev->get_ethaddr(edev, ethaddr) == 0) {
+ ret = eth_get_registered_ethaddr(dev->id, ethaddr);
+ if (!ret)
+ found = 1;
+
+ if (!found) {
+ ret = edev->get_ethaddr(edev, ethaddr);
+ if (!ret)
+ found = 1;
+ }
+
+ if (found) {
ethaddr_to_string(ethaddr, ethaddr_str);
if (is_valid_ether_addr(ethaddr)) {
dev_info(dev, "got MAC address from EEPROM: %s\n", ethaddr_str);