iwlwifi: move channels sysfs to debugfs
[safe/jmp/linux-2.6] / drivers / net / wireless / iwlwifi / iwl-agn.c
index 8264d37..e8368b6 100644 (file)
@@ -108,79 +108,6 @@ static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
 }
 
 /**
- * iwl_check_rxon_cmd - validate RXON structure is valid
- *
- * NOTE:  This is really only useful during development and can eventually
- * be #ifdef'd out once the driver is stable and folks aren't actively
- * making changes
- */
-static int iwl_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
-{
-       int error = 0;
-       int counter = 1;
-
-       if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
-               error |= le32_to_cpu(rxon->flags &
-                               (RXON_FLG_TGJ_NARROW_BAND_MSK |
-                                RXON_FLG_RADAR_DETECT_MSK));
-               if (error)
-                       IWL_WARNING("check 24G fields %d | %d\n",
-                                   counter++, error);
-       } else {
-               error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
-                               0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
-               if (error)
-                       IWL_WARNING("check 52 fields %d | %d\n",
-                                   counter++, error);
-               error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
-               if (error)
-                       IWL_WARNING("check 52 CCK %d | %d\n",
-                                   counter++, error);
-       }
-       error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
-       if (error)
-               IWL_WARNING("check mac addr %d | %d\n", counter++, error);
-
-       /* make sure basic rates 6Mbps and 1Mbps are supported */
-       error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
-                 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
-       if (error)
-               IWL_WARNING("check basic rate %d | %d\n", counter++, error);
-
-       error |= (le16_to_cpu(rxon->assoc_id) > 2007);
-       if (error)
-               IWL_WARNING("check assoc id %d | %d\n", counter++, error);
-
-       error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
-                       == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
-       if (error)
-               IWL_WARNING("check CCK and short slot %d | %d\n",
-                           counter++, error);
-
-       error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
-                       == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
-       if (error)
-               IWL_WARNING("check CCK & auto detect %d | %d\n",
-                           counter++, error);
-
-       error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
-                       RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
-       if (error)
-               IWL_WARNING("check TGG and auto detect %d | %d\n",
-                           counter++, error);
-
-       if (error)
-               IWL_WARNING("Tuning to channel %d\n",
-                           le16_to_cpu(rxon->channel));
-
-       if (error) {
-               IWL_ERROR("Not a valid iwl_rxon_assoc_cmd field values\n");
-               return -1;
-       }
-       return 0;
-}
-
-/**
  * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  * @priv: staging_rxon is compared to active_rxon
  *
@@ -252,7 +179,7 @@ static int iwl_commit_rxon(struct iwl_priv *priv)
         * 5000, but will not damage 4965 */
        priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
 
-       ret = iwl_check_rxon_cmd(&priv->staging_rxon);
+       ret = iwl_agn_check_rxon_cmd(&priv->staging_rxon);
        if (ret) {
                IWL_ERROR("Invalid RXON configuration.  Not committing.\n");
                return -EINVAL;
@@ -466,9 +393,9 @@ static u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
 
        /* Set rate mask*/
        if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
-               rate_mask = priv->active_rate_basic & 0xF;
+               rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
        else
-               rate_mask = priv->active_rate_basic & 0xFF0;
+               rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
 
        /* Find lowest valid rate */
        for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
@@ -871,138 +798,6 @@ static void iwl_set_rate(struct iwl_priv *priv)
                   (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
 }
 
-#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
-
-#include "iwl-spectrum.h"
-
-#define BEACON_TIME_MASK_LOW   0x00FFFFFF
-#define BEACON_TIME_MASK_HIGH  0xFF000000
-#define TIME_UNIT              1024
-
-/*
- * extended beacon time format
- * time in usec will be changed into a 32-bit value in 8:24 format
- * the high 1 byte is the beacon counts
- * the lower 3 bytes is the time in usec within one beacon interval
- */
-
-static u32 iwl_usecs_to_beacons(u32 usec, u32 beacon_interval)
-{
-       u32 quot;
-       u32 rem;
-       u32 interval = beacon_interval * 1024;
-
-       if (!interval || !usec)
-               return 0;
-
-       quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
-       rem = (usec % interval) & BEACON_TIME_MASK_LOW;
-
-       return (quot << 24) + rem;
-}
-
-/* base is usually what we get from ucode with each received frame,
- * the same as HW timer counter counting down
- */
-
-static __le32 iwl_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
-{
-       u32 base_low = base & BEACON_TIME_MASK_LOW;
-       u32 addon_low = addon & BEACON_TIME_MASK_LOW;
-       u32 interval = beacon_interval * TIME_UNIT;
-       u32 res = (base & BEACON_TIME_MASK_HIGH) +
-           (addon & BEACON_TIME_MASK_HIGH);
-
-       if (base_low > addon_low)
-               res += base_low - addon_low;
-       else if (base_low < addon_low) {
-               res += interval + base_low - addon_low;
-               res += (1 << 24);
-       } else
-               res += (1 << 24);
-
-       return cpu_to_le32(res);
-}
-
-static int iwl_get_measurement(struct iwl_priv *priv,
-                              struct ieee80211_measurement_params *params,
-                              u8 type)
-{
-       struct iwl4965_spectrum_cmd spectrum;
-       struct iwl_rx_packet *res;
-       struct iwl_host_cmd cmd = {
-               .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
-               .data = (void *)&spectrum,
-               .meta.flags = CMD_WANT_SKB,
-       };
-       u32 add_time = le64_to_cpu(params->start_time);
-       int rc;
-       int spectrum_resp_status;
-       int duration = le16_to_cpu(params->duration);
-
-       if (iwl_is_associated(priv))
-               add_time =
-                   iwl_usecs_to_beacons(
-                       le64_to_cpu(params->start_time) - priv->last_tsf,
-                       le16_to_cpu(priv->rxon_timing.beacon_interval));
-
-       memset(&spectrum, 0, sizeof(spectrum));
-
-       spectrum.channel_count = cpu_to_le16(1);
-       spectrum.flags =
-           RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
-       spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
-       cmd.len = sizeof(spectrum);
-       spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
-
-       if (iwl_is_associated(priv))
-               spectrum.start_time =
-                   iwl_add_beacon_time(priv->last_beacon_time,
-                               add_time,
-                               le16_to_cpu(priv->rxon_timing.beacon_interval));
-       else
-               spectrum.start_time = 0;
-
-       spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
-       spectrum.channels[0].channel = params->channel;
-       spectrum.channels[0].type = type;
-       if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
-               spectrum.flags |= RXON_FLG_BAND_24G_MSK |
-                   RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
-
-       rc = iwl_send_cmd_sync(priv, &cmd);
-       if (rc)
-               return rc;
-
-       res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
-       if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
-               IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
-               rc = -EIO;
-       }
-
-       spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
-       switch (spectrum_resp_status) {
-       case 0:         /* Command will be handled */
-               if (res->u.spectrum.id != 0xff) {
-                       IWL_DEBUG_INFO
-                           ("Replaced existing measurement: %d\n",
-                            res->u.spectrum.id);
-                       priv->measurement_status &= ~MEASUREMENT_READY;
-               }
-               priv->measurement_status |= MEASUREMENT_ACTIVE;
-               rc = 0;
-               break;
-
-       case 1:         /* Command will not be handled */
-               rc = -EAGAIN;
-               break;
-       }
-
-       dev_kfree_skb_any(cmd.meta.u.skb);
-
-       return rc;
-}
-#endif
 
 /******************************************************************************
  *
@@ -1072,24 +867,6 @@ static void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
        priv->staging_rxon.channel = csa->channel;
 }
 
-static void iwl_rx_spectrum_measure_notif(struct iwl_priv *priv,
-                                         struct iwl_rx_mem_buffer *rxb)
-{
-#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
-       struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
-       struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
-
-       if (!report->state) {
-               IWL_DEBUG(IWL_DL_11H,
-                       "Spectrum Measure Notification: Start\n");
-               return;
-       }
-
-       memcpy(&priv->measure_report, report, sizeof(*report));
-       priv->measurement_status |= MEASUREMENT_READY;
-#endif
-}
-
 static void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
                                      struct iwl_rx_mem_buffer *rxb)
 {
@@ -1298,8 +1075,6 @@ static void iwl_setup_rx_handlers(struct iwl_priv *priv)
        priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
        priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
        priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
-       priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
-           iwl_rx_spectrum_measure_notif;
        priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
        priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
            iwl_rx_pm_debug_statistics_notif;
@@ -1313,6 +1088,7 @@ static void iwl_setup_rx_handlers(struct iwl_priv *priv)
        priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
        priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
 
+       iwl_setup_spectrum_handlers(priv);
        iwl_setup_rx_scan_handlers(priv);
 
        /* status change handler */
@@ -1359,7 +1135,7 @@ void iwl_rx_handle(struct iwl_priv *priv)
 
        /* uCode's read index (stored in shared DRAM) indicates the last Rx
         * buffer that the driver may process (last buffer filled by ucode). */
-       r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
+       r = le16_to_cpu(rxq->rb_stts->closed_rb_num) &  0x0FFF;
        i = rxq->read;
 
        /* Rx interrupt, but nothing sent from uCode */
@@ -1379,9 +1155,11 @@ void iwl_rx_handle(struct iwl_priv *priv)
 
                rxq->queue[i] = NULL;
 
-               pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
-                                           priv->hw_params.rx_buf_size,
-                                           PCI_DMA_FROMDEVICE);
+               dma_sync_single_range_for_cpu(
+                               &priv->pci_dev->dev, rxb->real_dma_addr,
+                               rxb->aligned_dma_addr - rxb->real_dma_addr,
+                               priv->hw_params.rx_buf_size,
+                               PCI_DMA_FROMDEVICE);
                pkt = (struct iwl_rx_packet *)rxb->skb->data;
 
                /* Reclaim a command buffer only if this packet is a response
@@ -1432,8 +1210,8 @@ void iwl_rx_handle(struct iwl_priv *priv)
                        rxb->skb = NULL;
                }
 
-               pci_unmap_single(priv->pci_dev, rxb->dma_addr,
-                                priv->hw_params.rx_buf_size,
+               pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
+                                priv->hw_params.rx_buf_size + 256,
                                 PCI_DMA_FROMDEVICE);
                spin_lock_irqsave(&rxq->lock, flags);
                list_add_tail(&rxb->list, &priv->rxq.rx_used);
@@ -1477,13 +1255,6 @@ static void iwl_print_rx_config_cmd(struct iwl_priv *priv)
 }
 #endif
 
-static void iwl_enable_interrupts(struct iwl_priv *priv)
-{
-       IWL_DEBUG_ISR("Enabling interrupts\n");
-       set_bit(STATUS_INT_ENABLED, &priv->status);
-       iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
-}
-
 /* call this function to flush any scheduled tasklet */
 static inline void iwl_synchronize_irq(struct iwl_priv *priv)
 {
@@ -1492,21 +1263,6 @@ static inline void iwl_synchronize_irq(struct iwl_priv *priv)
        tasklet_kill(&priv->irq_tasklet);
 }
 
-static inline void iwl_disable_interrupts(struct iwl_priv *priv)
-{
-       clear_bit(STATUS_INT_ENABLED, &priv->status);
-
-       /* disable interrupts from uCode/NIC to host */
-       iwl_write32(priv, CSR_INT_MASK, 0x00000000);
-
-       /* acknowledge/clear/reset any interrupts still pending
-        * from uCode or flow handler (Rx/Tx DMA) */
-       iwl_write32(priv, CSR_INT, 0xffffffff);
-       iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
-       IWL_DEBUG_ISR("Disabled interrupts\n");
-}
-
-
 /**
  * iwl_irq_handle_error - called for HW or SW error interrupt from card
  */
@@ -1643,7 +1399,7 @@ static void iwl_irq_tasklet(struct iwl_priv *priv)
                        hw_rf_kill = 1;
 
                IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
-                               hw_rf_kill ? "disable radio":"enable radio");
+                               hw_rf_kill ? "disable radio" : "enable radio");
 
                /* driver only loads ucode once setting the interface up.
                 * the driver as well won't allow loading if RFKILL is set
@@ -1757,7 +1513,7 @@ static irqreturn_t iwl_isr(int irq, void *data)
        if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
                /* Hardware disappeared. It might have already raised
                 * an interrupt */
-               IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
+               IWL_WARNING("HARDWARE GONE?? INTA == 0x%08x\n", inta);
                goto unplugged;
        }
 
@@ -2002,6 +1758,10 @@ static int iwl_read_ucode(struct iwl_priv *priv)
        return ret;
 }
 
+/* temporary */
+static int iwl_mac_beacon_update(struct ieee80211_hw *hw,
+                                struct sk_buff *skb);
+
 /**
  * iwl_alive_start - called after REPLY_ALIVE notification received
  *                   from protocol/runtime uCode (initialization uCode's
@@ -2084,6 +1844,15 @@ static void iwl_alive_start(struct iwl_priv *priv)
 
        iwl_power_update_mode(priv, 1);
 
+       /* reassociate for ADHOC mode */
+       if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
+               struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
+                                                               priv->vif);
+               if (beacon)
+                       iwl_mac_beacon_update(priv->hw, beacon);
+       }
+
+
        if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
                iwl_set_mode(priv, priv->iw_mode);
 
@@ -2183,8 +1952,6 @@ static void __iwl_down(struct iwl_priv *priv)
                priv->cfg->ops->lib->apm_ops.stop(priv);
        else
                priv->cfg->ops->lib->apm_ops.reset(priv);
-       priv->cfg->ops->lib->free_shared_mem(priv);
-
  exit:
        memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
 
@@ -2237,12 +2004,6 @@ static int __iwl_up(struct iwl_priv *priv)
 
        iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
 
-       ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
-       if (ret) {
-               IWL_ERROR("Unable to allocate shared memory\n");
-               return ret;
-       }
-
        ret = iwl_hw_nic_init(priv);
        if (ret) {
                IWL_ERROR("Unable to init nic\n");
@@ -2334,7 +2095,6 @@ static void iwl_bg_alive_start(struct work_struct *data)
        mutex_lock(&priv->mutex);
        iwl_alive_start(priv);
        mutex_unlock(&priv->mutex);
-       ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
 }
 
 static void iwl_bg_rf_kill(struct work_struct *work)
@@ -2371,28 +2131,6 @@ static void iwl_bg_rf_kill(struct work_struct *work)
        iwl_rfkill_set_hw_state(priv);
 }
 
-static void iwl_bg_set_monitor(struct work_struct *work)
-{
-       struct iwl_priv *priv = container_of(work,
-                               struct iwl_priv, set_monitor);
-       int ret;
-
-       IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
-
-       mutex_lock(&priv->mutex);
-
-       ret = iwl_set_mode(priv, NL80211_IFTYPE_MONITOR);
-       if (ret) {
-               if (ret == -EAGAIN)
-                       IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
-               else
-                       IWL_ERROR("iwl_set_mode() failed ret = %d\n", ret);
-       }
-
-       mutex_unlock(&priv->mutex);
-       ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
-}
-
 static void iwl_bg_run_time_calib_work(struct work_struct *work)
 {
        struct iwl_priv *priv = container_of(work, struct iwl_priv,
@@ -2932,8 +2670,6 @@ static void iwl_config_ap(struct iwl_priv *priv)
         * clear sta table, add BCAST sta... */
 }
 
-/* temporary */
-static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb);
 
 static int iwl_mac_config_interface(struct ieee80211_hw *hw,
                                        struct ieee80211_vif *vif,
@@ -2955,7 +2691,9 @@ static int iwl_mac_config_interface(struct ieee80211_hw *hw,
                struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
                if (!beacon)
                        return -ENOMEM;
+               mutex_lock(&priv->mutex);
                rc = iwl_mac_beacon_update(hw, beacon);
+               mutex_unlock(&priv->mutex);
                if (rc)
                        return rc;
        }
@@ -3038,16 +2776,43 @@ static void iwl_configure_filter(struct ieee80211_hw *hw,
                                 int mc_count, struct dev_addr_list *mc_list)
 {
        struct iwl_priv *priv = hw->priv;
+       __le32 *filter_flags = &priv->staging_rxon.filter_flags;
+
+       IWL_DEBUG_MAC80211("Enter: changed: 0x%x, total: 0x%x\n",
+                       changed_flags, *total_flags);
 
-       if (changed_flags & (*total_flags) & FIF_OTHER_BSS) {
-               IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
-                                  NL80211_IFTYPE_MONITOR,
-                                  changed_flags, *total_flags);
-               /* queue work 'cuz mac80211 is holding a lock which
-                * prevents us from issuing (synchronous) f/w cmds */
-               queue_work(priv->workqueue, &priv->set_monitor);
+       if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
+               if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
+                       *filter_flags |= RXON_FILTER_PROMISC_MSK;
+               else
+                       *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
        }
-       *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI |
+       if (changed_flags & FIF_ALLMULTI) {
+               if (*total_flags & FIF_ALLMULTI)
+                       *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
+               else
+                       *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
+       }
+       if (changed_flags & FIF_CONTROL) {
+               if (*total_flags & FIF_CONTROL)
+                       *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
+               else
+                       *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
+       }
+       if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
+               if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
+                       *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
+               else
+                       *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
+       }
+
+       /* We avoid iwl_commit_rxon here to commit the new filter flags
+        * since mac80211 will call ieee80211_hw_config immediately.
+        * (mc_list is not supported at this time). Otherwise, we need to
+        * queue a background iwl_commit_rxon work.
+        */
+
+       *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
                        FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
 }
 
@@ -3206,49 +2971,11 @@ static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
                        struct ieee80211_key_conf *keyconf, const u8 *addr,
                        u32 iv32, u16 *phase1key)
 {
-       struct iwl_priv *priv = hw->priv;
-       u8 sta_id = IWL_INVALID_STATION;
-       unsigned long flags;
-       __le16 key_flags = 0;
-       int i;
 
+       struct iwl_priv *priv = hw->priv;
        IWL_DEBUG_MAC80211("enter\n");
 
-       sta_id = iwl_find_station(priv, addr);
-       if (sta_id == IWL_INVALID_STATION) {
-               IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
-                                  addr);
-               return;
-       }
-
-       if (iwl_scan_cancel(priv)) {
-               /* cancel scan failed, just live w/ bad key and rely
-                  briefly on SW decryption */
-               return;
-       }
-
-       key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
-       key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
-       key_flags &= ~STA_KEY_FLG_INVALID;
-
-       if (sta_id == priv->hw_params.bcast_sta_id)
-               key_flags |= STA_KEY_MULTICAST_MSK;
-
-       spin_lock_irqsave(&priv->sta_lock, flags);
-
-       priv->stations[sta_id].sta.key.key_flags = key_flags;
-       priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
-
-       for (i = 0; i < 5; i++)
-               priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
-                       cpu_to_le16(phase1key[i]);
-
-       priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
-       priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
-
-       iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
-
-       spin_unlock_irqrestore(&priv->sta_lock, flags);
+       iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
 
        IWL_DEBUG_MAC80211("leave\n");
 }
@@ -3387,10 +3114,10 @@ static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
        switch (action) {
        case IEEE80211_AMPDU_RX_START:
                IWL_DEBUG_HT("start Rx\n");
-               return iwl_rx_agg_start(priv, sta->addr, tid, *ssn);
+               return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
        case IEEE80211_AMPDU_RX_STOP:
                IWL_DEBUG_HT("stop Rx\n");
-               return iwl_rx_agg_stop(priv, sta->addr, tid);
+               return iwl_sta_rx_agg_stop(priv, sta->addr, tid);
        case IEEE80211_AMPDU_TX_START:
                IWL_DEBUG_HT("start Tx\n");
                return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
@@ -3404,6 +3131,7 @@ static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
        }
        return 0;
 }
+
 static int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
                                struct ieee80211_tx_queue_stats *stats)
 {
@@ -3531,18 +3259,15 @@ static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
        unsigned long flags;
        __le64 timestamp;
 
-       mutex_lock(&priv->mutex);
        IWL_DEBUG_MAC80211("enter\n");
 
        if (!iwl_is_ready_rf(priv)) {
                IWL_DEBUG_MAC80211("leave - RF not ready\n");
-               mutex_unlock(&priv->mutex);
                return -EIO;
        }
 
        if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
                IWL_DEBUG_MAC80211("leave - not IBSS\n");
-               mutex_unlock(&priv->mutex);
                return -EIO;
        }
 
@@ -3564,7 +3289,6 @@ static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
 
        iwl_post_associate(priv);
 
-       mutex_unlock(&priv->mutex);
 
        return 0;
 }
@@ -3768,79 +3492,6 @@ static ssize_t store_filter_flags(struct device *d,
 static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
                   store_filter_flags);
 
-#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
-
-static ssize_t show_measurement(struct device *d,
-                               struct device_attribute *attr, char *buf)
-{
-       struct iwl_priv *priv = dev_get_drvdata(d);
-       struct iwl4965_spectrum_notification measure_report;
-       u32 size = sizeof(measure_report), len = 0, ofs = 0;
-       u8 *data = (u8 *)&measure_report;
-       unsigned long flags;
-
-       spin_lock_irqsave(&priv->lock, flags);
-       if (!(priv->measurement_status & MEASUREMENT_READY)) {
-               spin_unlock_irqrestore(&priv->lock, flags);
-               return 0;
-       }
-       memcpy(&measure_report, &priv->measure_report, size);
-       priv->measurement_status = 0;
-       spin_unlock_irqrestore(&priv->lock, flags);
-
-       while (size && (PAGE_SIZE - len)) {
-               hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
-                                  PAGE_SIZE - len, 1);
-               len = strlen(buf);
-               if (PAGE_SIZE - len)
-                       buf[len++] = '\n';
-
-               ofs += 16;
-               size -= min(size, 16U);
-       }
-
-       return len;
-}
-
-static ssize_t store_measurement(struct device *d,
-                                struct device_attribute *attr,
-                                const char *buf, size_t count)
-{
-       struct iwl_priv *priv = dev_get_drvdata(d);
-       struct ieee80211_measurement_params params = {
-               .channel = le16_to_cpu(priv->active_rxon.channel),
-               .start_time = cpu_to_le64(priv->last_tsf),
-               .duration = cpu_to_le16(1),
-       };
-       u8 type = IWL_MEASURE_BASIC;
-       u8 buffer[32];
-       u8 channel;
-
-       if (count) {
-               char *p = buffer;
-               strncpy(buffer, buf, min(sizeof(buffer), count));
-               channel = simple_strtoul(p, NULL, 0);
-               if (channel)
-                       params.channel = channel;
-
-               p = buffer;
-               while (*p && *p != ' ')
-                       p++;
-               if (*p)
-                       type = simple_strtoul(p + 1, NULL, 0);
-       }
-
-       IWL_DEBUG_INFO("Invoking measurement of type %d on "
-                      "channel %d (for '%s')\n", type, params.channel, buf);
-       iwl_get_measurement(priv, &params, type);
-
-       return count;
-}
-
-static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
-                  show_measurement, store_measurement);
-#endif /* CONFIG_IWLAGN_SPECTRUM_MEASUREMENT */
-
 static ssize_t store_retry_rate(struct device *d,
                                struct device_attribute *attr,
                                const char *buf, size_t count)
@@ -3919,7 +3570,8 @@ static ssize_t show_power_level(struct device *d,
                break;
        }
 
-       p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO)?"fixed":"auto");
+       p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
+                       "fixed" : "auto");
        p += sprintf(p, "\tINDEX:%d", level);
        p += sprintf(p, "\n");
        return p - buf + 1;
@@ -3928,68 +3580,6 @@ static ssize_t show_power_level(struct device *d,
 static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
                   store_power_level);
 
-static ssize_t show_channels(struct device *d,
-                            struct device_attribute *attr, char *buf)
-{
-
-       struct iwl_priv *priv = dev_get_drvdata(d);
-       struct ieee80211_channel *channels = NULL;
-       const struct ieee80211_supported_band *supp_band = NULL;
-       int len = 0, i;
-       int count = 0;
-
-       if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
-               return -EAGAIN;
-
-       supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
-       channels = supp_band->channels;
-       count = supp_band->n_channels;
-
-       len += sprintf(&buf[len],
-                       "Displaying %d channels in 2.4GHz band "
-                       "(802.11bg):\n", count);
-
-       for (i = 0; i < count; i++)
-               len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
-                               ieee80211_frequency_to_channel(
-                               channels[i].center_freq),
-                               channels[i].max_power,
-                               channels[i].flags & IEEE80211_CHAN_RADAR ?
-                               " (IEEE 802.11h required)" : "",
-                               (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS)
-                               || (channels[i].flags &
-                               IEEE80211_CHAN_RADAR)) ? "" :
-                               ", IBSS",
-                               channels[i].flags &
-                               IEEE80211_CHAN_PASSIVE_SCAN ?
-                               "passive only" : "active/passive");
-
-       supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
-       channels = supp_band->channels;
-       count = supp_band->n_channels;
-
-       len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
-                       "(802.11a):\n", count);
-
-       for (i = 0; i < count; i++)
-               len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
-                               ieee80211_frequency_to_channel(
-                               channels[i].center_freq),
-                               channels[i].max_power,
-                               channels[i].flags & IEEE80211_CHAN_RADAR ?
-                               " (IEEE 802.11h required)" : "",
-                               ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
-                               || (channels[i].flags &
-                               IEEE80211_CHAN_RADAR)) ? "" :
-                               ", IBSS",
-                               channels[i].flags &
-                               IEEE80211_CHAN_PASSIVE_SCAN ?
-                               "passive only" : "active/passive");
-
-       return len;
-}
-
-static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
 
 static ssize_t show_statistics(struct device *d,
                               struct device_attribute *attr, char *buf)
@@ -4057,7 +3647,6 @@ static void iwl_setup_deferred_work(struct iwl_priv *priv)
        INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
        INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
        INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
-       INIT_WORK(&priv->set_monitor, iwl_bg_set_monitor);
        INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
        INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
        INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
@@ -4090,12 +3679,8 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv)
 }
 
 static struct attribute *iwl_sysfs_entries[] = {
-       &dev_attr_channels.attr,
        &dev_attr_flags.attr,
        &dev_attr_filter_flags.attr,
-#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
-       &dev_attr_measurement.attr,
-#endif
        &dev_attr_power_level.attr,
        &dev_attr_retry_rate.attr,
        &dev_attr_statistics.attr,
@@ -4467,7 +4052,11 @@ static struct pci_device_id iwl_hw_card_ids[] = {
        {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
        {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
        {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
+/* 5150 Wifi/WiMax */
+       {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)},
+       {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)},
 #endif /* CONFIG_IWL5000 */
+
        {0}
 };
 MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);