netdev: add more functions to netdevice ops
[safe/jmp/linux-2.6] / drivers / net / plip.c
index c17d9ac..d544d4a 100644 (file)
@@ -106,6 +106,7 @@ static const char version[] = "NET3 PLIP version 2.4-parport gniibe@mri.co.jp\n"
 #include <linux/if_plip.h>
 #include <linux/workqueue.h>
 #include <linux/spinlock.h>
+#include <linux/completion.h>
 #include <linux/parport.h>
 #include <linux/bitops.h>
 
@@ -114,7 +115,6 @@ static const char version[] = "NET3 PLIP version 2.4-parport gniibe@mri.co.jp\n"
 #include <asm/system.h>
 #include <asm/irq.h>
 #include <asm/byteorder.h>
-#include <asm/semaphore.h>
 
 /* Maximum number of devices to support. */
 #define PLIP_MAX  8
@@ -143,14 +143,14 @@ static void plip_bh(struct work_struct *work);
 static void plip_timer_bh(struct work_struct *work);
 
 /* Interrupt handler */
-static void plip_interrupt(int irq, void *dev_id);
+static void plip_interrupt(void *dev_id);
 
 /* Functions for DEV methods */
 static int plip_tx_packet(struct sk_buff *skb, struct net_device *dev);
 static int plip_hard_header(struct sk_buff *skb, struct net_device *dev,
-                            unsigned short type, void *daddr,
-                            void *saddr, unsigned len);
-static int plip_hard_header_cache(struct neighbour *neigh,
+                            unsigned short type, const void *daddr,
+                           const void *saddr, unsigned len);
+static int plip_hard_header_cache(const struct neighbour *neigh,
                                   struct hh_cache *hh);
 static int plip_open(struct net_device *dev);
 static int plip_close(struct net_device *dev);
@@ -219,14 +219,9 @@ struct net_local {
        int is_deferred;
        int port_owner;
        int should_relinquish;
-       int (*orig_hard_header)(struct sk_buff *skb, struct net_device *dev,
-                               unsigned short type, void *daddr,
-                               void *saddr, unsigned len);
-       int (*orig_hard_header_cache)(struct neighbour *neigh,
-                                     struct hh_cache *hh);
        spinlock_t lock;
        atomic_t kill_timer;
-       struct semaphore killed_timer_sem;
+       struct completion killed_timer_cmp;
 };
 
 static inline void enable_parport_interrupts (struct net_device *dev)
@@ -234,7 +229,7 @@ static inline void enable_parport_interrupts (struct net_device *dev)
        if (dev->irq != -1)
        {
                struct parport *port =
-                  ((struct net_local *)dev->priv)->pardev->port;
+                  ((struct net_local *)netdev_priv(dev))->pardev->port;
                port->ops->enable_irq (port);
        }
 }
@@ -244,7 +239,7 @@ static inline void disable_parport_interrupts (struct net_device *dev)
        if (dev->irq != -1)
        {
                struct parport *port =
-                  ((struct net_local *)dev->priv)->pardev->port;
+                  ((struct net_local *)netdev_priv(dev))->pardev->port;
                port->ops->disable_irq (port);
        }
 }
@@ -252,7 +247,7 @@ static inline void disable_parport_interrupts (struct net_device *dev)
 static inline void write_data (struct net_device *dev, unsigned char data)
 {
        struct parport *port =
-          ((struct net_local *)dev->priv)->pardev->port;
+          ((struct net_local *)netdev_priv(dev))->pardev->port;
 
        port->ops->write_data (port, data);
 }
@@ -260,11 +255,16 @@ static inline void write_data (struct net_device *dev, unsigned char data)
 static inline unsigned char read_status (struct net_device *dev)
 {
        struct parport *port =
-          ((struct net_local *)dev->priv)->pardev->port;
+          ((struct net_local *)netdev_priv(dev))->pardev->port;
 
        return port->ops->read_status (port);
 }
 
+static const struct header_ops plip_header_ops = {
+       .create = plip_hard_header,
+       .cache  = plip_hard_header_cache,
+};
+
 /* Entry point of PLIP driver.
    Probe the hardware, and register/initialize the driver.
 
@@ -284,17 +284,12 @@ plip_init_netdev(struct net_device *dev)
        dev->open                = plip_open;
        dev->stop                = plip_close;
        dev->do_ioctl            = plip_ioctl;
-       dev->header_cache_update = NULL;
+
        dev->tx_queue_len        = 10;
        dev->flags               = IFF_POINTOPOINT|IFF_NOARP;
        memset(dev->dev_addr, 0xfc, ETH_ALEN);
 
-       /* Set the private structure */
-       nl->orig_hard_header    = dev->hard_header;
-       dev->hard_header        = plip_hard_header;
-
-       nl->orig_hard_header_cache = dev->hard_header_cache;
-       dev->hard_header_cache     = plip_hard_header_cache;
+       dev->header_ops          = &plip_header_ops;
 
 
        nl->port_owner = 0;
@@ -385,12 +380,12 @@ plip_timer_bh(struct work_struct *work)
                container_of(work, struct net_local, timer.work);
 
        if (!(atomic_read (&nl->kill_timer))) {
-               plip_interrupt (-1, nl->dev);
+               plip_interrupt (nl->dev);
 
                schedule_delayed_work(&nl->timer, 1);
        }
        else {
-               up (&nl->killed_timer_sem);
+               complete(&nl->killed_timer_cmp);
        }
 }
 
@@ -668,8 +663,7 @@ plip_receive_packet(struct net_device *dev, struct net_local *nl,
        case PLIP_PK_DONE:
                /* Inform the upper layer for the arrival of a packet. */
                rcv->skb->protocol=plip_type_trans(rcv->skb, dev);
-               netif_rx(rcv->skb);
-               dev->last_rx = jiffies;
+               netif_rx_ni(rcv->skb);
                dev->stats.rx_bytes += rcv->length.h;
                dev->stats.rx_packets++;
                rcv->skb = NULL;
@@ -902,23 +896,24 @@ plip_error(struct net_device *dev, struct net_local *nl,
 
 /* Handle the parallel port interrupts. */
 static void
-plip_interrupt(int irq, void *dev_id)
+plip_interrupt(void *dev_id)
 {
        struct net_device *dev = dev_id;
        struct net_local *nl;
        struct plip_local *rcv;
        unsigned char c0;
+       unsigned long flags;
 
        nl = netdev_priv(dev);
        rcv = &nl->rcv_data;
 
-       spin_lock_irq (&nl->lock);
+       spin_lock_irqsave (&nl->lock, flags);
 
        c0 = read_status(dev);
        if ((c0 & 0xf8) != 0xc0) {
                if ((dev->irq != -1) && (net_debug > 1))
                        printk(KERN_DEBUG "%s: spurious interrupt\n", dev->name);
-               spin_unlock_irq (&nl->lock);
+               spin_unlock_irqrestore (&nl->lock, flags);
                return;
        }
 
@@ -947,7 +942,7 @@ plip_interrupt(int irq, void *dev_id)
                break;
        }
 
-       spin_unlock_irq(&nl->lock);
+       spin_unlock_irqrestore(&nl->lock, flags);
 }
 
 static int
@@ -993,14 +988,14 @@ plip_tx_packet(struct sk_buff *skb, struct net_device *dev)
 }
 
 static void
-plip_rewrite_address(struct net_device *dev, struct ethhdr *eth)
+plip_rewrite_address(const struct net_device *dev, struct ethhdr *eth)
 {
-       struct in_device *in_dev;
+       const struct in_device *in_dev = dev->ip_ptr;
 
-       if ((in_dev=dev->ip_ptr) != NULL) {
+       if (in_dev) {
                /* Any address will do - we take the first */
-               struct in_ifaddr *ifa=in_dev->ifa_list;
-               if (ifa != NULL) {
+               const struct in_ifaddr *ifa = in_dev->ifa_list;
+               if (ifa) {
                        memcpy(eth->h_source, dev->dev_addr, 6);
                        memset(eth->h_dest, 0xfc, 2);
                        memcpy(eth->h_dest+2, &ifa->ifa_address, 4);
@@ -1010,26 +1005,25 @@ plip_rewrite_address(struct net_device *dev, struct ethhdr *eth)
 
 static int
 plip_hard_header(struct sk_buff *skb, struct net_device *dev,
-                 unsigned short type, void *daddr,
-                void *saddr, unsigned len)
+                unsigned short type, const void *daddr,
+                const void *saddr, unsigned len)
 {
-       struct net_local *nl = netdev_priv(dev);
        int ret;
 
-       if ((ret = nl->orig_hard_header(skb, dev, type, daddr, saddr, len)) >= 0)
+       ret = eth_header(skb, dev, type, daddr, saddr, len);
+       if (ret >= 0)
                plip_rewrite_address (dev, (struct ethhdr *)skb->data);
 
        return ret;
 }
 
-int plip_hard_header_cache(struct neighbour *neigh,
+int plip_hard_header_cache(const struct neighbour *neigh,
                            struct hh_cache *hh)
 {
-       struct net_local *nl = neigh->dev->priv;
        int ret;
 
-       if ((ret = nl->orig_hard_header_cache(neigh, hh)) == 0)
-       {
+       ret = eth_header_cache(neigh, hh);
+       if (ret == 0) {
                struct ethhdr *eth;
 
                eth = (struct ethhdr*)(((u8*)hh->hh_data) +
@@ -1118,9 +1112,9 @@ plip_close(struct net_device *dev)
 
        if (dev->irq == -1)
        {
-               init_MUTEX_LOCKED (&nl->killed_timer_sem);
+               init_completion(&nl->killed_timer_cmp);
                atomic_set (&nl->kill_timer, 1);
-               down (&nl->killed_timer_sem);
+               wait_for_completion(&nl->killed_timer_cmp);
        }
 
 #ifdef NOTDEF
@@ -1275,7 +1269,7 @@ static void plip_attach (struct parport *port)
 
                nl = netdev_priv(dev);
                nl->dev = dev;
-               nl->pardev = parport_register_device(port, name, plip_preempt,
+               nl->pardev = parport_register_device(port, dev->name, plip_preempt,
                                                 plip_wakeup, plip_interrupt,
                                                 0, dev);