xref: /linux/drivers/net/wireless/intel/iwlwifi/fw/smem.c (revision 0d53cfd0cca3c729a089c39eef0e7d8ae7662974)
1d0b813fcSJohannes Berg /******************************************************************************
2d0b813fcSJohannes Berg  *
3d0b813fcSJohannes Berg  * This file is provided under a dual BSD/GPLv2 license.  When using or
4d0b813fcSJohannes Berg  * redistributing this file, you may do so under either license.
5d0b813fcSJohannes Berg  *
6d0b813fcSJohannes Berg  * GPL LICENSE SUMMARY
7d0b813fcSJohannes Berg  *
8d0b813fcSJohannes Berg  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
9d0b813fcSJohannes Berg  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10d0b813fcSJohannes Berg  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11*0d53cfd0SEmmanuel Grumbach  * Copyright(c) 2018 - 2019 Intel Corporation
12d0b813fcSJohannes Berg  *
13d0b813fcSJohannes Berg  * This program is free software; you can redistribute it and/or modify
14d0b813fcSJohannes Berg  * it under the terms of version 2 of the GNU General Public License as
15d0b813fcSJohannes Berg  * published by the Free Software Foundation.
16d0b813fcSJohannes Berg  *
17d0b813fcSJohannes Berg  * This program is distributed in the hope that it will be useful, but
18d0b813fcSJohannes Berg  * WITHOUT ANY WARRANTY; without even the implied warranty of
19d0b813fcSJohannes Berg  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20d0b813fcSJohannes Berg  * General Public License for more details.
21d0b813fcSJohannes Berg  *
22d0b813fcSJohannes Berg  * The full GNU General Public License is included in this distribution
23d0b813fcSJohannes Berg  * in the file called COPYING.
24d0b813fcSJohannes Berg  *
25d0b813fcSJohannes Berg  * Contact Information:
26d0b813fcSJohannes Berg  *  Intel Linux Wireless <linuxwifi@intel.com>
27d0b813fcSJohannes Berg  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28d0b813fcSJohannes Berg  *
29d0b813fcSJohannes Berg  * BSD LICENSE
30d0b813fcSJohannes Berg  *
31d0b813fcSJohannes Berg  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32d0b813fcSJohannes Berg  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33d0b813fcSJohannes Berg  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34*0d53cfd0SEmmanuel Grumbach  * Copyright(c) 2018 - 2019 Intel Corporation
35d0b813fcSJohannes Berg  * All rights reserved.
36d0b813fcSJohannes Berg  *
37d0b813fcSJohannes Berg  * Redistribution and use in source and binary forms, with or without
38d0b813fcSJohannes Berg  * modification, are permitted provided that the following conditions
39d0b813fcSJohannes Berg  * are met:
40d0b813fcSJohannes Berg  *
41d0b813fcSJohannes Berg  *  * Redistributions of source code must retain the above copyright
42d0b813fcSJohannes Berg  *    notice, this list of conditions and the following disclaimer.
43d0b813fcSJohannes Berg  *  * Redistributions in binary form must reproduce the above copyright
44d0b813fcSJohannes Berg  *    notice, this list of conditions and the following disclaimer in
45d0b813fcSJohannes Berg  *    the documentation and/or other materials provided with the
46d0b813fcSJohannes Berg  *    distribution.
47d0b813fcSJohannes Berg  *  * Neither the name Intel Corporation nor the names of its
48d0b813fcSJohannes Berg  *    contributors may be used to endorse or promote products derived
49d0b813fcSJohannes Berg  *    from this software without specific prior written permission.
50d0b813fcSJohannes Berg  *
51d0b813fcSJohannes Berg  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52d0b813fcSJohannes Berg  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53d0b813fcSJohannes Berg  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54d0b813fcSJohannes Berg  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55d0b813fcSJohannes Berg  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56d0b813fcSJohannes Berg  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57d0b813fcSJohannes Berg  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58d0b813fcSJohannes Berg  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59d0b813fcSJohannes Berg  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60d0b813fcSJohannes Berg  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61d0b813fcSJohannes Berg  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62d0b813fcSJohannes Berg  *
63d0b813fcSJohannes Berg  *****************************************************************************/
64d0b813fcSJohannes Berg #include "iwl-drv.h"
65d0b813fcSJohannes Berg #include "runtime.h"
66d172a5efSJohannes Berg #include "fw/api/commands.h"
67d0b813fcSJohannes Berg 
682f7a3863SLuca Coelho static void iwl_parse_shared_mem_22000(struct iwl_fw_runtime *fwrt,
69d0b813fcSJohannes Berg 				       struct iwl_rx_packet *pkt)
70d0b813fcSJohannes Berg {
71d0b813fcSJohannes Berg 	struct iwl_shared_mem_cfg *mem_cfg = (void *)pkt->data;
72d0b813fcSJohannes Berg 	int i, lmac;
73d0b813fcSJohannes Berg 	int lmac_num = le32_to_cpu(mem_cfg->lmac_num);
74d0b813fcSJohannes Berg 
75d0b813fcSJohannes Berg 	if (WARN_ON(lmac_num > ARRAY_SIZE(mem_cfg->lmac_smem)))
76d0b813fcSJohannes Berg 		return;
77d0b813fcSJohannes Berg 
78d0b813fcSJohannes Berg 	fwrt->smem_cfg.num_lmacs = lmac_num;
79d0b813fcSJohannes Berg 	fwrt->smem_cfg.num_txfifo_entries =
80d0b813fcSJohannes Berg 		ARRAY_SIZE(mem_cfg->lmac_smem[0].txfifo_size);
81d0b813fcSJohannes Berg 	fwrt->smem_cfg.rxfifo2_size = le32_to_cpu(mem_cfg->rxfifo2_size);
82d0b813fcSJohannes Berg 
83d0b813fcSJohannes Berg 	for (lmac = 0; lmac < lmac_num; lmac++) {
84d0b813fcSJohannes Berg 		struct iwl_shared_mem_lmac_cfg *lmac_cfg =
85d0b813fcSJohannes Berg 			&mem_cfg->lmac_smem[lmac];
86d0b813fcSJohannes Berg 
87d0b813fcSJohannes Berg 		for (i = 0; i < ARRAY_SIZE(lmac_cfg->txfifo_size); i++)
88d0b813fcSJohannes Berg 			fwrt->smem_cfg.lmac[lmac].txfifo_size[i] =
89d0b813fcSJohannes Berg 				le32_to_cpu(lmac_cfg->txfifo_size[i]);
90d0b813fcSJohannes Berg 		fwrt->smem_cfg.lmac[lmac].rxfifo1_size =
91d0b813fcSJohannes Berg 			le32_to_cpu(lmac_cfg->rxfifo1_size);
92d0b813fcSJohannes Berg 	}
93d0b813fcSJohannes Berg }
94d0b813fcSJohannes Berg 
95d0b813fcSJohannes Berg static void iwl_parse_shared_mem(struct iwl_fw_runtime *fwrt,
96d0b813fcSJohannes Berg 				 struct iwl_rx_packet *pkt)
97d0b813fcSJohannes Berg {
98d0b813fcSJohannes Berg 	struct iwl_shared_mem_cfg_v2 *mem_cfg = (void *)pkt->data;
99d0b813fcSJohannes Berg 	int i;
100d0b813fcSJohannes Berg 
101d0b813fcSJohannes Berg 	fwrt->smem_cfg.num_lmacs = 1;
102d0b813fcSJohannes Berg 
103d0b813fcSJohannes Berg 	fwrt->smem_cfg.num_txfifo_entries = ARRAY_SIZE(mem_cfg->txfifo_size);
104d0b813fcSJohannes Berg 	for (i = 0; i < ARRAY_SIZE(mem_cfg->txfifo_size); i++)
105d0b813fcSJohannes Berg 		fwrt->smem_cfg.lmac[0].txfifo_size[i] =
106d0b813fcSJohannes Berg 			le32_to_cpu(mem_cfg->txfifo_size[i]);
107d0b813fcSJohannes Berg 
108d0b813fcSJohannes Berg 	fwrt->smem_cfg.lmac[0].rxfifo1_size =
109d0b813fcSJohannes Berg 		le32_to_cpu(mem_cfg->rxfifo_size[0]);
110d0b813fcSJohannes Berg 	fwrt->smem_cfg.rxfifo2_size = le32_to_cpu(mem_cfg->rxfifo_size[1]);
111d0b813fcSJohannes Berg 
112d0b813fcSJohannes Berg 	/* new API has more data, from rxfifo_addr field and on */
113d0b813fcSJohannes Berg 	if (fw_has_capa(&fwrt->fw->ucode_capa,
114d0b813fcSJohannes Berg 			IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG)) {
115d0b813fcSJohannes Berg 		BUILD_BUG_ON(sizeof(fwrt->smem_cfg.internal_txfifo_size) !=
116d0b813fcSJohannes Berg 			     sizeof(mem_cfg->internal_txfifo_size));
117d0b813fcSJohannes Berg 
118ce27f005SGolan Ben-Ami 		fwrt->smem_cfg.internal_txfifo_addr =
119ce27f005SGolan Ben-Ami 			le32_to_cpu(mem_cfg->internal_txfifo_addr);
120ce27f005SGolan Ben-Ami 
121d0b813fcSJohannes Berg 		for (i = 0;
122d0b813fcSJohannes Berg 		     i < ARRAY_SIZE(fwrt->smem_cfg.internal_txfifo_size);
123d0b813fcSJohannes Berg 		     i++)
124d0b813fcSJohannes Berg 			fwrt->smem_cfg.internal_txfifo_size[i] =
125d0b813fcSJohannes Berg 				le32_to_cpu(mem_cfg->internal_txfifo_size[i]);
126d0b813fcSJohannes Berg 	}
127d0b813fcSJohannes Berg }
128d0b813fcSJohannes Berg 
129d0b813fcSJohannes Berg void iwl_get_shared_mem_conf(struct iwl_fw_runtime *fwrt)
130d0b813fcSJohannes Berg {
131d0b813fcSJohannes Berg 	struct iwl_host_cmd cmd = {
132d0b813fcSJohannes Berg 		.flags = CMD_WANT_SKB,
133d0b813fcSJohannes Berg 		.data = { NULL, },
134d0b813fcSJohannes Berg 		.len = { 0, },
135d0b813fcSJohannes Berg 	};
136d0b813fcSJohannes Berg 	struct iwl_rx_packet *pkt;
137*0d53cfd0SEmmanuel Grumbach 	int ret;
138d0b813fcSJohannes Berg 
139d0b813fcSJohannes Berg 	if (fw_has_capa(&fwrt->fw->ucode_capa,
140d0b813fcSJohannes Berg 			IWL_UCODE_TLV_CAPA_EXTEND_SHARED_MEM_CFG))
141d0b813fcSJohannes Berg 		cmd.id = iwl_cmd_id(SHARED_MEM_CFG_CMD, SYSTEM_GROUP, 0);
142d0b813fcSJohannes Berg 	else
143d0b813fcSJohannes Berg 		cmd.id = SHARED_MEM_CFG;
144d0b813fcSJohannes Berg 
145*0d53cfd0SEmmanuel Grumbach 	ret = iwl_trans_send_cmd(fwrt->trans, &cmd);
146*0d53cfd0SEmmanuel Grumbach 
147*0d53cfd0SEmmanuel Grumbach 	if (ret) {
148*0d53cfd0SEmmanuel Grumbach 		WARN(ret != -ERFKILL,
149*0d53cfd0SEmmanuel Grumbach 		     "Could not send the SMEM command: %d\n", ret);
150d0b813fcSJohannes Berg 		return;
151*0d53cfd0SEmmanuel Grumbach 	}
152d0b813fcSJohannes Berg 
153d0b813fcSJohannes Berg 	pkt = cmd.resp_pkt;
1545f01df3fSGolan Ben Ami 	if (fwrt->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22000)
1552f7a3863SLuca Coelho 		iwl_parse_shared_mem_22000(fwrt, pkt);
156d0b813fcSJohannes Berg 	else
157d0b813fcSJohannes Berg 		iwl_parse_shared_mem(fwrt, pkt);
158d0b813fcSJohannes Berg 
159d0b813fcSJohannes Berg 	IWL_DEBUG_INFO(fwrt, "SHARED MEM CFG: got memory offsets/sizes\n");
160d0b813fcSJohannes Berg 
161d0b813fcSJohannes Berg 	iwl_free_resp(&cmd);
162d0b813fcSJohannes Berg }
163d0b813fcSJohannes Berg IWL_EXPORT_SYMBOL(iwl_get_shared_mem_conf);
164