ath6kl: rename vif init and cleanup functions
[cascardo/linux.git] / drivers / net / wireless / ath / ath6kl / init.c
index 368ecbd..3cc4e08 100644 (file)
 unsigned int debug_mask;
 static unsigned int testmode;
 static bool suspend_cutpower;
+static unsigned int uart_debug;
 
 module_param(debug_mask, uint, 0644);
 module_param(testmode, uint, 0644);
 module_param(suspend_cutpower, bool, 0444);
+module_param(uart_debug, uint, 0644);
 
 static const struct ath6kl_hw hw_list[] = {
        {
@@ -47,11 +49,14 @@ static const struct ath6kl_hw hw_list[] = {
                /* hw2.0 needs override address hardcoded */
                .app_start_override_addr        = 0x944C00,
 
-               .fw_otp                 = AR6003_HW_2_0_OTP_FILE,
-               .fw                     = AR6003_HW_2_0_FIRMWARE_FILE,
-               .fw_tcmd                = AR6003_HW_2_0_TCMD_FIRMWARE_FILE,
-               .fw_patch               = AR6003_HW_2_0_PATCH_FILE,
-               .fw_api2                = AR6003_HW_2_0_FIRMWARE_2_FILE,
+               .fw = {
+                       .dir            = AR6003_HW_2_0_FW_DIR,
+                       .otp            = AR6003_HW_2_0_OTP_FILE,
+                       .fw             = AR6003_HW_2_0_FIRMWARE_FILE,
+                       .tcmd           = AR6003_HW_2_0_TCMD_FIRMWARE_FILE,
+                       .patch          = AR6003_HW_2_0_PATCH_FILE,
+               },
+
                .fw_board               = AR6003_HW_2_0_BOARD_DATA_FILE,
                .fw_default_board       = AR6003_HW_2_0_DEFAULT_BOARD_DATA_FILE,
        },
@@ -64,12 +69,18 @@ static const struct ath6kl_hw hw_list[] = {
                .reserved_ram_size              = 512,
                .refclk_hz                      = 26000000,
                .uarttx_pin                     = 8,
+               .testscript_addr                = 0x57ef74,
+
+               .fw = {
+                       .dir            = AR6003_HW_2_1_1_FW_DIR,
+                       .otp            = AR6003_HW_2_1_1_OTP_FILE,
+                       .fw             = AR6003_HW_2_1_1_FIRMWARE_FILE,
+                       .tcmd           = AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE,
+                       .patch          = AR6003_HW_2_1_1_PATCH_FILE,
+                       .utf            = AR6003_HW_2_1_1_UTF_FIRMWARE_FILE,
+                       .testscript     = AR6003_HW_2_1_1_TESTSCRIPT_FILE,
+               },
 
-               .fw_otp                 = AR6003_HW_2_1_1_OTP_FILE,
-               .fw                     = AR6003_HW_2_1_1_FIRMWARE_FILE,
-               .fw_tcmd                = AR6003_HW_2_1_1_TCMD_FIRMWARE_FILE,
-               .fw_patch               = AR6003_HW_2_1_1_PATCH_FILE,
-               .fw_api2                = AR6003_HW_2_1_1_FIRMWARE_2_FILE,
                .fw_board               = AR6003_HW_2_1_1_BOARD_DATA_FILE,
                .fw_default_board       = AR6003_HW_2_1_1_DEFAULT_BOARD_DATA_FILE,
        },
@@ -84,8 +95,11 @@ static const struct ath6kl_hw hw_list[] = {
                .refclk_hz                      = 26000000,
                .uarttx_pin                     = 11,
 
-               .fw                     = AR6004_HW_1_0_FIRMWARE_FILE,
-               .fw_api2                = AR6004_HW_1_0_FIRMWARE_2_FILE,
+               .fw = {
+                       .dir            = AR6004_HW_1_0_FW_DIR,
+                       .fw             = AR6004_HW_1_0_FIRMWARE_FILE,
+               },
+
                .fw_board               = AR6004_HW_1_0_BOARD_DATA_FILE,
                .fw_default_board       = AR6004_HW_1_0_DEFAULT_BOARD_DATA_FILE,
        },
@@ -100,8 +114,11 @@ static const struct ath6kl_hw hw_list[] = {
                .refclk_hz                      = 40000000,
                .uarttx_pin                     = 11,
 
-               .fw                     = AR6004_HW_1_1_FIRMWARE_FILE,
-               .fw_api2                = AR6004_HW_1_1_FIRMWARE_2_FILE,
+               .fw = {
+                       .dir            = AR6004_HW_1_1_FW_DIR,
+                       .fw             = AR6004_HW_1_1_FIRMWARE_FILE,
+               },
+
                .fw_board               = AR6004_HW_1_1_BOARD_DATA_FILE,
                .fw_default_board       = AR6004_HW_1_1_DEFAULT_BOARD_DATA_FILE,
        },
@@ -430,7 +447,7 @@ static int ath6kl_target_config_wlan_params(struct ath6kl *ar, int idx)
                        ath6kl_dbg(ATH6KL_DBG_TRC, "failed to request P2P "
                                   "capabilities (%d) - assuming P2P not "
                                   "supported\n", ret);
-                       ar->p2p = 0;
+                       ar->p2p = false;
                }
        }
 
@@ -452,6 +469,13 @@ int ath6kl_configure_target(struct ath6kl *ar)
        u8 fw_iftype, fw_mode = 0, fw_submode = 0;
        int i, status;
 
+       param = uart_debug;
+       if (ath6kl_bmi_write(ar, ath6kl_get_hi_item_addr(ar,
+                            HI_ITEM(hi_serial_enable)), (u8 *)&param, 4)) {
+               ath6kl_err("bmi_write_memory for uart debug failed\n");
+               return -EIO;
+       }
+
        /*
         * Note: Even though the firmware interface type is
         * chosen as BSS_STA for all three interfaces, can
@@ -599,6 +623,7 @@ void ath6kl_core_cleanup(struct ath6kl *ar)
        kfree(ar->fw_otp);
        kfree(ar->fw);
        kfree(ar->fw_patch);
+       kfree(ar->fw_testscript);
 
        ath6kl_deinit_ieee80211_hw(ar);
 }
@@ -626,21 +651,6 @@ static int ath6kl_get_fw(struct ath6kl *ar, const char *filename,
 }
 
 #ifdef CONFIG_OF
-static const char *get_target_ver_dir(const struct ath6kl *ar)
-{
-       switch (ar->version.target_ver) {
-       case AR6003_HW_1_0_VERSION:
-               return "ath6k/AR6003/hw1.0";
-       case AR6003_HW_2_0_VERSION:
-               return "ath6k/AR6003/hw2.0";
-       case AR6003_HW_2_1_1_VERSION:
-               return "ath6k/AR6003/hw2.1.1";
-       }
-       ath6kl_warn("%s: unsupported target version 0x%x.\n", __func__,
-                   ar->version.target_ver);
-       return NULL;
-}
-
 /*
  * Check the device tree for a board-id and use it to construct
  * the pathname to the firmware file.  Used (for now) to find a
@@ -663,7 +673,7 @@ static bool check_device_tree(struct ath6kl *ar)
                        continue;
                }
                snprintf(board_filename, sizeof(board_filename),
-                        "%s/bdata.%s.bin", get_target_ver_dir(ar), board_id);
+                        "%s/bdata.%s.bin", ar->hw.fw.dir, board_id);
 
                ret = ath6kl_get_fw(ar, board_filename, &ar->fw_board,
                                    &ar->fw_board_len);
@@ -730,19 +740,20 @@ static int ath6kl_fetch_board_file(struct ath6kl *ar)
 
 static int ath6kl_fetch_otp_file(struct ath6kl *ar)
 {
-       const char *filename;
+       char filename[100];
        int ret;
 
        if (ar->fw_otp != NULL)
                return 0;
 
-       if (ar->hw.fw_otp == NULL) {
+       if (ar->hw.fw.otp == NULL) {
                ath6kl_dbg(ATH6KL_DBG_BOOT,
                           "no OTP file configured for this hw\n");
                return 0;
        }
 
-       filename = ar->hw.fw_otp;
+       snprintf(filename, sizeof(filename), "%s/%s",
+                ar->hw.fw.dir, ar->hw.fw.otp);
 
        ret = ath6kl_get_fw(ar, filename, &ar->fw_otp,
                            &ar->fw_otp_len);
@@ -757,29 +768,43 @@ static int ath6kl_fetch_otp_file(struct ath6kl *ar)
 
 static int ath6kl_fetch_fw_file(struct ath6kl *ar)
 {
-       const char *filename;
+       char filename[100];
        int ret;
 
        if (ar->fw != NULL)
                return 0;
 
        if (testmode) {
-               if (ar->hw.fw_tcmd == NULL) {
-                       ath6kl_warn("testmode not supported\n");
-                       return -EOPNOTSUPP;
-               }
+               ath6kl_dbg(ATH6KL_DBG_BOOT, "testmode %d\n",
+                               testmode);
+               if (testmode == 2) {
+                       if (ar->hw.fw.utf == NULL) {
+                               ath6kl_warn("testmode 2 not supported\n");
+                               return -EOPNOTSUPP;
+                       }
 
-               filename = ar->hw.fw_tcmd;
+                       snprintf(filename, sizeof(filename), "%s/%s",
+                               ar->hw.fw.dir, ar->hw.fw.utf);
+               } else {
+                       if (ar->hw.fw.tcmd == NULL) {
+                               ath6kl_warn("testmode 1 not supported\n");
+                               return -EOPNOTSUPP;
+                       }
 
+                       snprintf(filename, sizeof(filename), "%s/%s",
+                               ar->hw.fw.dir, ar->hw.fw.tcmd);
+               }
                set_bit(TESTMODE, &ar->flag);
 
                goto get_fw;
        }
 
-       if (WARN_ON(ar->hw.fw == NULL))
+       /* FIXME: remove WARN_ON() as we won't support FW API 1 for long */
+       if (WARN_ON(ar->hw.fw.fw == NULL))
                return -EINVAL;
 
-       filename = ar->hw.fw;
+       snprintf(filename, sizeof(filename), "%s/%s",
+                ar->hw.fw.dir, ar->hw.fw.fw);
 
 get_fw:
        ret = ath6kl_get_fw(ar, filename, &ar->fw, &ar->fw_len);
@@ -794,16 +819,17 @@ get_fw:
 
 static int ath6kl_fetch_patch_file(struct ath6kl *ar)
 {
-       const char *filename;
+       char filename[100];
        int ret;
 
        if (ar->fw_patch != NULL)
                return 0;
 
-       if (ar->hw.fw_patch == NULL)
+       if (ar->hw.fw.patch == NULL)
                return 0;
 
-       filename = ar->hw.fw_patch;
+       snprintf(filename, sizeof(filename), "%s/%s",
+                ar->hw.fw.dir, ar->hw.fw.patch);
 
        ret = ath6kl_get_fw(ar, filename, &ar->fw_patch,
                            &ar->fw_patch_len);
@@ -816,6 +842,34 @@ static int ath6kl_fetch_patch_file(struct ath6kl *ar)
        return 0;
 }
 
+static int ath6kl_fetch_testscript_file(struct ath6kl *ar)
+{
+       char filename[100];
+       int ret;
+
+       if (testmode != 2)
+               return 0;
+
+       if (ar->fw_testscript != NULL)
+               return 0;
+
+       if (ar->hw.fw.testscript == NULL)
+               return 0;
+
+       snprintf(filename, sizeof(filename), "%s/%s",
+               ar->hw.fw.dir, ar->hw.fw.testscript);
+
+       ret = ath6kl_get_fw(ar, filename, &ar->fw_testscript,
+                               &ar->fw_testscript_len);
+       if (ret) {
+               ath6kl_err("Failed to get testscript file %s: %d\n",
+                       filename, ret);
+               return ret;
+       }
+
+       return 0;
+}
+
 static int ath6kl_fetch_fw_api1(struct ath6kl *ar)
 {
        int ret;
@@ -832,23 +886,24 @@ static int ath6kl_fetch_fw_api1(struct ath6kl *ar)
        if (ret)
                return ret;
 
+       ret = ath6kl_fetch_testscript_file(ar);
+       if (ret)
+               return ret;
+
        return 0;
 }
 
-static int ath6kl_fetch_fw_api2(struct ath6kl *ar)
+static int ath6kl_fetch_fw_apin(struct ath6kl *ar, const char *name)
 {
        size_t magic_len, len, ie_len;
        const struct firmware *fw;
        struct ath6kl_fw_ie *hdr;
-       const char *filename;
+       char filename[100];
        const u8 *data;
        int ret, ie_id, i, index, bit;
        __le32 *val;
 
-       if (ar->hw.fw_api2 == NULL)
-               return -EOPNOTSUPP;
-
-       filename = ar->hw.fw_api2;
+       snprintf(filename, sizeof(filename), "%s/%s", ar->hw.fw.dir, name);
 
        ret = request_firmware(&fw, filename, ar->dev);
        if (ret)
@@ -1018,17 +1073,26 @@ static int ath6kl_fetch_firmwares(struct ath6kl *ar)
        if (ret)
                return ret;
 
-       ret = ath6kl_fetch_fw_api2(ar);
+       ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API3_FILE);
        if (ret == 0) {
-               ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api 2\n");
-               return 0;
+               ar->fw_api = 3;
+               goto out;
+       }
+
+       ret = ath6kl_fetch_fw_apin(ar, ATH6KL_FW_API2_FILE);
+       if (ret == 0) {
+               ar->fw_api = 2;
+               goto out;
        }
 
        ret = ath6kl_fetch_fw_api1(ar);
        if (ret)
                return ret;
 
-       ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api 1\n");
+       ar->fw_api = 1;
+
+out:
+       ath6kl_dbg(ATH6KL_DBG_BOOT, "using fw api %d\n", ar->fw_api);
 
        return 0;
 }
@@ -1249,6 +1313,50 @@ static int ath6kl_upload_patch(struct ath6kl *ar)
        return 0;
 }
 
+static int ath6kl_upload_testscript(struct ath6kl *ar)
+{
+       u32 address, param;
+       int ret;
+
+       if (testmode != 2)
+               return 0;
+
+       if (ar->fw_testscript == NULL)
+               return 0;
+
+       address = ar->hw.testscript_addr;
+
+       ath6kl_dbg(ATH6KL_DBG_BOOT, "writing testscript to 0x%x (%zd B)\n",
+               address, ar->fw_testscript_len);
+
+       ret = ath6kl_bmi_write(ar, address, ar->fw_testscript,
+               ar->fw_testscript_len);
+       if (ret) {
+               ath6kl_err("Failed to write testscript file: %d\n", ret);
+               return ret;
+       }
+
+       param = address;
+       ath6kl_bmi_write(ar,
+                       ath6kl_get_hi_item_addr(ar,
+                       HI_ITEM(hi_ota_testscript)),
+                       (unsigned char *) &param, 4);
+
+       param = 4096;
+       ath6kl_bmi_write(ar,
+                       ath6kl_get_hi_item_addr(ar,
+                       HI_ITEM(hi_end_ram_reserve_sz)),
+                       (unsigned char *) &param, 4);
+
+       param = 1;
+       ath6kl_bmi_write(ar,
+                       ath6kl_get_hi_item_addr(ar,
+                       HI_ITEM(hi_test_apps_related)),
+                       (unsigned char *) &param, 4);
+
+       return 0;
+}
+
 static int ath6kl_init_upload(struct ath6kl *ar)
 {
        u32 param, options, sleep, address;
@@ -1357,6 +1465,11 @@ static int ath6kl_init_upload(struct ath6kl *ar)
        if (status)
                return status;
 
+       /* Download the test script */
+       status = ath6kl_upload_testscript(ar);
+       if (status)
+               return status;
+
        /* Restore system sleep */
        address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS;
        status = ath6kl_bmi_reg_write(ar, address, sleep);
@@ -1481,10 +1594,11 @@ int ath6kl_init_hw_start(struct ath6kl *ar)
 
 
        if (test_and_clear_bit(FIRST_BOOT, &ar->flag)) {
-               ath6kl_info("%s %s fw %s%s\n",
+               ath6kl_info("%s %s fw %s api %d%s\n",
                            ar->hw.name,
                            ath6kl_init_get_hif_name(ar->hif_type),
                            ar->wiphy->fw_version,
+                           ar->fw_api,
                            test_bit(TESTMODE, &ar->flag) ? " testmode" : "");
        }
 
@@ -1677,6 +1791,8 @@ int ath6kl_core_init(struct ath6kl *ar)
 
        set_bit(FIRST_BOOT, &ar->flag);
 
+       ndev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_RXCSUM;
+
        ret = ath6kl_init_hw_start(ar);
        if (ret) {
                ath6kl_err("Failed to start hardware: %d\n", ret);
@@ -1695,7 +1811,7 @@ err_rxbuf_cleanup:
        ath6kl_htc_flush_rx_buf(ar->htc_target);
        ath6kl_cleanup_amsdu_rxbufs(ar);
        rtnl_lock();
-       ath6kl_deinit_if_data(netdev_priv(ndev));
+       ath6kl_cfg80211_vif_cleanup(netdev_priv(ndev));
        rtnl_unlock();
        wiphy_unregister(ar->wiphy);
 err_debug_init:
@@ -1716,6 +1832,7 @@ err_wq:
        return ret;
 }
 
+/* FIXME: move this to cfg80211.c and rename to ath6kl_cfg80211_vif_stop() */
 void ath6kl_cleanup_vif(struct ath6kl_vif *vif, bool wmi_ready)
 {
        static u8 bcast_mac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
@@ -1761,7 +1878,7 @@ void ath6kl_stop_txrx(struct ath6kl *ar)
                spin_unlock_bh(&ar->list_lock);
                ath6kl_cleanup_vif(vif, test_bit(WMI_READY, &ar->flag));
                rtnl_lock();
-               ath6kl_deinit_if_data(vif);
+               ath6kl_cfg80211_vif_cleanup(vif);
                rtnl_unlock();
                spin_lock_bh(&ar->list_lock);
        }