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