Don't set ctl_name in Linux 2.6.33+, it was removed
[madwifi/.git] / ath_rate / amrr / amrr.c
index 7b16703c9cf993361879bf5a605d53a572a1f70e..c2ec5b812e81f23d6db8b1a94e6570f08374e113 100644 (file)
 #define        DPRINTF(sc, _fmt, ...)
 #endif
 
+#include "release.h"
+#if 0
+static char *version = "0.1 (" RELEASE_VERSION ")";
+#endif
+static char *dev_info = "ath_rate_amrr";
+
 static int ath_rateinterval = 1000;            /* rate ctl interval (ms)  */
 static int ath_rate_max_success_threshold = 10;
 static int ath_rate_min_success_threshold = 1;
@@ -195,8 +201,8 @@ ath_rate_update(struct ath_softc *sc, struct ieee80211_node *ni, int rate)
 
        KASSERT(rt != NULL, ("no rate table, mode %u", sc->sc_curmode));
 
-       DPRINTF(sc, "%s: set xmit rate for %s to %dM\n",
-               __func__, ether_sprintf(ni->ni_macaddr),
+       DPRINTF(sc, "%s: set xmit rate for " MAC_FMT " to %dM\n",
+               __func__, MAC_ADDR(ni->ni_macaddr),
                ni->ni_rates.rs_nrates > 0 ?
                        (ni->ni_rates.rs_rates[rate] & IEEE80211_RATE_VAL) / 2 : 0);
 
@@ -270,35 +276,41 @@ ath_rate_ctl_start(struct ath_softc *sc, struct ieee80211_node *ni)
        int srate;
 
        KASSERT(ni->ni_rates.rs_nrates > 0, ("no rates"));
-       if (vap->iv_fixed_rate == IEEE80211_FIXED_RATE_NONE) {
+
+       if (vap->iv_fixed_rate != IEEE80211_FIXED_RATE_NONE) {
                /*
-                * No fixed rate is requested. For 11b start with
-                * the highest negotiated rate; otherwise, for 11g
-                * and 11a, we start "in the middle" at 24Mb or 36Mb.
+                * A fixed rate is to be used.  Find the corresponding
+                * index in the rate table.
                 */
-               srate = ni->ni_rates.rs_nrates - 1;
-               if (sc->sc_curmode != IEEE80211_MODE_11B) {
-                       /*
-                        * Scan the negotiated rate set to find the
-                        * closest rate.
-                        */
-                       /* NB: the rate set is assumed sorted */
-                       for (; srate >= 0 && RATE(srate) > 72; srate--);
-                       KASSERT(srate >= 0, ("bogus rate set"));
-               }
-       } else {
+               for (srate = 0; srate < ni->ni_rates.rs_nrates; srate++)
+                       if (vap->iv_fixed_rate ==
+                           (ni->ni_rates.rs_rates[srate] & IEEE80211_RATE_VAL)) {
+                               ath_rate_update(sc, ni, srate);
+                               return;
+                       }
+
+               printk(KERN_WARNING "%s: %s: fixed rate %u%sMbps is not "
+                      "available and will be ignored\n", vap->iv_dev->name,
+                      dev_info, vap->iv_fixed_rate / 2,
+                      (vap->iv_fixed_rate & 1) ? ".5" : "");
+       }
+
+       /*
+        * No fixed rate is requested. For 11b start with
+        * the highest negotiated rate; otherwise, for 11g
+        * and 11a, we start "in the middle" at 24Mb or 36Mb.
+        */
+       srate = ni->ni_rates.rs_nrates - 1;
+       if (sc->sc_curmode != IEEE80211_MODE_11B) {
                /*
-                * A fixed rate is to be used; ic_fixed_rate is an
-                * index into the supported rate set.  Convert this
-                * to the index into the negotiated rate set for
-                * the node.  We know the rate is there because the
-                * rate set is checked when the station associates.
+                * Scan the negotiated rate set to find the
+                * closest rate.
                 */
-               srate = ni->ni_rates.rs_nrates - 1;
-               for (; srate >= 0 && RATE(srate) != vap->iv_fixed_rate; srate--);
-               KASSERT(srate >= 0,
-                       ("fixed rate %d not in rate set", vap->iv_fixed_rate));
+               /* NB: the rate set is assumed sorted */
+               for (; srate >= 0 && RATE(srate) > 72; srate--);
+               KASSERT(srate >= 0, ("bogus rate set"));
        }
+
        ath_rate_update(sc, ni, srate);
 #undef RATE
 }
@@ -306,7 +318,7 @@ ath_rate_ctl_start(struct ath_softc *sc, struct ieee80211_node *ni)
 static void
 ath_rate_cb(void *arg, struct ieee80211_node *ni)
 {
-       ath_rate_update(ni->ni_ic->ic_dev->priv, ni, (long) arg);
+       ath_rate_update(netdev_priv(ni->ni_ic->ic_dev), ni, (long) arg);
 }
 
 /*
@@ -316,8 +328,8 @@ static void
 ath_rate_newstate(struct ieee80211vap *vap, enum ieee80211_state state)
 {
        struct ieee80211com *ic = vap->iv_ic;
-       struct ath_softc *sc = ic->ic_dev->priv;
-       struct amrr_softc *asc = (struct amrr_softc *) sc->sc_rc;
+       struct ath_softc *sc = netdev_priv(ic->ic_dev);
+       struct amrr_softc *asc = (struct amrr_softc *)sc->sc_rc;
        struct ieee80211_node *ni;
 
        if (state == IEEE80211_S_INIT) {
@@ -428,7 +440,7 @@ static void
 ath_ratectl(unsigned long data)
 {
        struct net_device *dev = (struct net_device *)data;
-       struct ath_softc *sc = dev->priv;
+       struct ath_softc *sc = netdev_priv(dev);
        struct amrr_softc *asc = (struct amrr_softc *)sc->sc_rc;
        struct ieee80211com *ic = &sc->sc_ic;
        int interval;
@@ -447,8 +459,7 @@ ath_ratectl(unsigned long data)
        interval = ath_rateinterval;
        if (ic->ic_opmode == IEEE80211_M_STA)
                interval /= 2;
-       asc->timer.expires = jiffies + ((HZ * interval) / 1000);
-       add_timer(&asc->timer);
+       mod_timer(&asc->timer, jiffies + ((HZ * interval) / 1000));
 }
 
 static struct ath_ratectrl *
@@ -474,7 +485,7 @@ ath_rate_attach(struct ath_softc *sc)
 static void
 ath_rate_detach(struct ath_ratectrl *arc)
 {
-       struct amrr_softc *asc = (struct amrr_softc *) arc;
+       struct amrr_softc *asc = (struct amrr_softc *)arc;
 
        del_timer(&asc->timer);
        kfree(asc);
@@ -485,17 +496,12 @@ static int minrateinterval = 500; /* 500ms */
 static int maxint = 0x7fffffff;                /* 32-bit big */
 static int min_threshold = 1;
 
-#define        CTL_AUTO        -2      /* cannot be CTL_ANY or CTL_NONE */
-
 /*
  * Static (i.e. global) sysctls.
  */
-enum {
-       DEV_ATH         = 9,                    /* XXX known by many */
-};
 
 static ctl_table ath_rate_static_sysctls[] = {
-       { .ctl_name     = CTL_AUTO,
+       { ATH_INIT_CTL_NAME(CTL_AUTO)
          .procname     = "interval",
          .mode         = 0644,
          .data         = &ath_rateinterval,
@@ -504,7 +510,7 @@ static ctl_table ath_rate_static_sysctls[] = {
          .extra2       = &maxint,
          .proc_handler = proc_dointvec_minmax
        },
-       { .ctl_name     = CTL_AUTO,
+       { ATH_INIT_CTL_NAME(CTL_AUTO)
          .procname     = "max_success_threshold",
          .mode         = 0644,
          .data         = &ath_rate_max_success_threshold,
@@ -513,7 +519,7 @@ static ctl_table ath_rate_static_sysctls[] = {
          .extra2       = &maxint,
          .proc_handler = proc_dointvec_minmax
        },
-       { .ctl_name     = CTL_AUTO,
+       { ATH_INIT_CTL_NAME(CTL_AUTO)
          .procname     = "min_success_threshold",
          .mode         = 0644,
          .data         = &ath_rate_min_success_threshold,
@@ -525,21 +531,21 @@ static ctl_table ath_rate_static_sysctls[] = {
        { 0 }
 };
 static ctl_table ath_rate_table[] = {
-       { .ctl_name     = CTL_AUTO,
-         .procname     = "rate",
+       { ATH_INIT_CTL_NAME(CTL_AUTO)
+         .procname     = "rate_amrr",
          .mode         = 0555,
          .child        = ath_rate_static_sysctls
        }, { 0 }
 };
 static ctl_table ath_ath_table[] = {
-       { .ctl_name     = DEV_ATH,
+       { ATH_INIT_CTL_NAME(DEV_ATH)
          .procname     = "ath",
          .mode         = 0555,
          .child        = ath_rate_table
        }, { 0 }
 };
 static ctl_table ath_root_table[] = {
-       { .ctl_name     = CTL_DEV,
+       { ATH_INIT_CTL_NAME(CTL_DEV)
          .procname     = "dev",
          .mode         = 0555,
          .child        = ath_ath_table
@@ -560,10 +566,6 @@ static struct ieee80211_rate_ops ath_rate_ops = {
        .detach = ath_rate_detach,
 };
 
-#include "release.h"
-static char *version = "0.1 (" RELEASE_VERSION ")";
-static char *dev_info = "ath_rate_amrr";
-
 MODULE_AUTHOR("INRIA, Mathieu Lacage");
 MODULE_DESCRIPTION("AMRR Rate control algorithm");
 #ifdef MODULE_VERSION
@@ -576,10 +578,7 @@ MODULE_LICENSE("Dual BSD/GPL");
 static int __init
 init_ath_rate_amrr(void)
 {
-       int ret;
-       printk(KERN_INFO "%s: %s\n", dev_info, version);
-
-       ret = ieee80211_rate_register(&ath_rate_ops);
+       int ret = ieee80211_rate_register(&ath_rate_ops);
        if (ret)
                return ret;
 
@@ -594,7 +593,5 @@ exit_ath_rate_amrr(void)
        if (ath_sysctl_header != NULL)
                unregister_sysctl_table(ath_sysctl_header);
        ieee80211_rate_unregister(&ath_rate_ops);
-
-       printk(KERN_INFO "%s: unloaded\n", dev_info);
 }
 module_exit(exit_ath_rate_amrr);