drm/radeon: bump the UMS driver version for r6xx/r7xx const buffer support
[safe/jmp/linux-2.6] / net / wireless / reg.c
index 2d1d183..7a0754c 100644 (file)
@@ -62,6 +62,16 @@ const struct ieee80211_regdomain *cfg80211_regdomain;
  */
 static const struct ieee80211_regdomain *country_ie_regdomain;
 
+/*
+ * Protects static reg.c components:
+ *     - cfg80211_world_regdom
+ *     - cfg80211_regdom
+ *     - country_ie_regdomain
+ *     - last_request
+ */
+DEFINE_MUTEX(reg_mutex);
+#define assert_reg_lock() WARN_ON(!mutex_is_locked(&reg_mutex))
+
 /* Used to queue up regulatory hints */
 static LIST_HEAD(reg_requests_list);
 static spinlock_t reg_requests_lock;
@@ -131,62 +141,35 @@ static const struct ieee80211_regdomain us_regdom = {
        .reg_rules = {
                /* IEEE 802.11b/g, channels 1..11 */
                REG_RULE(2412-10, 2462+10, 40, 6, 27, 0),
-               /* IEEE 802.11a, channel 36 */
-               REG_RULE(5180-10, 5180+10, 40, 6, 23, 0),
-               /* IEEE 802.11a, channel 40 */
-               REG_RULE(5200-10, 5200+10, 40, 6, 23, 0),
-               /* IEEE 802.11a, channel 44 */
-               REG_RULE(5220-10, 5220+10, 40, 6, 23, 0),
+               /* IEEE 802.11a, channel 36..48 */
+               REG_RULE(5180-10, 5240+10, 40, 6, 17, 0),
                /* IEEE 802.11a, channels 48..64 */
-               REG_RULE(5240-10, 5320+10, 40, 6, 23, 0),
+               REG_RULE(5260-10, 5320+10, 40, 6, 20, NL80211_RRF_DFS),
+               /* IEEE 802.11a, channels 100..124 */
+               REG_RULE(5500-10, 5590+10, 40, 6, 20, NL80211_RRF_DFS),
+               /* IEEE 802.11a, channels 132..144 */
+               REG_RULE(5660-10, 5700+10, 40, 6, 20, NL80211_RRF_DFS),
                /* IEEE 802.11a, channels 149..165, outdoor */
                REG_RULE(5745-10, 5825+10, 40, 6, 30, 0),
        }
 };
 
 static const struct ieee80211_regdomain jp_regdom = {
-       .n_reg_rules = 3,
+       .n_reg_rules = 6,
        .alpha2 =  "JP",
        .reg_rules = {
-               /* IEEE 802.11b/g, channels 1..14 */
-               REG_RULE(2412-10, 2484+10, 40, 6, 20, 0),
-               /* IEEE 802.11a, channels 34..48 */
-               REG_RULE(5170-10, 5240+10, 40, 6, 20,
-                       NL80211_RRF_PASSIVE_SCAN),
+               /* IEEE 802.11b/g, channels 1..11 */
+               REG_RULE(2412-10, 2462+10, 40, 6, 20, 0),
+               /* IEEE 802.11b/g, channels 12..13 */
+               REG_RULE(2467-10, 2472+10, 20, 6, 20, 0),
+               /* IEEE 802.11b/g, channel 14 */
+               REG_RULE(2484-10, 2484+10, 20, 6, 20, NL80211_RRF_NO_OFDM),
+               /* IEEE 802.11a, channels 36..48 */
+               REG_RULE(5180-10, 5240+10, 40, 6, 20, 0),
                /* IEEE 802.11a, channels 52..64 */
-               REG_RULE(5260-10, 5320+10, 40, 6, 20,
-                       NL80211_RRF_NO_IBSS |
-                       NL80211_RRF_DFS),
-       }
-};
-
-static const struct ieee80211_regdomain eu_regdom = {
-       .n_reg_rules = 6,
-       /*
-        * This alpha2 is bogus, we leave it here just for stupid
-        * backward compatibility
-        */
-       .alpha2 =  "EU",
-       .reg_rules = {
-               /* IEEE 802.11b/g, channels 1..13 */
-               REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
-               /* IEEE 802.11a, channel 36 */
-               REG_RULE(5180-10, 5180+10, 40, 6, 23,
-                       NL80211_RRF_PASSIVE_SCAN),
-               /* IEEE 802.11a, channel 40 */
-               REG_RULE(5200-10, 5200+10, 40, 6, 23,
-                       NL80211_RRF_PASSIVE_SCAN),
-               /* IEEE 802.11a, channel 44 */
-               REG_RULE(5220-10, 5220+10, 40, 6, 23,
-                       NL80211_RRF_PASSIVE_SCAN),
-               /* IEEE 802.11a, channels 48..64 */
-               REG_RULE(5240-10, 5320+10, 40, 6, 20,
-                       NL80211_RRF_NO_IBSS |
-                       NL80211_RRF_DFS),
-               /* IEEE 802.11a, channels 100..140 */
-               REG_RULE(5500-10, 5700+10, 40, 6, 30,
-                       NL80211_RRF_NO_IBSS |
-                       NL80211_RRF_DFS),
+               REG_RULE(5260-10, 5320+10, 40, 6, 20, NL80211_RRF_DFS),
+               /* IEEE 802.11a, channels 100..144 */
+               REG_RULE(5500-10, 5700+10, 40, 6, 23, NL80211_RRF_DFS),
        }
 };
 
@@ -196,15 +179,17 @@ static const struct ieee80211_regdomain *static_regdom(char *alpha2)
                return &us_regdom;
        if (alpha2[0] == 'J' && alpha2[1] == 'P')
                return &jp_regdom;
+       /* Use world roaming rules for "EU", since it was a pseudo
+          domain anyway... */
        if (alpha2[0] == 'E' && alpha2[1] == 'U')
-               return &eu_regdom;
-       /* Default, as per the old rules */
-       return &us_regdom;
+               return &world_regdom;
+       /* Default, world roaming rules */
+       return &world_regdom;
 }
 
 static bool is_old_static_regdom(const struct ieee80211_regdomain *rd)
 {
-       if (rd == &us_regdom || rd == &jp_regdom || rd == &eu_regdom)
+       if (rd == &us_regdom || rd == &jp_regdom || rd == &world_regdom)
                return true;
        return false;
 }
@@ -998,7 +983,7 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
 
        if (last_request->initiator == NL80211_REGDOM_SET_BY_DRIVER &&
            request_wiphy && request_wiphy == wiphy &&
-           request_wiphy->strict_regulatory) {
+           request_wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY) {
                /*
                 * This gaurantees the driver's requested regulatory domain
                 * will always be used as a base for further regulatory
@@ -1008,7 +993,6 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
                        map_regdom_flags(reg_rule->flags) | bw_flags;
                chan->max_antenna_gain = chan->orig_mag =
                        (int) MBI_TO_DBI(power_rule->max_antenna_gain);
-               chan->max_bandwidth = KHZ_TO_MHZ(desired_bw_khz);
                chan->max_power = chan->orig_mpwr =
                        (int) MBM_TO_DBM(power_rule->max_eirp);
                return;
@@ -1017,7 +1001,6 @@ static void handle_channel(struct wiphy *wiphy, enum ieee80211_band band,
        chan->flags = flags | bw_flags | map_regdom_flags(reg_rule->flags);
        chan->max_antenna_gain = min(chan->orig_mag,
                (int) MBI_TO_DBI(power_rule->max_antenna_gain));
-       chan->max_bandwidth = KHZ_TO_MHZ(desired_bw_khz);
        if (chan->orig_mpwr)
                chan->max_power = min(chan->orig_mpwr,
                        (int) MBM_TO_DBM(power_rule->max_eirp));
@@ -1043,13 +1026,13 @@ static bool ignore_reg_update(struct wiphy *wiphy,
        if (!last_request)
                return true;
        if (initiator == NL80211_REGDOM_SET_BY_CORE &&
-                 wiphy->custom_regulatory)
+           wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
                return true;
        /*
         * wiphy->regd will be set once the device has its own
         * desired regulatory domain set
         */
-       if (wiphy->strict_regulatory && !wiphy->regd &&
+       if (wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY && !wiphy->regd &&
            !is_world_regdom(last_request->alpha2))
                return true;
        return false;
@@ -1085,17 +1068,18 @@ static void handle_reg_beacon(struct wiphy *wiphy,
 
        chan->beacon_found = true;
 
+       if (wiphy->flags & WIPHY_FLAG_DISABLE_BEACON_HINTS)
+               return;
+
        chan_before.center_freq = chan->center_freq;
        chan_before.flags = chan->flags;
 
-       if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) &&
-           !(chan->orig_flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
+       if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) {
                chan->flags &= ~IEEE80211_CHAN_PASSIVE_SCAN;
                channel_changed = true;
        }
 
-       if ((chan->flags & IEEE80211_CHAN_NO_IBSS) &&
-           !(chan->orig_flags & IEEE80211_CHAN_NO_IBSS)) {
+       if (chan->flags & IEEE80211_CHAN_NO_IBSS) {
                chan->flags &= ~IEEE80211_CHAN_NO_IBSS;
                channel_changed = true;
        }
@@ -1155,7 +1139,7 @@ static bool reg_is_world_roaming(struct wiphy *wiphy)
                return true;
        if (last_request &&
            last_request->initiator != NL80211_REGDOM_SET_BY_COUNTRY_IE &&
-           wiphy->custom_regulatory)
+           wiphy->flags & WIPHY_FLAG_CUSTOM_REGULATORY)
                return true;
        return false;
 }
@@ -1293,7 +1277,7 @@ static void handle_channel_custom(struct wiphy *wiphy,
        struct ieee80211_supported_band *sband;
        struct ieee80211_channel *chan;
 
-       assert_cfg80211_lock();
+       assert_reg_lock();
 
        sband = wiphy->bands[band];
        BUG_ON(chan_idx >= sband->n_channels);
@@ -1318,7 +1302,6 @@ static void handle_channel_custom(struct wiphy *wiphy,
 
        chan->flags |= map_regdom_flags(reg_rule->flags) | bw_flags;
        chan->max_antenna_gain = (int) MBI_TO_DBI(power_rule->max_antenna_gain);
-       chan->max_bandwidth = KHZ_TO_MHZ(desired_bw_khz);
        chan->max_power = (int) MBM_TO_DBM(power_rule->max_eirp);
 }
 
@@ -1342,14 +1325,14 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy,
        enum ieee80211_band band;
        unsigned int bands_set = 0;
 
-       mutex_lock(&cfg80211_mutex);
+       mutex_lock(&reg_mutex);
        for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
                if (!wiphy->bands[band])
                        continue;
                handle_band_custom(wiphy, band, regd);
                bands_set++;
        }
-       mutex_unlock(&cfg80211_mutex);
+       mutex_unlock(&reg_mutex);
 
        /*
         * no point in calling this if it won't have any effect
@@ -1416,7 +1399,7 @@ static int ignore_request(struct wiphy *wiphy,
                        if (last_wiphy != wiphy) {
                                /*
                                 * Two cards with two APs claiming different
-                                * different Country IE alpha2s. We could
+                                * Country IE alpha2s. We could
                                 * intersect them, but that seems unlikely
                                 * to be correct. Reject second one for now.
                                 */
@@ -1495,7 +1478,7 @@ static int ignore_request(struct wiphy *wiphy,
  * Returns zero if all went fine, %-EALREADY if a regulatory domain had
  * already been set or other standard error codes.
  *
- * Caller must hold &cfg80211_mutex
+ * Caller must hold &cfg80211_mutex and &reg_mutex
  */
 static int __regulatory_hint(struct wiphy *wiphy,
                             struct regulatory_request *pending_request)
@@ -1570,6 +1553,7 @@ static void reg_process_hint(struct regulatory_request *reg_request)
        BUG_ON(!reg_request->alpha2);
 
        mutex_lock(&cfg80211_mutex);
+       mutex_lock(&reg_mutex);
 
        if (wiphy_idx_valid(reg_request->wiphy_idx))
                wiphy = wiphy_idx_to_wiphy(reg_request->wiphy_idx);
@@ -1582,9 +1566,11 @@ static void reg_process_hint(struct regulatory_request *reg_request)
 
        r = __regulatory_hint(wiphy, reg_request);
        /* This is required so that the orig_* parameters are saved */
-       if (r == -EALREADY && wiphy && wiphy->strict_regulatory)
+       if (r == -EALREADY && wiphy &&
+           wiphy->flags & WIPHY_FLAG_STRICT_REGULATORY)
                wiphy_update_regulatory(wiphy, reg_request->initiator);
 out:
+       mutex_unlock(&reg_mutex);
        mutex_unlock(&cfg80211_mutex);
 }
 
@@ -1613,6 +1599,10 @@ static void reg_process_pending_beacon_hints(void)
        struct cfg80211_registered_device *rdev;
        struct reg_beacon *pending_beacon, *tmp;
 
+       /*
+        * No need to hold the reg_mutex here as we just touch wiphys
+        * and do not read or access regulatory variables.
+        */
        mutex_lock(&cfg80211_mutex);
 
        /* This goes through the _pending_ beacon list */
@@ -1700,7 +1690,7 @@ int regulatory_hint_user(const char *alpha2)
        request->wiphy_idx = WIPHY_IDX_STALE;
        request->alpha2[0] = alpha2[0];
        request->alpha2[1] = alpha2[1];
-       request->initiator = NL80211_REGDOM_SET_BY_USER,
+       request->initiator = NL80211_REGDOM_SET_BY_USER;
 
        queue_regulatory_request(request);
 
@@ -1734,12 +1724,13 @@ int regulatory_hint(struct wiphy *wiphy, const char *alpha2)
 }
 EXPORT_SYMBOL(regulatory_hint);
 
+/* Caller must hold reg_mutex */
 static bool reg_same_country_ie_hint(struct wiphy *wiphy,
                        u32 country_ie_checksum)
 {
        struct wiphy *request_wiphy;
 
-       assert_cfg80211_lock();
+       assert_reg_lock();
 
        if (unlikely(last_request->initiator !=
            NL80211_REGDOM_SET_BY_COUNTRY_IE))
@@ -1762,6 +1753,10 @@ static bool reg_same_country_ie_hint(struct wiphy *wiphy,
        return false;
 }
 
+/*
+ * We hold wdev_lock() here so we cannot hold cfg80211_mutex() and
+ * therefore cannot iterate over the rdev list here.
+ */
 void regulatory_hint_11d(struct wiphy *wiphy,
                        u8 *country_ie,
                        u8 country_ie_len)
@@ -1772,7 +1767,7 @@ void regulatory_hint_11d(struct wiphy *wiphy,
        enum environment_cap env = ENVIRON_ANY;
        struct regulatory_request *request;
 
-       mutex_lock(&cfg80211_mutex);
+       mutex_lock(&reg_mutex);
 
        if (unlikely(!last_request))
                goto out;
@@ -1801,54 +1796,14 @@ void regulatory_hint_11d(struct wiphy *wiphy,
                env = ENVIRON_OUTDOOR;
 
        /*
-        * We will run this for *every* beacon processed for the BSSID, so
-        * we optimize an early check to exit out early if we don't have to
-        * do anything
+        * We will run this only upon a successful connection on cfg80211.
+        * We leave conflict resolution to the workqueue, where can hold
+        * cfg80211_mutex.
         */
        if (likely(last_request->initiator ==
            NL80211_REGDOM_SET_BY_COUNTRY_IE &&
-           wiphy_idx_valid(last_request->wiphy_idx))) {
-               struct cfg80211_registered_device *rdev_last_ie;
-
-               rdev_last_ie =
-                       cfg80211_rdev_by_wiphy_idx(last_request->wiphy_idx);
-
-               /*
-                * Lets keep this simple -- we trust the first AP
-                * after we intersect with CRDA
-                */
-               if (likely(&rdev_last_ie->wiphy == wiphy)) {
-                       /*
-                        * Ignore IEs coming in on this wiphy with
-                        * the same alpha2 and environment cap
-                        */
-                       if (likely(alpha2_equal(rdev_last_ie->country_ie_alpha2,
-                                 alpha2) &&
-                                 env == rdev_last_ie->env)) {
-                               goto out;
-                       }
-                       /*
-                        * the wiphy moved on to another BSSID or the AP
-                        * was reconfigured. XXX: We need to deal with the
-                        * case where the user suspends and goes to goes
-                        * to another country, and then gets IEs from an
-                        * AP with different settings
-                        */
-                       goto out;
-               } else {
-                       /*
-                        * Ignore IEs coming in on two separate wiphys with
-                        * the same alpha2 and environment cap
-                        */
-                       if (likely(alpha2_equal(rdev_last_ie->country_ie_alpha2,
-                                 alpha2) &&
-                                 env == rdev_last_ie->env)) {
-                               goto out;
-                       }
-                       /* We could potentially intersect though */
-                       goto out;
-               }
-       }
+           wiphy_idx_valid(last_request->wiphy_idx)))
+               goto out;
 
        rd = country_ie_2_rd(country_ie, country_ie_len, &checksum);
        if (!rd)
@@ -1883,7 +1838,7 @@ void regulatory_hint_11d(struct wiphy *wiphy,
        request->country_ie_checksum = checksum;
        request->country_ie_env = env;
 
-       mutex_unlock(&cfg80211_mutex);
+       mutex_unlock(&reg_mutex);
 
        queue_regulatory_request(request);
 
@@ -1892,9 +1847,8 @@ void regulatory_hint_11d(struct wiphy *wiphy,
 free_rd_out:
        kfree(rd);
 out:
-       mutex_unlock(&cfg80211_mutex);
+       mutex_unlock(&reg_mutex);
 }
-EXPORT_SYMBOL(regulatory_hint_11d);
 
 static bool freq_is_chan_12_13_14(u16 freq)
 {
@@ -1952,7 +1906,7 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
        const struct ieee80211_freq_range *freq_range = NULL;
        const struct ieee80211_power_rule *power_rule = NULL;
 
-       printk(KERN_INFO "\t(start_freq - end_freq @ bandwidth), "
+       printk(KERN_INFO "    (start_freq - end_freq @ bandwidth), "
                "(max_antenna_gain, max_eirp)\n");
 
        for (i = 0; i < rd->n_reg_rules; i++) {
@@ -1965,7 +1919,7 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
                 * in certain regions
                 */
                if (power_rule->max_antenna_gain)
-                       printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), "
+                       printk(KERN_INFO "    (%d KHz - %d KHz @ %d KHz), "
                                "(%d mBi, %d mBm)\n",
                                freq_range->start_freq_khz,
                                freq_range->end_freq_khz,
@@ -1973,7 +1927,7 @@ static void print_rd_rules(const struct ieee80211_regdomain *rd)
                                power_rule->max_antenna_gain,
                                power_rule->max_eirp);
                else
-                       printk(KERN_INFO "\t(%d KHz - %d KHz @ %d KHz), "
+                       printk(KERN_INFO "    (%d KHz - %d KHz @ %d KHz), "
                                "(N/A, %d mBm)\n",
                                freq_range->start_freq_khz,
                                freq_range->end_freq_khz,
@@ -2225,10 +2179,13 @@ int set_regdom(const struct ieee80211_regdomain *rd)
 
        assert_cfg80211_lock();
 
+       mutex_lock(&reg_mutex);
+
        /* Note that this doesn't update the wiphys, this is done below */
        r = __set_regdom(rd);
        if (r) {
                kfree(rd);
+               mutex_unlock(&reg_mutex);
                return r;
        }
 
@@ -2243,6 +2200,8 @@ int set_regdom(const struct ieee80211_regdomain *rd)
 
        nl80211_send_reg_change_event(last_request);
 
+       mutex_unlock(&reg_mutex);
+
        return r;
 }
 
@@ -2253,16 +2212,20 @@ void reg_device_remove(struct wiphy *wiphy)
 
        assert_cfg80211_lock();
 
+       mutex_lock(&reg_mutex);
+
        kfree(wiphy->regd);
 
        if (last_request)
                request_wiphy = wiphy_idx_to_wiphy(last_request->wiphy_idx);
 
        if (!request_wiphy || request_wiphy != wiphy)
-               return;
+               goto out;
 
        last_request->wiphy_idx = WIPHY_IDX_STALE;
        last_request->country_ie_env = ENVIRON_ANY;
+out:
+       mutex_unlock(&reg_mutex);
 }
 
 int regulatory_init(void)
@@ -2323,6 +2286,7 @@ void regulatory_exit(void)
        cancel_work_sync(&reg_work);
 
        mutex_lock(&cfg80211_mutex);
+       mutex_lock(&reg_mutex);
 
        reset_regdomains();
 
@@ -2361,5 +2325,6 @@ void regulatory_exit(void)
        }
        spin_unlock(&reg_requests_lock);
 
+       mutex_unlock(&reg_mutex);
        mutex_unlock(&cfg80211_mutex);
 }