- just warn if gcc 3.x compiler can't be found
[linux-2.6.git] / drivers / net / shaper.c
index 2351e18..16bb1ce 100644 (file)
@@ -96,39 +96,12 @@ struct shaper_cb {
 }; 
 #define SHAPERCB(skb) ((struct shaper_cb *) ((skb)->cb))
 
-int sh_debug;          /* Debug flag */
+static int sh_debug;           /* Debug flag */
 
 #define SHAPER_BANNER  "CymruNet Traffic Shaper BETA 0.04 for Linux 2.1\n"
 
-/*
- *     Locking
- */
-static int shaper_lock(struct shaper *sh)
-{
-       /*
-        *      Lock in an interrupt must fail
-        */
-       while (test_and_set_bit(0, &sh->locked))
-       {
-               if (!in_interrupt())
-                       sleep_on(&sh->wait_queue);
-               else
-                       return 0;
-                       
-       }
-       return 1;
-}
-
 static void shaper_kick(struct shaper *sh);
 
-static void shaper_unlock(struct shaper *sh)
-{
-       clear_bit(0, &sh->locked);
-       wake_up(&sh->wait_queue);
-       shaper_kick(sh);
-}
-
 /*
  *     Compute clocks on a buffer
  */
@@ -157,17 +130,13 @@ static void shaper_setspeed(struct shaper *shaper, int bitspersec)
  *     Throw a frame at a shaper.
  */
   
-static int shaper_qframe(struct shaper *shaper, struct sk_buff *skb)
+
+static int shaper_start_xmit(struct sk_buff *skb, struct net_device *dev)
 {
+       struct shaper *shaper = dev->priv;
        struct sk_buff *ptr;
-   
-       /*
-        *      Get ready to work on this shaper. Lock may fail if its
-        *      an interrupt and locked.
-        */
-        
-       if(!shaper_lock(shaper))
-               return -1;
+
+       spin_lock(&shaper->lock);
        ptr=shaper->sendq.prev;
        
        /*
@@ -260,7 +229,8 @@ static int shaper_qframe(struct shaper *shaper, struct sk_buff *skb)
                 dev_kfree_skb(ptr);
                 shaper->stats.collisions++;
        }
-       shaper_unlock(shaper);
+       shaper_kick(shaper);
+       spin_unlock(&shaper->lock);
        return 0;
 }
 
@@ -297,8 +267,11 @@ static void shaper_queue_xmit(struct shaper *shaper, struct sk_buff *skb)
  
 static void shaper_timer(unsigned long data)
 {
-       struct shaper *sh=(struct shaper *)data;
-       shaper_kick(sh);
+       struct shaper *shaper = (struct shaper *)data;
+
+       spin_lock(&shaper->lock);
+       shaper_kick(shaper);
+       spin_unlock(&shaper->lock);
 }
 
 /*
@@ -310,19 +283,6 @@ static void shaper_kick(struct shaper *shaper)
 {
        struct sk_buff *skb;
        
-       /*
-        *      Shaper unlock will kick
-        */
-        
-       if (test_and_set_bit(0, &shaper->locked))
-       {
-               if(sh_debug)
-                       printk("Shaper locked.\n");
-               mod_timer(&shaper->timer, jiffies);
-               return;
-       }
-
-               
        /*
         *      Walk the list (may be empty)
         */
@@ -364,28 +324,9 @@ static void shaper_kick(struct shaper *shaper)
         
        if(skb!=NULL)
                mod_timer(&shaper->timer, SHAPERCB(skb)->shapeclock);
-
-       clear_bit(0, &shaper->locked);
 }
 
 
-/*
- *     Flush the shaper queues on a closedown
- */
-static void shaper_flush(struct shaper *shaper)
-{
-       struct sk_buff *skb;
-       if(!shaper_lock(shaper))
-       {
-               printk(KERN_ERR "shaper: shaper_flush() called by an irq!\n");
-               return;
-       }
-       while((skb=skb_dequeue(&shaper->sendq))!=NULL)
-               dev_kfree_skb(skb);
-       shaper_unlock(shaper);
-}
-
 /*
  *     Bring the interface up. We just disallow this until a 
  *     bind.
@@ -415,7 +356,15 @@ static int shaper_open(struct net_device *dev)
 static int shaper_close(struct net_device *dev)
 {
        struct shaper *shaper=dev->priv;
-       shaper_flush(shaper);
+       struct sk_buff *skb;
+
+       while ((skb = skb_dequeue(&shaper->sendq)) != NULL)
+               dev_kfree_skb(skb);
+
+       spin_lock_bh(&shaper->lock);
+       shaper_kick(shaper);
+       spin_unlock_bh(&shaper->lock);
+
        del_timer_sync(&shaper->timer);
        return 0;
 }
@@ -426,13 +375,6 @@ static int shaper_close(struct net_device *dev)
  *     ARP and other resolutions and not before.
  */
 
-
-static int shaper_start_xmit(struct sk_buff *skb, struct net_device *dev)
-{
-       struct shaper *sh=dev->priv;
-       return shaper_qframe(sh, skb);
-}
-
 static struct net_device_stats *shaper_get_stats(struct net_device *dev)
 {
        struct shaper *sh=dev->priv;
@@ -623,7 +565,7 @@ static void shaper_init_priv(struct net_device *dev)
        init_timer(&sh->timer);
        sh->timer.function=shaper_timer;
        sh->timer.data=(unsigned long)sh;
-       init_waitqueue_head(&sh->wait_queue);
+       spin_lock_init(&sh->lock);
 }
 
 /*
@@ -674,7 +616,7 @@ static void __init shaper_setup(struct net_device *dev)
 static int shapers = 1;
 #ifdef MODULE
 
-MODULE_PARM(shapers, "i");
+module_param(shapers, int, 0);
 MODULE_PARM_DESC(shapers, "Traffic shaper: maximum number of shapers");
 
 #else /* MODULE */