Path: blob/main/sys/contrib/dev/athk/ath12k/core.c
48378 views
// SPDX-License-Identifier: BSD-3-Clause-Clear1/*2* Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.3* Copyright (c) 2021-2022 Qualcomm Innovation Center, Inc. All rights reserved.4*/56#if defined(__FreeBSD__)7#define LINUXKPI_PARAM_PREFIX ath12k_core_8#endif910#include <linux/module.h>11#include <linux/slab.h>12#include <linux/remoteproc.h>13#include <linux/firmware.h>14#include <linux/of.h>15#if defined(__FreeBSD__)16#include <linux/delay.h>17#endif18#include "core.h"19#include "dp_tx.h"20#include "dp_rx.h"21#include "debug.h"22#include "hif.h"2324unsigned int ath12k_debug_mask;25module_param_named(debug_mask, ath12k_debug_mask, uint, 0644);26MODULE_PARM_DESC(debug_mask, "Debugging mask");2728int ath12k_core_suspend(struct ath12k_base *ab)29{30int ret;3132if (!ab->hw_params->supports_suspend)33return -EOPNOTSUPP;3435/* TODO: there can frames in queues so for now add delay as a hack.36* Need to implement to handle and remove this delay.37*/38#if defined(__linux__)39msleep(500);40#elif defined(__FreeBSD__)41linux_msleep(500);42#endif4344ret = ath12k_dp_rx_pktlog_stop(ab, true);45if (ret) {46ath12k_warn(ab, "failed to stop dp rx (and timer) pktlog during suspend: %d\n",47ret);48return ret;49}5051ret = ath12k_dp_rx_pktlog_stop(ab, false);52if (ret) {53ath12k_warn(ab, "failed to stop dp rx pktlog during suspend: %d\n",54ret);55return ret;56}5758ath12k_hif_irq_disable(ab);59ath12k_hif_ce_irq_disable(ab);6061ret = ath12k_hif_suspend(ab);62if (ret) {63ath12k_warn(ab, "failed to suspend hif: %d\n", ret);64return ret;65}6667return 0;68}6970int ath12k_core_resume(struct ath12k_base *ab)71{72int ret;7374if (!ab->hw_params->supports_suspend)75return -EOPNOTSUPP;7677ret = ath12k_hif_resume(ab);78if (ret) {79ath12k_warn(ab, "failed to resume hif during resume: %d\n", ret);80return ret;81}8283ath12k_hif_ce_irq_enable(ab);84ath12k_hif_irq_enable(ab);8586ret = ath12k_dp_rx_pktlog_start(ab);87if (ret) {88ath12k_warn(ab, "failed to start rx pktlog during resume: %d\n",89ret);90return ret;91}9293return 0;94}9596static int ath12k_core_create_board_name(struct ath12k_base *ab, char *name,97size_t name_len)98{99/* strlen(',variant=') + strlen(ab->qmi.target.bdf_ext) */100char variant[9 + ATH12K_QMI_BDF_EXT_STR_LENGTH] = { 0 };101102if (ab->qmi.target.bdf_ext[0] != '\0')103scnprintf(variant, sizeof(variant), ",variant=%s",104ab->qmi.target.bdf_ext);105106scnprintf(name, name_len,107"bus=%s,qmi-chip-id=%d,qmi-board-id=%d%s",108ath12k_bus_str(ab->hif.bus),109ab->qmi.target.chip_id,110ab->qmi.target.board_id, variant);111112ath12k_dbg(ab, ATH12K_DBG_BOOT, "boot using board name '%s'\n", name);113114return 0;115}116117const struct firmware *ath12k_core_firmware_request(struct ath12k_base *ab,118const char *file)119{120const struct firmware *fw;121char path[100];122int ret;123124if (!file)125return ERR_PTR(-ENOENT);126127ath12k_core_create_firmware_path(ab, file, path, sizeof(path));128129ret = firmware_request_nowarn(&fw, path, ab->dev);130if (ret)131return ERR_PTR(ret);132133ath12k_dbg(ab, ATH12K_DBG_BOOT, "boot firmware request %s size %zu\n",134path, fw->size);135136return fw;137}138139void ath12k_core_free_bdf(struct ath12k_base *ab, struct ath12k_board_data *bd)140{141if (!IS_ERR(bd->fw))142release_firmware(bd->fw);143144memset(bd, 0, sizeof(*bd));145}146147static int ath12k_core_parse_bd_ie_board(struct ath12k_base *ab,148struct ath12k_board_data *bd,149#if defined(__linux__)150const void *buf, size_t buf_len,151#elif defined(__FreeBSD__)152const u8 *buf, size_t buf_len,153#endif154const char *boardname,155int bd_ie_type)156{157const struct ath12k_fw_ie *hdr;158bool name_match_found;159int ret, board_ie_id;160size_t board_ie_len;161const void *board_ie_data;162163name_match_found = false;164165/* go through ATH12K_BD_IE_BOARD_ elements */166while (buf_len > sizeof(struct ath12k_fw_ie)) {167#if defined(__linux__)168hdr = buf;169#elif defined(__FreeBSD__)170hdr = (const struct ath12k_fw_ie *)buf;171#endif172board_ie_id = le32_to_cpu(hdr->id);173board_ie_len = le32_to_cpu(hdr->len);174board_ie_data = hdr->data;175176buf_len -= sizeof(*hdr);177buf += sizeof(*hdr);178179if (buf_len < ALIGN(board_ie_len, 4)) {180ath12k_err(ab, "invalid ATH12K_BD_IE_BOARD length: %zu < %zu\n",181buf_len, ALIGN(board_ie_len, 4));182ret = -EINVAL;183goto out;184}185186switch (board_ie_id) {187case ATH12K_BD_IE_BOARD_NAME:188ath12k_dbg_dump(ab, ATH12K_DBG_BOOT, "board name", "",189board_ie_data, board_ie_len);190191if (board_ie_len != strlen(boardname))192break;193194ret = memcmp(board_ie_data, boardname, strlen(boardname));195if (ret)196break;197198name_match_found = true;199ath12k_dbg(ab, ATH12K_DBG_BOOT,200"boot found match for name '%s'",201boardname);202break;203case ATH12K_BD_IE_BOARD_DATA:204if (!name_match_found)205/* no match found */206break;207208ath12k_dbg(ab, ATH12K_DBG_BOOT,209"boot found board data for '%s'", boardname);210211bd->data = board_ie_data;212bd->len = board_ie_len;213214ret = 0;215goto out;216default:217ath12k_warn(ab, "unknown ATH12K_BD_IE_BOARD found: %d\n",218board_ie_id);219break;220}221222/* jump over the padding */223board_ie_len = ALIGN(board_ie_len, 4);224225buf_len -= board_ie_len;226buf += board_ie_len;227}228229/* no match found */230ret = -ENOENT;231232out:233return ret;234}235236static int ath12k_core_fetch_board_data_api_n(struct ath12k_base *ab,237struct ath12k_board_data *bd,238const char *boardname)239{240size_t len, magic_len;241const u8 *data;242char *filename, filepath[100];243size_t ie_len;244#if defined(__linux__)245struct ath12k_fw_ie *hdr;246#elif defined(__FreeBSD__)247const struct ath12k_fw_ie *hdr;248#endif249int ret, ie_id;250251filename = ATH12K_BOARD_API2_FILE;252253if (!bd->fw)254bd->fw = ath12k_core_firmware_request(ab, filename);255256if (IS_ERR(bd->fw))257return PTR_ERR(bd->fw);258259data = bd->fw->data;260len = bd->fw->size;261262ath12k_core_create_firmware_path(ab, filename,263filepath, sizeof(filepath));264265/* magic has extra null byte padded */266magic_len = strlen(ATH12K_BOARD_MAGIC) + 1;267if (len < magic_len) {268ath12k_err(ab, "failed to find magic value in %s, file too short: %zu\n",269filepath, len);270ret = -EINVAL;271goto err;272}273274if (memcmp(data, ATH12K_BOARD_MAGIC, magic_len)) {275ath12k_err(ab, "found invalid board magic\n");276ret = -EINVAL;277goto err;278}279280/* magic is padded to 4 bytes */281magic_len = ALIGN(magic_len, 4);282if (len < magic_len) {283ath12k_err(ab, "failed: %s too small to contain board data, len: %zu\n",284filepath, len);285ret = -EINVAL;286goto err;287}288289data += magic_len;290len -= magic_len;291292while (len > sizeof(struct ath12k_fw_ie)) {293#if defined(__linux__)294hdr = (struct ath12k_fw_ie *)data;295#elif defined(__FreeBSD__)296hdr = (const struct ath12k_fw_ie *)data;297#endif298ie_id = le32_to_cpu(hdr->id);299ie_len = le32_to_cpu(hdr->len);300301len -= sizeof(*hdr);302data = hdr->data;303304if (len < ALIGN(ie_len, 4)) {305ath12k_err(ab, "invalid length for board ie_id %d ie_len %zu len %zu\n",306ie_id, ie_len, len);307ret = -EINVAL;308goto err;309}310311switch (ie_id) {312case ATH12K_BD_IE_BOARD:313ret = ath12k_core_parse_bd_ie_board(ab, bd, data,314ie_len,315boardname,316ATH12K_BD_IE_BOARD);317if (ret == -ENOENT)318/* no match found, continue */319break;320else if (ret)321/* there was an error, bail out */322goto err;323/* either found or error, so stop searching */324goto out;325}326327/* jump over the padding */328ie_len = ALIGN(ie_len, 4);329330len -= ie_len;331data += ie_len;332}333334out:335if (!bd->data || !bd->len) {336ath12k_err(ab,337"failed to fetch board data for %s from %s\n",338boardname, filepath);339ret = -ENODATA;340goto err;341}342343return 0;344345err:346ath12k_core_free_bdf(ab, bd);347return ret;348}349350int ath12k_core_fetch_board_data_api_1(struct ath12k_base *ab,351struct ath12k_board_data *bd,352char *filename)353{354bd->fw = ath12k_core_firmware_request(ab, filename);355if (IS_ERR(bd->fw))356return PTR_ERR(bd->fw);357358bd->data = bd->fw->data;359bd->len = bd->fw->size;360361return 0;362}363364#define BOARD_NAME_SIZE 100365int ath12k_core_fetch_bdf(struct ath12k_base *ab, struct ath12k_board_data *bd)366{367char boardname[BOARD_NAME_SIZE];368int ret;369370ret = ath12k_core_create_board_name(ab, boardname, BOARD_NAME_SIZE);371if (ret) {372ath12k_err(ab, "failed to create board name: %d", ret);373return ret;374}375376ab->bd_api = 2;377ret = ath12k_core_fetch_board_data_api_n(ab, bd, boardname);378if (!ret)379goto success;380381ab->bd_api = 1;382ret = ath12k_core_fetch_board_data_api_1(ab, bd, ATH12K_DEFAULT_BOARD_FILE);383if (ret) {384ath12k_err(ab, "failed to fetch board-2.bin or board.bin from %s\n",385ab->hw_params->fw.dir);386return ret;387}388389success:390ath12k_dbg(ab, ATH12K_DBG_BOOT, "using board api %d\n", ab->bd_api);391return 0;392}393394static void ath12k_core_stop(struct ath12k_base *ab)395{396if (!test_bit(ATH12K_FLAG_CRASH_FLUSH, &ab->dev_flags))397ath12k_qmi_firmware_stop(ab);398399ath12k_hif_stop(ab);400ath12k_wmi_detach(ab);401ath12k_dp_rx_pdev_reo_cleanup(ab);402403/* De-Init of components as needed */404}405406static int ath12k_core_soc_create(struct ath12k_base *ab)407{408int ret;409410ret = ath12k_qmi_init_service(ab);411if (ret) {412ath12k_err(ab, "failed to initialize qmi :%d\n", ret);413return ret;414}415416ret = ath12k_hif_power_up(ab);417if (ret) {418ath12k_err(ab, "failed to power up :%d\n", ret);419goto err_qmi_deinit;420}421422return 0;423424err_qmi_deinit:425ath12k_qmi_deinit_service(ab);426return ret;427}428429static void ath12k_core_soc_destroy(struct ath12k_base *ab)430{431ath12k_dp_free(ab);432ath12k_reg_free(ab);433ath12k_qmi_deinit_service(ab);434}435436static int ath12k_core_pdev_create(struct ath12k_base *ab)437{438int ret;439440ret = ath12k_mac_register(ab);441if (ret) {442ath12k_err(ab, "failed register the radio with mac80211: %d\n", ret);443return ret;444}445446ret = ath12k_dp_pdev_alloc(ab);447if (ret) {448ath12k_err(ab, "failed to attach DP pdev: %d\n", ret);449goto err_mac_unregister;450}451452return 0;453454err_mac_unregister:455ath12k_mac_unregister(ab);456457return ret;458}459460static void ath12k_core_pdev_destroy(struct ath12k_base *ab)461{462ath12k_mac_unregister(ab);463ath12k_hif_irq_disable(ab);464ath12k_dp_pdev_free(ab);465}466467static int ath12k_core_start(struct ath12k_base *ab,468enum ath12k_firmware_mode mode)469{470int ret;471472ret = ath12k_wmi_attach(ab);473if (ret) {474ath12k_err(ab, "failed to attach wmi: %d\n", ret);475return ret;476}477478ret = ath12k_htc_init(ab);479if (ret) {480ath12k_err(ab, "failed to init htc: %d\n", ret);481goto err_wmi_detach;482}483484ret = ath12k_hif_start(ab);485if (ret) {486ath12k_err(ab, "failed to start HIF: %d\n", ret);487goto err_wmi_detach;488}489490ret = ath12k_htc_wait_target(&ab->htc);491if (ret) {492ath12k_err(ab, "failed to connect to HTC: %d\n", ret);493goto err_hif_stop;494}495496ret = ath12k_dp_htt_connect(&ab->dp);497if (ret) {498ath12k_err(ab, "failed to connect to HTT: %d\n", ret);499goto err_hif_stop;500}501502ret = ath12k_wmi_connect(ab);503if (ret) {504ath12k_err(ab, "failed to connect wmi: %d\n", ret);505goto err_hif_stop;506}507508ret = ath12k_htc_start(&ab->htc);509if (ret) {510ath12k_err(ab, "failed to start HTC: %d\n", ret);511goto err_hif_stop;512}513514ret = ath12k_wmi_wait_for_service_ready(ab);515if (ret) {516ath12k_err(ab, "failed to receive wmi service ready event: %d\n",517ret);518goto err_hif_stop;519}520521ret = ath12k_mac_allocate(ab);522if (ret) {523ath12k_err(ab, "failed to create new hw device with mac80211 :%d\n",524ret);525goto err_hif_stop;526}527528ath12k_dp_cc_config(ab);529530ath12k_dp_pdev_pre_alloc(ab);531532ret = ath12k_dp_rx_pdev_reo_setup(ab);533if (ret) {534ath12k_err(ab, "failed to initialize reo destination rings: %d\n", ret);535goto err_mac_destroy;536}537538ret = ath12k_wmi_cmd_init(ab);539if (ret) {540ath12k_err(ab, "failed to send wmi init cmd: %d\n", ret);541goto err_reo_cleanup;542}543544ret = ath12k_wmi_wait_for_unified_ready(ab);545if (ret) {546ath12k_err(ab, "failed to receive wmi unified ready event: %d\n",547ret);548goto err_reo_cleanup;549}550551/* put hardware to DBS mode */552if (ab->hw_params->single_pdev_only) {553ret = ath12k_wmi_set_hw_mode(ab, WMI_HOST_HW_MODE_DBS);554if (ret) {555ath12k_err(ab, "failed to send dbs mode: %d\n", ret);556goto err_reo_cleanup;557}558}559560ret = ath12k_dp_tx_htt_h2t_ver_req_msg(ab);561if (ret) {562ath12k_err(ab, "failed to send htt version request message: %d\n",563ret);564goto err_reo_cleanup;565}566567return 0;568569err_reo_cleanup:570ath12k_dp_rx_pdev_reo_cleanup(ab);571err_mac_destroy:572ath12k_mac_destroy(ab);573err_hif_stop:574ath12k_hif_stop(ab);575err_wmi_detach:576ath12k_wmi_detach(ab);577return ret;578}579580static int ath12k_core_start_firmware(struct ath12k_base *ab,581enum ath12k_firmware_mode mode)582{583int ret;584585ath12k_ce_get_shadow_config(ab, &ab->qmi.ce_cfg.shadow_reg_v3,586&ab->qmi.ce_cfg.shadow_reg_v3_len);587588ret = ath12k_qmi_firmware_start(ab, mode);589if (ret) {590ath12k_err(ab, "failed to send firmware start: %d\n", ret);591return ret;592}593594return ret;595}596597int ath12k_core_qmi_firmware_ready(struct ath12k_base *ab)598{599int ret;600601ret = ath12k_core_start_firmware(ab, ATH12K_FIRMWARE_MODE_NORMAL);602if (ret) {603ath12k_err(ab, "failed to start firmware: %d\n", ret);604return ret;605}606607ret = ath12k_ce_init_pipes(ab);608if (ret) {609ath12k_err(ab, "failed to initialize CE: %d\n", ret);610goto err_firmware_stop;611}612613ret = ath12k_dp_alloc(ab);614if (ret) {615ath12k_err(ab, "failed to init DP: %d\n", ret);616goto err_firmware_stop;617}618619mutex_lock(&ab->core_lock);620ret = ath12k_core_start(ab, ATH12K_FIRMWARE_MODE_NORMAL);621if (ret) {622ath12k_err(ab, "failed to start core: %d\n", ret);623goto err_dp_free;624}625626ret = ath12k_core_pdev_create(ab);627if (ret) {628ath12k_err(ab, "failed to create pdev core: %d\n", ret);629goto err_core_stop;630}631ath12k_hif_irq_enable(ab);632mutex_unlock(&ab->core_lock);633634return 0;635636err_core_stop:637ath12k_core_stop(ab);638ath12k_mac_destroy(ab);639err_dp_free:640ath12k_dp_free(ab);641mutex_unlock(&ab->core_lock);642err_firmware_stop:643ath12k_qmi_firmware_stop(ab);644645return ret;646}647648static int ath12k_core_reconfigure_on_crash(struct ath12k_base *ab)649{650int ret;651652mutex_lock(&ab->core_lock);653ath12k_hif_irq_disable(ab);654ath12k_dp_pdev_free(ab);655ath12k_hif_stop(ab);656ath12k_wmi_detach(ab);657ath12k_dp_rx_pdev_reo_cleanup(ab);658mutex_unlock(&ab->core_lock);659660ath12k_dp_free(ab);661ath12k_hal_srng_deinit(ab);662663ab->free_vdev_map = (1LL << (ab->num_radios * TARGET_NUM_VDEVS)) - 1;664665ret = ath12k_hal_srng_init(ab);666if (ret)667return ret;668669clear_bit(ATH12K_FLAG_CRASH_FLUSH, &ab->dev_flags);670671ret = ath12k_core_qmi_firmware_ready(ab);672if (ret)673goto err_hal_srng_deinit;674675clear_bit(ATH12K_FLAG_RECOVERY, &ab->dev_flags);676677return 0;678679err_hal_srng_deinit:680ath12k_hal_srng_deinit(ab);681return ret;682}683684void ath12k_core_halt(struct ath12k *ar)685{686struct ath12k_base *ab = ar->ab;687688lockdep_assert_held(&ar->conf_mutex);689690ar->num_created_vdevs = 0;691ar->allocated_vdev_map = 0;692693ath12k_mac_scan_finish(ar);694ath12k_mac_peer_cleanup_all(ar);695cancel_delayed_work_sync(&ar->scan.timeout);696cancel_work_sync(&ar->regd_update_work);697698rcu_assign_pointer(ab->pdevs_active[ar->pdev_idx], NULL);699synchronize_rcu();700INIT_LIST_HEAD(&ar->arvifs);701idr_init(&ar->txmgmt_idr);702}703704static void ath12k_core_pre_reconfigure_recovery(struct ath12k_base *ab)705{706struct ath12k *ar;707struct ath12k_pdev *pdev;708int i;709710spin_lock_bh(&ab->base_lock);711ab->stats.fw_crash_counter++;712spin_unlock_bh(&ab->base_lock);713714for (i = 0; i < ab->num_radios; i++) {715pdev = &ab->pdevs[i];716ar = pdev->ar;717if (!ar || ar->state == ATH12K_STATE_OFF)718continue;719720ieee80211_stop_queues(ar->hw);721ath12k_mac_drain_tx(ar);722complete(&ar->scan.started);723complete(&ar->scan.completed);724complete(&ar->peer_assoc_done);725complete(&ar->peer_delete_done);726complete(&ar->install_key_done);727complete(&ar->vdev_setup_done);728complete(&ar->vdev_delete_done);729complete(&ar->bss_survey_done);730731wake_up(&ar->dp.tx_empty_waitq);732idr_for_each(&ar->txmgmt_idr,733ath12k_mac_tx_mgmt_pending_free, ar);734idr_destroy(&ar->txmgmt_idr);735wake_up(&ar->txmgmt_empty_waitq);736}737738wake_up(&ab->wmi_ab.tx_credits_wq);739wake_up(&ab->peer_mapping_wq);740}741742static void ath12k_core_post_reconfigure_recovery(struct ath12k_base *ab)743{744struct ath12k *ar;745struct ath12k_pdev *pdev;746int i;747748for (i = 0; i < ab->num_radios; i++) {749pdev = &ab->pdevs[i];750ar = pdev->ar;751if (!ar || ar->state == ATH12K_STATE_OFF)752continue;753754mutex_lock(&ar->conf_mutex);755756switch (ar->state) {757case ATH12K_STATE_ON:758ar->state = ATH12K_STATE_RESTARTING;759ath12k_core_halt(ar);760ieee80211_restart_hw(ar->hw);761break;762case ATH12K_STATE_OFF:763ath12k_warn(ab,764"cannot restart radio %d that hasn't been started\n",765i);766break;767case ATH12K_STATE_RESTARTING:768break;769case ATH12K_STATE_RESTARTED:770ar->state = ATH12K_STATE_WEDGED;771fallthrough;772case ATH12K_STATE_WEDGED:773ath12k_warn(ab,774"device is wedged, will not restart radio %d\n", i);775break;776}777mutex_unlock(&ar->conf_mutex);778}779complete(&ab->driver_recovery);780}781782static void ath12k_core_restart(struct work_struct *work)783{784struct ath12k_base *ab = container_of(work, struct ath12k_base, restart_work);785int ret;786787if (!ab->is_reset)788ath12k_core_pre_reconfigure_recovery(ab);789790ret = ath12k_core_reconfigure_on_crash(ab);791if (ret) {792ath12k_err(ab, "failed to reconfigure driver on crash recovery\n");793return;794}795796if (ab->is_reset)797complete_all(&ab->reconfigure_complete);798799if (!ab->is_reset)800ath12k_core_post_reconfigure_recovery(ab);801}802803static void ath12k_core_reset(struct work_struct *work)804{805struct ath12k_base *ab = container_of(work, struct ath12k_base, reset_work);806int reset_count, fail_cont_count;807long time_left;808809if (!(test_bit(ATH12K_FLAG_REGISTERED, &ab->dev_flags))) {810ath12k_warn(ab, "ignore reset dev flags 0x%lx\n", ab->dev_flags);811return;812}813814/* Sometimes the recovery will fail and then the next all recovery fail,815* this is to avoid infinite recovery since it can not recovery success816*/817fail_cont_count = atomic_read(&ab->fail_cont_count);818819if (fail_cont_count >= ATH12K_RESET_MAX_FAIL_COUNT_FINAL)820return;821822if (fail_cont_count >= ATH12K_RESET_MAX_FAIL_COUNT_FIRST &&823time_before(jiffies, ab->reset_fail_timeout))824return;825826reset_count = atomic_inc_return(&ab->reset_count);827828if (reset_count > 1) {829/* Sometimes it happened another reset worker before the previous one830* completed, then the second reset worker will destroy the previous one,831* thus below is to avoid that.832*/833ath12k_warn(ab, "already resetting count %d\n", reset_count);834835reinit_completion(&ab->reset_complete);836time_left = wait_for_completion_timeout(&ab->reset_complete,837ATH12K_RESET_TIMEOUT_HZ);838if (time_left) {839ath12k_dbg(ab, ATH12K_DBG_BOOT, "to skip reset\n");840atomic_dec(&ab->reset_count);841return;842}843844ab->reset_fail_timeout = jiffies + ATH12K_RESET_FAIL_TIMEOUT_HZ;845/* Record the continuous recovery fail count when recovery failed*/846fail_cont_count = atomic_inc_return(&ab->fail_cont_count);847}848849ath12k_dbg(ab, ATH12K_DBG_BOOT, "reset starting\n");850851ab->is_reset = true;852atomic_set(&ab->recovery_count, 0);853854ath12k_core_pre_reconfigure_recovery(ab);855856reinit_completion(&ab->reconfigure_complete);857ath12k_core_post_reconfigure_recovery(ab);858859reinit_completion(&ab->recovery_start);860atomic_set(&ab->recovery_start_count, 0);861862ath12k_dbg(ab, ATH12K_DBG_BOOT, "waiting recovery start...\n");863864time_left = wait_for_completion_timeout(&ab->recovery_start,865ATH12K_RECOVER_START_TIMEOUT_HZ);866867ath12k_hif_power_down(ab);868ath12k_hif_power_up(ab);869870ath12k_dbg(ab, ATH12K_DBG_BOOT, "reset started\n");871}872873int ath12k_core_pre_init(struct ath12k_base *ab)874{875int ret;876877ret = ath12k_hw_init(ab);878if (ret) {879ath12k_err(ab, "failed to init hw params: %d\n", ret);880return ret;881}882883return 0;884}885886int ath12k_core_init(struct ath12k_base *ab)887{888int ret;889890ret = ath12k_core_soc_create(ab);891if (ret) {892ath12k_err(ab, "failed to create soc core: %d\n", ret);893return ret;894}895896return 0;897}898899void ath12k_core_deinit(struct ath12k_base *ab)900{901mutex_lock(&ab->core_lock);902903ath12k_core_pdev_destroy(ab);904ath12k_core_stop(ab);905906mutex_unlock(&ab->core_lock);907908ath12k_hif_power_down(ab);909ath12k_mac_destroy(ab);910ath12k_core_soc_destroy(ab);911}912913void ath12k_core_free(struct ath12k_base *ab)914{915timer_delete_sync(&ab->rx_replenish_retry);916destroy_workqueue(ab->workqueue_aux);917destroy_workqueue(ab->workqueue);918kfree(ab);919}920921struct ath12k_base *ath12k_core_alloc(struct device *dev, size_t priv_size,922enum ath12k_bus bus)923{924struct ath12k_base *ab;925926ab = kzalloc(sizeof(*ab) + priv_size, GFP_KERNEL);927if (!ab)928return NULL;929930init_completion(&ab->driver_recovery);931932ab->workqueue = create_singlethread_workqueue("ath12k_wq");933if (!ab->workqueue)934goto err_sc_free;935936ab->workqueue_aux = create_singlethread_workqueue("ath12k_aux_wq");937if (!ab->workqueue_aux)938goto err_free_wq;939940mutex_init(&ab->core_lock);941spin_lock_init(&ab->base_lock);942init_completion(&ab->reset_complete);943init_completion(&ab->reconfigure_complete);944init_completion(&ab->recovery_start);945946INIT_LIST_HEAD(&ab->peers);947init_waitqueue_head(&ab->peer_mapping_wq);948init_waitqueue_head(&ab->wmi_ab.tx_credits_wq);949INIT_WORK(&ab->restart_work, ath12k_core_restart);950INIT_WORK(&ab->reset_work, ath12k_core_reset);951timer_setup(&ab->rx_replenish_retry, ath12k_ce_rx_replenish_retry, 0);952init_completion(&ab->htc_suspend);953954ab->dev = dev;955ab->hif.bus = bus;956957return ab;958959err_free_wq:960destroy_workqueue(ab->workqueue);961err_sc_free:962kfree(ab);963return NULL;964}965966MODULE_DESCRIPTION("Core module for Qualcomm Atheros 802.11be wireless LAN cards.");967MODULE_LICENSE("Dual BSD/GPL");968969970