ALSA: atmel: set "channel A event" output to debug
[safe/jmp/linux-2.6] / drivers / net / znet.c
index b24b072..c3a3292 100644 (file)
@@ -88,6 +88,7 @@
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
+#include <linux/slab.h>
 #include <linux/errno.h>
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
 #include <asm/io.h>
 #include <asm/dma.h>
 
-/* This include could be elsewhere, since it is not wireless specific */
-#include "wireless/i82593.h"
+#include <linux/i82593.h>
 
 static char version[] __initdata = "znet.c:v1.02 9/23/94 becker@scyld.com\n";
 
@@ -128,7 +128,6 @@ MODULE_LICENSE("GPL");
 
 struct znet_private {
        int rx_dma, tx_dma;
-       struct net_device_stats stats;
        spinlock_t lock;
        short sia_base, sia_size, io_size;
        struct i82593_conf_block i593_init;
@@ -157,11 +156,11 @@ struct netidblk {
 };
 
 static int     znet_open(struct net_device *dev);
-static int     znet_send_packet(struct sk_buff *skb, struct net_device *dev);
+static netdev_tx_t znet_send_packet(struct sk_buff *skb,
+                                   struct net_device *dev);
 static irqreturn_t znet_interrupt(int irq, void *dev_id);
 static void    znet_rx(struct net_device *dev);
 static int     znet_close(struct net_device *dev);
-static struct net_device_stats *net_get_stats(struct net_device *dev);
 static void hardware_init(struct net_device *dev);
 static void update_stop_hit(short ioaddr, unsigned short rx_stop_offset);
 static void znet_tx_timeout (struct net_device *dev);
@@ -169,10 +168,9 @@ static void znet_tx_timeout (struct net_device *dev);
 /* Request needed resources */
 static int znet_request_resources (struct net_device *dev)
 {
-       struct znet_private *znet = dev->priv;
-       unsigned long flags;
+       struct znet_private *znet = netdev_priv(dev);
 
-       if (request_irq (dev->irq, &znet_interrupt, 0, "ZNet", dev))
+       if (request_irq (dev->irq, znet_interrupt, 0, "ZNet", dev))
                goto failed;
        if (request_dma (znet->rx_dma, "ZNet rx"))
                goto free_irq;
@@ -188,13 +186,9 @@ static int znet_request_resources (struct net_device *dev)
  free_sia:
        release_region (znet->sia_base, znet->sia_size);
  free_tx_dma:
-       flags = claim_dma_lock();
        free_dma (znet->tx_dma);
-       release_dma_lock (flags);
  free_rx_dma:
-       flags = claim_dma_lock();
        free_dma (znet->rx_dma);
-       release_dma_lock (flags);
  free_irq:
        free_irq (dev->irq, dev);
  failed:
@@ -203,22 +197,19 @@ static int znet_request_resources (struct net_device *dev)
 
 static void znet_release_resources (struct net_device *dev)
 {
-       struct znet_private *znet = dev->priv;
-       unsigned long flags;
+       struct znet_private *znet = netdev_priv(dev);
 
        release_region (znet->sia_base, znet->sia_size);
        release_region (dev->base_addr, znet->io_size);
-       flags = claim_dma_lock();
        free_dma (znet->tx_dma);
        free_dma (znet->rx_dma);
-       release_dma_lock (flags);
        free_irq (dev->irq, dev);
 }
 
 /* Keep the magical SIA stuff in a single function... */
 static void znet_transceiver_power (struct net_device *dev, int on)
 {
-       struct znet_private *znet = dev->priv;
+       struct znet_private *znet = netdev_priv(dev);
        unsigned char v;
 
        /* Turn on/off the 82501 SIA, using zenith-specific magic. */
@@ -237,7 +228,7 @@ static void znet_transceiver_power (struct net_device *dev, int on)
    Also used from hardware_init. */
 static void znet_set_multicast_list (struct net_device *dev)
 {
-       struct znet_private *znet = dev->priv;
+       struct znet_private *znet = netdev_priv(dev);
        short ioaddr = dev->base_addr;
        struct i82593_conf_block *cfblk = &znet->i593_init;
 
@@ -323,7 +314,8 @@ static void znet_set_multicast_list (struct net_device *dev)
        /* Byte D */
        cfblk->dummy_1 = 1;     /* set to 1 */
        cfblk->tx_ifs_retrig = 3; /* Hmm... Disabled */
-       cfblk->mc_all = (dev->mc_list || (dev->flags&IFF_ALLMULTI));/* multicast all mode */
+       cfblk->mc_all = (!netdev_mc_empty(dev) ||
+                       (dev->flags & IFF_ALLMULTI)); /* multicast all mode */
        cfblk->rcv_mon = 0;     /* Monitor mode disabled */
        cfblk->frag_acpt = 0;   /* Do not accept fragments */
        cfblk->tstrttrs = 0;    /* No start transmission threshold */
@@ -360,6 +352,17 @@ static void znet_set_multicast_list (struct net_device *dev)
         * multicast address configured isn't equal to IFF_ALLMULTI */
 }
 
+static const struct net_device_ops znet_netdev_ops = {
+       .ndo_open               = znet_open,
+       .ndo_stop               = znet_close,
+       .ndo_start_xmit         = znet_send_packet,
+       .ndo_set_multicast_list = znet_set_multicast_list,
+       .ndo_tx_timeout         = znet_tx_timeout,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_validate_addr      = eth_validate_addr,
+};
+
 /* The Z-Note probe is pretty easy.  The NETIDBLK exists in the safe-to-probe
    BIOS area.  We just scan for the signature, and pull the vital parameters
    out of the structure. */
@@ -388,22 +391,20 @@ static int __init znet_probe (void)
        if (!dev)
                return -ENOMEM;
 
-       SET_MODULE_OWNER (dev);
-
-       znet = dev->priv;
+       znet = netdev_priv(dev);
 
        netinfo = (struct netidblk *)p;
        dev->base_addr = netinfo->iobase1;
        dev->irq = netinfo->irq1;
 
-       printk(KERN_INFO "%s: ZNET at %#3lx,", dev->name, dev->base_addr);
-
        /* The station address is in the "netidblk" at 0x0f0000. */
        for (i = 0; i < 6; i++)
-               printk(" %2.2x", dev->dev_addr[i] = netinfo->netid[i]);
+               dev->dev_addr[i] = netinfo->netid[i];
 
-       printk(", using IRQ %d DMA %d and %d.\n", dev->irq, netinfo->dma1,
-              netinfo->dma2);
+       printk(KERN_INFO "%s: ZNET at %#3lx, %pM"
+              ", using IRQ %d DMA %d and %d.\n",
+              dev->name, dev->base_addr, dev->dev_addr,
+              dev->irq, netinfo->dma1, netinfo->dma2);
 
        if (znet_debug > 1) {
                printk(KERN_INFO "%s: vendor '%16.16s' IRQ1 %d IRQ2 %d DMA1 %d DMA2 %d.\n",
@@ -444,12 +445,7 @@ static int __init znet_probe (void)
        znet->tx_end = znet->tx_start + znet->tx_buf_len;
 
        /* The ZNET-specific entries in the device structure. */
-       dev->open = &znet_open;
-       dev->hard_start_xmit = &znet_send_packet;
-       dev->stop = &znet_close;
-       dev->get_stats  = net_get_stats;
-       dev->set_multicast_list = &znet_set_multicast_list;
-       dev->tx_timeout = znet_tx_timeout;
+       dev->netdev_ops = &znet_netdev_ops;
        dev->watchdog_timeo = TX_TIMEOUT;
        err = register_netdev(dev);
        if (err)
@@ -532,10 +528,10 @@ static void znet_tx_timeout (struct net_device *dev)
        netif_wake_queue (dev);
 }
 
-static int znet_send_packet(struct sk_buff *skb, struct net_device *dev)
+static netdev_tx_t znet_send_packet(struct sk_buff *skb, struct net_device *dev)
 {
        int ioaddr = dev->base_addr;
-       struct znet_private *znet = dev->priv;
+       struct znet_private *znet = netdev_priv(dev);
        unsigned long flags;
        short length = skb->len;
 
@@ -544,7 +540,7 @@ static int znet_send_packet(struct sk_buff *skb, struct net_device *dev)
 
        if (length < ETH_ZLEN) {
                if (skb_padto(skb, ETH_ZLEN))
-                       return 0;
+                       return NETDEV_TX_OK;
                length = ETH_ZLEN;
        }
 
@@ -566,7 +562,7 @@ static int znet_send_packet(struct sk_buff *skb, struct net_device *dev)
                ushort *tx_link = znet->tx_cur - 1;
                ushort rnd_len = (length + 1)>>1;
 
-               znet->stats.tx_bytes+=length;
+               dev->stats.tx_bytes+=length;
 
                if (znet->tx_cur >= znet->tx_end)
                  znet->tx_cur = znet->tx_start;
@@ -591,21 +587,20 @@ static int znet_send_packet(struct sk_buff *skb, struct net_device *dev)
                }
                spin_unlock_irqrestore (&znet->lock, flags);
 
-               dev->trans_start = jiffies;
                netif_start_queue (dev);
 
                if (znet_debug > 4)
                  printk(KERN_DEBUG "%s: Transmitter queued, length %d.\n", dev->name, length);
        }
        dev_kfree_skb(skb);
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 /* The ZNET interrupt handler. */
 static irqreturn_t znet_interrupt(int irq, void *dev_id)
 {
        struct net_device *dev = dev_id;
-       struct znet_private *znet = dev->priv;
+       struct znet_private *znet = netdev_priv(dev);
        int ioaddr;
        int boguscnt = 20;
        int handled = 0;
@@ -641,20 +636,20 @@ static irqreturn_t znet_interrupt(int irq, void *dev_id)
                        tx_status = inw(ioaddr);
                        /* It's undocumented, but tx_status seems to match the i82586. */
                        if (tx_status & TX_OK) {
-                               znet->stats.tx_packets++;
-                               znet->stats.collisions += tx_status & TX_NCOL_MASK;
+                               dev->stats.tx_packets++;
+                               dev->stats.collisions += tx_status & TX_NCOL_MASK;
                        } else {
                                if (tx_status & (TX_LOST_CTS | TX_LOST_CRS))
-                                       znet->stats.tx_carrier_errors++;
+                                       dev->stats.tx_carrier_errors++;
                                if (tx_status & TX_UND_RUN)
-                                       znet->stats.tx_fifo_errors++;
+                                       dev->stats.tx_fifo_errors++;
                                if (!(tx_status & TX_HRT_BEAT))
-                                       znet->stats.tx_heartbeat_errors++;
+                                       dev->stats.tx_heartbeat_errors++;
                                if (tx_status & TX_MAX_COL)
-                                       znet->stats.tx_aborted_errors++;
+                                       dev->stats.tx_aborted_errors++;
                                /* ...and the catch-all. */
                                if ((tx_status | (TX_LOST_CRS | TX_LOST_CTS | TX_UND_RUN | TX_HRT_BEAT | TX_MAX_COL)) != (TX_LOST_CRS | TX_LOST_CTS | TX_UND_RUN | TX_HRT_BEAT | TX_MAX_COL))
-                                       znet->stats.tx_errors++;
+                                       dev->stats.tx_errors++;
 
                                /* Transceiver may be stuck if cable
                                 * was removed while emiting a
@@ -683,7 +678,7 @@ static irqreturn_t znet_interrupt(int irq, void *dev_id)
 
 static void znet_rx(struct net_device *dev)
 {
-       struct znet_private *znet = dev->priv;
+       struct znet_private *znet = netdev_priv(dev);
        int ioaddr = dev->base_addr;
        int boguscount = 1;
        short next_frame_end_offset = 0;                /* Offset of next frame start. */
@@ -703,8 +698,8 @@ static void znet_rx(struct net_device *dev)
           the same area of the backwards links we now have.  This allows us to
           pass packets to the upper layers in the order they were received --
           important for fast-path sequential operations. */
-        while (znet->rx_start + cur_frame_end_offset != znet->rx_cur
-                       && ++boguscount < 5) {
+       while (znet->rx_start + cur_frame_end_offset != znet->rx_cur &&
+              ++boguscount < 5) {
                unsigned short hi_cnt, lo_cnt, hi_status, lo_status;
                int count, status;
 
@@ -750,19 +745,19 @@ static void znet_rx(struct net_device *dev)
                                 this_rfp_ptr[-3]<<1);
                /* Once again we must assume that the i82586 docs apply. */
                if ( ! (status & RX_RCV_OK)) { /* There was an error. */
-                       znet->stats.rx_errors++;
-                       if (status & RX_CRC_ERR) znet->stats.rx_crc_errors++;
-                       if (status & RX_ALG_ERR) znet->stats.rx_frame_errors++;
+                       dev->stats.rx_errors++;
+                       if (status & RX_CRC_ERR) dev->stats.rx_crc_errors++;
+                       if (status & RX_ALG_ERR) dev->stats.rx_frame_errors++;
 #if 0
-                       if (status & 0x0200) znet->stats.rx_over_errors++; /* Wrong. */
-                       if (status & 0x0100) znet->stats.rx_fifo_errors++;
+                       if (status & 0x0200) dev->stats.rx_over_errors++; /* Wrong. */
+                       if (status & 0x0100) dev->stats.rx_fifo_errors++;
 #else
                        /* maz : Wild guess... */
-                       if (status & RX_OVRRUN) znet->stats.rx_over_errors++;
+                       if (status & RX_OVRRUN) dev->stats.rx_over_errors++;
 #endif
-                       if (status & RX_SRT_FRM) znet->stats.rx_length_errors++;
+                       if (status & RX_SRT_FRM) dev->stats.rx_length_errors++;
                } else if (pkt_len > 1536) {
-                       znet->stats.rx_length_errors++;
+                       dev->stats.rx_length_errors++;
                } else {
                        /* Malloc up new buffer. */
                        struct sk_buff *skb;
@@ -771,10 +766,9 @@ static void znet_rx(struct net_device *dev)
                        if (skb == NULL) {
                                if (znet_debug)
                                  printk(KERN_WARNING "%s: Memory squeeze, dropping packet.\n", dev->name);
-                               znet->stats.rx_dropped++;
+                               dev->stats.rx_dropped++;
                                break;
                        }
-                       skb->dev = dev;
 
                        if (&znet->rx_cur[(pkt_len+1)>>1] > znet->rx_end) {
                                int semi_cnt = (znet->rx_end - znet->rx_cur)<<1;
@@ -791,9 +785,8 @@ static void znet_rx(struct net_device *dev)
                  }
                  skb->protocol=eth_type_trans(skb,dev);
                  netif_rx(skb);
-                 dev->last_rx = jiffies;
-                 znet->stats.rx_packets++;
-                 znet->stats.rx_bytes += pkt_len;
+                 dev->stats.rx_packets++;
+                 dev->stats.rx_bytes += pkt_len;
                }
                znet->rx_cur = this_rfp_ptr;
                if (znet->rx_cur >= znet->rx_end)
@@ -808,7 +801,6 @@ static void znet_rx(struct net_device *dev)
        /* If any worth-while packets have been received, dev_rint()
           has done a mark_bh(INET_BH) for us and will work on them
           when we get to the bottom-half routine. */
-       return;
 }
 
 /* The inverse routine to znet_open(). */
@@ -830,20 +822,11 @@ static int znet_close(struct net_device *dev)
        return 0;
 }
 
-/* Get the current statistics. This may be called with the card open or
-   closed. */
-static struct net_device_stats *net_get_stats(struct net_device *dev)
-{
-       struct znet_private *znet = dev->priv;
-
-       return &znet->stats;
-}
-
 static void show_dma(struct net_device *dev)
 {
        short ioaddr = dev->base_addr;
        unsigned char stat = inb (ioaddr);
-       struct znet_private *znet = dev->priv;
+       struct znet_private *znet = netdev_priv(dev);
        unsigned long flags;
        short dma_port = ((znet->tx_dma&3)<<2) + IO_DMA2_BASE;
        unsigned addr = inb(dma_port);
@@ -866,7 +849,7 @@ static void hardware_init(struct net_device *dev)
 {
        unsigned long flags;
        short ioaddr = dev->base_addr;
-       struct znet_private *znet = dev->priv;
+       struct znet_private *znet = netdev_priv(dev);
 
        znet->rx_cur = znet->rx_start;
        znet->tx_cur = znet->tx_start;
@@ -928,7 +911,7 @@ static void update_stop_hit(short ioaddr, unsigned short rx_stop_offset)
 static __exit void znet_cleanup (void)
 {
        if (znet_dev) {
-               struct znet_private *znet = znet_dev->priv;
+               struct znet_private *znet = netdev_priv(znet_dev);
 
                unregister_netdev (znet_dev);
                kfree (znet->rx_start);