diff options
author | Shawn Guo <shawn.guo@freescale.com> | 2011-01-05 16:13:11 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2011-01-09 18:42:55 -0500 |
commit | 49da97dcb6b00a6869bbc3fa6ec7fdfd8a6e41a3 (patch) | |
tree | 8d558ccfa1cd3c7c20bf0822250a4631d00519c4 /drivers/net/fec.c | |
parent | 8649a230e33320b00f778a6f7c17a2764e844730 (diff) |
net/fec: add mac field into platform data and consolidate fec_get_mac
Add mac field into fec_platform_data and consolidate function
fec_get_mac to get mac address in following order.
1) module parameter via kernel command line fec.macaddr=0x00,0x04,...
2) from flash in case of CONFIG_M5272 or fec_platform_data mac
field for others, which typically have mac stored in fuse
3) fec mac address registers set by bootloader
Signed-off-by: Shawn Guo <shawn.guo@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/fec.c')
-rw-r--r-- | drivers/net/fec.c | 81 |
1 files changed, 38 insertions, 43 deletions
diff --git a/drivers/net/fec.c b/drivers/net/fec.c index 47f6b3b91423..47a3c7b499e9 100644 --- a/drivers/net/fec.c +++ b/drivers/net/fec.c | |||
@@ -59,15 +59,11 @@ | |||
59 | #define FEC_ALIGNMENT 0x3 | 59 | #define FEC_ALIGNMENT 0x3 |
60 | #endif | 60 | #endif |
61 | 61 | ||
62 | /* | 62 | static unsigned char macaddr[ETH_ALEN]; |
63 | * Define the fixed address of the FEC hardware. | 63 | module_param_array(macaddr, byte, NULL, 0); |
64 | */ | 64 | MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address"); |
65 | #if defined(CONFIG_M5272) | ||
66 | |||
67 | static unsigned char fec_mac_default[] = { | ||
68 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
69 | }; | ||
70 | 65 | ||
66 | #if defined(CONFIG_M5272) | ||
71 | /* | 67 | /* |
72 | * Some hardware gets it MAC address out of local flash memory. | 68 | * Some hardware gets it MAC address out of local flash memory. |
73 | * if this is non-zero then assume it is the address to get MAC from. | 69 | * if this is non-zero then assume it is the address to get MAC from. |
@@ -537,37 +533,50 @@ rx_processing_done: | |||
537 | } | 533 | } |
538 | 534 | ||
539 | /* ------------------------------------------------------------------------- */ | 535 | /* ------------------------------------------------------------------------- */ |
540 | #ifdef CONFIG_M5272 | ||
541 | static void __inline__ fec_get_mac(struct net_device *dev) | 536 | static void __inline__ fec_get_mac(struct net_device *dev) |
542 | { | 537 | { |
543 | struct fec_enet_private *fep = netdev_priv(dev); | 538 | struct fec_enet_private *fep = netdev_priv(dev); |
539 | struct fec_platform_data *pdata = fep->pdev->dev.platform_data; | ||
544 | unsigned char *iap, tmpaddr[ETH_ALEN]; | 540 | unsigned char *iap, tmpaddr[ETH_ALEN]; |
545 | 541 | ||
546 | if (FEC_FLASHMAC) { | 542 | /* |
547 | /* | 543 | * try to get mac address in following order: |
548 | * Get MAC address from FLASH. | 544 | * |
549 | * If it is all 1's or 0's, use the default. | 545 | * 1) module parameter via kernel command line in form |
550 | */ | 546 | * fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0 |
551 | iap = (unsigned char *)FEC_FLASHMAC; | 547 | */ |
552 | if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) && | 548 | iap = macaddr; |
553 | (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0)) | 549 | |
554 | iap = fec_mac_default; | 550 | /* |
555 | if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) && | 551 | * 2) from flash or fuse (via platform data) |
556 | (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff)) | 552 | */ |
557 | iap = fec_mac_default; | 553 | if (!is_valid_ether_addr(iap)) { |
558 | } else { | 554 | #ifdef CONFIG_M5272 |
559 | *((unsigned long *) &tmpaddr[0]) = readl(fep->hwp + FEC_ADDR_LOW); | 555 | if (FEC_FLASHMAC) |
560 | *((unsigned short *) &tmpaddr[4]) = (readl(fep->hwp + FEC_ADDR_HIGH) >> 16); | 556 | iap = (unsigned char *)FEC_FLASHMAC; |
557 | #else | ||
558 | if (pdata) | ||
559 | memcpy(iap, pdata->mac, ETH_ALEN); | ||
560 | #endif | ||
561 | } | ||
562 | |||
563 | /* | ||
564 | * 3) FEC mac registers set by bootloader | ||
565 | */ | ||
566 | if (!is_valid_ether_addr(iap)) { | ||
567 | *((unsigned long *) &tmpaddr[0]) = | ||
568 | be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW)); | ||
569 | *((unsigned short *) &tmpaddr[4]) = | ||
570 | be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH) >> 16); | ||
561 | iap = &tmpaddr[0]; | 571 | iap = &tmpaddr[0]; |
562 | } | 572 | } |
563 | 573 | ||
564 | memcpy(dev->dev_addr, iap, ETH_ALEN); | 574 | memcpy(dev->dev_addr, iap, ETH_ALEN); |
565 | 575 | ||
566 | /* Adjust MAC if using default MAC address */ | 576 | /* Adjust MAC if using macaddr */ |
567 | if (iap == fec_mac_default) | 577 | if (iap == macaddr) |
568 | dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id; | 578 | dev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->pdev->id; |
569 | } | 579 | } |
570 | #endif | ||
571 | 580 | ||
572 | /* ------------------------------------------------------------------------- */ | 581 | /* ------------------------------------------------------------------------- */ |
573 | 582 | ||
@@ -1087,22 +1096,8 @@ static int fec_enet_init(struct net_device *dev) | |||
1087 | fep->hwp = (void __iomem *)dev->base_addr; | 1096 | fep->hwp = (void __iomem *)dev->base_addr; |
1088 | fep->netdev = dev; | 1097 | fep->netdev = dev; |
1089 | 1098 | ||
1090 | /* Set the Ethernet address */ | 1099 | /* Get the Ethernet address */ |
1091 | #ifdef CONFIG_M5272 | ||
1092 | fec_get_mac(dev); | 1100 | fec_get_mac(dev); |
1093 | #else | ||
1094 | { | ||
1095 | unsigned long l; | ||
1096 | l = readl(fep->hwp + FEC_ADDR_LOW); | ||
1097 | dev->dev_addr[0] = (unsigned char)((l & 0xFF000000) >> 24); | ||
1098 | dev->dev_addr[1] = (unsigned char)((l & 0x00FF0000) >> 16); | ||
1099 | dev->dev_addr[2] = (unsigned char)((l & 0x0000FF00) >> 8); | ||
1100 | dev->dev_addr[3] = (unsigned char)((l & 0x000000FF) >> 0); | ||
1101 | l = readl(fep->hwp + FEC_ADDR_HIGH); | ||
1102 | dev->dev_addr[4] = (unsigned char)((l & 0xFF000000) >> 24); | ||
1103 | dev->dev_addr[5] = (unsigned char)((l & 0x00FF0000) >> 16); | ||
1104 | } | ||
1105 | #endif | ||
1106 | 1101 | ||
1107 | /* Set receive and transmit descriptor base. */ | 1102 | /* Set receive and transmit descriptor base. */ |
1108 | fep->rx_bd_base = cbd_base; | 1103 | fep->rx_bd_base = cbd_base; |