Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Shawn Guo and committed by
David S. Miller
49da97dc 8649a230

+41 -43
+38 -43
drivers/net/fec.c
··· 59 59 #define FEC_ALIGNMENT 0x3 60 60 #endif 61 61 62 - /* 63 - * Define the fixed address of the FEC hardware. 64 - */ 62 + static unsigned char macaddr[ETH_ALEN]; 63 + module_param_array(macaddr, byte, NULL, 0); 64 + MODULE_PARM_DESC(macaddr, "FEC Ethernet MAC address"); 65 + 65 66 #if defined(CONFIG_M5272) 66 - 67 - static unsigned char fec_mac_default[] = { 68 - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 69 - }; 70 - 71 67 /* 72 68 * Some hardware gets it MAC address out of local flash memory. 73 69 * if this is non-zero then assume it is the address to get MAC from. ··· 533 537 } 534 538 535 539 /* ------------------------------------------------------------------------- */ 536 - #ifdef CONFIG_M5272 537 540 static void __inline__ fec_get_mac(struct net_device *dev) 538 541 { 539 542 struct fec_enet_private *fep = netdev_priv(dev); 543 + struct fec_platform_data *pdata = fep->pdev->dev.platform_data; 540 544 unsigned char *iap, tmpaddr[ETH_ALEN]; 541 545 542 - if (FEC_FLASHMAC) { 543 - /* 544 - * Get MAC address from FLASH. 545 - * If it is all 1's or 0's, use the default. 546 - */ 547 - iap = (unsigned char *)FEC_FLASHMAC; 548 - if ((iap[0] == 0) && (iap[1] == 0) && (iap[2] == 0) && 549 - (iap[3] == 0) && (iap[4] == 0) && (iap[5] == 0)) 550 - iap = fec_mac_default; 551 - if ((iap[0] == 0xff) && (iap[1] == 0xff) && (iap[2] == 0xff) && 552 - (iap[3] == 0xff) && (iap[4] == 0xff) && (iap[5] == 0xff)) 553 - iap = fec_mac_default; 554 - } else { 555 - *((unsigned long *) &tmpaddr[0]) = readl(fep->hwp + FEC_ADDR_LOW); 556 - *((unsigned short *) &tmpaddr[4]) = (readl(fep->hwp + FEC_ADDR_HIGH) >> 16); 546 + /* 547 + * try to get mac address in following order: 548 + * 549 + * 1) module parameter via kernel command line in form 550 + * fec.macaddr=0x00,0x04,0x9f,0x01,0x30,0xe0 551 + */ 552 + iap = macaddr; 553 + 554 + /* 555 + * 2) from flash or fuse (via platform data) 556 + */ 557 + if (!is_valid_ether_addr(iap)) { 558 + #ifdef CONFIG_M5272 559 + if (FEC_FLASHMAC) 560 + iap = (unsigned char *)FEC_FLASHMAC; 561 + #else 562 + if (pdata) 563 + memcpy(iap, pdata->mac, ETH_ALEN); 564 + #endif 565 + } 566 + 567 + /* 568 + * 3) FEC mac registers set by bootloader 569 + */ 570 + if (!is_valid_ether_addr(iap)) { 571 + *((unsigned long *) &tmpaddr[0]) = 572 + be32_to_cpu(readl(fep->hwp + FEC_ADDR_LOW)); 573 + *((unsigned short *) &tmpaddr[4]) = 574 + be16_to_cpu(readl(fep->hwp + FEC_ADDR_HIGH) >> 16); 557 575 iap = &tmpaddr[0]; 558 576 } 559 577 560 578 memcpy(dev->dev_addr, iap, ETH_ALEN); 561 579 562 - /* Adjust MAC if using default MAC address */ 563 - if (iap == fec_mac_default) 564 - dev->dev_addr[ETH_ALEN-1] = fec_mac_default[ETH_ALEN-1] + fep->pdev->id; 580 + /* Adjust MAC if using macaddr */ 581 + if (iap == macaddr) 582 + dev->dev_addr[ETH_ALEN-1] = macaddr[ETH_ALEN-1] + fep->pdev->id; 565 583 } 566 - #endif 567 584 568 585 /* ------------------------------------------------------------------------- */ 569 586 ··· 1096 1087 fep->hwp = (void __iomem *)dev->base_addr; 1097 1088 fep->netdev = dev; 1098 1089 1099 - /* Set the Ethernet address */ 1100 - #ifdef CONFIG_M5272 1090 + /* Get the Ethernet address */ 1101 1091 fec_get_mac(dev); 1102 - #else 1103 - { 1104 - unsigned long l; 1105 - l = readl(fep->hwp + FEC_ADDR_LOW); 1106 - dev->dev_addr[0] = (unsigned char)((l & 0xFF000000) >> 24); 1107 - dev->dev_addr[1] = (unsigned char)((l & 0x00FF0000) >> 16); 1108 - dev->dev_addr[2] = (unsigned char)((l & 0x0000FF00) >> 8); 1109 - dev->dev_addr[3] = (unsigned char)((l & 0x000000FF) >> 0); 1110 - l = readl(fep->hwp + FEC_ADDR_HIGH); 1111 - dev->dev_addr[4] = (unsigned char)((l & 0xFF000000) >> 24); 1112 - dev->dev_addr[5] = (unsigned char)((l & 0x00FF0000) >> 16); 1113 - } 1114 - #endif 1115 1092 1116 1093 /* Set receive and transmit descriptor base. */ 1117 1094 fep->rx_bd_base = cbd_base;
+3
include/linux/fec.h
··· 3 3 * Copyright (c) 2009 Orex Computed Radiography 4 4 * Baruch Siach <baruch@tkos.co.il> 5 5 * 6 + * Copyright (C) 2010 Freescale Semiconductor, Inc. 7 + * 6 8 * Header file for the FEC platform data 7 9 * 8 10 * This program is free software; you can redistribute it and/or modify ··· 18 16 19 17 struct fec_platform_data { 20 18 phy_interface_t phy; 19 + unsigned char mac[ETH_ALEN]; 21 20 }; 22 21 23 22 #endif