Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / net / shaper.c
index 269e7f7..88e2120 100644 (file)
@@ -83,6 +83,7 @@
 #include <linux/if_arp.h>
 #include <linux/init.h>
 #include <linux/if_shaper.h>
+#include <linux/jiffies.h>
 
 #include <net/dst.h>
 #include <net/arp.h>
@@ -96,39 +97,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 +131,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;
        
        /*
@@ -187,52 +157,6 @@ static int shaper_qframe(struct shaper *shaper, struct sk_buff *skb)
         
        SHAPERCB(skb)->shapelen= shaper_clocks(shaper,skb);
        
-#ifdef SHAPER_COMPLEX /* and broken.. */
-
-       while(ptr && ptr!=(struct sk_buff *)&shaper->sendq)
-       {
-               if(ptr->pri<skb->pri 
-                       && jiffies - SHAPERCB(ptr)->shapeclock < SHAPER_MAXSLIP)
-               {
-                       struct sk_buff *tmp=ptr->prev;
-
-                       /*
-                        *      It goes before us therefore we slip the length
-                        *      of the new frame.
-                        */
-
-                       SHAPERCB(ptr)->shapeclock+=SHAPERCB(skb)->shapelen;
-                       SHAPERCB(ptr)->shapelatency+=SHAPERCB(skb)->shapelen;
-
-                       /*
-                        *      The packet may have slipped so far back it
-                        *      fell off.
-                        */
-                       if(SHAPERCB(ptr)->shapelatency > SHAPER_LATENCY)
-                       {
-                               skb_unlink(ptr);
-                               dev_kfree_skb(ptr);
-                       }
-                       ptr=tmp;
-               }
-               else
-                       break;
-       }
-       if(ptr==NULL || ptr==(struct sk_buff *)&shaper->sendq)
-               skb_queue_head(&shaper->sendq,skb);
-       else
-       {
-               struct sk_buff *tmp;
-               /*
-                *      Set the packet clock out time according to the
-                *      frames ahead. Im sure a bit of thought could drop
-                *      this loop.
-                */
-               for(tmp=skb_peek(&shaper->sendq); tmp!=NULL && tmp!=ptr; tmp=tmp->next)
-                       SHAPERCB(skb)->shapeclock+=tmp->shapelen;
-               skb_append(ptr,skb);
-       }
-#else
        {
                struct sk_buff *tmp;
                /*
@@ -245,13 +169,13 @@ static int shaper_qframe(struct shaper *shaper, struct sk_buff *skb)
                /*
                 *      Queue over time. Spill packet.
                 */
-               if(SHAPERCB(skb)->shapeclock-jiffies > SHAPER_LATENCY) {
+               if(time_after(SHAPERCB(skb)->shapeclock,jiffies + SHAPER_LATENCY)) {
                        dev_kfree_skb(skb);
                        shaper->stats.tx_dropped++;
                } else
                        skb_queue_tail(&shaper->sendq, skb);
        }
-#endif         
+
        if(sh_debug)
                printk("Frame queued.\n");
        if(skb_queue_len(&shaper->sendq)>SHAPER_QLEN)
@@ -260,7 +184,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 +222,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 +238,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)
         */
@@ -342,7 +257,7 @@ static void shaper_kick(struct shaper *shaper)
                         *      Pull the frame and get interrupts back on.
                         */
                         
-                       skb_unlink(skb);
+                       skb_unlink(skb, &shaper->sendq);
                        if (shaper->recovery < 
                            SHAPERCB(skb)->shapeclock + SHAPERCB(skb)->shapelen)
                                shaper->recovery = SHAPERCB(skb)->shapeclock + SHAPERCB(skb)->shapelen;
@@ -364,28 +279,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 +311,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 +330,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 +520,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);
 }
 
 /*