Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Alchemy Au1x00 ethernet driver |
| 4 | * |
Sergei Shtylyov | 89be050 | 2006-04-19 22:46:21 +0400 | [diff] [blame] | 5 | * Copyright 2001-2003, 2006 MontaVista Software Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * Copyright 2002 TimeSys Corp. |
| 7 | * Added ethtool/mii-tool support, |
| 8 | * Copyright 2004 Matt Porter <mporter@kernel.crashing.org> |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 9 | * Update: 2004 Bjoern Riemer, riemer@fokus.fraunhofer.de |
| 10 | * or riemer@riemer-nt.de: fixed the link beat detection with |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * ioctls (SIOCGMIIPHY) |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 12 | * Copyright 2006 Herbert Valerio Riedel <hvr@gnu.org> |
| 13 | * converted to use linux-2.6.x's PHY framework |
| 14 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | * Author: MontaVista Software, Inc. |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 16 | * ppopov@mvista.com or source@mvista.com |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * |
| 18 | * ######################################################################## |
| 19 | * |
| 20 | * This program is free software; you can distribute it and/or modify it |
| 21 | * under the terms of the GNU General Public License (Version 2) as |
| 22 | * published by the Free Software Foundation. |
| 23 | * |
| 24 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 25 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 26 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 27 | * for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License along |
| 30 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 31 | * 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 32 | * |
| 33 | * ######################################################################## |
| 34 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 35 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | */ |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 37 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 38 | |
Manuel Lauss | bc36b42 | 2009-10-17 02:00:07 +0000 | [diff] [blame] | 39 | #include <linux/capability.h> |
Ralf Baechle | d791c2b | 2007-06-24 15:59:54 +0200 | [diff] [blame] | 40 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/module.h> |
| 42 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/string.h> |
| 44 | #include <linux/timer.h> |
| 45 | #include <linux/errno.h> |
| 46 | #include <linux/in.h> |
| 47 | #include <linux/ioport.h> |
| 48 | #include <linux/bitops.h> |
| 49 | #include <linux/slab.h> |
| 50 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #include <linux/init.h> |
| 52 | #include <linux/netdevice.h> |
| 53 | #include <linux/etherdevice.h> |
| 54 | #include <linux/ethtool.h> |
| 55 | #include <linux/mii.h> |
| 56 | #include <linux/skbuff.h> |
| 57 | #include <linux/delay.h> |
Herbert Valerio Riedel | 8cd35da | 2006-05-01 15:37:09 +0200 | [diff] [blame] | 58 | #include <linux/crc32.h> |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 59 | #include <linux/phy.h> |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 60 | #include <linux/platform_device.h> |
Florian Fainelli | 49a42c0 | 2010-09-08 11:11:49 +0000 | [diff] [blame^] | 61 | #include <linux/cpu.h> |
| 62 | #include <linux/io.h> |
Yoichi Yuasa | 25b31cb | 2007-10-15 19:11:24 +0900 | [diff] [blame] | 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #include <asm/mipsregs.h> |
| 65 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | #include <asm/processor.h> |
| 67 | |
Yoichi Yuasa | 25b31cb | 2007-10-15 19:11:24 +0900 | [diff] [blame] | 68 | #include <au1000.h> |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 69 | #include <au1xxx_eth.h> |
Yoichi Yuasa | 25b31cb | 2007-10-15 19:11:24 +0900 | [diff] [blame] | 70 | #include <prom.h> |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #include "au1000_eth.h" |
| 73 | |
| 74 | #ifdef AU1000_ETH_DEBUG |
| 75 | static int au1000_debug = 5; |
| 76 | #else |
| 77 | static int au1000_debug = 3; |
| 78 | #endif |
| 79 | |
Florian Fainelli | 7cd2e6e | 2010-04-06 22:09:09 +0000 | [diff] [blame] | 80 | #define AU1000_DEF_MSG_ENABLE (NETIF_MSG_DRV | \ |
| 81 | NETIF_MSG_PROBE | \ |
| 82 | NETIF_MSG_LINK) |
| 83 | |
Sergei Shtylyov | 89be050 | 2006-04-19 22:46:21 +0400 | [diff] [blame] | 84 | #define DRV_NAME "au1000_eth" |
Florian Fainelli | 8020eb8 | 2010-04-06 22:09:20 +0000 | [diff] [blame] | 85 | #define DRV_VERSION "1.7" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | #define DRV_AUTHOR "Pete Popov <ppopov@embeddedalley.com>" |
| 87 | #define DRV_DESC "Au1xxx on-chip Ethernet driver" |
| 88 | |
| 89 | MODULE_AUTHOR(DRV_AUTHOR); |
| 90 | MODULE_DESCRIPTION(DRV_DESC); |
| 91 | MODULE_LICENSE("GPL"); |
Florian Fainelli | 13130c7 | 2010-04-06 22:08:57 +0000 | [diff] [blame] | 92 | MODULE_VERSION(DRV_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | /* |
| 95 | * Theory of operation |
| 96 | * |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 97 | * The Au1000 MACs use a simple rx and tx descriptor ring scheme. |
| 98 | * There are four receive and four transmit descriptors. These |
| 99 | * descriptors are not in memory; rather, they are just a set of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | * hardware registers. |
| 101 | * |
| 102 | * Since the Au1000 has a coherent data cache, the receive and |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 103 | * transmit buffers are allocated from the KSEG0 segment. The |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | * hardware registers, however, are still mapped at KSEG1 to |
| 105 | * make sure there's no out-of-order writes, and that all writes |
| 106 | * complete immediately. |
| 107 | */ |
| 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | struct au1000_private *au_macs[NUM_ETH_INTERFACES]; |
| 110 | |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 111 | /* |
| 112 | * board-specific configurations |
| 113 | * |
| 114 | * PHY detection algorithm |
| 115 | * |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 116 | * If phy_static_config is undefined, the PHY setup is |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 117 | * autodetected: |
| 118 | * |
| 119 | * mii_probe() first searches the current MAC's MII bus for a PHY, |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 120 | * selecting the first (or last, if phy_search_highest_addr is |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 121 | * defined) PHY address not already claimed by another netdev. |
| 122 | * |
| 123 | * If nothing was found that way when searching for the 2nd ethernet |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 124 | * controller's PHY and phy1_search_mac0 is defined, then |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 125 | * the first MII bus is searched as well for an unclaimed PHY; this is |
| 126 | * needed in case of a dual-PHY accessible only through the MAC0's MII |
| 127 | * bus. |
| 128 | * |
| 129 | * Finally, if no PHY is found, then the corresponding ethernet |
| 130 | * controller is not registered to the network subsystem. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | */ |
| 132 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 133 | /* autodetection defaults: phy1_search_mac0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 135 | /* static PHY setup |
| 136 | * |
| 137 | * most boards PHY setup should be detectable properly with the |
| 138 | * autodetection algorithm in mii_probe(), but in some cases (e.g. if |
| 139 | * you have a switch attached, or want to use the PHY's interrupt |
| 140 | * notification capabilities) you can provide a static PHY |
| 141 | * configuration here |
| 142 | * |
| 143 | * IRQs may only be set, if a PHY address was configured |
| 144 | * If a PHY address is given, also a bus id is required to be set |
| 145 | * |
| 146 | * ps: make sure the used irqs are configured properly in the board |
| 147 | * specific irq-map |
| 148 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 150 | static void au1000_enable_mac(struct net_device *dev, int force_reset) |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 151 | { |
| 152 | unsigned long flags; |
| 153 | struct au1000_private *aup = netdev_priv(dev); |
| 154 | |
| 155 | spin_lock_irqsave(&aup->lock, flags); |
| 156 | |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 157 | if (force_reset || (!aup->mac_enabled)) { |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 158 | *aup->enable = MAC_EN_CLOCK_ENABLE; |
| 159 | au_sync_delay(2); |
| 160 | *aup->enable = (MAC_EN_RESET0 | MAC_EN_RESET1 | MAC_EN_RESET2 |
| 161 | | MAC_EN_CLOCK_ENABLE); |
| 162 | au_sync_delay(2); |
| 163 | |
| 164 | aup->mac_enabled = 1; |
| 165 | } |
| 166 | |
| 167 | spin_unlock_irqrestore(&aup->lock, flags); |
| 168 | } |
| 169 | |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 170 | /* |
| 171 | * MII operations |
| 172 | */ |
Adrian Bunk | 1210dde | 2008-10-12 21:02:19 -0700 | [diff] [blame] | 173 | static int au1000_mdio_read(struct net_device *dev, int phy_addr, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 175 | struct au1000_private *aup = netdev_priv(dev); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 176 | volatile u32 *const mii_control_reg = &aup->mac->mii_control; |
| 177 | volatile u32 *const mii_data_reg = &aup->mac->mii_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | u32 timedout = 20; |
| 179 | u32 mii_control; |
| 180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | while (*mii_control_reg & MAC_MII_BUSY) { |
| 182 | mdelay(1); |
| 183 | if (--timedout == 0) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 184 | netdev_err(dev, "read_MII busy timeout!!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | return -1; |
| 186 | } |
| 187 | } |
| 188 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 189 | mii_control = MAC_SET_MII_SELECT_REG(reg) | |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 190 | MAC_SET_MII_SELECT_PHY(phy_addr) | MAC_MII_READ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | *mii_control_reg = mii_control; |
| 193 | |
| 194 | timedout = 20; |
| 195 | while (*mii_control_reg & MAC_MII_BUSY) { |
| 196 | mdelay(1); |
| 197 | if (--timedout == 0) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 198 | netdev_err(dev, "mdio_read busy timeout!!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | return -1; |
| 200 | } |
| 201 | } |
| 202 | return (int)*mii_data_reg; |
| 203 | } |
| 204 | |
Adrian Bunk | 1210dde | 2008-10-12 21:02:19 -0700 | [diff] [blame] | 205 | static void au1000_mdio_write(struct net_device *dev, int phy_addr, |
| 206 | int reg, u16 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 208 | struct au1000_private *aup = netdev_priv(dev); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 209 | volatile u32 *const mii_control_reg = &aup->mac->mii_control; |
| 210 | volatile u32 *const mii_data_reg = &aup->mac->mii_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | u32 timedout = 20; |
| 212 | u32 mii_control; |
| 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | while (*mii_control_reg & MAC_MII_BUSY) { |
| 215 | mdelay(1); |
| 216 | if (--timedout == 0) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 217 | netdev_err(dev, "mdio_write busy timeout!!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | return; |
| 219 | } |
| 220 | } |
| 221 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 222 | mii_control = MAC_SET_MII_SELECT_REG(reg) | |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 223 | MAC_SET_MII_SELECT_PHY(phy_addr) | MAC_MII_WRITE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | *mii_data_reg = value; |
| 226 | *mii_control_reg = mii_control; |
| 227 | } |
| 228 | |
Adrian Bunk | 1210dde | 2008-10-12 21:02:19 -0700 | [diff] [blame] | 229 | static int au1000_mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | { |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 231 | /* WARNING: bus->phy_map[phy_addr].attached_dev == dev does |
| 232 | * _NOT_ hold (e.g. when PHY is accessed through other MAC's MII bus) */ |
| 233 | struct net_device *const dev = bus->priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 235 | au1000_enable_mac(dev, 0); /* make sure the MAC associated with this |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 236 | * mii_bus is enabled */ |
Adrian Bunk | 1210dde | 2008-10-12 21:02:19 -0700 | [diff] [blame] | 237 | return au1000_mdio_read(dev, phy_addr, regnum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Adrian Bunk | 1210dde | 2008-10-12 21:02:19 -0700 | [diff] [blame] | 240 | static int au1000_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, |
| 241 | u16 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 243 | struct net_device *const dev = bus->priv; |
| 244 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 245 | au1000_enable_mac(dev, 0); /* make sure the MAC associated with this |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 246 | * mii_bus is enabled */ |
Adrian Bunk | 1210dde | 2008-10-12 21:02:19 -0700 | [diff] [blame] | 247 | au1000_mdio_write(dev, phy_addr, regnum, value); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 248 | return 0; |
| 249 | } |
| 250 | |
Adrian Bunk | 1210dde | 2008-10-12 21:02:19 -0700 | [diff] [blame] | 251 | static int au1000_mdiobus_reset(struct mii_bus *bus) |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 252 | { |
| 253 | struct net_device *const dev = bus->priv; |
| 254 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 255 | au1000_enable_mac(dev, 0); /* make sure the MAC associated with this |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 256 | * mii_bus is enabled */ |
| 257 | return 0; |
| 258 | } |
| 259 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 260 | static void au1000_hard_stop(struct net_device *dev) |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 261 | { |
| 262 | struct au1000_private *aup = netdev_priv(dev); |
| 263 | |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 264 | netif_dbg(aup, drv, dev, "hard stop\n"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 265 | |
| 266 | aup->mac->control &= ~(MAC_RX_ENABLE | MAC_TX_ENABLE); |
| 267 | au_sync_delay(10); |
| 268 | } |
| 269 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 270 | static void au1000_enable_rx_tx(struct net_device *dev) |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 271 | { |
| 272 | struct au1000_private *aup = netdev_priv(dev); |
| 273 | |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 274 | netif_dbg(aup, hw, dev, "enable_rx_tx\n"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 275 | |
| 276 | aup->mac->control |= (MAC_RX_ENABLE | MAC_TX_ENABLE); |
| 277 | au_sync_delay(10); |
| 278 | } |
| 279 | |
| 280 | static void |
| 281 | au1000_adjust_link(struct net_device *dev) |
| 282 | { |
| 283 | struct au1000_private *aup = netdev_priv(dev); |
| 284 | struct phy_device *phydev = aup->phy_dev; |
| 285 | unsigned long flags; |
| 286 | |
| 287 | int status_change = 0; |
| 288 | |
| 289 | BUG_ON(!aup->phy_dev); |
| 290 | |
| 291 | spin_lock_irqsave(&aup->lock, flags); |
| 292 | |
| 293 | if (phydev->link && (aup->old_speed != phydev->speed)) { |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 294 | /* speed changed */ |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 295 | |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 296 | switch (phydev->speed) { |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 297 | case SPEED_10: |
| 298 | case SPEED_100: |
| 299 | break; |
| 300 | default: |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 301 | netdev_warn(dev, "Speed (%d) is not 10/100 ???\n", |
| 302 | phydev->speed); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 303 | break; |
| 304 | } |
| 305 | |
| 306 | aup->old_speed = phydev->speed; |
| 307 | |
| 308 | status_change = 1; |
| 309 | } |
| 310 | |
| 311 | if (phydev->link && (aup->old_duplex != phydev->duplex)) { |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 312 | /* duplex mode changed */ |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 313 | |
| 314 | /* switching duplex mode requires to disable rx and tx! */ |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 315 | au1000_hard_stop(dev); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 316 | |
| 317 | if (DUPLEX_FULL == phydev->duplex) |
| 318 | aup->mac->control = ((aup->mac->control |
| 319 | | MAC_FULL_DUPLEX) |
| 320 | & ~MAC_DISABLE_RX_OWN); |
| 321 | else |
| 322 | aup->mac->control = ((aup->mac->control |
| 323 | & ~MAC_FULL_DUPLEX) |
| 324 | | MAC_DISABLE_RX_OWN); |
| 325 | au_sync_delay(1); |
| 326 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 327 | au1000_enable_rx_tx(dev); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 328 | aup->old_duplex = phydev->duplex; |
| 329 | |
| 330 | status_change = 1; |
| 331 | } |
| 332 | |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 333 | if (phydev->link != aup->old_link) { |
| 334 | /* link state changed */ |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 335 | |
| 336 | if (!phydev->link) { |
| 337 | /* link went down */ |
| 338 | aup->old_speed = 0; |
| 339 | aup->old_duplex = -1; |
| 340 | } |
| 341 | |
| 342 | aup->old_link = phydev->link; |
| 343 | status_change = 1; |
| 344 | } |
| 345 | |
| 346 | spin_unlock_irqrestore(&aup->lock, flags); |
| 347 | |
| 348 | if (status_change) { |
| 349 | if (phydev->link) |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 350 | netdev_info(dev, "link up (%d/%s)\n", |
| 351 | phydev->speed, |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 352 | DUPLEX_FULL == phydev->duplex ? "Full" : "Half"); |
| 353 | else |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 354 | netdev_info(dev, "link down\n"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 355 | } |
| 356 | } |
| 357 | |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 358 | static int au1000_mii_probe(struct net_device *dev) |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 359 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 360 | struct au1000_private *const aup = netdev_priv(dev); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 361 | struct phy_device *phydev = NULL; |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 362 | int phy_addr; |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 363 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 364 | if (aup->phy_static_config) { |
| 365 | BUG_ON(aup->mac_id < 0 || aup->mac_id > 1); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 366 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 367 | if (aup->phy_addr) |
| 368 | phydev = aup->mii_bus->phy_map[aup->phy_addr]; |
| 369 | else |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 370 | netdev_info(dev, "using PHY-less setup\n"); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 371 | return 0; |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 372 | } |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 373 | |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 374 | /* find the first (lowest address) PHY |
| 375 | * on the current MAC's MII bus */ |
| 376 | for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) |
| 377 | if (aup->mii_bus->phy_map[phy_addr]) { |
| 378 | phydev = aup->mii_bus->phy_map[phy_addr]; |
| 379 | if (!aup->phy_search_highest_addr) |
| 380 | /* break out with first one found */ |
| 381 | break; |
| 382 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 384 | if (aup->phy1_search_mac0) { |
| 385 | /* try harder to find a PHY */ |
| 386 | if (!phydev && (aup->mac_id == 1)) { |
| 387 | /* no PHY found, maybe we have a dual PHY? */ |
| 388 | dev_info(&dev->dev, ": no PHY found on MAC1, " |
| 389 | "let's see if it's attached to MAC0...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 391 | /* find the first (lowest address) non-attached |
| 392 | * PHY on the MAC0 MII bus |
| 393 | */ |
| 394 | for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) { |
| 395 | struct phy_device *const tmp_phydev = |
| 396 | aup->mii_bus->phy_map[phy_addr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 398 | if (aup->mac_id == 1) |
| 399 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 401 | /* no PHY here... */ |
| 402 | if (!tmp_phydev) |
| 403 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 405 | /* already claimed by MAC0 */ |
| 406 | if (tmp_phydev->attached_dev) |
| 407 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 409 | phydev = tmp_phydev; |
| 410 | break; /* found it */ |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 411 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 415 | if (!phydev) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 416 | netdev_err(dev, "no PHY found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | return -1; |
| 418 | } |
| 419 | |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 420 | /* now we are supposed to have a proper phydev, to attach to... */ |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 421 | BUG_ON(phydev->attached_dev); |
| 422 | |
Kay Sievers | db1d7bf | 2009-01-26 21:12:58 -0800 | [diff] [blame] | 423 | phydev = phy_connect(dev, dev_name(&phydev->dev), &au1000_adjust_link, |
| 424 | 0, PHY_INTERFACE_MODE_MII); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 425 | |
| 426 | if (IS_ERR(phydev)) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 427 | netdev_err(dev, "Could not attach to PHY\n"); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 428 | return PTR_ERR(phydev); |
| 429 | } |
| 430 | |
| 431 | /* mask with MAC supported features */ |
| 432 | phydev->supported &= (SUPPORTED_10baseT_Half |
| 433 | | SUPPORTED_10baseT_Full |
| 434 | | SUPPORTED_100baseT_Half |
| 435 | | SUPPORTED_100baseT_Full |
| 436 | | SUPPORTED_Autoneg |
| 437 | /* | SUPPORTED_Pause | SUPPORTED_Asym_Pause */ |
| 438 | | SUPPORTED_MII |
| 439 | | SUPPORTED_TP); |
| 440 | |
| 441 | phydev->advertising = phydev->supported; |
| 442 | |
| 443 | aup->old_link = 0; |
| 444 | aup->old_speed = 0; |
| 445 | aup->old_duplex = -1; |
| 446 | aup->phy_dev = phydev; |
| 447 | |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 448 | netdev_info(dev, "attached PHY driver [%s] " |
| 449 | "(mii_bus:phy_addr=%s, irq=%d)\n", |
Kay Sievers | db1d7bf | 2009-01-26 21:12:58 -0800 | [diff] [blame] | 450 | phydev->drv->name, dev_name(&phydev->dev), phydev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | |
| 456 | /* |
| 457 | * Buffer allocation/deallocation routines. The buffer descriptor returned |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 458 | * has the virtual and dma address of a buffer suitable for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | * both, receive and transmit operations. |
| 460 | */ |
Florian Fainelli | 3441592 | 2010-09-08 11:11:25 +0000 | [diff] [blame] | 461 | static struct db_dest *au1000_GetFreeDB(struct au1000_private *aup) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | { |
Florian Fainelli | 3441592 | 2010-09-08 11:11:25 +0000 | [diff] [blame] | 463 | struct db_dest *pDB; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | pDB = aup->pDBfree; |
| 465 | |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 466 | if (pDB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | aup->pDBfree = pDB->pnext; |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 468 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | return pDB; |
| 470 | } |
| 471 | |
Florian Fainelli | 3441592 | 2010-09-08 11:11:25 +0000 | [diff] [blame] | 472 | void au1000_ReleaseDB(struct au1000_private *aup, struct db_dest *pDB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | { |
Florian Fainelli | 3441592 | 2010-09-08 11:11:25 +0000 | [diff] [blame] | 474 | struct db_dest *pDBfree = aup->pDBfree; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | if (pDBfree) |
| 476 | pDBfree->pnext = pDB; |
| 477 | aup->pDBfree = pDB; |
| 478 | } |
| 479 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 480 | static void au1000_reset_mac_unlocked(struct net_device *dev) |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 481 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 482 | struct au1000_private *const aup = netdev_priv(dev); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 483 | int i; |
| 484 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 485 | au1000_hard_stop(dev); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 486 | |
| 487 | *aup->enable = MAC_EN_CLOCK_ENABLE; |
| 488 | au_sync_delay(2); |
| 489 | *aup->enable = 0; |
| 490 | au_sync_delay(2); |
| 491 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | aup->tx_full = 0; |
| 493 | for (i = 0; i < NUM_RX_DMA; i++) { |
| 494 | /* reset control bits */ |
| 495 | aup->rx_dma_ring[i]->buff_stat &= ~0xf; |
| 496 | } |
| 497 | for (i = 0; i < NUM_TX_DMA; i++) { |
| 498 | /* reset control bits */ |
| 499 | aup->tx_dma_ring[i]->buff_stat &= ~0xf; |
| 500 | } |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 501 | |
| 502 | aup->mac_enabled = 0; |
| 503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | } |
| 505 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 506 | static void au1000_reset_mac(struct net_device *dev) |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 507 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 508 | struct au1000_private *const aup = netdev_priv(dev); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 509 | unsigned long flags; |
| 510 | |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 511 | netif_dbg(aup, hw, dev, "reset mac, aup %x\n", |
| 512 | (unsigned)aup); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 513 | |
| 514 | spin_lock_irqsave(&aup->lock, flags); |
| 515 | |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 516 | au1000_reset_mac_unlocked(dev); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 517 | |
| 518 | spin_unlock_irqrestore(&aup->lock, flags); |
| 519 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 521 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | * Setup the receive and transmit "rings". These pointers are the addresses |
| 523 | * of the rx and tx MAC DMA registers so they are fixed by the hardware -- |
| 524 | * these are not descriptors sitting in memory. |
| 525 | */ |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 526 | static void |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 527 | au1000_setup_hw_rings(struct au1000_private *aup, u32 rx_base, u32 tx_base) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
| 529 | int i; |
| 530 | |
| 531 | for (i = 0; i < NUM_RX_DMA; i++) { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 532 | aup->rx_dma_ring[i] = |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 533 | (volatile struct rx_dma *) |
| 534 | (rx_base + sizeof(struct rx_dma)*i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | } |
| 536 | for (i = 0; i < NUM_TX_DMA; i++) { |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 537 | aup->tx_dma_ring[i] = |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 538 | (volatile struct tx_dma *) |
| 539 | (tx_base + sizeof(struct tx_dma)*i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | /* |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 544 | * ethtool operations |
| 545 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | static int au1000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 548 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 549 | struct au1000_private *aup = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 551 | if (aup->phy_dev) |
| 552 | return phy_ethtool_gset(aup->phy_dev, cmd); |
| 553 | |
| 554 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | static int au1000_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 558 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 559 | struct au1000_private *aup = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 561 | if (!capable(CAP_NET_ADMIN)) |
| 562 | return -EPERM; |
| 563 | |
| 564 | if (aup->phy_dev) |
| 565 | return phy_ethtool_sset(aup->phy_dev, cmd); |
| 566 | |
| 567 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | static void |
| 571 | au1000_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 572 | { |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 573 | struct au1000_private *aup = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
| 575 | strcpy(info->driver, DRV_NAME); |
| 576 | strcpy(info->version, DRV_VERSION); |
| 577 | info->fw_version[0] = '\0'; |
| 578 | sprintf(info->bus_info, "%s %d", DRV_NAME, aup->mac_id); |
| 579 | info->regdump_len = 0; |
| 580 | } |
| 581 | |
Florian Fainelli | 7cd2e6e | 2010-04-06 22:09:09 +0000 | [diff] [blame] | 582 | static void au1000_set_msglevel(struct net_device *dev, u32 value) |
| 583 | { |
| 584 | struct au1000_private *aup = netdev_priv(dev); |
| 585 | aup->msg_enable = value; |
| 586 | } |
| 587 | |
| 588 | static u32 au1000_get_msglevel(struct net_device *dev) |
| 589 | { |
| 590 | struct au1000_private *aup = netdev_priv(dev); |
| 591 | return aup->msg_enable; |
| 592 | } |
| 593 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 594 | static const struct ethtool_ops au1000_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | .get_settings = au1000_get_settings, |
| 596 | .set_settings = au1000_set_settings, |
| 597 | .get_drvinfo = au1000_get_drvinfo, |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 598 | .get_link = ethtool_op_get_link, |
Florian Fainelli | 7cd2e6e | 2010-04-06 22:09:09 +0000 | [diff] [blame] | 599 | .get_msglevel = au1000_get_msglevel, |
| 600 | .set_msglevel = au1000_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | }; |
| 602 | |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 603 | |
| 604 | /* |
| 605 | * Initialize the interface. |
| 606 | * |
| 607 | * When the device powers up, the clocks are disabled and the |
| 608 | * mac is in reset state. When the interface is closed, we |
| 609 | * do the same -- reset the device and disable the clocks to |
| 610 | * conserve power. Thus, whenever au1000_init() is called, |
| 611 | * the device should already be in reset state. |
| 612 | */ |
| 613 | static int au1000_init(struct net_device *dev) |
| 614 | { |
| 615 | struct au1000_private *aup = netdev_priv(dev); |
| 616 | unsigned long flags; |
| 617 | int i; |
| 618 | u32 control; |
| 619 | |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 620 | netif_dbg(aup, hw, dev, "au1000_init\n"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 621 | |
| 622 | /* bring the device out of reset */ |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 623 | au1000_enable_mac(dev, 1); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 624 | |
| 625 | spin_lock_irqsave(&aup->lock, flags); |
| 626 | |
| 627 | aup->mac->control = 0; |
| 628 | aup->tx_head = (aup->tx_dma_ring[0]->buff_stat & 0xC) >> 2; |
| 629 | aup->tx_tail = aup->tx_head; |
| 630 | aup->rx_head = (aup->rx_dma_ring[0]->buff_stat & 0xC) >> 2; |
| 631 | |
| 632 | aup->mac->mac_addr_high = dev->dev_addr[5]<<8 | dev->dev_addr[4]; |
| 633 | aup->mac->mac_addr_low = dev->dev_addr[3]<<24 | dev->dev_addr[2]<<16 | |
| 634 | dev->dev_addr[1]<<8 | dev->dev_addr[0]; |
| 635 | |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 636 | |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 637 | for (i = 0; i < NUM_RX_DMA; i++) |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 638 | aup->rx_dma_ring[i]->buff_stat |= RX_DMA_ENABLE; |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 639 | |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 640 | au_sync(); |
| 641 | |
| 642 | control = MAC_RX_ENABLE | MAC_TX_ENABLE; |
| 643 | #ifndef CONFIG_CPU_LITTLE_ENDIAN |
| 644 | control |= MAC_BIG_ENDIAN; |
| 645 | #endif |
| 646 | if (aup->phy_dev) { |
| 647 | if (aup->phy_dev->link && (DUPLEX_FULL == aup->phy_dev->duplex)) |
| 648 | control |= MAC_FULL_DUPLEX; |
| 649 | else |
| 650 | control |= MAC_DISABLE_RX_OWN; |
| 651 | } else { /* PHY-less op, assume full-duplex */ |
| 652 | control |= MAC_FULL_DUPLEX; |
| 653 | } |
| 654 | |
| 655 | aup->mac->control = control; |
| 656 | aup->mac->vlan1_tag = 0x8100; /* activate vlan support */ |
| 657 | au_sync(); |
| 658 | |
| 659 | spin_unlock_irqrestore(&aup->lock, flags); |
| 660 | return 0; |
| 661 | } |
| 662 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 663 | static inline void au1000_update_rx_stats(struct net_device *dev, u32 status) |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 664 | { |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 665 | struct net_device_stats *ps = &dev->stats; |
| 666 | |
| 667 | ps->rx_packets++; |
| 668 | if (status & RX_MCAST_FRAME) |
| 669 | ps->multicast++; |
| 670 | |
| 671 | if (status & RX_ERROR) { |
| 672 | ps->rx_errors++; |
| 673 | if (status & RX_MISSED_FRAME) |
| 674 | ps->rx_missed_errors++; |
roel kluin | 4989ccb | 2009-10-06 09:54:18 +0000 | [diff] [blame] | 675 | if (status & (RX_OVERLEN | RX_RUNT | RX_LEN_ERROR)) |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 676 | ps->rx_length_errors++; |
| 677 | if (status & RX_CRC_ERROR) |
| 678 | ps->rx_crc_errors++; |
| 679 | if (status & RX_COLL) |
| 680 | ps->collisions++; |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 681 | } else |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 682 | ps->rx_bytes += status & RX_FRAME_LEN_MASK; |
| 683 | |
| 684 | } |
| 685 | |
| 686 | /* |
| 687 | * Au1000 receive routine. |
| 688 | */ |
| 689 | static int au1000_rx(struct net_device *dev) |
| 690 | { |
| 691 | struct au1000_private *aup = netdev_priv(dev); |
| 692 | struct sk_buff *skb; |
Florian Fainelli | 3441592 | 2010-09-08 11:11:25 +0000 | [diff] [blame] | 693 | volatile struct rx_dma *prxd; |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 694 | u32 buff_stat, status; |
Florian Fainelli | 3441592 | 2010-09-08 11:11:25 +0000 | [diff] [blame] | 695 | struct db_dest *pDB; |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 696 | u32 frmlen; |
| 697 | |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 698 | netif_dbg(aup, rx_status, dev, "au1000_rx head %d\n", aup->rx_head); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 699 | |
| 700 | prxd = aup->rx_dma_ring[aup->rx_head]; |
| 701 | buff_stat = prxd->buff_stat; |
| 702 | while (buff_stat & RX_T_DONE) { |
| 703 | status = prxd->status; |
| 704 | pDB = aup->rx_db_inuse[aup->rx_head]; |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 705 | au1000_update_rx_stats(dev, status); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 706 | if (!(status & RX_ERROR)) { |
| 707 | |
| 708 | /* good frame */ |
| 709 | frmlen = (status & RX_FRAME_LEN_MASK); |
| 710 | frmlen -= 4; /* Remove FCS */ |
| 711 | skb = dev_alloc_skb(frmlen + 2); |
| 712 | if (skb == NULL) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 713 | netdev_err(dev, "Memory squeeze, dropping packet.\n"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 714 | dev->stats.rx_dropped++; |
| 715 | continue; |
| 716 | } |
| 717 | skb_reserve(skb, 2); /* 16 byte IP header align */ |
| 718 | skb_copy_to_linear_data(skb, |
| 719 | (unsigned char *)pDB->vaddr, frmlen); |
| 720 | skb_put(skb, frmlen); |
| 721 | skb->protocol = eth_type_trans(skb, dev); |
| 722 | netif_rx(skb); /* pass the packet to upper layers */ |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 723 | } else { |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 724 | if (au1000_debug > 4) { |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 725 | pr_err("rx_error(s):"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 726 | if (status & RX_MISSED_FRAME) |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 727 | pr_cont(" miss"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 728 | if (status & RX_WDOG_TIMER) |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 729 | pr_cont(" wdog"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 730 | if (status & RX_RUNT) |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 731 | pr_cont(" runt"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 732 | if (status & RX_OVERLEN) |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 733 | pr_cont(" overlen"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 734 | if (status & RX_COLL) |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 735 | pr_cont(" coll"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 736 | if (status & RX_MII_ERROR) |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 737 | pr_cont(" mii error"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 738 | if (status & RX_CRC_ERROR) |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 739 | pr_cont(" crc error"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 740 | if (status & RX_LEN_ERROR) |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 741 | pr_cont(" len error"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 742 | if (status & RX_U_CNTRL_FRAME) |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 743 | pr_cont(" u control frame"); |
| 744 | pr_cont("\n"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 745 | } |
| 746 | } |
| 747 | prxd->buff_stat = (u32)(pDB->dma_addr | RX_DMA_ENABLE); |
| 748 | aup->rx_head = (aup->rx_head + 1) & (NUM_RX_DMA - 1); |
| 749 | au_sync(); |
| 750 | |
| 751 | /* next descriptor */ |
| 752 | prxd = aup->rx_dma_ring[aup->rx_head]; |
| 753 | buff_stat = prxd->buff_stat; |
| 754 | } |
| 755 | return 0; |
| 756 | } |
| 757 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 758 | static void au1000_update_tx_stats(struct net_device *dev, u32 status) |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 759 | { |
| 760 | struct au1000_private *aup = netdev_priv(dev); |
| 761 | struct net_device_stats *ps = &dev->stats; |
| 762 | |
| 763 | if (status & TX_FRAME_ABORTED) { |
| 764 | if (!aup->phy_dev || (DUPLEX_FULL == aup->phy_dev->duplex)) { |
| 765 | if (status & (TX_JAB_TIMEOUT | TX_UNDERRUN)) { |
| 766 | /* any other tx errors are only valid |
| 767 | * in half duplex mode */ |
| 768 | ps->tx_errors++; |
| 769 | ps->tx_aborted_errors++; |
| 770 | } |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 771 | } else { |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 772 | ps->tx_errors++; |
| 773 | ps->tx_aborted_errors++; |
| 774 | if (status & (TX_NO_CARRIER | TX_LOSS_CARRIER)) |
| 775 | ps->tx_carrier_errors++; |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | /* |
| 781 | * Called from the interrupt service routine to acknowledge |
| 782 | * the TX DONE bits. This is a must if the irq is setup as |
| 783 | * edge triggered. |
| 784 | */ |
| 785 | static void au1000_tx_ack(struct net_device *dev) |
| 786 | { |
| 787 | struct au1000_private *aup = netdev_priv(dev); |
Florian Fainelli | 3441592 | 2010-09-08 11:11:25 +0000 | [diff] [blame] | 788 | volatile struct tx_dma *ptxd; |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 789 | |
| 790 | ptxd = aup->tx_dma_ring[aup->tx_tail]; |
| 791 | |
| 792 | while (ptxd->buff_stat & TX_T_DONE) { |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 793 | au1000_update_tx_stats(dev, ptxd->status); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 794 | ptxd->buff_stat &= ~TX_T_DONE; |
| 795 | ptxd->len = 0; |
| 796 | au_sync(); |
| 797 | |
| 798 | aup->tx_tail = (aup->tx_tail + 1) & (NUM_TX_DMA - 1); |
| 799 | ptxd = aup->tx_dma_ring[aup->tx_tail]; |
| 800 | |
| 801 | if (aup->tx_full) { |
| 802 | aup->tx_full = 0; |
| 803 | netif_wake_queue(dev); |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | /* |
| 809 | * Au1000 interrupt service routine. |
| 810 | */ |
| 811 | static irqreturn_t au1000_interrupt(int irq, void *dev_id) |
| 812 | { |
| 813 | struct net_device *dev = dev_id; |
| 814 | |
| 815 | /* Handle RX interrupts first to minimize chance of overrun */ |
| 816 | |
| 817 | au1000_rx(dev); |
| 818 | au1000_tx_ack(dev); |
| 819 | return IRQ_RETVAL(1); |
| 820 | } |
| 821 | |
| 822 | static int au1000_open(struct net_device *dev) |
| 823 | { |
| 824 | int retval; |
| 825 | struct au1000_private *aup = netdev_priv(dev); |
| 826 | |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 827 | netif_dbg(aup, drv, dev, "open: dev=%p\n", dev); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 828 | |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 829 | retval = request_irq(dev->irq, au1000_interrupt, 0, |
| 830 | dev->name, dev); |
| 831 | if (retval) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 832 | netdev_err(dev, "unable to get IRQ %d\n", dev->irq); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 833 | return retval; |
| 834 | } |
| 835 | |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 836 | retval = au1000_init(dev); |
| 837 | if (retval) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 838 | netdev_err(dev, "error in au1000_init\n"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 839 | free_irq(dev->irq, dev); |
| 840 | return retval; |
| 841 | } |
| 842 | |
| 843 | if (aup->phy_dev) { |
| 844 | /* cause the PHY state machine to schedule a link state check */ |
| 845 | aup->phy_dev->state = PHY_CHANGELINK; |
| 846 | phy_start(aup->phy_dev); |
| 847 | } |
| 848 | |
| 849 | netif_start_queue(dev); |
| 850 | |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 851 | netif_dbg(aup, drv, dev, "open: Initialization done.\n"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 852 | |
| 853 | return 0; |
| 854 | } |
| 855 | |
| 856 | static int au1000_close(struct net_device *dev) |
| 857 | { |
| 858 | unsigned long flags; |
| 859 | struct au1000_private *const aup = netdev_priv(dev); |
| 860 | |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 861 | netif_dbg(aup, drv, dev, "close: dev=%p\n", dev); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 862 | |
| 863 | if (aup->phy_dev) |
| 864 | phy_stop(aup->phy_dev); |
| 865 | |
| 866 | spin_lock_irqsave(&aup->lock, flags); |
| 867 | |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 868 | au1000_reset_mac_unlocked(dev); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 869 | |
| 870 | /* stop the device */ |
| 871 | netif_stop_queue(dev); |
| 872 | |
| 873 | /* disable the interrupt */ |
| 874 | free_irq(dev->irq, dev); |
| 875 | spin_unlock_irqrestore(&aup->lock, flags); |
| 876 | |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | /* |
| 881 | * Au1000 transmit routine. |
| 882 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 883 | static netdev_tx_t au1000_tx(struct sk_buff *skb, struct net_device *dev) |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 884 | { |
| 885 | struct au1000_private *aup = netdev_priv(dev); |
| 886 | struct net_device_stats *ps = &dev->stats; |
Florian Fainelli | 3441592 | 2010-09-08 11:11:25 +0000 | [diff] [blame] | 887 | volatile struct tx_dma *ptxd; |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 888 | u32 buff_stat; |
Florian Fainelli | 3441592 | 2010-09-08 11:11:25 +0000 | [diff] [blame] | 889 | struct db_dest *pDB; |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 890 | int i; |
| 891 | |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 892 | netif_dbg(aup, tx_queued, dev, "tx: aup %x len=%d, data=%p, head %d\n", |
| 893 | (unsigned)aup, skb->len, |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 894 | skb->data, aup->tx_head); |
| 895 | |
| 896 | ptxd = aup->tx_dma_ring[aup->tx_head]; |
| 897 | buff_stat = ptxd->buff_stat; |
| 898 | if (buff_stat & TX_DMA_ENABLE) { |
| 899 | /* We've wrapped around and the transmitter is still busy */ |
| 900 | netif_stop_queue(dev); |
| 901 | aup->tx_full = 1; |
Patrick McHardy | 5b54814 | 2009-06-12 06:22:29 +0000 | [diff] [blame] | 902 | return NETDEV_TX_BUSY; |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 903 | } else if (buff_stat & TX_T_DONE) { |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 904 | au1000_update_tx_stats(dev, ptxd->status); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 905 | ptxd->len = 0; |
| 906 | } |
| 907 | |
| 908 | if (aup->tx_full) { |
| 909 | aup->tx_full = 0; |
| 910 | netif_wake_queue(dev); |
| 911 | } |
| 912 | |
| 913 | pDB = aup->tx_db_inuse[aup->tx_head]; |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 914 | skb_copy_from_linear_data(skb, (void *)pDB->vaddr, skb->len); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 915 | if (skb->len < ETH_ZLEN) { |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 916 | for (i = skb->len; i < ETH_ZLEN; i++) |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 917 | ((char *)pDB->vaddr)[i] = 0; |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 918 | |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 919 | ptxd->len = ETH_ZLEN; |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 920 | } else |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 921 | ptxd->len = skb->len; |
| 922 | |
| 923 | ps->tx_packets++; |
| 924 | ps->tx_bytes += ptxd->len; |
| 925 | |
| 926 | ptxd->buff_stat = pDB->dma_addr | TX_DMA_ENABLE; |
| 927 | au_sync(); |
| 928 | dev_kfree_skb(skb); |
| 929 | aup->tx_head = (aup->tx_head + 1) & (NUM_TX_DMA - 1); |
Patrick McHardy | 6ed1065 | 2009-06-23 06:03:08 +0000 | [diff] [blame] | 930 | return NETDEV_TX_OK; |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | /* |
| 934 | * The Tx ring has been full longer than the watchdog timeout |
| 935 | * value. The transmitter must be hung? |
| 936 | */ |
| 937 | static void au1000_tx_timeout(struct net_device *dev) |
| 938 | { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 939 | netdev_err(dev, "au1000_tx_timeout: dev=%p\n", dev); |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 940 | au1000_reset_mac(dev); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 941 | au1000_init(dev); |
Eric Dumazet | 1ae5dc3 | 2010-05-10 05:01:31 -0700 | [diff] [blame] | 942 | dev->trans_start = jiffies; /* prevent tx timeout */ |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 943 | netif_wake_queue(dev); |
| 944 | } |
| 945 | |
Alexander Beregalov | d9a92ce | 2009-04-14 18:30:23 +0000 | [diff] [blame] | 946 | static void au1000_multicast_list(struct net_device *dev) |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 947 | { |
| 948 | struct au1000_private *aup = netdev_priv(dev); |
| 949 | |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 950 | netif_dbg(aup, drv, dev, "%s: flags=%x\n", __func__, dev->flags); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 951 | if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ |
| 952 | aup->mac->control |= MAC_PROMISCUOUS; |
| 953 | } else if ((dev->flags & IFF_ALLMULTI) || |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 954 | netdev_mc_count(dev) > MULTICAST_FILTER_LIMIT) { |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 955 | aup->mac->control |= MAC_PASS_ALL_MULTI; |
| 956 | aup->mac->control &= ~MAC_PROMISCUOUS; |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 957 | netdev_info(dev, "Pass all multicast\n"); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 958 | } else { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 959 | struct netdev_hw_addr *ha; |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 960 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 961 | |
| 962 | mc_filter[1] = mc_filter[0] = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 963 | netdev_for_each_mc_addr(ha, dev) |
| 964 | set_bit(ether_crc(ETH_ALEN, ha->addr)>>26, |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 965 | (long *)mc_filter); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 966 | aup->mac->multi_hash_high = mc_filter[1]; |
| 967 | aup->mac->multi_hash_low = mc_filter[0]; |
| 968 | aup->mac->control &= ~MAC_PROMISCUOUS; |
| 969 | aup->mac->control |= MAC_HASH_MODE; |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | static int au1000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 974 | { |
| 975 | struct au1000_private *aup = netdev_priv(dev); |
| 976 | |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 977 | if (!netif_running(dev)) |
| 978 | return -EINVAL; |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 979 | |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 980 | if (!aup->phy_dev) |
| 981 | return -EINVAL; /* PHY not controllable */ |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 982 | |
Richard Cochran | 28b0411 | 2010-07-17 08:48:55 +0000 | [diff] [blame] | 983 | return phy_mii_ioctl(aup->phy_dev, rq, cmd); |
Florian Fainelli | 5ef3041 | 2009-01-22 14:06:25 -0800 | [diff] [blame] | 984 | } |
| 985 | |
Alexander Beregalov | d9a92ce | 2009-04-14 18:30:23 +0000 | [diff] [blame] | 986 | static const struct net_device_ops au1000_netdev_ops = { |
| 987 | .ndo_open = au1000_open, |
| 988 | .ndo_stop = au1000_close, |
| 989 | .ndo_start_xmit = au1000_tx, |
| 990 | .ndo_set_multicast_list = au1000_multicast_list, |
| 991 | .ndo_do_ioctl = au1000_ioctl, |
| 992 | .ndo_tx_timeout = au1000_tx_timeout, |
| 993 | .ndo_set_mac_address = eth_mac_addr, |
| 994 | .ndo_validate_addr = eth_validate_addr, |
| 995 | .ndo_change_mtu = eth_change_mtu, |
| 996 | }; |
| 997 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 998 | static int __devinit au1000_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | { |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 1000 | static unsigned version_printed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | struct au1000_private *aup = NULL; |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1002 | struct au1000_eth_platform_data *pd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | struct net_device *dev = NULL; |
Florian Fainelli | 3441592 | 2010-09-08 11:11:25 +0000 | [diff] [blame] | 1004 | struct db_dest *pDB, *pDBfree; |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1005 | int irq, i, err = 0; |
| 1006 | struct resource *base, *macen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1008 | base = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1009 | if (!base) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1010 | dev_err(&pdev->dev, "failed to retrieve base register\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1011 | err = -ENODEV; |
| 1012 | goto out; |
| 1013 | } |
Sergei Shtylyov | 89be050 | 2006-04-19 22:46:21 +0400 | [diff] [blame] | 1014 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1015 | macen = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 1016 | if (!macen) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1017 | dev_err(&pdev->dev, "failed to retrieve MAC Enable register\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1018 | err = -ENODEV; |
| 1019 | goto out; |
| 1020 | } |
Sergei Shtylyov | 89be050 | 2006-04-19 22:46:21 +0400 | [diff] [blame] | 1021 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1022 | irq = platform_get_irq(pdev, 0); |
| 1023 | if (irq < 0) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1024 | dev_err(&pdev->dev, "failed to retrieve IRQ\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1025 | err = -ENODEV; |
| 1026 | goto out; |
| 1027 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 1029 | if (!request_mem_region(base->start, resource_size(base), |
| 1030 | pdev->name)) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1031 | dev_err(&pdev->dev, "failed to request memory region for base registers\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1032 | err = -ENXIO; |
| 1033 | goto out; |
| 1034 | } |
| 1035 | |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 1036 | if (!request_mem_region(macen->start, resource_size(macen), |
| 1037 | pdev->name)) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1038 | dev_err(&pdev->dev, "failed to request memory region for MAC enable register\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1039 | err = -ENXIO; |
| 1040 | goto err_request; |
| 1041 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | |
| 1043 | dev = alloc_etherdev(sizeof(struct au1000_private)); |
| 1044 | if (!dev) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1045 | dev_err(&pdev->dev, "alloc_etherdev failed\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1046 | err = -ENOMEM; |
| 1047 | goto err_alloc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1050 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 1051 | platform_set_drvdata(pdev, dev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 1052 | aup = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | |
Martin Gebert | 533763d | 2008-07-23 09:40:09 +0200 | [diff] [blame] | 1054 | spin_lock_init(&aup->lock); |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 1055 | aup->msg_enable = (au1000_debug < 4 ? |
| 1056 | AU1000_DEF_MSG_ENABLE : au1000_debug); |
Martin Gebert | 533763d | 2008-07-23 09:40:09 +0200 | [diff] [blame] | 1057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | /* Allocate the data buffers */ |
| 1059 | /* Snooping works fine with eth on all au1xxx */ |
Sergei Shtylyov | 89be050 | 2006-04-19 22:46:21 +0400 | [diff] [blame] | 1060 | aup->vaddr = (u32)dma_alloc_noncoherent(NULL, MAX_BUF_SIZE * |
| 1061 | (NUM_TX_BUFFS + NUM_RX_BUFFS), |
| 1062 | &aup->dma_addr, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | if (!aup->vaddr) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1064 | dev_err(&pdev->dev, "failed to allocate data buffers\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1065 | err = -ENOMEM; |
| 1066 | goto err_vaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | /* aup->mac is the base address of the MAC's registers */ |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 1070 | aup->mac = (volatile struct mac_reg *) |
| 1071 | ioremap_nocache(base->start, resource_size(base)); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1072 | if (!aup->mac) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1073 | dev_err(&pdev->dev, "failed to ioremap MAC registers\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1074 | err = -ENXIO; |
| 1075 | goto err_remap1; |
| 1076 | } |
Sergei Shtylyov | 89be050 | 2006-04-19 22:46:21 +0400 | [diff] [blame] | 1077 | |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 1078 | /* Setup some variables for quick register address access */ |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 1079 | aup->enable = (volatile u32 *)ioremap_nocache(macen->start, |
| 1080 | resource_size(macen)); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1081 | if (!aup->enable) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1082 | dev_err(&pdev->dev, "failed to ioremap MAC enable register\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1083 | err = -ENXIO; |
| 1084 | goto err_remap2; |
| 1085 | } |
| 1086 | aup->mac_id = pdev->id; |
Sergei Shtylyov | 89be050 | 2006-04-19 22:46:21 +0400 | [diff] [blame] | 1087 | |
Manuel Lauss | f667365 | 2010-07-21 14:30:50 +0200 | [diff] [blame] | 1088 | if (pdev->id == 0) |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 1089 | au1000_setup_hw_rings(aup, MAC0_RX_DMA_ADDR, MAC0_TX_DMA_ADDR); |
Manuel Lauss | f667365 | 2010-07-21 14:30:50 +0200 | [diff] [blame] | 1090 | else if (pdev->id == 1) |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 1091 | au1000_setup_hw_rings(aup, MAC1_RX_DMA_ADDR, MAC1_TX_DMA_ADDR); |
Sergei Shtylyov | 89be050 | 2006-04-19 22:46:21 +0400 | [diff] [blame] | 1092 | |
Manuel Lauss | f667365 | 2010-07-21 14:30:50 +0200 | [diff] [blame] | 1093 | /* set a random MAC now in case platform_data doesn't provide one */ |
| 1094 | random_ether_addr(dev->dev_addr); |
Sergei Shtylyov | 89be050 | 2006-04-19 22:46:21 +0400 | [diff] [blame] | 1095 | |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 1096 | *aup->enable = 0; |
| 1097 | aup->mac_enabled = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1099 | pd = pdev->dev.platform_data; |
| 1100 | if (!pd) { |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 1101 | dev_info(&pdev->dev, "no platform_data passed," |
| 1102 | " PHY search on MAC0\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1103 | aup->phy1_search_mac0 = 1; |
| 1104 | } else { |
Manuel Lauss | f667365 | 2010-07-21 14:30:50 +0200 | [diff] [blame] | 1105 | if (is_valid_ether_addr(pd->mac)) |
| 1106 | memcpy(dev->dev_addr, pd->mac, 6); |
| 1107 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1108 | aup->phy_static_config = pd->phy_static_config; |
| 1109 | aup->phy_search_highest_addr = pd->phy_search_highest_addr; |
| 1110 | aup->phy1_search_mac0 = pd->phy1_search_mac0; |
| 1111 | aup->phy_addr = pd->phy_addr; |
| 1112 | aup->phy_busid = pd->phy_busid; |
| 1113 | aup->phy_irq = pd->phy_irq; |
| 1114 | } |
| 1115 | |
| 1116 | if (aup->phy_busid && aup->phy_busid > 0) { |
Florian Fainelli | 18b8e15 | 2010-09-08 11:11:40 +0000 | [diff] [blame] | 1117 | dev_err(&pdev->dev, "MAC0-associated PHY attached 2nd MACs MII bus not supported yet\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1118 | err = -ENODEV; |
| 1119 | goto err_mdiobus_alloc; |
| 1120 | } |
| 1121 | |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1122 | aup->mii_bus = mdiobus_alloc(); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1123 | if (aup->mii_bus == NULL) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1124 | dev_err(&pdev->dev, "failed to allocate mdiobus structure\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1125 | err = -ENOMEM; |
| 1126 | goto err_mdiobus_alloc; |
| 1127 | } |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1128 | |
| 1129 | aup->mii_bus->priv = dev; |
Adrian Bunk | 1210dde | 2008-10-12 21:02:19 -0700 | [diff] [blame] | 1130 | aup->mii_bus->read = au1000_mdiobus_read; |
| 1131 | aup->mii_bus->write = au1000_mdiobus_write; |
| 1132 | aup->mii_bus->reset = au1000_mdiobus_reset; |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1133 | aup->mii_bus->name = "au1000_eth_mii"; |
| 1134 | snprintf(aup->mii_bus->id, MII_BUS_ID_SIZE, "%x", aup->mac_id); |
| 1135 | aup->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); |
roel kluin | dcbfef8 | 2009-08-30 22:40:15 +0000 | [diff] [blame] | 1136 | if (aup->mii_bus->irq == NULL) |
| 1137 | goto err_out; |
| 1138 | |
Florian Fainelli | 2cc3c6b | 2010-04-06 22:09:06 +0000 | [diff] [blame] | 1139 | for (i = 0; i < PHY_MAX_ADDR; ++i) |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1140 | aup->mii_bus->irq[i] = PHY_POLL; |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 1141 | /* if known, set corresponding PHY IRQs */ |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1142 | if (aup->phy_static_config) |
| 1143 | if (aup->phy_irq && aup->phy_busid == aup->mac_id) |
| 1144 | aup->mii_bus->irq[aup->phy_addr] = aup->phy_irq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1146 | err = mdiobus_register(aup->mii_bus); |
| 1147 | if (err) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1148 | dev_err(&pdev->dev, "failed to register MDIO bus\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1149 | goto err_mdiobus_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | } |
| 1151 | |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 1152 | if (au1000_mii_probe(dev) != 0) |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1153 | goto err_out; |
| 1154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | pDBfree = NULL; |
| 1156 | /* setup the data buffer descriptors and attach a buffer to each one */ |
| 1157 | pDB = aup->db; |
| 1158 | for (i = 0; i < (NUM_TX_BUFFS+NUM_RX_BUFFS); i++) { |
| 1159 | pDB->pnext = pDBfree; |
| 1160 | pDBfree = pDB; |
| 1161 | pDB->vaddr = (u32 *)((unsigned)aup->vaddr + MAX_BUF_SIZE*i); |
| 1162 | pDB->dma_addr = (dma_addr_t)virt_to_bus(pDB->vaddr); |
| 1163 | pDB++; |
| 1164 | } |
| 1165 | aup->pDBfree = pDBfree; |
| 1166 | |
| 1167 | for (i = 0; i < NUM_RX_DMA; i++) { |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 1168 | pDB = au1000_GetFreeDB(aup); |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 1169 | if (!pDB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | goto err_out; |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 1171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | aup->rx_dma_ring[i]->buff_stat = (unsigned)pDB->dma_addr; |
| 1173 | aup->rx_db_inuse[i] = pDB; |
| 1174 | } |
| 1175 | for (i = 0; i < NUM_TX_DMA; i++) { |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 1176 | pDB = au1000_GetFreeDB(aup); |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 1177 | if (!pDB) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | goto err_out; |
Florian Fainelli | ec7eabdd | 2010-09-08 11:11:31 +0000 | [diff] [blame] | 1179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | aup->tx_dma_ring[i]->buff_stat = (unsigned)pDB->dma_addr; |
| 1181 | aup->tx_dma_ring[i]->len = 0; |
| 1182 | aup->tx_db_inuse[i] = pDB; |
| 1183 | } |
| 1184 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1185 | dev->base_addr = base->start; |
| 1186 | dev->irq = irq; |
| 1187 | dev->netdev_ops = &au1000_netdev_ops; |
| 1188 | SET_ETHTOOL_OPS(dev, &au1000_ethtool_ops); |
| 1189 | dev->watchdog_timeo = ETH_TX_TIMEOUT; |
| 1190 | |
Jeff Garzik | 6aa20a2 | 2006-09-13 13:24:59 -0400 | [diff] [blame] | 1191 | /* |
| 1192 | * The boot code uses the ethernet controller, so reset it to start |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | * fresh. au1000_init() expects that the device is in reset state. |
| 1194 | */ |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 1195 | au1000_reset_mac(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1197 | err = register_netdev(dev); |
| 1198 | if (err) { |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1199 | netdev_err(dev, "Cannot register net device, aborting.\n"); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1200 | goto err_out; |
| 1201 | } |
| 1202 | |
Florian Fainelli | 5368c72 | 2010-04-06 22:09:17 +0000 | [diff] [blame] | 1203 | netdev_info(dev, "Au1xx0 Ethernet found at 0x%lx, irq %d\n", |
| 1204 | (unsigned long)base->start, irq); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1205 | if (version_printed++ == 0) |
Florian Fainelli | 215e17b | 2010-09-08 11:11:45 +0000 | [diff] [blame] | 1206 | pr_info("%s version %s %s\n", |
| 1207 | DRV_NAME, DRV_VERSION, DRV_AUTHOR); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1208 | |
| 1209 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | |
| 1211 | err_out: |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1212 | if (aup->mii_bus != NULL) |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1213 | mdiobus_unregister(aup->mii_bus); |
Lennert Buytenhek | 298cf9b | 2008-10-08 16:29:57 -0700 | [diff] [blame] | 1214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | /* here we should have a valid dev plus aup-> register addresses |
| 1216 | * so we can reset the mac properly.*/ |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 1217 | au1000_reset_mac(dev); |
Herbert Valerio Riedel | 0638dec | 2006-06-01 09:41:04 +0200 | [diff] [blame] | 1218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | for (i = 0; i < NUM_RX_DMA; i++) { |
| 1220 | if (aup->rx_db_inuse[i]) |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 1221 | au1000_ReleaseDB(aup, aup->rx_db_inuse[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | } |
| 1223 | for (i = 0; i < NUM_TX_DMA; i++) { |
| 1224 | if (aup->tx_db_inuse[i]) |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 1225 | au1000_ReleaseDB(aup, aup->tx_db_inuse[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | } |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1227 | err_mdiobus_reg: |
| 1228 | mdiobus_free(aup->mii_bus); |
| 1229 | err_mdiobus_alloc: |
| 1230 | iounmap(aup->enable); |
| 1231 | err_remap2: |
| 1232 | iounmap(aup->mac); |
| 1233 | err_remap1: |
Sergei Shtylyov | 89be050 | 2006-04-19 22:46:21 +0400 | [diff] [blame] | 1234 | dma_free_noncoherent(NULL, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS), |
| 1235 | (void *)aup->vaddr, aup->dma_addr); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1236 | err_vaddr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | free_netdev(dev); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1238 | err_alloc: |
| 1239 | release_mem_region(macen->start, resource_size(macen)); |
| 1240 | err_request: |
| 1241 | release_mem_region(base->start, resource_size(base)); |
| 1242 | out: |
| 1243 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1246 | static int __devexit au1000_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1247 | { |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1248 | struct net_device *dev = platform_get_drvdata(pdev); |
| 1249 | struct au1000_private *aup = netdev_priv(dev); |
| 1250 | int i; |
| 1251 | struct resource *base, *macen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1253 | platform_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1255 | unregister_netdev(dev); |
| 1256 | mdiobus_unregister(aup->mii_bus); |
| 1257 | mdiobus_free(aup->mii_bus); |
| 1258 | |
| 1259 | for (i = 0; i < NUM_RX_DMA; i++) |
| 1260 | if (aup->rx_db_inuse[i]) |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 1261 | au1000_ReleaseDB(aup, aup->rx_db_inuse[i]); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1262 | |
| 1263 | for (i = 0; i < NUM_TX_DMA; i++) |
| 1264 | if (aup->tx_db_inuse[i]) |
Florian Fainelli | eb04963 | 2010-04-06 22:09:01 +0000 | [diff] [blame] | 1265 | au1000_ReleaseDB(aup, aup->tx_db_inuse[i]); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1266 | |
| 1267 | dma_free_noncoherent(NULL, MAX_BUF_SIZE * |
| 1268 | (NUM_TX_BUFFS + NUM_RX_BUFFS), |
| 1269 | (void *)aup->vaddr, aup->dma_addr); |
| 1270 | |
| 1271 | iounmap(aup->mac); |
| 1272 | iounmap(aup->enable); |
| 1273 | |
| 1274 | base = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1275 | release_mem_region(base->start, resource_size(base)); |
| 1276 | |
| 1277 | macen = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 1278 | release_mem_region(macen->start, resource_size(macen)); |
| 1279 | |
| 1280 | free_netdev(dev); |
| 1281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | return 0; |
| 1283 | } |
| 1284 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1285 | static struct platform_driver au1000_eth_driver = { |
| 1286 | .probe = au1000_probe, |
| 1287 | .remove = __devexit_p(au1000_remove), |
| 1288 | .driver = { |
| 1289 | .name = "au1000-eth", |
| 1290 | .owner = THIS_MODULE, |
| 1291 | }, |
| 1292 | }; |
| 1293 | MODULE_ALIAS("platform:au1000-eth"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1295 | |
| 1296 | static int __init au1000_init_module(void) |
| 1297 | { |
| 1298 | return platform_driver_register(&au1000_eth_driver); |
| 1299 | } |
| 1300 | |
| 1301 | static void __exit au1000_exit_module(void) |
| 1302 | { |
| 1303 | platform_driver_unregister(&au1000_eth_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | module_init(au1000_init_module); |
Florian Fainelli | bd2302c | 2009-11-10 01:13:38 +0100 | [diff] [blame] | 1307 | module_exit(au1000_exit_module); |