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