blob: ecc2573b3dce29d7580331b1e9339fa458872fdb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 *
3 * Alchemy Au1x00 ethernet driver
4 *
Sergei Shtylyov89be0502006-04-19 22:46:21 +04005 * Copyright 2001-2003, 2006 MontaVista Software Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Copyright 2002 TimeSys Corp.
7 * Added ethtool/mii-tool support,
8 * Copyright 2004 Matt Porter <mporter@kernel.crashing.org>
Jeff Garzik6aa20a22006-09-13 13:24:59 -04009 * Update: 2004 Bjoern Riemer, riemer@fokus.fraunhofer.de
10 * or riemer@riemer-nt.de: fixed the link beat detection with
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * ioctls (SIOCGMIIPHY)
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +020012 * Copyright 2006 Herbert Valerio Riedel <hvr@gnu.org>
13 * converted to use linux-2.6.x's PHY framework
14 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * 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 Garzik6aa20a22006-09-13 13:24:59 -040035 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 */
Ralf Baechled791c2b2007-06-24 15:59:54 +020037#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/module.h>
39#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include <linux/string.h>
41#include <linux/timer.h>
42#include <linux/errno.h>
43#include <linux/in.h>
44#include <linux/ioport.h>
45#include <linux/bitops.h>
46#include <linux/slab.h>
47#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/init.h>
49#include <linux/netdevice.h>
50#include <linux/etherdevice.h>
51#include <linux/ethtool.h>
52#include <linux/mii.h>
53#include <linux/skbuff.h>
54#include <linux/delay.h>
Herbert Valerio Riedel8cd35da2006-05-01 15:37:09 +020055#include <linux/crc32.h>
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +020056#include <linux/phy.h>
Yoichi Yuasa25b31cb2007-10-15 19:11:24 +090057
58#include <asm/cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#include <asm/mipsregs.h>
60#include <asm/irq.h>
61#include <asm/io.h>
62#include <asm/processor.h>
63
Yoichi Yuasa25b31cb2007-10-15 19:11:24 +090064#include <au1000.h>
65#include <prom.h>
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067#include "au1000_eth.h"
68
69#ifdef AU1000_ETH_DEBUG
70static int au1000_debug = 5;
71#else
72static int au1000_debug = 3;
73#endif
74
Sergei Shtylyov89be0502006-04-19 22:46:21 +040075#define DRV_NAME "au1000_eth"
Andy Gospodarekd5b20692006-09-11 17:39:18 -040076#define DRV_VERSION "1.6"
Linus Torvalds1da177e2005-04-16 15:20:36 -070077#define DRV_AUTHOR "Pete Popov <ppopov@embeddedalley.com>"
78#define DRV_DESC "Au1xxx on-chip Ethernet driver"
79
80MODULE_AUTHOR(DRV_AUTHOR);
81MODULE_DESCRIPTION(DRV_DESC);
82MODULE_LICENSE("GPL");
83
84// prototypes
85static void hard_stop(struct net_device *);
86static void enable_rx_tx(struct net_device *dev);
Sergei Shtylyov89be0502006-04-19 22:46:21 +040087static struct net_device * au1000_probe(int port_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088static int au1000_init(struct net_device *);
89static int au1000_open(struct net_device *);
90static int au1000_close(struct net_device *);
91static int au1000_tx(struct sk_buff *, struct net_device *);
92static int au1000_rx(struct net_device *);
David Howells7d12e782006-10-05 14:55:46 +010093static irqreturn_t au1000_interrupt(int, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070094static void au1000_tx_timeout(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095static void set_rx_mode(struct net_device *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096static int au1000_ioctl(struct net_device *, struct ifreq *, int);
Adrian Bunk1210dde2008-10-12 21:02:19 -070097static int au1000_mdio_read(struct net_device *, int, int);
98static void au1000_mdio_write(struct net_device *, int, int, u16);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +020099static void au1000_adjust_link(struct net_device *);
100static void enable_mac(struct net_device *, int);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102/*
103 * Theory of operation
104 *
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400105 * The Au1000 MACs use a simple rx and tx descriptor ring scheme.
106 * There are four receive and four transmit descriptors. These
107 * descriptors are not in memory; rather, they are just a set of
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 * hardware registers.
109 *
110 * Since the Au1000 has a coherent data cache, the receive and
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400111 * transmit buffers are allocated from the KSEG0 segment. The
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 * hardware registers, however, are still mapped at KSEG1 to
113 * make sure there's no out-of-order writes, and that all writes
114 * complete immediately.
115 */
116
117/* These addresses are only used if yamon doesn't tell us what
118 * the mac address is, and the mac address is not passed on the
119 * command line.
120 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400121static unsigned char au1000_mac_addr[6] __devinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 0x00, 0x50, 0xc2, 0x0c, 0x30, 0x00
123};
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125struct au1000_private *au_macs[NUM_ETH_INTERFACES];
126
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200127/*
128 * board-specific configurations
129 *
130 * PHY detection algorithm
131 *
132 * If AU1XXX_PHY_STATIC_CONFIG is undefined, the PHY setup is
133 * autodetected:
134 *
135 * mii_probe() first searches the current MAC's MII bus for a PHY,
136 * selecting the first (or last, if AU1XXX_PHY_SEARCH_HIGHEST_ADDR is
137 * defined) PHY address not already claimed by another netdev.
138 *
139 * If nothing was found that way when searching for the 2nd ethernet
140 * controller's PHY and AU1XXX_PHY1_SEARCH_ON_MAC0 is defined, then
141 * the first MII bus is searched as well for an unclaimed PHY; this is
142 * needed in case of a dual-PHY accessible only through the MAC0's MII
143 * bus.
144 *
145 * Finally, if no PHY is found, then the corresponding ethernet
146 * controller is not registered to the network subsystem.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 */
148
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200149/* autodetection defaults */
150#undef AU1XXX_PHY_SEARCH_HIGHEST_ADDR
151#define AU1XXX_PHY1_SEARCH_ON_MAC0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200153/* static PHY setup
154 *
155 * most boards PHY setup should be detectable properly with the
156 * autodetection algorithm in mii_probe(), but in some cases (e.g. if
157 * you have a switch attached, or want to use the PHY's interrupt
158 * notification capabilities) you can provide a static PHY
159 * configuration here
160 *
161 * IRQs may only be set, if a PHY address was configured
162 * If a PHY address is given, also a bus id is required to be set
163 *
164 * ps: make sure the used irqs are configured properly in the board
165 * specific irq-map
166 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200168#if defined(CONFIG_MIPS_BOSPORUS)
169/*
170 * Micrel/Kendin 5 port switch attached to MAC0,
171 * MAC0 is associated with PHY address 5 (== WAN port)
172 * MAC1 is not associated with any PHY, since it's connected directly
173 * to the switch.
174 * no interrupts are used
175 */
176# define AU1XXX_PHY_STATIC_CONFIG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200178# define AU1XXX_PHY0_ADDR 5
179# define AU1XXX_PHY0_BUSID 0
180# undef AU1XXX_PHY0_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200182# undef AU1XXX_PHY1_ADDR
183# undef AU1XXX_PHY1_BUSID
184# undef AU1XXX_PHY1_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185#endif
186
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200187#if defined(AU1XXX_PHY0_BUSID) && (AU1XXX_PHY0_BUSID > 0)
188# error MAC0-associated PHY attached 2nd MACs MII bus not supported yet
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189#endif
190
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200191/*
192 * MII operations
193 */
Adrian Bunk1210dde2008-10-12 21:02:19 -0700194static int au1000_mdio_read(struct net_device *dev, int phy_addr, int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Wang Chen454d7c92008-11-12 23:37:49 -0800196 struct au1000_private *aup = netdev_priv(dev);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200197 volatile u32 *const mii_control_reg = &aup->mac->mii_control;
198 volatile u32 *const mii_data_reg = &aup->mac->mii_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 u32 timedout = 20;
200 u32 mii_control;
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 while (*mii_control_reg & MAC_MII_BUSY) {
203 mdelay(1);
204 if (--timedout == 0) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400205 printk(KERN_ERR "%s: read_MII busy timeout!!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 dev->name);
207 return -1;
208 }
209 }
210
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400211 mii_control = MAC_SET_MII_SELECT_REG(reg) |
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200212 MAC_SET_MII_SELECT_PHY(phy_addr) | MAC_MII_READ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 *mii_control_reg = mii_control;
215
216 timedout = 20;
217 while (*mii_control_reg & MAC_MII_BUSY) {
218 mdelay(1);
219 if (--timedout == 0) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400220 printk(KERN_ERR "%s: mdio_read busy timeout!!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 dev->name);
222 return -1;
223 }
224 }
225 return (int)*mii_data_reg;
226}
227
Adrian Bunk1210dde2008-10-12 21:02:19 -0700228static void au1000_mdio_write(struct net_device *dev, int phy_addr,
229 int reg, u16 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Wang Chen454d7c92008-11-12 23:37:49 -0800231 struct au1000_private *aup = netdev_priv(dev);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200232 volatile u32 *const mii_control_reg = &aup->mac->mii_control;
233 volatile u32 *const mii_data_reg = &aup->mac->mii_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 u32 timedout = 20;
235 u32 mii_control;
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 while (*mii_control_reg & MAC_MII_BUSY) {
238 mdelay(1);
239 if (--timedout == 0) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400240 printk(KERN_ERR "%s: mdio_write busy timeout!!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 dev->name);
242 return;
243 }
244 }
245
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400246 mii_control = MAC_SET_MII_SELECT_REG(reg) |
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200247 MAC_SET_MII_SELECT_PHY(phy_addr) | MAC_MII_WRITE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 *mii_data_reg = value;
250 *mii_control_reg = mii_control;
251}
252
Adrian Bunk1210dde2008-10-12 21:02:19 -0700253static int au1000_mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200255 /* WARNING: bus->phy_map[phy_addr].attached_dev == dev does
256 * _NOT_ hold (e.g. when PHY is accessed through other MAC's MII bus) */
257 struct net_device *const dev = bus->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200259 enable_mac(dev, 0); /* make sure the MAC associated with this
260 * mii_bus is enabled */
Adrian Bunk1210dde2008-10-12 21:02:19 -0700261 return au1000_mdio_read(dev, phy_addr, regnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
263
Adrian Bunk1210dde2008-10-12 21:02:19 -0700264static int au1000_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum,
265 u16 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200267 struct net_device *const dev = bus->priv;
268
269 enable_mac(dev, 0); /* make sure the MAC associated with this
270 * mii_bus is enabled */
Adrian Bunk1210dde2008-10-12 21:02:19 -0700271 au1000_mdio_write(dev, phy_addr, regnum, value);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200272 return 0;
273}
274
Adrian Bunk1210dde2008-10-12 21:02:19 -0700275static int au1000_mdiobus_reset(struct mii_bus *bus)
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200276{
277 struct net_device *const dev = bus->priv;
278
279 enable_mac(dev, 0); /* make sure the MAC associated with this
280 * mii_bus is enabled */
281 return 0;
282}
283
284static int mii_probe (struct net_device *dev)
285{
Wang Chen454d7c92008-11-12 23:37:49 -0800286 struct au1000_private *const aup = netdev_priv(dev);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200287 struct phy_device *phydev = NULL;
288
289#if defined(AU1XXX_PHY_STATIC_CONFIG)
290 BUG_ON(aup->mac_id < 0 || aup->mac_id > 1);
291
292 if(aup->mac_id == 0) { /* get PHY0 */
293# if defined(AU1XXX_PHY0_ADDR)
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700294 phydev = au_macs[AU1XXX_PHY0_BUSID]->mii_bus->phy_map[AU1XXX_PHY0_ADDR];
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200295# else
296 printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n",
297 dev->name);
298 return 0;
299# endif /* defined(AU1XXX_PHY0_ADDR) */
300 } else if (aup->mac_id == 1) { /* get PHY1 */
301# if defined(AU1XXX_PHY1_ADDR)
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700302 phydev = au_macs[AU1XXX_PHY1_BUSID]->mii_bus->phy_map[AU1XXX_PHY1_ADDR];
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200303# else
304 printk (KERN_INFO DRV_NAME ":%s: using PHY-less setup\n",
305 dev->name);
306 return 0;
307# endif /* defined(AU1XXX_PHY1_ADDR) */
308 }
309
310#else /* defined(AU1XXX_PHY_STATIC_CONFIG) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 int phy_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200313 /* find the first (lowest address) PHY on the current MAC's MII bus */
314 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++)
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700315 if (aup->mii_bus->phy_map[phy_addr]) {
316 phydev = aup->mii_bus->phy_map[phy_addr];
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200317# if !defined(AU1XXX_PHY_SEARCH_HIGHEST_ADDR)
318 break; /* break out with first one found */
319# endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200322# if defined(AU1XXX_PHY1_SEARCH_ON_MAC0)
323 /* try harder to find a PHY */
324 if (!phydev && (aup->mac_id == 1)) {
325 /* no PHY found, maybe we have a dual PHY? */
326 printk (KERN_INFO DRV_NAME ": no PHY found on MAC1, "
327 "let's see if it's attached to MAC0...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200329 BUG_ON(!au_macs[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200331 /* find the first (lowest address) non-attached PHY on
332 * the MAC0 MII bus */
333 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
334 struct phy_device *const tmp_phydev =
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700335 au_macs[0]->mii_bus->phy_map[phy_addr];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200337 if (!tmp_phydev)
338 continue; /* no PHY here... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200340 if (tmp_phydev->attached_dev)
341 continue; /* already claimed by MAC0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200343 phydev = tmp_phydev;
344 break; /* found it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
346 }
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200347# endif /* defined(AU1XXX_PHY1_SEARCH_OTHER_BUS) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200349#endif /* defined(AU1XXX_PHY_STATIC_CONFIG) */
350 if (!phydev) {
351 printk (KERN_ERR DRV_NAME ":%s: no PHY found\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 return -1;
353 }
354
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200355 /* now we are supposed to have a proper phydev, to attach to... */
356 BUG_ON(!phydev);
357 BUG_ON(phydev->attached_dev);
358
Andy Fleminge8a2b6a2006-12-01 12:01:06 -0600359 phydev = phy_connect(dev, phydev->dev.bus_id, &au1000_adjust_link, 0,
360 PHY_INTERFACE_MODE_MII);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200361
362 if (IS_ERR(phydev)) {
363 printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
364 return PTR_ERR(phydev);
365 }
366
367 /* mask with MAC supported features */
368 phydev->supported &= (SUPPORTED_10baseT_Half
369 | SUPPORTED_10baseT_Full
370 | SUPPORTED_100baseT_Half
371 | SUPPORTED_100baseT_Full
372 | SUPPORTED_Autoneg
373 /* | SUPPORTED_Pause | SUPPORTED_Asym_Pause */
374 | SUPPORTED_MII
375 | SUPPORTED_TP);
376
377 phydev->advertising = phydev->supported;
378
379 aup->old_link = 0;
380 aup->old_speed = 0;
381 aup->old_duplex = -1;
382 aup->phy_dev = phydev;
383
384 printk(KERN_INFO "%s: attached PHY driver [%s] "
385 "(mii_bus:phy_addr=%s, irq=%d)\n",
386 dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
388 return 0;
389}
390
391
392/*
393 * Buffer allocation/deallocation routines. The buffer descriptor returned
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400394 * has the virtual and dma address of a buffer suitable for
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 * both, receive and transmit operations.
396 */
397static db_dest_t *GetFreeDB(struct au1000_private *aup)
398{
399 db_dest_t *pDB;
400 pDB = aup->pDBfree;
401
402 if (pDB) {
403 aup->pDBfree = pDB->pnext;
404 }
405 return pDB;
406}
407
408void ReleaseDB(struct au1000_private *aup, db_dest_t *pDB)
409{
410 db_dest_t *pDBfree = aup->pDBfree;
411 if (pDBfree)
412 pDBfree->pnext = pDB;
413 aup->pDBfree = pDB;
414}
415
416static void enable_rx_tx(struct net_device *dev)
417{
Wang Chen454d7c92008-11-12 23:37:49 -0800418 struct au1000_private *aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420 if (au1000_debug > 4)
421 printk(KERN_INFO "%s: enable_rx_tx\n", dev->name);
422
423 aup->mac->control |= (MAC_RX_ENABLE | MAC_TX_ENABLE);
424 au_sync_delay(10);
425}
426
427static void hard_stop(struct net_device *dev)
428{
Wang Chen454d7c92008-11-12 23:37:49 -0800429 struct au1000_private *aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
431 if (au1000_debug > 4)
432 printk(KERN_INFO "%s: hard stop\n", dev->name);
433
434 aup->mac->control &= ~(MAC_RX_ENABLE | MAC_TX_ENABLE);
435 au_sync_delay(10);
436}
437
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200438static void enable_mac(struct net_device *dev, int force_reset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200440 unsigned long flags;
Wang Chen454d7c92008-11-12 23:37:49 -0800441 struct au1000_private *aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 spin_lock_irqsave(&aup->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200445 if(force_reset || (!aup->mac_enabled)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 *aup->enable = MAC_EN_CLOCK_ENABLE;
447 au_sync_delay(2);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200448 *aup->enable = (MAC_EN_RESET0 | MAC_EN_RESET1 | MAC_EN_RESET2
449 | MAC_EN_CLOCK_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 au_sync_delay(2);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200451
452 aup->mac_enabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 }
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200454
455 spin_unlock_irqrestore(&aup->lock, flags);
456}
457
458static void reset_mac_unlocked(struct net_device *dev)
459{
Wang Chen454d7c92008-11-12 23:37:49 -0800460 struct au1000_private *const aup = netdev_priv(dev);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200461 int i;
462
463 hard_stop(dev);
464
465 *aup->enable = MAC_EN_CLOCK_ENABLE;
466 au_sync_delay(2);
467 *aup->enable = 0;
468 au_sync_delay(2);
469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 aup->tx_full = 0;
471 for (i = 0; i < NUM_RX_DMA; i++) {
472 /* reset control bits */
473 aup->rx_dma_ring[i]->buff_stat &= ~0xf;
474 }
475 for (i = 0; i < NUM_TX_DMA; i++) {
476 /* reset control bits */
477 aup->tx_dma_ring[i]->buff_stat &= ~0xf;
478 }
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200479
480 aup->mac_enabled = 0;
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482}
483
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200484static void reset_mac(struct net_device *dev)
485{
Wang Chen454d7c92008-11-12 23:37:49 -0800486 struct au1000_private *const aup = netdev_priv(dev);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200487 unsigned long flags;
488
489 if (au1000_debug > 4)
490 printk(KERN_INFO "%s: reset mac, aup %x\n",
491 dev->name, (unsigned)aup);
492
493 spin_lock_irqsave(&aup->lock, flags);
494
495 reset_mac_unlocked (dev);
496
497 spin_unlock_irqrestore(&aup->lock, flags);
498}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400500/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 * Setup the receive and transmit "rings". These pointers are the addresses
502 * of the rx and tx MAC DMA registers so they are fixed by the hardware --
503 * these are not descriptors sitting in memory.
504 */
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400505static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506setup_hw_rings(struct au1000_private *aup, u32 rx_base, u32 tx_base)
507{
508 int i;
509
510 for (i = 0; i < NUM_RX_DMA; i++) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400511 aup->rx_dma_ring[i] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 (volatile rx_dma_t *) (rx_base + sizeof(rx_dma_t)*i);
513 }
514 for (i = 0; i < NUM_TX_DMA; i++) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400515 aup->tx_dma_ring[i] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 (volatile tx_dma_t *) (tx_base + sizeof(tx_dma_t)*i);
517 }
518}
519
520static struct {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 u32 base_addr;
522 u32 macen_addr;
523 int irq;
524 struct net_device *dev;
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400525} iflist[2] = {
526#ifdef CONFIG_SOC_AU1000
527 {AU1000_ETH0_BASE, AU1000_MAC0_ENABLE, AU1000_MAC0_DMA_INT},
528 {AU1000_ETH1_BASE, AU1000_MAC1_ENABLE, AU1000_MAC1_DMA_INT}
529#endif
530#ifdef CONFIG_SOC_AU1100
531 {AU1100_ETH0_BASE, AU1100_MAC0_ENABLE, AU1100_MAC0_DMA_INT}
532#endif
533#ifdef CONFIG_SOC_AU1500
534 {AU1500_ETH0_BASE, AU1500_MAC0_ENABLE, AU1500_MAC0_DMA_INT},
535 {AU1500_ETH1_BASE, AU1500_MAC1_ENABLE, AU1500_MAC1_DMA_INT}
536#endif
537#ifdef CONFIG_SOC_AU1550
538 {AU1550_ETH0_BASE, AU1550_MAC0_ENABLE, AU1550_MAC0_DMA_INT},
539 {AU1550_ETH1_BASE, AU1550_MAC1_ENABLE, AU1550_MAC1_DMA_INT}
540#endif
541};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543static int num_ifs;
544
545/*
Robert P. J. Day3a4fa0a2007-10-19 23:10:43 +0200546 * Setup the base address and interrupt of the Au1xxx ethernet macs
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 * based on cpu type and whether the interface is enabled in sys_pinfunc
548 * register. The last interface is enabled if SYS_PF_NI2 (bit 4) is 0.
549 */
550static int __init au1000_init_module(void)
551{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 int ni = (int)((au_readl(SYS_PINFUNC) & (u32)(SYS_PF_NI2)) >> 4);
553 struct net_device *dev;
554 int i, found_one = 0;
555
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400556 num_ifs = NUM_ETH_INTERFACES - ni;
557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 for(i = 0; i < num_ifs; i++) {
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400559 dev = au1000_probe(i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 iflist[i].dev = dev;
561 if (dev)
562 found_one++;
563 }
564 if (!found_one)
565 return -ENODEV;
566 return 0;
567}
568
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200569/*
570 * ethtool operations
571 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573static int au1000_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
574{
Wang Chen454d7c92008-11-12 23:37:49 -0800575 struct au1000_private *aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200577 if (aup->phy_dev)
578 return phy_ethtool_gset(aup->phy_dev, cmd);
579
580 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581}
582
583static int au1000_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
584{
Wang Chen454d7c92008-11-12 23:37:49 -0800585 struct au1000_private *aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200587 if (!capable(CAP_NET_ADMIN))
588 return -EPERM;
589
590 if (aup->phy_dev)
591 return phy_ethtool_sset(aup->phy_dev, cmd);
592
593 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594}
595
596static void
597au1000_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
598{
Wang Chen454d7c92008-11-12 23:37:49 -0800599 struct au1000_private *aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 strcpy(info->driver, DRV_NAME);
602 strcpy(info->version, DRV_VERSION);
603 info->fw_version[0] = '\0';
604 sprintf(info->bus_info, "%s %d", DRV_NAME, aup->mac_id);
605 info->regdump_len = 0;
606}
607
Jeff Garzik7282d492006-09-13 14:30:00 -0400608static const struct ethtool_ops au1000_ethtool_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 .get_settings = au1000_get_settings,
610 .set_settings = au1000_set_settings,
611 .get_drvinfo = au1000_get_drvinfo,
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200612 .get_link = ethtool_op_get_link,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613};
614
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400615static struct net_device * au1000_probe(int port_num)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616{
617 static unsigned version_printed = 0;
618 struct au1000_private *aup = NULL;
619 struct net_device *dev = NULL;
620 db_dest_t *pDB, *pDBfree;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 char ethaddr[6];
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400622 int irq, i, err;
623 u32 base, macen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400625 if (port_num >= NUM_ETH_INTERFACES)
626 return NULL;
627
628 base = CPHYSADDR(iflist[port_num].base_addr );
629 macen = CPHYSADDR(iflist[port_num].macen_addr);
630 irq = iflist[port_num].irq;
631
632 if (!request_mem_region( base, MAC_IOSIZE, "Au1x00 ENET") ||
633 !request_mem_region(macen, 4, "Au1x00 ENET"))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 return NULL;
635
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400636 if (version_printed++ == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 printk("%s version %s %s\n", DRV_NAME, DRV_VERSION, DRV_AUTHOR);
638
639 dev = alloc_etherdev(sizeof(struct au1000_private));
640 if (!dev) {
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400641 printk(KERN_ERR "%s: alloc_etherdev failed\n", DRV_NAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 return NULL;
643 }
644
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400645 if ((err = register_netdev(dev)) != 0) {
646 printk(KERN_ERR "%s: Cannot register net device, error %d\n",
647 DRV_NAME, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 free_netdev(dev);
649 return NULL;
650 }
651
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400652 printk("%s: Au1xx0 Ethernet found at 0x%x, irq %d\n",
653 dev->name, base, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
Wang Chen454d7c92008-11-12 23:37:49 -0800655 aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Martin Gebert533763d2008-07-23 09:40:09 +0200657 spin_lock_init(&aup->lock);
658
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 /* Allocate the data buffers */
660 /* Snooping works fine with eth on all au1xxx */
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400661 aup->vaddr = (u32)dma_alloc_noncoherent(NULL, MAX_BUF_SIZE *
662 (NUM_TX_BUFFS + NUM_RX_BUFFS),
663 &aup->dma_addr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 if (!aup->vaddr) {
665 free_netdev(dev);
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400666 release_mem_region( base, MAC_IOSIZE);
667 release_mem_region(macen, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return NULL;
669 }
670
671 /* aup->mac is the base address of the MAC's registers */
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400672 aup->mac = (volatile mac_reg_t *)iflist[port_num].base_addr;
673
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 /* Setup some variables for quick register address access */
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400675 aup->enable = (volatile u32 *)iflist[port_num].macen_addr;
676 aup->mac_id = port_num;
677 au_macs[port_num] = aup;
678
679 if (port_num == 0) {
Yoichi Yuasa2de88922007-10-15 19:06:20 +0900680 if (prom_get_ethernet_addr(ethaddr) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 memcpy(au1000_mac_addr, ethaddr, sizeof(au1000_mac_addr));
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400682 else {
Yoichi Yuasa2de88922007-10-15 19:06:20 +0900683 printk(KERN_INFO "%s: No MAC address found\n",
684 dev->name);
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400685 /* Use the hard coded MAC addresses */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400688 setup_hw_rings(aup, MAC0_RX_DMA_ADDR, MAC0_TX_DMA_ADDR);
689 } else if (port_num == 1)
690 setup_hw_rings(aup, MAC1_RX_DMA_ADDR, MAC1_TX_DMA_ADDR);
691
692 /*
693 * Assign to the Ethernet ports two consecutive MAC addresses
694 * to match those that are printed on their stickers
695 */
696 memcpy(dev->dev_addr, au1000_mac_addr, sizeof(au1000_mac_addr));
697 dev->dev_addr[5] += port_num;
698
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200699 *aup->enable = 0;
700 aup->mac_enabled = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700702 aup->mii_bus = mdiobus_alloc();
703 if (aup->mii_bus == NULL)
704 goto err_out;
705
706 aup->mii_bus->priv = dev;
Adrian Bunk1210dde2008-10-12 21:02:19 -0700707 aup->mii_bus->read = au1000_mdiobus_read;
708 aup->mii_bus->write = au1000_mdiobus_write;
709 aup->mii_bus->reset = au1000_mdiobus_reset;
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700710 aup->mii_bus->name = "au1000_eth_mii";
711 snprintf(aup->mii_bus->id, MII_BUS_ID_SIZE, "%x", aup->mac_id);
712 aup->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200713 for(i = 0; i < PHY_MAX_ADDR; ++i)
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700714 aup->mii_bus->irq[i] = PHY_POLL;
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200715
716 /* if known, set corresponding PHY IRQs */
717#if defined(AU1XXX_PHY_STATIC_CONFIG)
718# if defined(AU1XXX_PHY0_IRQ)
Andy Fleming9d9326d2008-04-09 19:38:13 -0500719 if (AU1XXX_PHY0_BUSID == aup->mac_id)
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700720 aup->mii_bus->irq[AU1XXX_PHY0_ADDR] = AU1XXX_PHY0_IRQ;
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200721# endif
722# if defined(AU1XXX_PHY1_IRQ)
Andy Fleming9d9326d2008-04-09 19:38:13 -0500723 if (AU1XXX_PHY1_BUSID == aup->mac_id)
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700724 aup->mii_bus->irq[AU1XXX_PHY1_ADDR] = AU1XXX_PHY1_IRQ;
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200725# endif
726#endif
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700727 mdiobus_register(aup->mii_bus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
729 if (mii_probe(dev) != 0) {
730 goto err_out;
731 }
732
733 pDBfree = NULL;
734 /* setup the data buffer descriptors and attach a buffer to each one */
735 pDB = aup->db;
736 for (i = 0; i < (NUM_TX_BUFFS+NUM_RX_BUFFS); i++) {
737 pDB->pnext = pDBfree;
738 pDBfree = pDB;
739 pDB->vaddr = (u32 *)((unsigned)aup->vaddr + MAX_BUF_SIZE*i);
740 pDB->dma_addr = (dma_addr_t)virt_to_bus(pDB->vaddr);
741 pDB++;
742 }
743 aup->pDBfree = pDBfree;
744
745 for (i = 0; i < NUM_RX_DMA; i++) {
746 pDB = GetFreeDB(aup);
747 if (!pDB) {
748 goto err_out;
749 }
750 aup->rx_dma_ring[i]->buff_stat = (unsigned)pDB->dma_addr;
751 aup->rx_db_inuse[i] = pDB;
752 }
753 for (i = 0; i < NUM_TX_DMA; i++) {
754 pDB = GetFreeDB(aup);
755 if (!pDB) {
756 goto err_out;
757 }
758 aup->tx_dma_ring[i]->buff_stat = (unsigned)pDB->dma_addr;
759 aup->tx_dma_ring[i]->len = 0;
760 aup->tx_db_inuse[i] = pDB;
761 }
762
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400763 dev->base_addr = base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 dev->irq = irq;
765 dev->open = au1000_open;
766 dev->hard_start_xmit = au1000_tx;
767 dev->stop = au1000_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 dev->set_multicast_list = &set_rx_mode;
769 dev->do_ioctl = &au1000_ioctl;
770 SET_ETHTOOL_OPS(dev, &au1000_ethtool_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 dev->tx_timeout = au1000_tx_timeout;
772 dev->watchdog_timeo = ETH_TX_TIMEOUT;
773
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400774 /*
775 * The boot code uses the ethernet controller, so reset it to start
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 * fresh. au1000_init() expects that the device is in reset state.
777 */
778 reset_mac(dev);
779
780 return dev;
781
782err_out:
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700783 if (aup->mii_bus != NULL) {
784 mdiobus_unregister(aup->mii_bus);
785 mdiobus_free(aup->mii_bus);
786 }
787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 /* here we should have a valid dev plus aup-> register addresses
789 * so we can reset the mac properly.*/
790 reset_mac(dev);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200791
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 for (i = 0; i < NUM_RX_DMA; i++) {
793 if (aup->rx_db_inuse[i])
794 ReleaseDB(aup, aup->rx_db_inuse[i]);
795 }
796 for (i = 0; i < NUM_TX_DMA; i++) {
797 if (aup->tx_db_inuse[i])
798 ReleaseDB(aup, aup->tx_db_inuse[i]);
799 }
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400800 dma_free_noncoherent(NULL, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS),
801 (void *)aup->vaddr, aup->dma_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 unregister_netdev(dev);
803 free_netdev(dev);
Sergei Shtylyov89be0502006-04-19 22:46:21 +0400804 release_mem_region( base, MAC_IOSIZE);
805 release_mem_region(macen, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 return NULL;
807}
808
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400809/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 * Initialize the interface.
811 *
812 * When the device powers up, the clocks are disabled and the
813 * mac is in reset state. When the interface is closed, we
814 * do the same -- reset the device and disable the clocks to
815 * conserve power. Thus, whenever au1000_init() is called,
816 * the device should already be in reset state.
817 */
818static int au1000_init(struct net_device *dev)
819{
Wang Chen454d7c92008-11-12 23:37:49 -0800820 struct au1000_private *aup = netdev_priv(dev);
Vegard Nossum2726fcf2008-08-06 14:12:11 +0200821 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 int i;
823 u32 control;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Jeff Garzik6aa20a22006-09-13 13:24:59 -0400825 if (au1000_debug > 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 printk("%s: au1000_init\n", dev->name);
827
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 /* bring the device out of reset */
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200829 enable_mac(dev, 1);
830
831 spin_lock_irqsave(&aup->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832
833 aup->mac->control = 0;
834 aup->tx_head = (aup->tx_dma_ring[0]->buff_stat & 0xC) >> 2;
835 aup->tx_tail = aup->tx_head;
836 aup->rx_head = (aup->rx_dma_ring[0]->buff_stat & 0xC) >> 2;
837
838 aup->mac->mac_addr_high = dev->dev_addr[5]<<8 | dev->dev_addr[4];
839 aup->mac->mac_addr_low = dev->dev_addr[3]<<24 | dev->dev_addr[2]<<16 |
840 dev->dev_addr[1]<<8 | dev->dev_addr[0];
841
842 for (i = 0; i < NUM_RX_DMA; i++) {
843 aup->rx_dma_ring[i]->buff_stat |= RX_DMA_ENABLE;
844 }
845 au_sync();
846
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200847 control = MAC_RX_ENABLE | MAC_TX_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848#ifndef CONFIG_CPU_LITTLE_ENDIAN
849 control |= MAC_BIG_ENDIAN;
850#endif
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200851 if (aup->phy_dev) {
852 if (aup->phy_dev->link && (DUPLEX_FULL == aup->phy_dev->duplex))
853 control |= MAC_FULL_DUPLEX;
854 else
855 control |= MAC_DISABLE_RX_OWN;
856 } else { /* PHY-less op, assume full-duplex */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 control |= MAC_FULL_DUPLEX;
858 }
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 aup->mac->control = control;
861 aup->mac->vlan1_tag = 0x8100; /* activate vlan support */
862 au_sync();
863
864 spin_unlock_irqrestore(&aup->lock, flags);
865 return 0;
866}
867
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200868static void
869au1000_adjust_link(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870{
Wang Chen454d7c92008-11-12 23:37:49 -0800871 struct au1000_private *aup = netdev_priv(dev);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200872 struct phy_device *phydev = aup->phy_dev;
873 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200875 int status_change = 0;
876
877 BUG_ON(!aup->phy_dev);
878
879 spin_lock_irqsave(&aup->lock, flags);
880
881 if (phydev->link && (aup->old_speed != phydev->speed)) {
882 // speed changed
883
884 switch(phydev->speed) {
885 case SPEED_10:
886 case SPEED_100:
887 break;
888 default:
889 printk(KERN_WARNING
890 "%s: Speed (%d) is not 10/100 ???\n",
891 dev->name, phydev->speed);
892 break;
893 }
894
895 aup->old_speed = phydev->speed;
896
897 status_change = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200900 if (phydev->link && (aup->old_duplex != phydev->duplex)) {
901 // duplex mode changed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200903 /* switching duplex mode requires to disable rx and tx! */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 hard_stop(dev);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200905
906 if (DUPLEX_FULL == phydev->duplex)
907 aup->mac->control = ((aup->mac->control
908 | MAC_FULL_DUPLEX)
909 & ~MAC_DISABLE_RX_OWN);
910 else
911 aup->mac->control = ((aup->mac->control
912 & ~MAC_FULL_DUPLEX)
913 | MAC_DISABLE_RX_OWN);
914 au_sync_delay(1);
915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 enable_rx_tx(dev);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200917 aup->old_duplex = phydev->duplex;
918
919 status_change = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
921
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200922 if(phydev->link != aup->old_link) {
923 // link state changed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Anton Vorontsovc8f15682008-07-22 15:41:24 -0700925 if (!phydev->link) {
926 /* link went down */
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200927 aup->old_speed = 0;
928 aup->old_duplex = -1;
929 }
930
931 aup->old_link = phydev->link;
932 status_change = 1;
933 }
934
935 spin_unlock_irqrestore(&aup->lock, flags);
936
937 if (status_change) {
938 if (phydev->link)
939 printk(KERN_INFO "%s: link up (%d/%s)\n",
940 dev->name, phydev->speed,
941 DUPLEX_FULL == phydev->duplex ? "Full" : "Half");
942 else
943 printk(KERN_INFO "%s: link down\n", dev->name);
944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945}
946
947static int au1000_open(struct net_device *dev)
948{
949 int retval;
Wang Chen454d7c92008-11-12 23:37:49 -0800950 struct au1000_private *aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 if (au1000_debug > 4)
953 printk("%s: open: dev=%p\n", dev->name, dev);
954
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200955 if ((retval = request_irq(dev->irq, &au1000_interrupt, 0,
956 dev->name, dev))) {
957 printk(KERN_ERR "%s: unable to get IRQ %d\n",
958 dev->name, dev->irq);
959 return retval;
960 }
961
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 if ((retval = au1000_init(dev))) {
963 printk(KERN_ERR "%s: error in au1000_init\n", dev->name);
964 free_irq(dev->irq, dev);
965 return retval;
966 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200968 if (aup->phy_dev) {
969 /* cause the PHY state machine to schedule a link state check */
970 aup->phy_dev->state = PHY_CHANGELINK;
971 phy_start(aup->phy_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 }
973
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200974 netif_start_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
976 if (au1000_debug > 4)
977 printk("%s: open: Initialization done.\n", dev->name);
978
979 return 0;
980}
981
982static int au1000_close(struct net_device *dev)
983{
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200984 unsigned long flags;
Wang Chen454d7c92008-11-12 23:37:49 -0800985 struct au1000_private *const aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
987 if (au1000_debug > 4)
988 printk("%s: close: dev=%p\n", dev->name, dev);
989
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200990 if (aup->phy_dev)
991 phy_stop(aup->phy_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
993 spin_lock_irqsave(&aup->lock, flags);
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +0200994
995 reset_mac_unlocked (dev);
996
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 /* stop the device */
998 netif_stop_queue(dev);
999
1000 /* disable the interrupt */
1001 free_irq(dev->irq, dev);
1002 spin_unlock_irqrestore(&aup->lock, flags);
1003
1004 return 0;
1005}
1006
1007static void __exit au1000_cleanup_module(void)
1008{
1009 int i, j;
1010 struct net_device *dev;
1011 struct au1000_private *aup;
1012
1013 for (i = 0; i < num_ifs; i++) {
1014 dev = iflist[i].dev;
1015 if (dev) {
Wang Chen454d7c92008-11-12 23:37:49 -08001016 aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 unregister_netdev(dev);
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -07001018 mdiobus_unregister(aup->mii_bus);
1019 mdiobus_free(aup->mii_bus);
Sergei Shtylyov89be0502006-04-19 22:46:21 +04001020 for (j = 0; j < NUM_RX_DMA; j++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 if (aup->rx_db_inuse[j])
1022 ReleaseDB(aup, aup->rx_db_inuse[j]);
Sergei Shtylyov89be0502006-04-19 22:46:21 +04001023 for (j = 0; j < NUM_TX_DMA; j++)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (aup->tx_db_inuse[j])
1025 ReleaseDB(aup, aup->tx_db_inuse[j]);
Sergei Shtylyov89be0502006-04-19 22:46:21 +04001026 dma_free_noncoherent(NULL, MAX_BUF_SIZE *
1027 (NUM_TX_BUFFS + NUM_RX_BUFFS),
1028 (void *)aup->vaddr, aup->dma_addr);
1029 release_mem_region(dev->base_addr, MAC_IOSIZE);
1030 release_mem_region(CPHYSADDR(iflist[i].macen_addr), 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 free_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 }
1033 }
1034}
1035
Sergei Shtylylovc2d3d4b2006-03-21 22:53:52 -08001036static void update_tx_stats(struct net_device *dev, u32 status)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037{
Wang Chen454d7c92008-11-12 23:37:49 -08001038 struct au1000_private *aup = netdev_priv(dev);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001039 struct net_device_stats *ps = &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 if (status & TX_FRAME_ABORTED) {
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +02001042 if (!aup->phy_dev || (DUPLEX_FULL == aup->phy_dev->duplex)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 if (status & (TX_JAB_TIMEOUT | TX_UNDERRUN)) {
1044 /* any other tx errors are only valid
1045 * in half duplex mode */
1046 ps->tx_errors++;
1047 ps->tx_aborted_errors++;
1048 }
1049 }
1050 else {
1051 ps->tx_errors++;
1052 ps->tx_aborted_errors++;
1053 if (status & (TX_NO_CARRIER | TX_LOSS_CARRIER))
1054 ps->tx_carrier_errors++;
1055 }
1056 }
1057}
1058
1059
1060/*
1061 * Called from the interrupt service routine to acknowledge
1062 * the TX DONE bits. This is a must if the irq is setup as
1063 * edge triggered.
1064 */
1065static void au1000_tx_ack(struct net_device *dev)
1066{
Wang Chen454d7c92008-11-12 23:37:49 -08001067 struct au1000_private *aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 volatile tx_dma_t *ptxd;
1069
1070 ptxd = aup->tx_dma_ring[aup->tx_tail];
1071
1072 while (ptxd->buff_stat & TX_T_DONE) {
Sergei Shtylylovc2d3d4b2006-03-21 22:53:52 -08001073 update_tx_stats(dev, ptxd->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 ptxd->buff_stat &= ~TX_T_DONE;
1075 ptxd->len = 0;
1076 au_sync();
1077
1078 aup->tx_tail = (aup->tx_tail + 1) & (NUM_TX_DMA - 1);
1079 ptxd = aup->tx_dma_ring[aup->tx_tail];
1080
1081 if (aup->tx_full) {
1082 aup->tx_full = 0;
1083 netif_wake_queue(dev);
1084 }
1085 }
1086}
1087
1088
1089/*
1090 * Au1000 transmit routine.
1091 */
1092static int au1000_tx(struct sk_buff *skb, struct net_device *dev)
1093{
Wang Chen454d7c92008-11-12 23:37:49 -08001094 struct au1000_private *aup = netdev_priv(dev);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001095 struct net_device_stats *ps = &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 volatile tx_dma_t *ptxd;
1097 u32 buff_stat;
1098 db_dest_t *pDB;
1099 int i;
1100
1101 if (au1000_debug > 5)
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001102 printk("%s: tx: aup %x len=%d, data=%p, head %d\n",
1103 dev->name, (unsigned)aup, skb->len,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 skb->data, aup->tx_head);
1105
1106 ptxd = aup->tx_dma_ring[aup->tx_head];
1107 buff_stat = ptxd->buff_stat;
1108 if (buff_stat & TX_DMA_ENABLE) {
1109 /* We've wrapped around and the transmitter is still busy */
1110 netif_stop_queue(dev);
1111 aup->tx_full = 1;
1112 return 1;
1113 }
1114 else if (buff_stat & TX_T_DONE) {
Sergei Shtylylovc2d3d4b2006-03-21 22:53:52 -08001115 update_tx_stats(dev, ptxd->status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 ptxd->len = 0;
1117 }
1118
1119 if (aup->tx_full) {
1120 aup->tx_full = 0;
1121 netif_wake_queue(dev);
1122 }
1123
1124 pDB = aup->tx_db_inuse[aup->tx_head];
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001125 skb_copy_from_linear_data(skb, pDB->vaddr, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 if (skb->len < ETH_ZLEN) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001127 for (i=skb->len; i<ETH_ZLEN; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 ((char *)pDB->vaddr)[i] = 0;
1129 }
1130 ptxd->len = ETH_ZLEN;
1131 }
1132 else
1133 ptxd->len = skb->len;
1134
Sergei Shtylylovc2d3d4b2006-03-21 22:53:52 -08001135 ps->tx_packets++;
1136 ps->tx_bytes += ptxd->len;
1137
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 ptxd->buff_stat = pDB->dma_addr | TX_DMA_ENABLE;
1139 au_sync();
1140 dev_kfree_skb(skb);
1141 aup->tx_head = (aup->tx_head + 1) & (NUM_TX_DMA - 1);
1142 dev->trans_start = jiffies;
1143 return 0;
1144}
1145
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146static inline void update_rx_stats(struct net_device *dev, u32 status)
1147{
Wang Chen454d7c92008-11-12 23:37:49 -08001148 struct au1000_private *aup = netdev_priv(dev);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001149 struct net_device_stats *ps = &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 ps->rx_packets++;
1152 if (status & RX_MCAST_FRAME)
1153 ps->multicast++;
1154
1155 if (status & RX_ERROR) {
1156 ps->rx_errors++;
1157 if (status & RX_MISSED_FRAME)
1158 ps->rx_missed_errors++;
1159 if (status & (RX_OVERLEN | RX_OVERLEN | RX_LEN_ERROR))
1160 ps->rx_length_errors++;
1161 if (status & RX_CRC_ERROR)
1162 ps->rx_crc_errors++;
1163 if (status & RX_COLL)
1164 ps->collisions++;
1165 }
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001166 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 ps->rx_bytes += status & RX_FRAME_LEN_MASK;
1168
1169}
1170
1171/*
1172 * Au1000 receive routine.
1173 */
1174static int au1000_rx(struct net_device *dev)
1175{
Wang Chen454d7c92008-11-12 23:37:49 -08001176 struct au1000_private *aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 struct sk_buff *skb;
1178 volatile rx_dma_t *prxd;
1179 u32 buff_stat, status;
1180 db_dest_t *pDB;
1181 u32 frmlen;
1182
1183 if (au1000_debug > 5)
1184 printk("%s: au1000_rx head %d\n", dev->name, aup->rx_head);
1185
1186 prxd = aup->rx_dma_ring[aup->rx_head];
1187 buff_stat = prxd->buff_stat;
1188 while (buff_stat & RX_T_DONE) {
1189 status = prxd->status;
1190 pDB = aup->rx_db_inuse[aup->rx_head];
1191 update_rx_stats(dev, status);
1192 if (!(status & RX_ERROR)) {
1193
1194 /* good frame */
1195 frmlen = (status & RX_FRAME_LEN_MASK);
1196 frmlen -= 4; /* Remove FCS */
1197 skb = dev_alloc_skb(frmlen + 2);
1198 if (skb == NULL) {
1199 printk(KERN_ERR
1200 "%s: Memory squeeze, dropping packet.\n",
1201 dev->name);
Jeff Garzik09f75cd2007-10-03 17:41:50 -07001202 dev->stats.rx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 continue;
1204 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 skb_reserve(skb, 2); /* 16 byte IP header align */
David S. Miller8c7b7fa2007-07-10 22:08:12 -07001206 skb_copy_to_linear_data(skb,
1207 (unsigned char *)pDB->vaddr, frmlen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 skb_put(skb, frmlen);
1209 skb->protocol = eth_type_trans(skb, dev);
1210 netif_rx(skb); /* pass the packet to upper layers */
1211 }
1212 else {
1213 if (au1000_debug > 4) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001214 if (status & RX_MISSED_FRAME)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 printk("rx miss\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001216 if (status & RX_WDOG_TIMER)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 printk("rx wdog\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001218 if (status & RX_RUNT)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 printk("rx runt\n");
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001220 if (status & RX_OVERLEN)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 printk("rx overlen\n");
1222 if (status & RX_COLL)
1223 printk("rx coll\n");
1224 if (status & RX_MII_ERROR)
1225 printk("rx mii error\n");
1226 if (status & RX_CRC_ERROR)
1227 printk("rx crc error\n");
1228 if (status & RX_LEN_ERROR)
1229 printk("rx len error\n");
1230 if (status & RX_U_CNTRL_FRAME)
1231 printk("rx u control frame\n");
1232 if (status & RX_MISSED_FRAME)
1233 printk("rx miss\n");
1234 }
1235 }
1236 prxd->buff_stat = (u32)(pDB->dma_addr | RX_DMA_ENABLE);
1237 aup->rx_head = (aup->rx_head + 1) & (NUM_RX_DMA - 1);
1238 au_sync();
1239
1240 /* next descriptor */
1241 prxd = aup->rx_dma_ring[aup->rx_head];
1242 buff_stat = prxd->buff_stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 }
1244 return 0;
1245}
1246
1247
1248/*
1249 * Au1000 interrupt service routine.
1250 */
David Howells7d12e782006-10-05 14:55:46 +01001251static irqreturn_t au1000_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252{
Francois Romieud04455f2008-05-12 18:44:21 +02001253 struct net_device *dev = dev_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
1255 /* Handle RX interrupts first to minimize chance of overrun */
1256
1257 au1000_rx(dev);
1258 au1000_tx_ack(dev);
1259 return IRQ_RETVAL(1);
1260}
1261
1262
1263/*
1264 * The Tx ring has been full longer than the watchdog timeout
1265 * value. The transmitter must be hung?
1266 */
1267static void au1000_tx_timeout(struct net_device *dev)
1268{
1269 printk(KERN_ERR "%s: au1000_tx_timeout: dev=%p\n", dev->name, dev);
1270 reset_mac(dev);
1271 au1000_init(dev);
1272 dev->trans_start = jiffies;
1273 netif_wake_queue(dev);
1274}
1275
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276static void set_rx_mode(struct net_device *dev)
1277{
Wang Chen454d7c92008-11-12 23:37:49 -08001278 struct au1000_private *aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001280 if (au1000_debug > 4)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 printk("%s: set_rx_mode: flags=%x\n", dev->name, dev->flags);
1282
1283 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
1284 aup->mac->control |= MAC_PROMISCUOUS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 } else if ((dev->flags & IFF_ALLMULTI) ||
1286 dev->mc_count > MULTICAST_FILTER_LIMIT) {
1287 aup->mac->control |= MAC_PASS_ALL_MULTI;
1288 aup->mac->control &= ~MAC_PROMISCUOUS;
1289 printk(KERN_INFO "%s: Pass all multicast\n", dev->name);
1290 } else {
1291 int i;
1292 struct dev_mc_list *mclist;
1293 u32 mc_filter[2]; /* Multicast hash filter */
1294
1295 mc_filter[1] = mc_filter[0] = 0;
1296 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
1297 i++, mclist = mclist->next) {
Jeff Garzik6aa20a22006-09-13 13:24:59 -04001298 set_bit(ether_crc(ETH_ALEN, mclist->dmi_addr)>>26,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 (long *)mc_filter);
1300 }
1301 aup->mac->multi_hash_high = mc_filter[1];
1302 aup->mac->multi_hash_low = mc_filter[0];
1303 aup->mac->control &= ~MAC_PROMISCUOUS;
1304 aup->mac->control |= MAC_HASH_MODE;
1305 }
1306}
1307
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308static int au1000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1309{
Wang Chen454d7c92008-11-12 23:37:49 -08001310 struct au1000_private *aup = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +02001312 if (!netif_running(dev)) return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +02001314 if (!aup->phy_dev) return -EINVAL; // PHY not controllable
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
Herbert Valerio Riedel0638dec2006-06-01 09:41:04 +02001316 return phy_mii_ioctl(aup->phy_dev, if_mii(rq), cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317}
1318
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319module_init(au1000_init_module);
1320module_exit(au1000_cleanup_module);