Merge branch 'sh-latest' of git://git.kernel.org/pub/scm/linux/kernel/git/lethal...
[pandora-kernel.git] / drivers / net / wireless / iwlwifi / iwl-agn.c
index e99cd94..08e3cae 100644 (file)
@@ -102,70 +102,6 @@ void iwl_update_chain_flags(struct iwl_priv *priv)
        }
 }
 
-static void iwl_clear_free_frames(struct iwl_priv *priv)
-{
-       struct list_head *element;
-
-       IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
-                      priv->frames_count);
-
-       while (!list_empty(&priv->free_frames)) {
-               element = priv->free_frames.next;
-               list_del(element);
-               kfree(list_entry(element, struct iwl_frame, list));
-               priv->frames_count--;
-       }
-
-       if (priv->frames_count) {
-               IWL_WARN(priv, "%d frames still in use.  Did we lose one?\n",
-                           priv->frames_count);
-               priv->frames_count = 0;
-       }
-}
-
-static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
-{
-       struct iwl_frame *frame;
-       struct list_head *element;
-       if (list_empty(&priv->free_frames)) {
-               frame = kzalloc(sizeof(*frame), GFP_KERNEL);
-               if (!frame) {
-                       IWL_ERR(priv, "Could not allocate frame!\n");
-                       return NULL;
-               }
-
-               priv->frames_count++;
-               return frame;
-       }
-
-       element = priv->free_frames.next;
-       list_del(element);
-       return list_entry(element, struct iwl_frame, list);
-}
-
-static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
-{
-       memset(frame, 0, sizeof(*frame));
-       list_add(&frame->list, &priv->free_frames);
-}
-
-static u32 iwl_fill_beacon_frame(struct iwl_priv *priv,
-                                struct ieee80211_hdr *hdr,
-                                int left)
-{
-       lockdep_assert_held(&priv->mutex);
-
-       if (!priv->beacon_skb)
-               return 0;
-
-       if (priv->beacon_skb->len > left)
-               return 0;
-
-       memcpy(hdr, priv->beacon_skb->data, priv->beacon_skb->len);
-
-       return priv->beacon_skb->len;
-}
-
 /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
 static void iwl_set_beacon_tim(struct iwl_priv *priv,
                               struct iwl_tx_beacon_cmd *tx_beacon_cmd,
@@ -193,13 +129,18 @@ static void iwl_set_beacon_tim(struct iwl_priv *priv,
                IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
 }
 
-static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
-                                      struct iwl_frame *frame)
+int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
 {
        struct iwl_tx_beacon_cmd *tx_beacon_cmd;
+       struct iwl_host_cmd cmd = {
+               .id = REPLY_TX_BEACON,
+               .flags = CMD_SIZE_HUGE,
+       };
        u32 frame_size;
        u32 rate_flags;
        u32 rate;
+       int err;
+
        /*
         * We have to set up the TX command, the TX Beacon command, and the
         * beacon contents.
@@ -212,17 +153,19 @@ static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
                return 0;
        }
 
-       /* Initialize memory */
-       tx_beacon_cmd = &frame->u.beacon;
-       memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
+       if (WARN_ON(!priv->beacon_skb))
+               return -EINVAL;
+
+       /* Allocate beacon memory */
+       tx_beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd) + priv->beacon_skb->len,
+                               GFP_KERNEL);
+       if (!tx_beacon_cmd)
+               return -ENOMEM;
+
+       frame_size = priv->beacon_skb->len;
 
        /* Set up TX beacon contents */
-       frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
-                               sizeof(frame->u) - sizeof(*tx_beacon_cmd));
-       if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
-               return 0;
-       if (!frame_size)
-               return 0;
+       memcpy(tx_beacon_cmd->frame, priv->beacon_skb->data, frame_size);
 
        /* Set up TX command fields */
        tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
@@ -245,41 +188,16 @@ static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
        tx_beacon_cmd->tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate,
                        rate_flags);
 
-       return sizeof(*tx_beacon_cmd) + frame_size;
-}
+       /* Submit command */
+       cmd.len = sizeof(*tx_beacon_cmd) + frame_size;
+       cmd.data = tx_beacon_cmd;
 
-int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
-{
-       struct iwl_frame *frame;
-       unsigned int frame_size;
-       int rc;
-       struct iwl_host_cmd cmd = {
-               .id = REPLY_TX_BEACON,
-               .flags = CMD_SIZE_HUGE,
-       };
-
-       frame = iwl_get_free_frame(priv);
-       if (!frame) {
-               IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
-                         "command.\n");
-               return -ENOMEM;
-       }
-
-       frame_size = iwl_hw_get_beacon_cmd(priv, frame);
-       if (!frame_size) {
-               IWL_ERR(priv, "Error configuring the beacon command\n");
-               iwl_free_frame(priv, frame);
-               return -EINVAL;
-       }
+       err = iwl_send_cmd_sync(priv, &cmd);
 
-       cmd.len = frame_size;
-       cmd.data = &frame->u.cmd[0];
+       /* Free temporary storage */
+       kfree(tx_beacon_cmd);
 
-       rc = iwl_send_cmd_sync(priv, &cmd);
-
-       iwl_free_frame(priv, frame);
-
-       return rc;
+       return err;
 }
 
 static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
@@ -769,13 +687,15 @@ static void iwl_rx_handle(struct iwl_priv *priv)
                                if (w->cmd == pkt->hdr.cmd) {
                                        w->triggered = true;
                                        if (w->fn)
-                                               w->fn(priv, pkt);
+                                               w->fn(priv, pkt, w->fn_data);
                                }
                        }
                        spin_unlock(&priv->_agn.notif_wait_lock);
 
                        wake_up_all(&priv->_agn.notif_waitq);
                }
+               if (priv->pre_rx_handler)
+                       priv->pre_rx_handler(priv, rxb);
 
                /* Based on type of command response or notification,
                 *   handle those that need handling via function in
@@ -1173,18 +1093,42 @@ static struct attribute_group iwl_attribute_group = {
  *
  ******************************************************************************/
 
-static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
+static void iwl_free_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc)
+{
+       if (desc->v_addr)
+               dma_free_coherent(&pci_dev->dev, desc->len,
+                                 desc->v_addr, desc->p_addr);
+       desc->v_addr = NULL;
+       desc->len = 0;
+}
+
+static void iwl_free_fw_img(struct pci_dev *pci_dev, struct fw_img *img)
 {
-       iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
-       iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
-       iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
-       iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
+       iwl_free_fw_desc(pci_dev, &img->code);
+       iwl_free_fw_desc(pci_dev, &img->data);
 }
 
-static void iwl_nic_start(struct iwl_priv *priv)
+static int iwl_alloc_fw_desc(struct pci_dev *pci_dev, struct fw_desc *desc,
+                            const void *data, size_t len)
 {
-       /* Remove all resets to allow NIC to operate */
-       iwl_write32(priv, CSR_RESET, 0);
+       if (!len) {
+               desc->v_addr = NULL;
+               return -EINVAL;
+       }
+
+       desc->v_addr = dma_alloc_coherent(&pci_dev->dev, len,
+                                         &desc->p_addr, GFP_KERNEL);
+       if (!desc->v_addr)
+               return -ENOMEM;
+       desc->len = len;
+       memcpy(desc->v_addr, data, len);
+       return 0;
+}
+
+static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
+{
+       iwl_free_fw_img(priv->pci_dev, &priv->ucode_rt);
+       iwl_free_fw_img(priv->pci_dev, &priv->ucode_init);
 }
 
 struct iwlagn_ucode_capabilities {
@@ -1653,24 +1597,20 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
        /* Runtime instructions and 2 copies of data:
         * 1) unmodified from disk
         * 2) backup cache for save/restore during power-downs */
-       priv->ucode_code.len = pieces.inst_size;
-       iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
-
-       priv->ucode_data.len = pieces.data_size;
-       iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
-
-       if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr)
+       if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_rt.code,
+                             pieces.inst, pieces.inst_size))
+               goto err_pci_alloc;
+       if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_rt.data,
+                             pieces.data, pieces.data_size))
                goto err_pci_alloc;
 
        /* Initialization instructions and data */
        if (pieces.init_size && pieces.init_data_size) {
-               priv->ucode_init.len = pieces.init_size;
-               iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
-
-               priv->ucode_init_data.len = pieces.init_data_size;
-               iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
-
-               if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
+               if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init.code,
+                                     pieces.init, pieces.init_size))
+                       goto err_pci_alloc;
+               if (iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init.data,
+                                     pieces.init_data, pieces.init_data_size))
                        goto err_pci_alloc;
        }
 
@@ -1696,6 +1636,9 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
                        priv->cfg->base_params->max_event_log_size;
        priv->_agn.inst_errlog_ptr = pieces.inst_errlog_ptr;
 
+       priv->new_scan_threshold_behaviour =
+               !!(ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
+
        if (ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN) {
                priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
                priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
@@ -1707,39 +1650,6 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
        else
                priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
 
-       /* Copy images into buffers for card's bus-master reads ... */
-
-       /* Runtime instructions (first block of data in file) */
-       IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n",
-                       pieces.inst_size);
-       memcpy(priv->ucode_code.v_addr, pieces.inst, pieces.inst_size);
-
-       IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
-               priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
-
-       /*
-        * Runtime data
-        * NOTE:  Copy into backup buffer will be done in iwl_up()
-        */
-       IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n",
-                       pieces.data_size);
-       memcpy(priv->ucode_data.v_addr, pieces.data, pieces.data_size);
-
-       /* Initialization instructions */
-       if (pieces.init_size) {
-               IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
-                               pieces.init_size);
-               memcpy(priv->ucode_init.v_addr, pieces.init, pieces.init_size);
-       }
-
-       /* Initialization data */
-       if (pieces.init_data_size) {
-               IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
-                              pieces.init_data_size);
-               memcpy(priv->ucode_init_data.v_addr, pieces.init_data,
-                      pieces.init_data_size);
-       }
-
        /*
         * figure out the offset of chain noise reset and gain commands
         * base on the size of standard phy calibration commands table size
@@ -1856,7 +1766,7 @@ static const char *desc_lookup(u32 num)
        max = ARRAY_SIZE(advanced_lookup) - 1;
        for (i = 0; i < max; i++) {
                if (advanced_lookup[i].num == num)
-                       break;;
+                       break;
        }
        return advanced_lookup[i].name;
 }
@@ -1873,7 +1783,7 @@ void iwl_dump_nic_error_log(struct iwl_priv *priv)
        struct iwl_error_event_table table;
 
        base = priv->device_pointers.error_event_table;
-       if (priv->ucode_type == UCODE_INIT) {
+       if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
                if (!base)
                        base = priv->_agn.init_errlog_ptr;
        } else {
@@ -1884,7 +1794,9 @@ void iwl_dump_nic_error_log(struct iwl_priv *priv)
        if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
                IWL_ERR(priv,
                        "Not valid error log pointer 0x%08X for %s uCode\n",
-                       base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
+                       base,
+                       (priv->ucode_type == UCODE_SUBTYPE_INIT)
+                                       ? "Init" : "RT");
                return;
        }
 
@@ -1944,7 +1856,7 @@ static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
                return pos;
 
        base = priv->device_pointers.log_event_table;
-       if (priv->ucode_type == UCODE_INIT) {
+       if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
                if (!base)
                        base = priv->_agn.init_evtlog_ptr;
        } else {
@@ -2057,7 +1969,7 @@ int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
        size_t bufsz = 0;
 
        base = priv->device_pointers.log_event_table;
-       if (priv->ucode_type == UCODE_INIT) {
+       if (priv->ucode_type == UCODE_SUBTYPE_INIT) {
                logsize = priv->_agn.init_evtlog_size;
                if (!base)
                        base = priv->_agn.init_evtlog_ptr;
@@ -2070,7 +1982,9 @@ int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
        if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
                IWL_ERR(priv,
                        "Invalid event log pointer 0x%08X for %s uCode\n",
-                       base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
+                       base,
+                       (priv->ucode_type == UCODE_SUBTYPE_INIT)
+                                       ? "Init" : "RT");
                return -EINVAL;
        }
 
@@ -2217,30 +2131,14 @@ static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  *                   from protocol/runtime uCode (initialization uCode's
  *                   Alive gets handled by iwl_init_alive_start()).
  */
-static void iwl_alive_start(struct iwl_priv *priv)
+int iwl_alive_start(struct iwl_priv *priv)
 {
        int ret = 0;
        struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
 
-       IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
-
-       /* Initialize uCode has loaded Runtime uCode ... verify inst image.
-        * This is a paranoid check, because we would not have gotten the
-        * "runtime" alive if code weren't properly loaded.  */
-       if (iwl_verify_ucode(priv, &priv->ucode_code)) {
-               /* Runtime instruction load was bad;
-                * take it all the way back down so we can try again */
-               IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
-               goto restart;
-       }
-
-       ret = iwlagn_alive_notify(priv);
-       if (ret) {
-               IWL_WARN(priv,
-                       "Could not complete ALIVE transition [ntf]: %d\n", ret);
-               goto restart;
-       }
+       iwl_reset_ict(priv);
 
+       IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
 
        /* After the ALIVE response, we can send host commands to the uCode */
        set_bit(STATUS_ALIVE, &priv->status);
@@ -2249,7 +2147,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
        iwl_setup_watchdog(priv);
 
        if (iwl_is_rfkill(priv))
-               return;
+               return -ERFKILL;
 
        /* download priority table before any calibration request */
        if (priv->cfg->bt_params &&
@@ -2263,10 +2161,14 @@ static void iwl_alive_start(struct iwl_priv *priv)
                iwlagn_send_prio_tbl(priv);
 
                /* FIXME: w/a to force change uCode BT state machine */
-               iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
-                       BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
-               iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
-                       BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
+               ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
+                                        BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
+               if (ret)
+                       return ret;
+               ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
+                                        BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
+               if (ret)
+                       return ret;
        }
        if (priv->hw_params.calib_rt_cfg)
                iwlagn_send_calib_cfg_rt(priv, priv->hw_params.calib_rt_cfg);
@@ -2308,22 +2210,16 @@ static void iwl_alive_start(struct iwl_priv *priv)
        set_bit(STATUS_READY, &priv->status);
 
        /* Configure the adapter for unassociated operation */
-       iwlcore_commit_rxon(priv, ctx);
+       ret = iwlcore_commit_rxon(priv, ctx);
+       if (ret)
+               return ret;
 
        /* At this point, the NIC is initialized and operational */
        iwl_rf_kill_ct_config(priv);
 
        IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
-       wake_up_interruptible(&priv->wait_command_queue);
-
-       iwl_power_update_mode(priv, true);
-       IWL_DEBUG_INFO(priv, "Updated power mode\n");
 
-
-       return;
-
- restart:
-       queue_work(priv->workqueue, &priv->restart);
+       return iwl_power_update_mode(priv, true);
 }
 
 static void iwl_cancel_deferred_work(struct iwl_priv *priv);
@@ -2378,9 +2274,6 @@ static void __iwl_down(struct iwl_priv *priv)
 
        dev_kfree_skb(priv->beacon_skb);
        priv->beacon_skb = NULL;
-
-       /* clear out any free frames */
-       iwl_clear_free_frames(priv);
 }
 
 static void iwl_down(struct iwl_priv *priv)
@@ -2394,9 +2287,10 @@ static void iwl_down(struct iwl_priv *priv)
 
 #define HW_READY_TIMEOUT (50)
 
+/* Note: returns poll_bit return value, which is >= 0 if success */
 static int iwl_set_hw_ready(struct iwl_priv *priv)
 {
-       int ret = 0;
+       int ret;
 
        iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
                CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
@@ -2406,25 +2300,21 @@ static int iwl_set_hw_ready(struct iwl_priv *priv)
                                CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
                                CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
                                HW_READY_TIMEOUT);
-       if (ret != -ETIMEDOUT)
-               priv->hw_ready = true;
-       else
-               priv->hw_ready = false;
 
-       IWL_DEBUG_INFO(priv, "hardware %s\n",
-                     (priv->hw_ready == 1) ? "ready" : "not ready");
+       IWL_DEBUG_INFO(priv, "hardware%s ready\n", ret < 0 ? " not" : "");
        return ret;
 }
 
+/* Note: returns standard 0/-ERROR code */
 int iwl_prepare_card_hw(struct iwl_priv *priv)
 {
-       int ret = 0;
+       int ret;
 
        IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter\n");
 
        ret = iwl_set_hw_ready(priv);
-       if (priv->hw_ready)
-               return ret;
+       if (ret >= 0)
+               return 0;
 
        /* If HW is not ready, prepare the conditions to check again */
        iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
@@ -2434,10 +2324,13 @@ int iwl_prepare_card_hw(struct iwl_priv *priv)
                        ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
                        CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
 
-       /* HW should be ready by now, check again. */
-       if (ret != -ETIMEDOUT)
-               iwl_set_hw_ready(priv);
+       if (ret < 0)
+               return ret;
 
+       /* HW should be ready by now, check again. */
+       ret = iwl_set_hw_ready(priv);
+       if (ret >= 0)
+               return 0;
        return ret;
 }
 
@@ -2446,9 +2339,10 @@ int iwl_prepare_card_hw(struct iwl_priv *priv)
 static int __iwl_up(struct iwl_priv *priv)
 {
        struct iwl_rxon_context *ctx;
-       int i;
        int ret;
 
+       lockdep_assert_held(&priv->mutex);
+
        if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
                IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
                return -EIO;
@@ -2462,39 +2356,33 @@ static int __iwl_up(struct iwl_priv *priv)
                }
        }
 
-       ret = iwlagn_start_device(priv);
-       if (ret)
-               return ret;
-
-       for (i = 0; i < MAX_HW_RESTARTS; i++) {
-
-               /* load bootstrap state machine,
-                * load bootstrap program into processor's memory,
-                * prepare to load the "initialize" uCode */
-               ret = iwlagn_load_ucode(priv);
-
-               if (ret) {
-                       IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
-                               ret);
-                       continue;
-               }
-
-               /* start card; "initialize" will load runtime ucode */
-               iwl_nic_start(priv);
-
-               IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
+       ret = iwlagn_run_init_ucode(priv);
+       if (ret) {
+               IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
+               goto error;
+       }
 
-               return 0;
+       ret = iwlagn_load_ucode_wait_alive(priv,
+                                          &priv->ucode_rt,
+                                          UCODE_SUBTYPE_REGULAR,
+                                          UCODE_SUBTYPE_REGULAR_NEW);
+       if (ret) {
+               IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
+               goto error;
        }
 
+       ret = iwl_alive_start(priv);
+       if (ret)
+               goto error;
+       return 0;
+
+ error:
        set_bit(STATUS_EXIT_PENDING, &priv->status);
        __iwl_down(priv);
        clear_bit(STATUS_EXIT_PENDING, &priv->status);
 
-       /* tried to restart and config the device for as long as our
-        * patience could withstand */
-       IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
-       return -EIO;
+       IWL_ERR(priv, "Unable to initialize device.\n");
+       return ret;
 }
 
 
@@ -2504,39 +2392,6 @@ static int __iwl_up(struct iwl_priv *priv)
  *
  *****************************************************************************/
 
-static void iwl_bg_init_alive_start(struct work_struct *data)
-{
-       struct iwl_priv *priv =
-           container_of(data, struct iwl_priv, init_alive_start.work);
-
-       mutex_lock(&priv->mutex);
-
-       if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
-               mutex_unlock(&priv->mutex);
-               return;
-       }
-
-       iwlagn_init_alive_start(priv);
-       mutex_unlock(&priv->mutex);
-}
-
-static void iwl_bg_alive_start(struct work_struct *data)
-{
-       struct iwl_priv *priv =
-           container_of(data, struct iwl_priv, alive_start.work);
-
-       mutex_lock(&priv->mutex);
-       if (test_bit(STATUS_EXIT_PENDING, &priv->status))
-               goto unlock;
-
-       /* enable dram interrupt */
-       iwl_reset_ict(priv);
-
-       iwl_alive_start(priv);
-unlock:
-       mutex_unlock(&priv->mutex);
-}
-
 static void iwl_bg_run_time_calib_work(struct work_struct *work)
 {
        struct iwl_priv *priv = container_of(work, struct iwl_priv,
@@ -2558,6 +2413,42 @@ static void iwl_bg_run_time_calib_work(struct work_struct *work)
        mutex_unlock(&priv->mutex);
 }
 
+static void iwlagn_prepare_restart(struct iwl_priv *priv)
+{
+       struct iwl_rxon_context *ctx;
+       bool bt_full_concurrent;
+       u8 bt_ci_compliance;
+       u8 bt_load;
+       u8 bt_status;
+
+       lockdep_assert_held(&priv->mutex);
+
+       for_each_context(priv, ctx)
+               ctx->vif = NULL;
+       priv->is_open = 0;
+
+       /*
+        * __iwl_down() will clear the BT status variables,
+        * which is correct, but when we restart we really
+        * want to keep them so restore them afterwards.
+        *
+        * The restart process will later pick them up and
+        * re-configure the hw when we reconfigure the BT
+        * command.
+        */
+       bt_full_concurrent = priv->bt_full_concurrent;
+       bt_ci_compliance = priv->bt_ci_compliance;
+       bt_load = priv->bt_traffic_load;
+       bt_status = priv->bt_status;
+
+       __iwl_down(priv);
+
+       priv->bt_full_concurrent = bt_full_concurrent;
+       priv->bt_ci_compliance = bt_ci_compliance;
+       priv->bt_traffic_load = bt_load;
+       priv->bt_status = bt_status;
+}
+
 static void iwl_bg_restart(struct work_struct *data)
 {
        struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
@@ -2566,50 +2457,13 @@ static void iwl_bg_restart(struct work_struct *data)
                return;
 
        if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
-               struct iwl_rxon_context *ctx;
-               bool bt_full_concurrent;
-               u8 bt_ci_compliance;
-               u8 bt_load;
-               u8 bt_status;
-
                mutex_lock(&priv->mutex);
-               for_each_context(priv, ctx)
-                       ctx->vif = NULL;
-               priv->is_open = 0;
-
-               /*
-                * __iwl_down() will clear the BT status variables,
-                * which is correct, but when we restart we really
-                * want to keep them so restore them afterwards.
-                *
-                * The restart process will later pick them up and
-                * re-configure the hw when we reconfigure the BT
-                * command.
-                */
-               bt_full_concurrent = priv->bt_full_concurrent;
-               bt_ci_compliance = priv->bt_ci_compliance;
-               bt_load = priv->bt_traffic_load;
-               bt_status = priv->bt_status;
-
-               __iwl_down(priv);
-
-               priv->bt_full_concurrent = bt_full_concurrent;
-               priv->bt_ci_compliance = bt_ci_compliance;
-               priv->bt_traffic_load = bt_load;
-               priv->bt_status = bt_status;
-
+               iwlagn_prepare_restart(priv);
                mutex_unlock(&priv->mutex);
                iwl_cancel_deferred_work(priv);
                ieee80211_restart_hw(priv->hw);
        } else {
-               iwl_down(priv);
-
-               if (test_bit(STATUS_EXIT_PENDING, &priv->status))
-                       return;
-
-               mutex_lock(&priv->mutex);
-               __iwl_up(priv);
-               mutex_unlock(&priv->mutex);
+               WARN_ON(1);
        }
 }
 
@@ -2720,8 +2574,6 @@ unlock:
  *
  *****************************************************************************/
 
-#define UCODE_READY_TIMEOUT    (4 * HZ)
-
 /*
  * Not a mac80211 entry point function, but it fits in with all the
  * other mac80211 functions grouped here.
@@ -2814,31 +2666,17 @@ static int iwlagn_mac_start(struct ieee80211_hw *hw)
        mutex_lock(&priv->mutex);
        ret = __iwl_up(priv);
        mutex_unlock(&priv->mutex);
-
        if (ret)
                return ret;
 
-       if (iwl_is_rfkill(priv))
-               goto out;
-
        IWL_DEBUG_INFO(priv, "Start UP work done.\n");
 
-       /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
-        * mac80211 will not be run successfully. */
-       ret = wait_event_interruptible_timeout(priv->wait_command_queue,
-                       test_bit(STATUS_READY, &priv->status),
-                       UCODE_READY_TIMEOUT);
-       if (!ret) {
-               if (!test_bit(STATUS_READY, &priv->status)) {
-                       IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
-                               jiffies_to_msecs(UCODE_READY_TIMEOUT));
-                       return -ETIMEDOUT;
-               }
-       }
+       /* Now we should be done, and the READY bit should be set. */
+       if (WARN_ON(!test_bit(STATUS_READY, &priv->status)))
+               ret = -EIO;
 
        iwlagn_led_enable(priv);
 
-out:
        priv->is_open = 1;
        IWL_DEBUG_MAC80211(priv, "leave\n");
        return 0;
@@ -2913,7 +2751,7 @@ static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
 
        IWL_DEBUG_MAC80211(priv, "enter\n");
 
-       if (priv->cfg->mod_params->sw_crypto) {
+       if (iwlagn_mod_params.sw_crypto) {
                IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
                return -EOPNOTSUPP;
        }
@@ -3425,8 +3263,6 @@ static void iwl_setup_deferred_work(struct iwl_priv *priv)
        INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
        INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
        INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
-       INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
-       INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
        INIT_DELAYED_WORK(&priv->_agn.hw_roc_work, iwlagn_bg_roc_done);
 
        iwl_setup_scan_deferred_work(priv);
@@ -3455,8 +3291,6 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv)
        if (priv->cfg->ops->lib->cancel_deferred_work)
                priv->cfg->ops->lib->cancel_deferred_work(priv);
 
-       cancel_delayed_work_sync(&priv->init_alive_start);
-       cancel_delayed_work(&priv->alive_start);
        cancel_work_sync(&priv->run_time_calib_work);
        cancel_work_sync(&priv->beacon_update);
 
@@ -3497,8 +3331,6 @@ static int iwl_init_drv(struct iwl_priv *priv)
        spin_lock_init(&priv->sta_lock);
        spin_lock_init(&priv->hcmd_lock);
 
-       INIT_LIST_HEAD(&priv->free_frames);
-
        mutex_init(&priv->mutex);
 
        priv->ieee_channels = NULL;
@@ -3536,12 +3368,6 @@ static int iwl_init_drv(struct iwl_priv *priv)
                priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
        }
 
-       /* Set the tx_power_user_lmt to the lowest power level
-        * this value will get overwritten by channel max power avg
-        * from eeprom */
-       priv->tx_power_user_lmt = IWLAGN_TX_POWER_TARGET_POWER_MIN;
-       priv->tx_power_next = IWLAGN_TX_POWER_TARGET_POWER_MIN;
-
        ret = iwl_init_channel_map(priv);
        if (ret) {
                IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
@@ -3596,6 +3422,7 @@ struct ieee80211_ops iwlagn_hw_ops = {
        .cancel_remain_on_channel = iwl_mac_cancel_remain_on_channel,
        .offchannel_tx = iwl_mac_offchannel_tx,
        .offchannel_tx_cancel_wait = iwl_mac_offchannel_tx_cancel_wait,
+       CFG80211_TESTMODE_CMD(iwl_testmode_cmd)
 };
 
 static u32 iwl_hw_detect(struct iwl_priv *priv)
@@ -3611,14 +3438,14 @@ static int iwl_set_hw_params(struct iwl_priv *priv)
 {
        priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
        priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
-       if (priv->cfg->mod_params->amsdu_size_8K)
+       if (iwlagn_mod_params.amsdu_size_8K)
                priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
        else
                priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
 
        priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
 
-       if (priv->cfg->mod_params->disable_11n)
+       if (iwlagn_mod_params.disable_11n)
                priv->cfg->sku &= ~IWL_SKU_N;
 
        /* Device-specific setup */
@@ -3691,6 +3518,8 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        priv = hw->priv;
        /* At this point both hw and priv are allocated. */
 
+       priv->ucode_type = UCODE_SUBTYPE_NONE_LOADED;
+
        /*
         * The default context is always valid,
         * more may be discovered when firmware
@@ -3831,8 +3660,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
         * PCI Tx retries from interfering with C3 CPU state */
        pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
 
-       iwl_prepare_card_hw(priv);
-       if (!priv->hw_ready) {
+       if (iwl_prepare_card_hw(priv)) {
                IWL_WARN(priv, "Failed, HW not ready\n");
                goto out_iounmap;
        }
@@ -3904,6 +3732,7 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 
        iwl_setup_deferred_work(priv);
        iwl_setup_rx_handlers(priv);
+       iwl_testmode_init(priv);
 
        /*********************************************
         * 8. Enable interrupts and read RFKILL state
@@ -4217,21 +4046,21 @@ static DEFINE_PCI_DEVICE_TABLE(iwl_hw_card_ids) = {
        {IWL_PCI_DEVICE(0x088F, 0x4266, iwl6035_2bg_cfg)},
        {IWL_PCI_DEVICE(0x088E, 0x4466, iwl6035_2bg_cfg)},
 
-/* 200 Series */
-       {IWL_PCI_DEVICE(0x0894, 0x0022, iwl200_bgn_cfg)},
-       {IWL_PCI_DEVICE(0x0895, 0x0222, iwl200_bgn_cfg)},
-       {IWL_PCI_DEVICE(0x0894, 0x0422, iwl200_bgn_cfg)},
-       {IWL_PCI_DEVICE(0x0894, 0x0026, iwl200_bg_cfg)},
-       {IWL_PCI_DEVICE(0x0895, 0x0226, iwl200_bg_cfg)},
-       {IWL_PCI_DEVICE(0x0894, 0x0426, iwl200_bg_cfg)},
-
-/* 230 Series */
-       {IWL_PCI_DEVICE(0x0892, 0x0062, iwl230_bgn_cfg)},
-       {IWL_PCI_DEVICE(0x0893, 0x0262, iwl230_bgn_cfg)},
-       {IWL_PCI_DEVICE(0x0892, 0x0462, iwl230_bgn_cfg)},
-       {IWL_PCI_DEVICE(0x0892, 0x0066, iwl230_bg_cfg)},
-       {IWL_PCI_DEVICE(0x0893, 0x0266, iwl230_bg_cfg)},
-       {IWL_PCI_DEVICE(0x0892, 0x0466, iwl230_bg_cfg)},
+/* 105 Series */
+       {IWL_PCI_DEVICE(0x0894, 0x0022, iwl105_bgn_cfg)},
+       {IWL_PCI_DEVICE(0x0895, 0x0222, iwl105_bgn_cfg)},
+       {IWL_PCI_DEVICE(0x0894, 0x0422, iwl105_bgn_cfg)},
+       {IWL_PCI_DEVICE(0x0894, 0x0026, iwl105_bg_cfg)},
+       {IWL_PCI_DEVICE(0x0895, 0x0226, iwl105_bg_cfg)},
+       {IWL_PCI_DEVICE(0x0894, 0x0426, iwl105_bg_cfg)},
+
+/* 135 Series */
+       {IWL_PCI_DEVICE(0x0892, 0x0062, iwl135_bgn_cfg)},
+       {IWL_PCI_DEVICE(0x0893, 0x0262, iwl135_bgn_cfg)},
+       {IWL_PCI_DEVICE(0x0892, 0x0462, iwl135_bgn_cfg)},
+       {IWL_PCI_DEVICE(0x0892, 0x0066, iwl135_bg_cfg)},
+       {IWL_PCI_DEVICE(0x0893, 0x0266, iwl135_bg_cfg)},
+       {IWL_PCI_DEVICE(0x0892, 0x0466, iwl135_bg_cfg)},
 
        {0}
 };