i2c: Document the message size limit
[safe/jmp/linux-2.6] / drivers / net / plip.c
index baf2cbf..3327e9f 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
@@ -221,7 +221,7 @@ struct net_local {
        int should_relinquish;
        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)
@@ -229,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);
        }
 }
@@ -239,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);
        }
 }
@@ -247,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);
 }
@@ -255,7 +255,7 @@ 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);
 }
@@ -265,6 +265,16 @@ static const struct header_ops plip_header_ops = {
        .cache  = plip_hard_header_cache,
 };
 
+static const struct net_device_ops plip_netdev_ops = {
+       .ndo_open                = plip_open,
+       .ndo_stop                = plip_close,
+       .ndo_start_xmit          = plip_tx_packet,
+       .ndo_do_ioctl            = plip_ioctl,
+       .ndo_change_mtu          = eth_change_mtu,
+       .ndo_set_mac_address     = eth_mac_addr,
+       .ndo_validate_addr       = eth_validate_addr,
+};
+
 /* Entry point of PLIP driver.
    Probe the hardware, and register/initialize the driver.
 
@@ -280,15 +290,11 @@ plip_init_netdev(struct net_device *dev)
        struct net_local *nl = netdev_priv(dev);
 
        /* Then, override parts of it */
-       dev->hard_start_xmit     = plip_tx_packet;
-       dev->open                = plip_open;
-       dev->stop                = plip_close;
-       dev->do_ioctl            = plip_ioctl;
-
        dev->tx_queue_len        = 10;
        dev->flags               = IFF_POINTOPOINT|IFF_NOARP;
        memset(dev->dev_addr, 0xfc, ETH_ALEN);
 
+       dev->netdev_ops          = &plip_netdev_ops;
        dev->header_ops          = &plip_header_ops;
 
 
@@ -366,8 +372,8 @@ plip_bh(struct work_struct *work)
 
        nl->is_deferred = 0;
        f = connection_state_table[nl->connection];
-       if ((r = (*f)(nl->dev, nl, snd, rcv)) != OK
-           && (r = plip_bh_timeout_error(nl->dev, nl, snd, rcv, r)) != OK) {
+       if ((r = (*f)(nl->dev, nl, snd, rcv)) != OK &&
+           (r = plip_bh_timeout_error(nl->dev, nl, snd, rcv, r)) != OK) {
                nl->is_deferred = 1;
                schedule_delayed_work(&nl->deferred, 1);
        }
@@ -385,7 +391,7 @@ plip_timer_bh(struct work_struct *work)
                schedule_delayed_work(&nl->timer, 1);
        }
        else {
-               up (&nl->killed_timer_sem);
+               complete(&nl->killed_timer_cmp);
        }
 }
 
@@ -410,9 +416,8 @@ plip_bh_timeout_error(struct net_device *dev, struct net_local *nl,
 
                if (error != ERROR) { /* Timeout */
                        nl->timeout_count++;
-                       if ((error == HS_TIMEOUT
-                            && nl->timeout_count <= 10)
-                           || nl->timeout_count <= 3) {
+                       if ((error == HS_TIMEOUT && nl->timeout_count <= 10) ||
+                           nl->timeout_count <= 3) {
                                spin_unlock_irq(&nl->lock);
                                /* Try again later */
                                return TIMEOUT;
@@ -618,8 +623,8 @@ plip_receive_packet(struct net_device *dev, struct net_local *nl,
                if (plip_receive(nibble_timeout, dev,
                                 &rcv->nibble, &rcv->length.b.msb))
                        return TIMEOUT;
-               if (rcv->length.h > dev->mtu + dev->hard_header_len
-                   || rcv->length.h < 8) {
+               if (rcv->length.h > dev->mtu + dev->hard_header_len ||
+                   rcv->length.h < 8) {
                        printk(KERN_WARNING "%s: bogus packet size %d.\n", dev->name, rcv->length.h);
                        return ERROR;
                }
@@ -638,14 +643,14 @@ plip_receive_packet(struct net_device *dev, struct net_local *nl,
 
        case PLIP_PK_DATA:
                lbuf = rcv->skb->data;
-               do
+               do {
                        if (plip_receive(nibble_timeout, dev,
                                         &rcv->nibble, &lbuf[rcv->byte]))
                                return TIMEOUT;
-               while (++rcv->byte < rcv->length.h);
-               do
+               while (++rcv->byte < rcv->length.h);
+               do {
                        rcv->checksum += lbuf[--rcv->byte];
-               while (rcv->byte);
+               while (rcv->byte);
                rcv->state = PLIP_PK_CHECKSUM;
 
        case PLIP_PK_CHECKSUM:
@@ -664,7 +669,6 @@ plip_receive_packet(struct net_device *dev, struct net_local *nl,
                /* Inform the upper layer for the arrival of a packet. */
                rcv->skb->protocol=plip_type_trans(rcv->skb, dev);
                netif_rx_ni(rcv->skb);
-               dev->last_rx = jiffies;
                dev->stats.rx_bytes += rcv->length.h;
                dev->stats.rx_packets++;
                rcv->skb = NULL;
@@ -817,14 +821,14 @@ plip_send_packet(struct net_device *dev, struct net_local *nl,
                snd->checksum = 0;
 
        case PLIP_PK_DATA:
-               do
+               do {
                        if (plip_send(nibble_timeout, dev,
                                      &snd->nibble, lbuf[snd->byte]))
                                return TIMEOUT;
-               while (++snd->byte < snd->length.h);
-               do
+               while (++snd->byte < snd->length.h);
+               do {
                        snd->checksum += lbuf[--snd->byte];
-               while (snd->byte);
+               while (snd->byte);
                snd->state = PLIP_PK_CHECKSUM;
 
        case PLIP_PK_CHECKSUM:
@@ -903,17 +907,18 @@ plip_interrupt(void *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;
        }
 
@@ -942,7 +947,7 @@ plip_interrupt(void *dev_id)
                break;
        }
 
-       spin_unlock_irq(&nl->lock);
+       spin_unlock_irqrestore(&nl->lock, flags);
 }
 
 static int
@@ -952,12 +957,12 @@ plip_tx_packet(struct sk_buff *skb, struct net_device *dev)
        struct plip_local *snd = &nl->snd_data;
 
        if (netif_queue_stopped(dev))
-               return 1;
+               return NETDEV_TX_BUSY;
 
        /* We may need to grab the bus */
        if (!nl->port_owner) {
                if (parport_claim(nl->pardev))
-                       return 1;
+                       return NETDEV_TX_BUSY;
                nl->port_owner = 1;
        }
 
@@ -966,7 +971,7 @@ plip_tx_packet(struct sk_buff *skb, struct net_device *dev)
        if (skb->len > dev->mtu + dev->hard_header_len) {
                printk(KERN_WARNING "%s: packet too big, %d.\n", dev->name, (int)skb->len);
                netif_start_queue (dev);
-               return 1;
+               return NETDEV_TX_BUSY;
        }
 
        if (net_debug > 2)
@@ -984,7 +989,7 @@ plip_tx_packet(struct sk_buff *skb, struct net_device *dev)
        schedule_work(&nl->immediate);
        spin_unlock_irq(&nl->lock);
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 static void
@@ -1017,8 +1022,8 @@ plip_hard_header(struct sk_buff *skb, struct net_device *dev,
        return ret;
 }
 
-int plip_hard_header_cache(const struct neighbour *neigh,
-                           struct hh_cache *hh)
+static int plip_hard_header_cache(const struct neighbour *neigh,
+                                 struct hh_cache *hh)
 {
        int ret;
 
@@ -1112,9 +1117,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
@@ -1269,7 +1274,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);
 
@@ -1396,9 +1401,3 @@ static int __init plip_init (void)
 module_init(plip_init);
 module_exit(plip_cleanup_module);
 MODULE_LICENSE("GPL");
-
-/*
- * Local variables:
- * compile-command: "gcc -DMODULE -DMODVERSIONS -D__KERNEL__ -Wall -Wstrict-prototypes -O2 -g -fomit-frame-pointer -pipe -c plip.c"
- * End:
- */