Merge branch 'for-2.6.26' of git://git.farnsworth.org/dale/linux-2.6-mv643xx_eth into upstream

authored by Jeff Garzik and committed by Jeff Garzik 54c852a2 7ab267d4

+148 -39
+2
arch/arm/mach-orion5x/common.c
··· 223 224 void __init orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data) 225 { 226 orion5x_eth.dev.platform_data = eth_data; 227 platform_device_register(&orion5x_eth_shared); 228 platform_device_register(&orion5x_eth); 229 }
··· 223 224 void __init orion5x_eth_init(struct mv643xx_eth_platform_data *eth_data) 225 { 226 + eth_data->shared = &orion5x_eth_shared; 227 orion5x_eth.dev.platform_data = eth_data; 228 + 229 platform_device_register(&orion5x_eth_shared); 230 platform_device_register(&orion5x_eth); 231 }
+4
arch/powerpc/platforms/chrp/pegasos_eth.c
··· 58 59 60 static struct mv643xx_eth_platform_data eth0_pd = { 61 .port_number = 0, 62 .tx_sram_addr = PEGASOS2_SRAM_BASE_ETH0, 63 .tx_sram_size = PEGASOS2_SRAM_TXRING_SIZE, 64 .tx_queue_size = PEGASOS2_SRAM_TXRING_SIZE/16, ··· 90 }; 91 92 static struct mv643xx_eth_platform_data eth1_pd = { 93 .port_number = 1, 94 .tx_sram_addr = PEGASOS2_SRAM_BASE_ETH1, 95 .tx_sram_size = PEGASOS2_SRAM_TXRING_SIZE, 96 .tx_queue_size = PEGASOS2_SRAM_TXRING_SIZE/16,
··· 58 59 60 static struct mv643xx_eth_platform_data eth0_pd = { 61 + .shared = &mv643xx_eth_shared_device, 62 .port_number = 0, 63 + 64 .tx_sram_addr = PEGASOS2_SRAM_BASE_ETH0, 65 .tx_sram_size = PEGASOS2_SRAM_TXRING_SIZE, 66 .tx_queue_size = PEGASOS2_SRAM_TXRING_SIZE/16, ··· 88 }; 89 90 static struct mv643xx_eth_platform_data eth1_pd = { 91 + .shared = &mv643xx_eth_shared_device, 92 .port_number = 1, 93 + 94 .tx_sram_addr = PEGASOS2_SRAM_BASE_ETH1, 95 .tx_sram_size = PEGASOS2_SRAM_TXRING_SIZE, 96 .tx_queue_size = PEGASOS2_SRAM_TXRING_SIZE/16,
+2
arch/powerpc/sysdev/mv64x60_dev.c
··· 239 240 memset(&pdata, 0, sizeof(pdata)); 241 242 prop = of_get_property(np, "reg", NULL); 243 if (!prop) 244 return -ENODEV;
··· 239 240 memset(&pdata, 0, sizeof(pdata)); 241 242 + pdata.shared = shared_pdev; 243 + 244 prop = of_get_property(np, "reg", NULL); 245 if (!prop) 246 return -ENODEV;
+3
arch/ppc/syslib/mv64x60.c
··· 341 }; 342 343 static struct mv643xx_eth_platform_data eth0_pd = { 344 .port_number = 0, 345 }; 346 ··· 367 }; 368 369 static struct mv643xx_eth_platform_data eth1_pd = { 370 .port_number = 1, 371 }; 372 ··· 393 }; 394 395 static struct mv643xx_eth_platform_data eth2_pd = { 396 .port_number = 2, 397 }; 398
··· 341 }; 342 343 static struct mv643xx_eth_platform_data eth0_pd = { 344 + .shared = &mv64x60_eth_shared_device; 345 .port_number = 0, 346 }; 347 ··· 366 }; 367 368 static struct mv643xx_eth_platform_data eth1_pd = { 369 + .shared = &mv64x60_eth_shared_device; 370 .port_number = 1, 371 }; 372 ··· 391 }; 392 393 static struct mv643xx_eth_platform_data eth2_pd = { 394 + .shared = &mv64x60_eth_shared_device; 395 .port_number = 2, 396 }; 397
+123 -37
drivers/net/mv643xx_eth.c
··· 91 */ 92 #define PHY_ADDR_REG 0x0000 93 #define SMI_REG 0x0004 94 95 /* 96 * Per-port registers. ··· 512 u32 late_collision; 513 }; 514 515 struct mv643xx_private { 516 int port_num; /* User Ethernet port number */ 517 518 u32 rx_sram_addr; /* Base address of rx sram area */ 519 u32 rx_sram_size; /* Size of rx sram area */ ··· 633 static char mv643xx_driver_name[] = "mv643xx_eth"; 634 static char mv643xx_driver_version[] = "1.0"; 635 636 - static void __iomem *mv643xx_eth_base; 637 - 638 - /* used to protect SMI_REG, which is shared across ports */ 639 - static DEFINE_SPINLOCK(mv643xx_eth_phy_lock); 640 - 641 static inline u32 rdl(struct mv643xx_private *mp, int offset) 642 { 643 - return readl(mv643xx_eth_base + offset); 644 } 645 646 static inline void wrl(struct mv643xx_private *mp, int offset, u32 data) 647 { 648 - writel(data, mv643xx_eth_base + offset); 649 } 650 651 /* ··· 1133 * 1134 * INPUT: 1135 * struct mv643xx_private *mp Ethernet port 1136 - * unsigned int t_clk t_clk of the MV-643xx chip in HZ units 1137 * unsigned int delay Delay in usec 1138 * 1139 * OUTPUT: ··· 1143 * 1144 */ 1145 static unsigned int eth_port_set_rx_coal(struct mv643xx_private *mp, 1146 - unsigned int t_clk, unsigned int delay) 1147 { 1148 unsigned int port_num = mp->port_num; 1149 - unsigned int coal = ((t_clk / 1000000) * delay) / 64; 1150 1151 /* Set RX Coalescing mechanism */ 1152 wrl(mp, SDMA_CONFIG_REG(port_num), ··· 1171 * 1172 * INPUT: 1173 * struct mv643xx_private *mp Ethernet port 1174 - * unsigned int t_clk t_clk of the MV-643xx chip in HZ units 1175 * unsigned int delay Delay in uSeconds 1176 * 1177 * OUTPUT: ··· 1181 * 1182 */ 1183 static unsigned int eth_port_set_tx_coal(struct mv643xx_private *mp, 1184 - unsigned int t_clk, unsigned int delay) 1185 { 1186 - unsigned int coal = ((t_clk / 1000000) * delay) / 64; 1187 1188 /* Set TX Coalescing mechanism */ 1189 wrl(mp, TX_FIFO_URGENT_THRESHOLD_REG(mp->port_num), coal << 4); ··· 1425 1426 #ifdef MV643XX_COAL 1427 mp->rx_int_coal = 1428 - eth_port_set_rx_coal(mp, 133000000, MV643XX_RX_COAL); 1429 #endif 1430 1431 mp->tx_int_coal = 1432 - eth_port_set_tx_coal(mp, 133000000, MV643XX_TX_COAL); 1433 1434 /* Unmask phy and link status changes interrupts */ 1435 wrl(mp, INTERRUPT_EXTEND_MASK_REG(port_num), ETH_INT_UNMASK_ALL_EXT); ··· 1839 return -ENODEV; 1840 } 1841 1842 dev = alloc_etherdev(sizeof(struct mv643xx_private)); 1843 if (!dev) 1844 return -ENOMEM; ··· 1894 1895 spin_lock_init(&mp->lock); 1896 1897 port_num = mp->port_num = pd->port_number; 1898 1899 /* set default config values */ 1900 eth_port_uc_addr_get(mp, dev->dev_addr); ··· 2008 return 0; 2009 } 2010 2011 static int mv643xx_eth_shared_probe(struct platform_device *pdev) 2012 { 2013 static int mv643xx_version_printed = 0; 2014 struct resource *res; 2015 2016 if (!mv643xx_version_printed++) 2017 printk(KERN_NOTICE "MV-643xx 10/100/1000 Ethernet Driver\n"); 2018 2019 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2020 if (res == NULL) 2021 - return -ENODEV; 2022 2023 - mv643xx_eth_base = ioremap(res->start, res->end - res->start + 1); 2024 - if (mv643xx_eth_base == NULL) 2025 - return -ENOMEM; 2026 2027 return 0; 2028 2029 } 2030 2031 static int mv643xx_eth_shared_remove(struct platform_device *pdev) 2032 { 2033 - iounmap(mv643xx_eth_base); 2034 - mv643xx_eth_base = NULL; 2035 2036 return 0; 2037 } ··· 2992 static void eth_port_read_smi_reg(struct mv643xx_private *mp, 2993 unsigned int phy_reg, unsigned int *value) 2994 { 2995 int phy_addr = ethernet_phy_get(mp); 2996 unsigned long flags; 2997 int i; 2998 2999 /* the SMI register is a shared resource */ 3000 - spin_lock_irqsave(&mv643xx_eth_phy_lock, flags); 3001 3002 /* wait for the SMI register to become available */ 3003 - for (i = 0; rdl(mp, SMI_REG) & ETH_SMI_BUSY; i++) { 3004 if (i == PHY_WAIT_ITERATIONS) { 3005 printk("%s: PHY busy timeout\n", mp->dev->name); 3006 goto out; ··· 3009 udelay(PHY_WAIT_MICRO_SECONDS); 3010 } 3011 3012 - wrl(mp, SMI_REG, 3013 - (phy_addr << 16) | (phy_reg << 21) | ETH_SMI_OPCODE_READ); 3014 3015 /* now wait for the data to be valid */ 3016 - for (i = 0; !(rdl(mp, SMI_REG) & ETH_SMI_READ_VALID); i++) { 3017 if (i == PHY_WAIT_ITERATIONS) { 3018 printk("%s: PHY read timeout\n", mp->dev->name); 3019 goto out; ··· 3021 udelay(PHY_WAIT_MICRO_SECONDS); 3022 } 3023 3024 - *value = rdl(mp, SMI_REG) & 0xffff; 3025 out: 3026 - spin_unlock_irqrestore(&mv643xx_eth_phy_lock, flags); 3027 } 3028 3029 /* ··· 3049 static void eth_port_write_smi_reg(struct mv643xx_private *mp, 3050 unsigned int phy_reg, unsigned int value) 3051 { 3052 - int phy_addr; 3053 - int i; 3054 unsigned long flags; 3055 - 3056 - phy_addr = ethernet_phy_get(mp); 3057 3058 /* the SMI register is a shared resource */ 3059 - spin_lock_irqsave(&mv643xx_eth_phy_lock, flags); 3060 3061 /* wait for the SMI register to become available */ 3062 - for (i = 0; rdl(mp, SMI_REG) & ETH_SMI_BUSY; i++) { 3063 if (i == PHY_WAIT_ITERATIONS) { 3064 printk("%s: PHY busy timeout\n", mp->dev->name); 3065 goto out; ··· 3066 udelay(PHY_WAIT_MICRO_SECONDS); 3067 } 3068 3069 - wrl(mp, SMI_REG, (phy_addr << 16) | (phy_reg << 21) | 3070 - ETH_SMI_OPCODE_WRITE | (value & 0xffff)); 3071 out: 3072 - spin_unlock_irqrestore(&mv643xx_eth_phy_lock, flags); 3073 } 3074 3075 /*
··· 91 */ 92 #define PHY_ADDR_REG 0x0000 93 #define SMI_REG 0x0004 94 + #define WINDOW_BASE(i) (0x0200 + ((i) << 3)) 95 + #define WINDOW_SIZE(i) (0x0204 + ((i) << 3)) 96 + #define WINDOW_REMAP_HIGH(i) (0x0280 + ((i) << 2)) 97 + #define WINDOW_BAR_ENABLE 0x0290 98 + #define WINDOW_PROTECT(i) (0x0294 + ((i) << 4)) 99 100 /* 101 * Per-port registers. ··· 507 u32 late_collision; 508 }; 509 510 + struct mv643xx_shared_private { 511 + void __iomem *eth_base; 512 + 513 + /* used to protect SMI_REG, which is shared across ports */ 514 + spinlock_t phy_lock; 515 + 516 + u32 win_protect; 517 + 518 + unsigned int t_clk; 519 + }; 520 + 521 struct mv643xx_private { 522 + struct mv643xx_shared_private *shared; 523 int port_num; /* User Ethernet port number */ 524 + 525 + struct mv643xx_shared_private *shared_smi; 526 527 u32 rx_sram_addr; /* Base address of rx sram area */ 528 u32 rx_sram_size; /* Size of rx sram area */ ··· 614 static char mv643xx_driver_name[] = "mv643xx_eth"; 615 static char mv643xx_driver_version[] = "1.0"; 616 617 static inline u32 rdl(struct mv643xx_private *mp, int offset) 618 { 619 + return readl(mp->shared->eth_base + offset); 620 } 621 622 static inline void wrl(struct mv643xx_private *mp, int offset, u32 data) 623 { 624 + writel(data, mp->shared->eth_base + offset); 625 } 626 627 /* ··· 1119 * 1120 * INPUT: 1121 * struct mv643xx_private *mp Ethernet port 1122 * unsigned int delay Delay in usec 1123 * 1124 * OUTPUT: ··· 1130 * 1131 */ 1132 static unsigned int eth_port_set_rx_coal(struct mv643xx_private *mp, 1133 + unsigned int delay) 1134 { 1135 unsigned int port_num = mp->port_num; 1136 + unsigned int coal = ((mp->shared->t_clk / 1000000) * delay) / 64; 1137 1138 /* Set RX Coalescing mechanism */ 1139 wrl(mp, SDMA_CONFIG_REG(port_num), ··· 1158 * 1159 * INPUT: 1160 * struct mv643xx_private *mp Ethernet port 1161 * unsigned int delay Delay in uSeconds 1162 * 1163 * OUTPUT: ··· 1169 * 1170 */ 1171 static unsigned int eth_port_set_tx_coal(struct mv643xx_private *mp, 1172 + unsigned int delay) 1173 { 1174 + unsigned int coal = ((mp->shared->t_clk / 1000000) * delay) / 64; 1175 1176 /* Set TX Coalescing mechanism */ 1177 wrl(mp, TX_FIFO_URGENT_THRESHOLD_REG(mp->port_num), coal << 4); ··· 1413 1414 #ifdef MV643XX_COAL 1415 mp->rx_int_coal = 1416 + eth_port_set_rx_coal(mp, MV643XX_RX_COAL); 1417 #endif 1418 1419 mp->tx_int_coal = 1420 + eth_port_set_tx_coal(mp, MV643XX_TX_COAL); 1421 1422 /* Unmask phy and link status changes interrupts */ 1423 wrl(mp, INTERRUPT_EXTEND_MASK_REG(port_num), ETH_INT_UNMASK_ALL_EXT); ··· 1827 return -ENODEV; 1828 } 1829 1830 + if (pd->shared == NULL) { 1831 + printk(KERN_ERR "No mv643xx_eth_platform_data->shared\n"); 1832 + return -ENODEV; 1833 + } 1834 + 1835 dev = alloc_etherdev(sizeof(struct mv643xx_private)); 1836 if (!dev) 1837 return -ENOMEM; ··· 1877 1878 spin_lock_init(&mp->lock); 1879 1880 + mp->shared = platform_get_drvdata(pd->shared); 1881 port_num = mp->port_num = pd->port_number; 1882 + 1883 + if (mp->shared->win_protect) 1884 + wrl(mp, WINDOW_PROTECT(port_num), mp->shared->win_protect); 1885 + 1886 + mp->shared_smi = mp->shared; 1887 + if (pd->shared_smi != NULL) 1888 + mp->shared_smi = platform_get_drvdata(pd->shared_smi); 1889 1890 /* set default config values */ 1891 eth_port_uc_addr_get(mp, dev->dev_addr); ··· 1983 return 0; 1984 } 1985 1986 + static void mv643xx_eth_conf_mbus_windows(struct mv643xx_shared_private *msp, 1987 + struct mbus_dram_target_info *dram) 1988 + { 1989 + void __iomem *base = msp->eth_base; 1990 + u32 win_enable; 1991 + u32 win_protect; 1992 + int i; 1993 + 1994 + for (i = 0; i < 6; i++) { 1995 + writel(0, base + WINDOW_BASE(i)); 1996 + writel(0, base + WINDOW_SIZE(i)); 1997 + if (i < 4) 1998 + writel(0, base + WINDOW_REMAP_HIGH(i)); 1999 + } 2000 + 2001 + win_enable = 0x3f; 2002 + win_protect = 0; 2003 + 2004 + for (i = 0; i < dram->num_cs; i++) { 2005 + struct mbus_dram_window *cs = dram->cs + i; 2006 + 2007 + writel((cs->base & 0xffff0000) | 2008 + (cs->mbus_attr << 8) | 2009 + dram->mbus_dram_target_id, base + WINDOW_BASE(i)); 2010 + writel((cs->size - 1) & 0xffff0000, base + WINDOW_SIZE(i)); 2011 + 2012 + win_enable &= ~(1 << i); 2013 + win_protect |= 3 << (2 * i); 2014 + } 2015 + 2016 + writel(win_enable, base + WINDOW_BAR_ENABLE); 2017 + msp->win_protect = win_protect; 2018 + } 2019 + 2020 static int mv643xx_eth_shared_probe(struct platform_device *pdev) 2021 { 2022 static int mv643xx_version_printed = 0; 2023 + struct mv643xx_eth_shared_platform_data *pd = pdev->dev.platform_data; 2024 + struct mv643xx_shared_private *msp; 2025 struct resource *res; 2026 + int ret; 2027 2028 if (!mv643xx_version_printed++) 2029 printk(KERN_NOTICE "MV-643xx 10/100/1000 Ethernet Driver\n"); 2030 2031 + ret = -EINVAL; 2032 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2033 if (res == NULL) 2034 + goto out; 2035 2036 + ret = -ENOMEM; 2037 + msp = kmalloc(sizeof(*msp), GFP_KERNEL); 2038 + if (msp == NULL) 2039 + goto out; 2040 + memset(msp, 0, sizeof(*msp)); 2041 + 2042 + msp->eth_base = ioremap(res->start, res->end - res->start + 1); 2043 + if (msp->eth_base == NULL) 2044 + goto out_free; 2045 + 2046 + spin_lock_init(&msp->phy_lock); 2047 + msp->t_clk = (pd != NULL && pd->t_clk != 0) ? pd->t_clk : 133000000; 2048 + 2049 + platform_set_drvdata(pdev, msp); 2050 + 2051 + /* 2052 + * (Re-)program MBUS remapping windows if we are asked to. 2053 + */ 2054 + if (pd != NULL && pd->dram != NULL) 2055 + mv643xx_eth_conf_mbus_windows(msp, pd->dram); 2056 2057 return 0; 2058 2059 + out_free: 2060 + kfree(msp); 2061 + out: 2062 + return ret; 2063 } 2064 2065 static int mv643xx_eth_shared_remove(struct platform_device *pdev) 2066 { 2067 + struct mv643xx_shared_private *msp = platform_get_drvdata(pdev); 2068 + 2069 + iounmap(msp->eth_base); 2070 + kfree(msp); 2071 2072 return 0; 2073 } ··· 2906 static void eth_port_read_smi_reg(struct mv643xx_private *mp, 2907 unsigned int phy_reg, unsigned int *value) 2908 { 2909 + void __iomem *smi_reg = mp->shared_smi->eth_base + SMI_REG; 2910 int phy_addr = ethernet_phy_get(mp); 2911 unsigned long flags; 2912 int i; 2913 2914 /* the SMI register is a shared resource */ 2915 + spin_lock_irqsave(&mp->shared_smi->phy_lock, flags); 2916 2917 /* wait for the SMI register to become available */ 2918 + for (i = 0; readl(smi_reg) & ETH_SMI_BUSY; i++) { 2919 if (i == PHY_WAIT_ITERATIONS) { 2920 printk("%s: PHY busy timeout\n", mp->dev->name); 2921 goto out; ··· 2922 udelay(PHY_WAIT_MICRO_SECONDS); 2923 } 2924 2925 + writel((phy_addr << 16) | (phy_reg << 21) | ETH_SMI_OPCODE_READ, 2926 + smi_reg); 2927 2928 /* now wait for the data to be valid */ 2929 + for (i = 0; !(readl(smi_reg) & ETH_SMI_READ_VALID); i++) { 2930 if (i == PHY_WAIT_ITERATIONS) { 2931 printk("%s: PHY read timeout\n", mp->dev->name); 2932 goto out; ··· 2934 udelay(PHY_WAIT_MICRO_SECONDS); 2935 } 2936 2937 + *value = readl(smi_reg) & 0xffff; 2938 out: 2939 + spin_unlock_irqrestore(&mp->shared_smi->phy_lock, flags); 2940 } 2941 2942 /* ··· 2962 static void eth_port_write_smi_reg(struct mv643xx_private *mp, 2963 unsigned int phy_reg, unsigned int value) 2964 { 2965 + void __iomem *smi_reg = mp->shared_smi->eth_base + SMI_REG; 2966 + int phy_addr = ethernet_phy_get(mp); 2967 unsigned long flags; 2968 + int i; 2969 2970 /* the SMI register is a shared resource */ 2971 + spin_lock_irqsave(&mp->shared_smi->phy_lock, flags); 2972 2973 /* wait for the SMI register to become available */ 2974 + for (i = 0; readl(smi_reg) & ETH_SMI_BUSY; i++) { 2975 if (i == PHY_WAIT_ITERATIONS) { 2976 printk("%s: PHY busy timeout\n", mp->dev->name); 2977 goto out; ··· 2980 udelay(PHY_WAIT_MICRO_SECONDS); 2981 } 2982 2983 + writel((phy_addr << 16) | (phy_reg << 21) | 2984 + ETH_SMI_OPCODE_WRITE | (value & 0xffff), smi_reg); 2985 out: 2986 + spin_unlock_irqrestore(&mp->shared_smi->phy_lock, flags); 2987 } 2988 2989 /*
+14 -2
include/linux/mv643xx_eth.h
··· 1 /* 2 * MV-643XX ethernet platform device data definition file. 3 */ 4 #ifndef __LINUX_MV643XX_ETH_H 5 #define __LINUX_MV643XX_ETH_H 6 7 - #define MV643XX_ETH_SHARED_NAME "mv643xx_eth_shared" 8 - #define MV643XX_ETH_NAME "mv643xx_eth" 9 #define MV643XX_ETH_SHARED_REGS 0x2000 10 #define MV643XX_ETH_SHARED_REGS_SIZE 0x2000 11 #define MV643XX_ETH_BAR_4 0x2220 12 #define MV643XX_ETH_SIZE_REG_4 0x2224 13 #define MV643XX_ETH_BASE_ADDR_ENABLE_REG 0x2290 14 15 struct mv643xx_eth_platform_data { 16 int port_number; 17 u16 force_phy_addr; /* force override if phy_addr == 0 */ 18 u16 phy_addr; 19
··· 1 /* 2 * MV-643XX ethernet platform device data definition file. 3 */ 4 + 5 #ifndef __LINUX_MV643XX_ETH_H 6 #define __LINUX_MV643XX_ETH_H 7 8 + #include <linux/mbus.h> 9 + 10 + #define MV643XX_ETH_SHARED_NAME "mv643xx_eth" 11 + #define MV643XX_ETH_NAME "mv643xx_eth_port" 12 #define MV643XX_ETH_SHARED_REGS 0x2000 13 #define MV643XX_ETH_SHARED_REGS_SIZE 0x2000 14 #define MV643XX_ETH_BAR_4 0x2220 15 #define MV643XX_ETH_SIZE_REG_4 0x2224 16 #define MV643XX_ETH_BASE_ADDR_ENABLE_REG 0x2290 17 18 + struct mv643xx_eth_shared_platform_data { 19 + struct mbus_dram_target_info *dram; 20 + unsigned int t_clk; 21 + }; 22 + 23 struct mv643xx_eth_platform_data { 24 + struct platform_device *shared; 25 int port_number; 26 + 27 + struct platform_device *shared_smi; 28 + 29 u16 force_phy_addr; /* force override if phy_addr == 0 */ 30 u16 phy_addr; 31