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