2 * Copyright (c) 2018 The Linux Foundation. All rights reserved.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/completion.h>
18 #include <linux/device.h>
19 #include <linux/debugfs.h>
20 #include <linux/idr.h>
21 #include <linux/kernel.h>
23 #include <linux/of_address.h>
24 #include <linux/module.h>
25 #include <linux/net.h>
26 #include <linux/platform_device.h>
27 #include <linux/qcom_scm.h>
28 #include <linux/string.h>
34 #define ATH10K_QMI_CLIENT_ID 0x4b4e454c
35 #define ATH10K_QMI_TIMEOUT 30
37 static int ath10k_qmi_map_msa_permission(struct ath10k_qmi *qmi,
38 struct ath10k_msa_mem_info *mem_info)
40 struct qcom_scm_vmperm dst_perms[3];
41 struct ath10k *ar = qmi->ar;
42 unsigned int src_perms;
46 src_perms = BIT(QCOM_SCM_VMID_HLOS);
48 dst_perms[0].vmid = QCOM_SCM_VMID_MSS_MSA;
49 dst_perms[0].perm = QCOM_SCM_PERM_RW;
50 dst_perms[1].vmid = QCOM_SCM_VMID_WLAN;
51 dst_perms[1].perm = QCOM_SCM_PERM_RW;
53 if (mem_info->secure) {
56 dst_perms[2].vmid = QCOM_SCM_VMID_WLAN_CE;
57 dst_perms[2].perm = QCOM_SCM_PERM_RW;
61 ret = qcom_scm_assign_mem(mem_info->addr, mem_info->size,
62 &src_perms, dst_perms, perm_count);
64 ath10k_err(ar, "failed to assign msa map permissions: %d\n", ret);
69 static int ath10k_qmi_unmap_msa_permission(struct ath10k_qmi *qmi,
70 struct ath10k_msa_mem_info *mem_info)
72 struct qcom_scm_vmperm dst_perms;
73 struct ath10k *ar = qmi->ar;
74 unsigned int src_perms;
77 src_perms = BIT(QCOM_SCM_VMID_MSS_MSA) | BIT(QCOM_SCM_VMID_WLAN);
79 if (!mem_info->secure)
80 src_perms |= BIT(QCOM_SCM_VMID_WLAN_CE);
82 dst_perms.vmid = QCOM_SCM_VMID_HLOS;
83 dst_perms.perm = QCOM_SCM_PERM_RW;
85 ret = qcom_scm_assign_mem(mem_info->addr, mem_info->size,
86 &src_perms, &dst_perms, 1);
88 ath10k_err(ar, "failed to unmap msa permissions: %d\n", ret);
93 static int ath10k_qmi_setup_msa_permissions(struct ath10k_qmi *qmi)
98 for (i = 0; i < qmi->nr_mem_region; i++) {
99 ret = ath10k_qmi_map_msa_permission(qmi, &qmi->mem_region[i]);
107 for (i--; i >= 0; i--)
108 ath10k_qmi_unmap_msa_permission(qmi, &qmi->mem_region[i]);
112 static void ath10k_qmi_remove_msa_permission(struct ath10k_qmi *qmi)
116 for (i = 0; i < qmi->nr_mem_region; i++)
117 ath10k_qmi_unmap_msa_permission(qmi, &qmi->mem_region[i]);
120 static int ath10k_qmi_msa_mem_info_send_sync_msg(struct ath10k_qmi *qmi)
122 struct wlfw_msa_info_resp_msg_v01 resp = {};
123 struct wlfw_msa_info_req_msg_v01 req = {};
124 struct ath10k *ar = qmi->ar;
129 req.msa_addr = qmi->msa_pa;
130 req.size = qmi->msa_mem_size;
132 ret = qmi_txn_init(&qmi->qmi_hdl, &txn,
133 wlfw_msa_info_resp_msg_v01_ei, &resp);
137 ret = qmi_send_request(&qmi->qmi_hdl, NULL, &txn,
138 QMI_WLFW_MSA_INFO_REQ_V01,
139 WLFW_MSA_INFO_REQ_MSG_V01_MAX_MSG_LEN,
140 wlfw_msa_info_req_msg_v01_ei, &req);
142 qmi_txn_cancel(&txn);
143 ath10k_err(ar, "failed to send msa mem info req: %d\n", ret);
147 ret = qmi_txn_wait(&txn, ATH10K_QMI_TIMEOUT * HZ);
151 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
152 ath10k_err(ar, "msa info req rejected: %d\n", resp.resp.error);
157 if (resp.mem_region_info_len > QMI_WLFW_MAX_MEM_REG_V01) {
158 ath10k_err(ar, "invalid memory region length received: %d\n",
159 resp.mem_region_info_len);
164 qmi->nr_mem_region = resp.mem_region_info_len;
165 for (i = 0; i < resp.mem_region_info_len; i++) {
166 qmi->mem_region[i].addr = resp.mem_region_info[i].region_addr;
167 qmi->mem_region[i].size = resp.mem_region_info[i].size;
168 qmi->mem_region[i].secure = resp.mem_region_info[i].secure_flag;
169 ath10k_dbg(ar, ATH10K_DBG_QMI,
170 "qmi msa mem region %d addr 0x%pa size 0x%x flag 0x%08x\n",
171 i, &qmi->mem_region[i].addr,
172 qmi->mem_region[i].size,
173 qmi->mem_region[i].secure);
176 ath10k_dbg(ar, ATH10K_DBG_QMI, "qmi msa mem info request completed\n");
183 static int ath10k_qmi_msa_ready_send_sync_msg(struct ath10k_qmi *qmi)
185 struct wlfw_msa_ready_resp_msg_v01 resp = {};
186 struct wlfw_msa_ready_req_msg_v01 req = {};
187 struct ath10k *ar = qmi->ar;
191 ret = qmi_txn_init(&qmi->qmi_hdl, &txn,
192 wlfw_msa_ready_resp_msg_v01_ei, &resp);
196 ret = qmi_send_request(&qmi->qmi_hdl, NULL, &txn,
197 QMI_WLFW_MSA_READY_REQ_V01,
198 WLFW_MSA_READY_REQ_MSG_V01_MAX_MSG_LEN,
199 wlfw_msa_ready_req_msg_v01_ei, &req);
201 qmi_txn_cancel(&txn);
202 ath10k_err(ar, "failed to send msa mem ready request: %d\n", ret);
206 ret = qmi_txn_wait(&txn, ATH10K_QMI_TIMEOUT * HZ);
210 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
211 ath10k_err(ar, "msa ready request rejected: %d\n", resp.resp.error);
215 ath10k_dbg(ar, ATH10K_DBG_QMI, "qmi msa mem ready request completed\n");
222 static int ath10k_qmi_bdf_dnld_send_sync(struct ath10k_qmi *qmi)
224 struct wlfw_bdf_download_resp_msg_v01 resp = {};
225 struct wlfw_bdf_download_req_msg_v01 *req;
226 struct ath10k *ar = qmi->ar;
227 unsigned int remaining;
232 req = kzalloc(sizeof(*req), GFP_KERNEL);
236 temp = ar->normal_mode_fw.board_data;
237 remaining = ar->normal_mode_fw.board_len;
241 req->file_id_valid = 1;
243 req->total_size_valid = 1;
244 req->total_size = ar->normal_mode_fw.board_len;
245 req->seg_id_valid = 1;
249 if (remaining > QMI_WLFW_MAX_DATA_SIZE_V01) {
250 req->data_len = QMI_WLFW_MAX_DATA_SIZE_V01;
252 req->data_len = remaining;
256 memcpy(req->data, temp, req->data_len);
258 ret = qmi_txn_init(&qmi->qmi_hdl, &txn,
259 wlfw_bdf_download_resp_msg_v01_ei,
264 ret = qmi_send_request(&qmi->qmi_hdl, NULL, &txn,
265 QMI_WLFW_BDF_DOWNLOAD_REQ_V01,
266 WLFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_MSG_LEN,
267 wlfw_bdf_download_req_msg_v01_ei, req);
269 qmi_txn_cancel(&txn);
273 ret = qmi_txn_wait(&txn, ATH10K_QMI_TIMEOUT * HZ);
278 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
279 ath10k_err(ar, "failed to download board data file: %d\n",
285 remaining -= req->data_len;
286 temp += req->data_len;
290 ath10k_dbg(ar, ATH10K_DBG_QMI, "qmi bdf download request completed\n");
300 static int ath10k_qmi_send_cal_report_req(struct ath10k_qmi *qmi)
302 struct wlfw_cal_report_resp_msg_v01 resp = {};
303 struct wlfw_cal_report_req_msg_v01 req = {};
304 struct ath10k *ar = qmi->ar;
309 ret = qmi_txn_init(&qmi->qmi_hdl, &txn, wlfw_cal_report_resp_msg_v01_ei,
314 for (i = 0; i < QMI_WLFW_MAX_NUM_CAL_V01; i++) {
315 if (qmi->cal_data[i].total_size &&
316 qmi->cal_data[i].data) {
317 req.meta_data[j] = qmi->cal_data[i].cal_id;
321 req.meta_data_len = j;
323 ret = qmi_send_request(&qmi->qmi_hdl, NULL, &txn,
324 QMI_WLFW_CAL_REPORT_REQ_V01,
325 WLFW_CAL_REPORT_REQ_MSG_V01_MAX_MSG_LEN,
326 wlfw_cal_report_req_msg_v01_ei, &req);
328 qmi_txn_cancel(&txn);
329 ath10k_err(ar, "failed to send calibration request: %d\n", ret);
333 ret = qmi_txn_wait(&txn, ATH10K_QMI_TIMEOUT * HZ);
337 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
338 ath10k_err(ar, "calibration request rejected: %d\n", resp.resp.error);
343 ath10k_dbg(ar, ATH10K_DBG_QMI, "qmi cal report request completed\n");
351 ath10k_qmi_mode_send_sync_msg(struct ath10k *ar, enum wlfw_driver_mode_enum_v01 mode)
353 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
354 struct ath10k_qmi *qmi = ar_snoc->qmi;
355 struct wlfw_wlan_mode_resp_msg_v01 resp = {};
356 struct wlfw_wlan_mode_req_msg_v01 req = {};
360 ret = qmi_txn_init(&qmi->qmi_hdl, &txn,
361 wlfw_wlan_mode_resp_msg_v01_ei,
367 req.hw_debug_valid = 1;
370 ret = qmi_send_request(&qmi->qmi_hdl, NULL, &txn,
371 QMI_WLFW_WLAN_MODE_REQ_V01,
372 WLFW_WLAN_MODE_REQ_MSG_V01_MAX_MSG_LEN,
373 wlfw_wlan_mode_req_msg_v01_ei, &req);
375 qmi_txn_cancel(&txn);
376 ath10k_err(ar, "failed to send wlan mode %d request: %d\n", mode, ret);
380 ret = qmi_txn_wait(&txn, ATH10K_QMI_TIMEOUT * HZ);
384 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
385 ath10k_err(ar, "more request rejected: %d\n", resp.resp.error);
390 ath10k_dbg(ar, ATH10K_DBG_QMI, "qmi wlan mode req completed: %d\n", mode);
398 ath10k_qmi_cfg_send_sync_msg(struct ath10k *ar,
399 struct ath10k_qmi_wlan_enable_cfg *config,
402 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
403 struct ath10k_qmi *qmi = ar_snoc->qmi;
404 struct wlfw_wlan_cfg_resp_msg_v01 resp = {};
405 struct wlfw_wlan_cfg_req_msg_v01 *req;
410 req = kzalloc(sizeof(*req), GFP_KERNEL);
414 ret = qmi_txn_init(&qmi->qmi_hdl, &txn,
415 wlfw_wlan_cfg_resp_msg_v01_ei,
420 req->host_version_valid = 0;
422 req->tgt_cfg_valid = 1;
423 if (config->num_ce_tgt_cfg > QMI_WLFW_MAX_NUM_CE_V01)
424 req->tgt_cfg_len = QMI_WLFW_MAX_NUM_CE_V01;
426 req->tgt_cfg_len = config->num_ce_tgt_cfg;
427 for (i = 0; i < req->tgt_cfg_len; i++) {
428 req->tgt_cfg[i].pipe_num = config->ce_tgt_cfg[i].pipe_num;
429 req->tgt_cfg[i].pipe_dir = config->ce_tgt_cfg[i].pipe_dir;
430 req->tgt_cfg[i].nentries = config->ce_tgt_cfg[i].nentries;
431 req->tgt_cfg[i].nbytes_max = config->ce_tgt_cfg[i].nbytes_max;
432 req->tgt_cfg[i].flags = config->ce_tgt_cfg[i].flags;
435 req->svc_cfg_valid = 1;
436 if (config->num_ce_svc_pipe_cfg > QMI_WLFW_MAX_NUM_SVC_V01)
437 req->svc_cfg_len = QMI_WLFW_MAX_NUM_SVC_V01;
439 req->svc_cfg_len = config->num_ce_svc_pipe_cfg;
440 for (i = 0; i < req->svc_cfg_len; i++) {
441 req->svc_cfg[i].service_id = config->ce_svc_cfg[i].service_id;
442 req->svc_cfg[i].pipe_dir = config->ce_svc_cfg[i].pipe_dir;
443 req->svc_cfg[i].pipe_num = config->ce_svc_cfg[i].pipe_num;
446 req->shadow_reg_valid = 1;
447 if (config->num_shadow_reg_cfg >
448 QMI_WLFW_MAX_NUM_SHADOW_REG_V01)
449 req->shadow_reg_len = QMI_WLFW_MAX_NUM_SHADOW_REG_V01;
451 req->shadow_reg_len = config->num_shadow_reg_cfg;
453 memcpy(req->shadow_reg, config->shadow_reg_cfg,
454 sizeof(struct wlfw_shadow_reg_cfg_s_v01) * req->shadow_reg_len);
456 ret = qmi_send_request(&qmi->qmi_hdl, NULL, &txn,
457 QMI_WLFW_WLAN_CFG_REQ_V01,
458 WLFW_WLAN_CFG_REQ_MSG_V01_MAX_MSG_LEN,
459 wlfw_wlan_cfg_req_msg_v01_ei, req);
461 qmi_txn_cancel(&txn);
462 ath10k_err(ar, "failed to send config request: %d\n", ret);
466 ret = qmi_txn_wait(&txn, ATH10K_QMI_TIMEOUT * HZ);
470 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
471 ath10k_err(ar, "config request rejected: %d\n", resp.resp.error);
476 ath10k_dbg(ar, ATH10K_DBG_QMI, "qmi config request completed\n");
485 int ath10k_qmi_wlan_enable(struct ath10k *ar,
486 struct ath10k_qmi_wlan_enable_cfg *config,
487 enum wlfw_driver_mode_enum_v01 mode,
492 ath10k_dbg(ar, ATH10K_DBG_QMI, "qmi mode %d config %p\n",
495 ret = ath10k_qmi_cfg_send_sync_msg(ar, config, version);
497 ath10k_err(ar, "failed to send qmi config: %d\n", ret);
501 ret = ath10k_qmi_mode_send_sync_msg(ar, mode);
503 ath10k_err(ar, "failed to send qmi mode: %d\n", ret);
510 int ath10k_qmi_wlan_disable(struct ath10k *ar)
512 return ath10k_qmi_mode_send_sync_msg(ar, QMI_WLFW_OFF_V01);
515 static int ath10k_qmi_cap_send_sync_msg(struct ath10k_qmi *qmi)
517 struct wlfw_cap_resp_msg_v01 *resp;
518 struct wlfw_cap_req_msg_v01 req = {};
519 struct ath10k *ar = qmi->ar;
523 resp = kzalloc(sizeof(*resp), GFP_KERNEL);
527 ret = qmi_txn_init(&qmi->qmi_hdl, &txn, wlfw_cap_resp_msg_v01_ei, resp);
531 ret = qmi_send_request(&qmi->qmi_hdl, NULL, &txn,
532 QMI_WLFW_CAP_REQ_V01,
533 WLFW_CAP_REQ_MSG_V01_MAX_MSG_LEN,
534 wlfw_cap_req_msg_v01_ei, &req);
536 qmi_txn_cancel(&txn);
537 ath10k_err(ar, "failed to send capability request: %d\n", ret);
541 ret = qmi_txn_wait(&txn, ATH10K_QMI_TIMEOUT * HZ);
545 if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
546 ath10k_err(ar, "capability req rejected: %d\n", resp->resp.error);
551 if (resp->chip_info_valid) {
552 qmi->chip_info.chip_id = resp->chip_info.chip_id;
553 qmi->chip_info.chip_family = resp->chip_info.chip_family;
556 if (resp->board_info_valid)
557 qmi->board_info.board_id = resp->board_info.board_id;
559 qmi->board_info.board_id = 0xFF;
561 if (resp->soc_info_valid)
562 qmi->soc_info.soc_id = resp->soc_info.soc_id;
564 if (resp->fw_version_info_valid) {
565 qmi->fw_version = resp->fw_version_info.fw_version;
566 strlcpy(qmi->fw_build_timestamp, resp->fw_version_info.fw_build_timestamp,
567 sizeof(qmi->fw_build_timestamp));
570 if (resp->fw_build_id_valid)
571 strlcpy(qmi->fw_build_id, resp->fw_build_id,
572 MAX_BUILD_ID_LEN + 1);
574 ath10k_dbg(ar, ATH10K_DBG_QMI,
575 "qmi chip_id 0x%x chip_family 0x%x board_id 0x%x soc_id 0x%x",
576 qmi->chip_info.chip_id, qmi->chip_info.chip_family,
577 qmi->board_info.board_id, qmi->soc_info.soc_id);
578 ath10k_dbg(ar, ATH10K_DBG_QMI,
579 "qmi fw_version 0x%x fw_build_timestamp %s fw_build_id %s",
580 qmi->fw_version, qmi->fw_build_timestamp, qmi->fw_build_id);
590 static int ath10k_qmi_host_cap_send_sync(struct ath10k_qmi *qmi)
592 struct wlfw_host_cap_resp_msg_v01 resp = {};
593 struct wlfw_host_cap_req_msg_v01 req = {};
594 struct ath10k *ar = qmi->ar;
598 req.daemon_support_valid = 1;
599 req.daemon_support = 0;
601 ret = qmi_txn_init(&qmi->qmi_hdl, &txn,
602 wlfw_host_cap_resp_msg_v01_ei, &resp);
606 ret = qmi_send_request(&qmi->qmi_hdl, NULL, &txn,
607 QMI_WLFW_HOST_CAP_REQ_V01,
608 WLFW_HOST_CAP_REQ_MSG_V01_MAX_MSG_LEN,
609 wlfw_host_cap_req_msg_v01_ei, &req);
611 qmi_txn_cancel(&txn);
612 ath10k_err(ar, "failed to send host capability request: %d\n", ret);
616 ret = qmi_txn_wait(&txn, ATH10K_QMI_TIMEOUT * HZ);
620 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
621 ath10k_err(ar, "host capability request rejected: %d\n", resp.resp.error);
626 ath10k_dbg(ar, ATH10K_DBG_QMI, "qmi host capability request completed\n");
634 ath10k_qmi_ind_register_send_sync_msg(struct ath10k_qmi *qmi)
636 struct wlfw_ind_register_resp_msg_v01 resp = {};
637 struct wlfw_ind_register_req_msg_v01 req = {};
638 struct ath10k *ar = qmi->ar;
642 req.client_id_valid = 1;
643 req.client_id = ATH10K_QMI_CLIENT_ID;
644 req.fw_ready_enable_valid = 1;
645 req.fw_ready_enable = 1;
646 req.msa_ready_enable_valid = 1;
647 req.msa_ready_enable = 1;
649 ret = qmi_txn_init(&qmi->qmi_hdl, &txn,
650 wlfw_ind_register_resp_msg_v01_ei, &resp);
654 ret = qmi_send_request(&qmi->qmi_hdl, NULL, &txn,
655 QMI_WLFW_IND_REGISTER_REQ_V01,
656 WLFW_IND_REGISTER_REQ_MSG_V01_MAX_MSG_LEN,
657 wlfw_ind_register_req_msg_v01_ei, &req);
659 qmi_txn_cancel(&txn);
660 ath10k_err(ar, "failed to send indication registered request: %d\n", ret);
664 ret = qmi_txn_wait(&txn, ATH10K_QMI_TIMEOUT * HZ);
668 if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
669 ath10k_err(ar, "indication request rejected: %d\n", resp.resp.error);
674 if (resp.fw_status_valid) {
675 if (resp.fw_status & QMI_WLFW_FW_READY_V01)
676 qmi->fw_ready = true;
678 ath10k_dbg(ar, ATH10K_DBG_QMI, "qmi indication register request completed\n");
685 static void ath10k_qmi_event_server_arrive(struct ath10k_qmi *qmi)
687 struct ath10k *ar = qmi->ar;
690 ret = ath10k_qmi_ind_register_send_sync_msg(qmi);
695 ath10k_snoc_fw_indication(ar, ATH10K_QMI_EVENT_FW_READY_IND);
699 ret = ath10k_qmi_host_cap_send_sync(qmi);
703 ret = ath10k_qmi_msa_mem_info_send_sync_msg(qmi);
707 ret = ath10k_qmi_setup_msa_permissions(qmi);
711 ret = ath10k_qmi_msa_ready_send_sync_msg(qmi);
715 ret = ath10k_qmi_cap_send_sync_msg(qmi);
722 ath10k_qmi_remove_msa_permission(qmi);
725 static int ath10k_qmi_fetch_board_file(struct ath10k_qmi *qmi)
727 struct ath10k *ar = qmi->ar;
729 ar->hif.bus = ATH10K_BUS_SNOC;
730 ar->id.qmi_ids_valid = true;
731 ar->id.qmi_board_id = qmi->board_info.board_id;
732 ar->hw_params.fw.dir = WCN3990_HW_1_0_FW_DIR;
734 return ath10k_core_fetch_board_file(qmi->ar, ATH10K_BD_IE_BOARD);
738 ath10k_qmi_driver_event_post(struct ath10k_qmi *qmi,
739 enum ath10k_qmi_driver_event_type type,
742 struct ath10k_qmi_driver_event *event;
744 event = kzalloc(sizeof(*event), GFP_ATOMIC);
751 spin_lock(&qmi->event_lock);
752 list_add_tail(&event->list, &qmi->event_list);
753 spin_unlock(&qmi->event_lock);
755 queue_work(qmi->event_wq, &qmi->event_work);
760 static void ath10k_qmi_event_server_exit(struct ath10k_qmi *qmi)
762 struct ath10k *ar = qmi->ar;
764 ath10k_qmi_remove_msa_permission(qmi);
765 ath10k_core_free_board_files(ar);
766 ath10k_snoc_fw_indication(ar, ATH10K_QMI_EVENT_FW_DOWN_IND);
767 ath10k_dbg(ar, ATH10K_DBG_QMI, "wifi fw qmi service disconnected\n");
770 static void ath10k_qmi_event_msa_ready(struct ath10k_qmi *qmi)
774 ret = ath10k_qmi_fetch_board_file(qmi);
778 ret = ath10k_qmi_bdf_dnld_send_sync(qmi);
782 ret = ath10k_qmi_send_cal_report_req(qmi);
788 static int ath10k_qmi_event_fw_ready_ind(struct ath10k_qmi *qmi)
790 struct ath10k *ar = qmi->ar;
792 ath10k_dbg(ar, ATH10K_DBG_QMI, "wifi fw ready event received\n");
793 ath10k_snoc_fw_indication(ar, ATH10K_QMI_EVENT_FW_READY_IND);
798 static void ath10k_qmi_fw_ready_ind(struct qmi_handle *qmi_hdl,
799 struct sockaddr_qrtr *sq,
800 struct qmi_txn *txn, const void *data)
802 struct ath10k_qmi *qmi = container_of(qmi_hdl, struct ath10k_qmi, qmi_hdl);
804 ath10k_qmi_driver_event_post(qmi, ATH10K_QMI_EVENT_FW_READY_IND, NULL);
807 static void ath10k_qmi_msa_ready_ind(struct qmi_handle *qmi_hdl,
808 struct sockaddr_qrtr *sq,
809 struct qmi_txn *txn, const void *data)
811 struct ath10k_qmi *qmi = container_of(qmi_hdl, struct ath10k_qmi, qmi_hdl);
813 ath10k_qmi_driver_event_post(qmi, ATH10K_QMI_EVENT_MSA_READY_IND, NULL);
816 static struct qmi_msg_handler qmi_msg_handler[] = {
818 .type = QMI_INDICATION,
819 .msg_id = QMI_WLFW_FW_READY_IND_V01,
820 .ei = wlfw_fw_ready_ind_msg_v01_ei,
821 .decoded_size = sizeof(struct wlfw_fw_ready_ind_msg_v01),
822 .fn = ath10k_qmi_fw_ready_ind,
825 .type = QMI_INDICATION,
826 .msg_id = QMI_WLFW_MSA_READY_IND_V01,
827 .ei = wlfw_msa_ready_ind_msg_v01_ei,
828 .decoded_size = sizeof(struct wlfw_msa_ready_ind_msg_v01),
829 .fn = ath10k_qmi_msa_ready_ind,
834 static int ath10k_qmi_new_server(struct qmi_handle *qmi_hdl,
835 struct qmi_service *service)
837 struct ath10k_qmi *qmi = container_of(qmi_hdl, struct ath10k_qmi, qmi_hdl);
838 struct sockaddr_qrtr *sq = &qmi->sq;
839 struct ath10k *ar = qmi->ar;
842 sq->sq_family = AF_QIPCRTR;
843 sq->sq_node = service->node;
844 sq->sq_port = service->port;
846 ath10k_dbg(ar, ATH10K_DBG_QMI, "wifi fw qmi service found\n");
848 ret = kernel_connect(qmi_hdl->sock, (struct sockaddr *)&qmi->sq,
851 ath10k_err(ar, "failed to connect to a remote QMI service port\n");
855 ath10k_dbg(ar, ATH10K_DBG_QMI, "qmi wifi fw qmi service connected\n");
856 ath10k_qmi_driver_event_post(qmi, ATH10K_QMI_EVENT_SERVER_ARRIVE, NULL);
861 static void ath10k_qmi_del_server(struct qmi_handle *qmi_hdl,
862 struct qmi_service *service)
864 struct ath10k_qmi *qmi =
865 container_of(qmi_hdl, struct ath10k_qmi, qmi_hdl);
867 qmi->fw_ready = false;
868 ath10k_qmi_driver_event_post(qmi, ATH10K_QMI_EVENT_SERVER_EXIT, NULL);
871 static struct qmi_ops ath10k_qmi_ops = {
872 .new_server = ath10k_qmi_new_server,
873 .del_server = ath10k_qmi_del_server,
876 static void ath10k_qmi_driver_event_work(struct work_struct *work)
878 struct ath10k_qmi *qmi = container_of(work, struct ath10k_qmi,
880 struct ath10k_qmi_driver_event *event;
881 struct ath10k *ar = qmi->ar;
883 spin_lock(&qmi->event_lock);
884 while (!list_empty(&qmi->event_list)) {
885 event = list_first_entry(&qmi->event_list,
886 struct ath10k_qmi_driver_event, list);
887 list_del(&event->list);
888 spin_unlock(&qmi->event_lock);
890 switch (event->type) {
891 case ATH10K_QMI_EVENT_SERVER_ARRIVE:
892 ath10k_qmi_event_server_arrive(qmi);
894 case ATH10K_QMI_EVENT_SERVER_EXIT:
895 ath10k_qmi_event_server_exit(qmi);
897 case ATH10K_QMI_EVENT_FW_READY_IND:
898 ath10k_qmi_event_fw_ready_ind(qmi);
900 case ATH10K_QMI_EVENT_MSA_READY_IND:
901 ath10k_qmi_event_msa_ready(qmi);
904 ath10k_warn(ar, "invalid event type: %d", event->type);
908 spin_lock(&qmi->event_lock);
910 spin_unlock(&qmi->event_lock);
913 static int ath10k_qmi_setup_msa_resources(struct ath10k_qmi *qmi, u32 msa_size)
915 struct ath10k *ar = qmi->ar;
916 struct device *dev = ar->dev;
917 struct device_node *node;
921 node = of_parse_phandle(dev->of_node, "memory-region", 0);
923 ret = of_address_to_resource(node, 0, &r);
925 dev_err(dev, "failed to resolve msa fixed region\n");
930 qmi->msa_pa = r.start;
931 qmi->msa_mem_size = resource_size(&r);
932 qmi->msa_va = devm_memremap(dev, qmi->msa_pa, qmi->msa_mem_size,
934 if (IS_ERR(qmi->msa_va)) {
935 dev_err(dev, "failed to map memory region: %pa\n", &r.start);
936 return PTR_ERR(qmi->msa_va);
939 qmi->msa_va = dmam_alloc_coherent(dev, msa_size,
940 &qmi->msa_pa, GFP_KERNEL);
942 ath10k_err(ar, "failed to allocate dma memory for msa region\n");
945 qmi->msa_mem_size = msa_size;
948 ath10k_dbg(ar, ATH10K_DBG_QMI, "msa pa: %pad , msa va: 0x%p\n",
955 int ath10k_qmi_init(struct ath10k *ar, u32 msa_size)
957 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
958 struct ath10k_qmi *qmi;
961 qmi = kzalloc(sizeof(*qmi), GFP_KERNEL);
968 ret = ath10k_qmi_setup_msa_resources(qmi, msa_size);
972 ret = qmi_handle_init(&qmi->qmi_hdl,
973 WLFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_MSG_LEN,
974 &ath10k_qmi_ops, qmi_msg_handler);
978 qmi->event_wq = alloc_workqueue("ath10k_qmi_driver_event",
980 if (!qmi->event_wq) {
981 ath10k_err(ar, "failed to allocate workqueue\n");
983 goto err_release_qmi_handle;
986 INIT_LIST_HEAD(&qmi->event_list);
987 spin_lock_init(&qmi->event_lock);
988 INIT_WORK(&qmi->event_work, ath10k_qmi_driver_event_work);
990 ret = qmi_add_lookup(&qmi->qmi_hdl, WLFW_SERVICE_ID_V01,
991 WLFW_SERVICE_VERS_V01, 0);
998 destroy_workqueue(qmi->event_wq);
1000 err_release_qmi_handle:
1001 qmi_handle_release(&qmi->qmi_hdl);
1008 int ath10k_qmi_deinit(struct ath10k *ar)
1010 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1011 struct ath10k_qmi *qmi = ar_snoc->qmi;
1013 qmi_handle_release(&qmi->qmi_hdl);
1014 cancel_work_sync(&qmi->event_work);
1015 destroy_workqueue(qmi->event_wq);
1016 ar_snoc->qmi = NULL;