xref: /linux/drivers/net/wireless/intel/iwlwifi/fw/smem.c (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
18e99ea8dSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
28e99ea8dSJohannes Berg /*
3*f0c86427SJohannes Berg  * Copyright (C) 2012-2014, 2018-2021 Intel Corporation
48e99ea8dSJohannes Berg  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
58e99ea8dSJohannes Berg  * Copyright (C) 2016-2017 Intel Deutschland GmbH
68e99ea8dSJohannes Berg  */
7d0b813fcSJohannes Berg #include "iwl-drv.h"
8d0b813fcSJohannes Berg #include "runtime.h"
9d172a5efSJohannes Berg #include "fw/api/commands.h"
10d0b813fcSJohannes Berg 
iwl_parse_shared_mem_22000(struct iwl_fw_runtime * fwrt,struct iwl_rx_packet * pkt)112f7a3863SLuca Coelho static void iwl_parse_shared_mem_22000(struct iwl_fw_runtime *fwrt,
12d0b813fcSJohannes Berg 				       struct iwl_rx_packet *pkt)
13d0b813fcSJohannes Berg {
14d0b813fcSJohannes Berg 	struct iwl_shared_mem_cfg *mem_cfg = (void *)pkt->data;
15d0b813fcSJohannes Berg 	int i, lmac;
16d0b813fcSJohannes Berg 	int lmac_num = le32_to_cpu(mem_cfg->lmac_num);
17ebfa7f8aSMordechay Goodstein 	u8 api_ver = iwl_fw_lookup_notif_ver(fwrt->fw, SYSTEM_GROUP,
18ebfa7f8aSMordechay Goodstein 					     SHARED_MEM_CFG_CMD, 0);
19d0b813fcSJohannes Berg 
20d0b813fcSJohannes Berg 	if (WARN_ON(lmac_num > ARRAY_SIZE(mem_cfg->lmac_smem)))
21d0b813fcSJohannes Berg 		return;
22d0b813fcSJohannes Berg 
23d0b813fcSJohannes Berg 	fwrt->smem_cfg.num_lmacs = lmac_num;
24d0b813fcSJohannes Berg 	fwrt->smem_cfg.num_txfifo_entries =
25d0b813fcSJohannes Berg 		ARRAY_SIZE(mem_cfg->lmac_smem[0].txfifo_size);
26d0b813fcSJohannes Berg 	fwrt->smem_cfg.rxfifo2_size = le32_to_cpu(mem_cfg->rxfifo2_size);
27d0b813fcSJohannes Berg 
28ebfa7f8aSMordechay Goodstein 	if (api_ver >= 4 &&
29ebfa7f8aSMordechay Goodstein 	    !WARN_ON_ONCE(iwl_rx_packet_payload_len(pkt) < sizeof(*mem_cfg))) {
30ebfa7f8aSMordechay Goodstein 		fwrt->smem_cfg.rxfifo2_control_size =
31ebfa7f8aSMordechay Goodstein 			le32_to_cpu(mem_cfg->rxfifo2_control_size);
32ebfa7f8aSMordechay Goodstein 	}
33ebfa7f8aSMordechay Goodstein 
34d0b813fcSJohannes Berg 	for (lmac = 0; lmac < lmac_num; lmac++) {
35d0b813fcSJohannes Berg 		struct iwl_shared_mem_lmac_cfg *lmac_cfg =
36d0b813fcSJohannes Berg 			&mem_cfg->lmac_smem[lmac];
37d0b813fcSJohannes Berg 
38d0b813fcSJohannes Berg 		for (i = 0; i < ARRAY_SIZE(lmac_cfg->txfifo_size); i++)
39d0b813fcSJohannes Berg 			fwrt->smem_cfg.lmac[lmac].txfifo_size[i] =
40d0b813fcSJohannes Berg 				le32_to_cpu(lmac_cfg->txfifo_size[i]);
41d0b813fcSJohannes Berg 		fwrt->smem_cfg.lmac[lmac].rxfifo1_size =
42d0b813fcSJohannes Berg 			le32_to_cpu(lmac_cfg->rxfifo1_size);
43d0b813fcSJohannes Berg 	}
44d0b813fcSJohannes Berg }
45d0b813fcSJohannes Berg 
iwl_parse_shared_mem(struct iwl_fw_runtime * fwrt,struct iwl_rx_packet * pkt)46d0b813fcSJohannes Berg static void iwl_parse_shared_mem(struct iwl_fw_runtime *fwrt,
47d0b813fcSJohannes Berg 				 struct iwl_rx_packet *pkt)
48d0b813fcSJohannes Berg {
49d0b813fcSJohannes Berg 	struct iwl_shared_mem_cfg_v2 *mem_cfg = (void *)pkt->data;
50d0b813fcSJohannes Berg 	int i;
51d0b813fcSJohannes Berg 
52d0b813fcSJohannes Berg 	fwrt->smem_cfg.num_lmacs = 1;
53d0b813fcSJohannes Berg 
54d0b813fcSJohannes Berg 	fwrt->smem_cfg.num_txfifo_entries = ARRAY_SIZE(mem_cfg->txfifo_size);
55d0b813fcSJohannes Berg 	for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++)
56d0b813fcSJohannes Berg 		fwrt->smem_cfg.lmac[0].txfifo_size[i] =
57d0b813fcSJohannes Berg 			le32_to_cpu(mem_cfg->txfifo_size[i]);
58d0b813fcSJohannes Berg 
59d0b813fcSJohannes Berg 	fwrt->smem_cfg.lmac[0].rxfifo1_size =
60d0b813fcSJohannes Berg 		le32_to_cpu(mem_cfg->rxfifo_size[0]);
61d0b813fcSJohannes Berg 	fwrt->smem_cfg.rxfifo2_size = le32_to_cpu(mem_cfg->rxfifo_size[1]);
62d0b813fcSJohannes Berg 
63d0b813fcSJohannes Berg 	/* new API has more data, from rxfifo_addr field and on */
64d0b813fcSJohannes Berg 	if (fw_has_capa(&fwrt->fw->ucode_capa,
65d0b813fcSJohannes Berg 			IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
66d0b813fcSJohannes Berg 		BUILD_BUG_ON(sizeof(fwrt->smem_cfg.internal_txfifo_size) !=
67d0b813fcSJohannes Berg 			     sizeof(mem_cfg->internal_txfifo_size));
68d0b813fcSJohannes Berg 
69ce27f005SGolan Ben-Ami 		fwrt->smem_cfg.internal_txfifo_addr =
70ce27f005SGolan Ben-Ami 			le32_to_cpu(mem_cfg->internal_txfifo_addr);
71ce27f005SGolan Ben-Ami 
72d0b813fcSJohannes Berg 		for (i = 0;
73d0b813fcSJohannes Berg 		     i < ARRAY_SIZE(fwrt->smem_cfg.internal_txfifo_size);
74d0b813fcSJohannes Berg 		     i++)
75d0b813fcSJohannes Berg 			fwrt->smem_cfg.internal_txfifo_size[i] =
76d0b813fcSJohannes Berg 				le32_to_cpu(mem_cfg->internal_txfifo_size[i]);
77d0b813fcSJohannes Berg 	}
78d0b813fcSJohannes Berg }
79d0b813fcSJohannes Berg 
iwl_get_shared_mem_conf(struct iwl_fw_runtime * fwrt)80d0b813fcSJohannes Berg void iwl_get_shared_mem_conf(struct iwl_fw_runtime *fwrt)
81d0b813fcSJohannes Berg {
82d0b813fcSJohannes Berg 	struct iwl_host_cmd cmd = {
83d0b813fcSJohannes Berg 		.flags = CMD_WANT_SKB,
84d0b813fcSJohannes Berg 		.data = { NULL, },
85d0b813fcSJohannes Berg 		.len = { 0, },
86d0b813fcSJohannes Berg 	};
87d0b813fcSJohannes Berg 	struct iwl_rx_packet *pkt;
880d53cfd0SEmmanuel Grumbach 	int ret;
89d0b813fcSJohannes Berg 
90d0b813fcSJohannes Berg 	if (fw_has_capa(&fwrt->fw->ucode_capa,
91d0b813fcSJohannes Berg 			IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG))
92*f0c86427SJohannes Berg 		cmd.id = WIDE_ID(SYSTEM_GROUP, SHARED_MEM_CFG_CMD);
93d0b813fcSJohannes Berg 	else
94d0b813fcSJohannes Berg 		cmd.id = SHARED_MEM_CFG;
95d0b813fcSJohannes Berg 
960d53cfd0SEmmanuel Grumbach 	ret = iwl_trans_send_cmd(fwrt->trans, &cmd);
970d53cfd0SEmmanuel Grumbach 
980d53cfd0SEmmanuel Grumbach 	if (ret) {
990d53cfd0SEmmanuel Grumbach 		WARN(ret != -ERFKILL,
1000d53cfd0SEmmanuel Grumbach 		     "Could not send the SMEM command: %d\n", ret);
101d0b813fcSJohannes Berg 		return;
1020d53cfd0SEmmanuel Grumbach 	}
103d0b813fcSJohannes Berg 
104d0b813fcSJohannes Berg 	pkt = cmd.resp_pkt;
105286ca8ebSLuca Coelho 	if (fwrt->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000)
1062f7a3863SLuca Coelho 		iwl_parse_shared_mem_22000(fwrt, pkt);
107d0b813fcSJohannes Berg 	else
108d0b813fcSJohannes Berg 		iwl_parse_shared_mem(fwrt, pkt);
109d0b813fcSJohannes Berg 
110d0b813fcSJohannes Berg 	IWL_DEBUG_INFO(fwrt, "SHARED MEM CFG: got memory offsets/sizes\n");
111d0b813fcSJohannes Berg 
112d0b813fcSJohannes Berg 	iwl_free_resp(&cmd);
113d0b813fcSJohannes Berg }
114d0b813fcSJohannes Berg IWL_EXPORT_SYMBOL(iwl_get_shared_mem_conf);
115