xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/intel/iwlwifi/fw/paging.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) 2012 - 2014 Intel Corporation. All rights reserved.
9*4882a593Smuzhiyun  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
10*4882a593Smuzhiyun  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
11*4882a593Smuzhiyun  * Copyright(c) 2018 - 2019 Intel Corporation
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify
14*4882a593Smuzhiyun  * it under the terms of version 2 of the GNU General Public License as
15*4882a593Smuzhiyun  * published by the Free Software Foundation.
16*4882a593Smuzhiyun  *
17*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but
18*4882a593Smuzhiyun  * WITHOUT ANY WARRANTY; without even the implied warranty of
19*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20*4882a593Smuzhiyun  * General Public License for more details.
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * The full GNU General Public License is included in this distribution
23*4882a593Smuzhiyun  * in the file called COPYING.
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * Contact Information:
26*4882a593Smuzhiyun  *  Intel Linux Wireless <linuxwifi@intel.com>
27*4882a593Smuzhiyun  * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28*4882a593Smuzhiyun  *
29*4882a593Smuzhiyun  * BSD LICENSE
30*4882a593Smuzhiyun  *
31*4882a593Smuzhiyun  * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
32*4882a593Smuzhiyun  * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
33*4882a593Smuzhiyun  * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
34*4882a593Smuzhiyun  * Copyright(c) 2018 - 2019 Intel Corporation
35*4882a593Smuzhiyun  * All rights reserved.
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
38*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
39*4882a593Smuzhiyun  * are met:
40*4882a593Smuzhiyun  *
41*4882a593Smuzhiyun  *  * Redistributions of source code must retain the above copyright
42*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer.
43*4882a593Smuzhiyun  *  * Redistributions in binary form must reproduce the above copyright
44*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer in
45*4882a593Smuzhiyun  *    the documentation and/or other materials provided with the
46*4882a593Smuzhiyun  *    distribution.
47*4882a593Smuzhiyun  *  * Neither the name Intel Corporation nor the names of its
48*4882a593Smuzhiyun  *    contributors may be used to endorse or promote products derived
49*4882a593Smuzhiyun  *    from this software without specific prior written permission.
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
52*4882a593Smuzhiyun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
53*4882a593Smuzhiyun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
54*4882a593Smuzhiyun  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
55*4882a593Smuzhiyun  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
56*4882a593Smuzhiyun  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
57*4882a593Smuzhiyun  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
58*4882a593Smuzhiyun  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
59*4882a593Smuzhiyun  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
61*4882a593Smuzhiyun  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  *****************************************************************************/
64*4882a593Smuzhiyun #include "iwl-drv.h"
65*4882a593Smuzhiyun #include "runtime.h"
66*4882a593Smuzhiyun #include "fw/api/commands.h"
67*4882a593Smuzhiyun 
iwl_free_fw_paging(struct iwl_fw_runtime * fwrt)68*4882a593Smuzhiyun void iwl_free_fw_paging(struct iwl_fw_runtime *fwrt)
69*4882a593Smuzhiyun {
70*4882a593Smuzhiyun 	int i;
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun 	if (!fwrt->fw_paging_db[0].fw_paging_block)
73*4882a593Smuzhiyun 		return;
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	for (i = 0; i < NUM_OF_FW_PAGING_BLOCKS; i++) {
76*4882a593Smuzhiyun 		struct iwl_fw_paging *paging = &fwrt->fw_paging_db[i];
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 		if (!paging->fw_paging_block) {
79*4882a593Smuzhiyun 			IWL_DEBUG_FW(fwrt,
80*4882a593Smuzhiyun 				     "Paging: block %d already freed, continue to next page\n",
81*4882a593Smuzhiyun 				     i);
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 			continue;
84*4882a593Smuzhiyun 		}
85*4882a593Smuzhiyun 		dma_unmap_page(fwrt->trans->dev, paging->fw_paging_phys,
86*4882a593Smuzhiyun 			       paging->fw_paging_size, DMA_BIDIRECTIONAL);
87*4882a593Smuzhiyun 
88*4882a593Smuzhiyun 		__free_pages(paging->fw_paging_block,
89*4882a593Smuzhiyun 			     get_order(paging->fw_paging_size));
90*4882a593Smuzhiyun 		paging->fw_paging_block = NULL;
91*4882a593Smuzhiyun 	}
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 	memset(fwrt->fw_paging_db, 0, sizeof(fwrt->fw_paging_db));
94*4882a593Smuzhiyun }
95*4882a593Smuzhiyun IWL_EXPORT_SYMBOL(iwl_free_fw_paging);
96*4882a593Smuzhiyun 
iwl_alloc_fw_paging_mem(struct iwl_fw_runtime * fwrt,const struct fw_img * image)97*4882a593Smuzhiyun static int iwl_alloc_fw_paging_mem(struct iwl_fw_runtime *fwrt,
98*4882a593Smuzhiyun 				   const struct fw_img *image)
99*4882a593Smuzhiyun {
100*4882a593Smuzhiyun 	struct page *block;
101*4882a593Smuzhiyun 	dma_addr_t phys = 0;
102*4882a593Smuzhiyun 	int blk_idx, order, num_of_pages, size;
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun 	if (fwrt->fw_paging_db[0].fw_paging_block)
105*4882a593Smuzhiyun 		return 0;
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun 	/* ensure BLOCK_2_EXP_SIZE is power of 2 of PAGING_BLOCK_SIZE */
108*4882a593Smuzhiyun 	BUILD_BUG_ON(BIT(BLOCK_2_EXP_SIZE) != PAGING_BLOCK_SIZE);
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun 	num_of_pages = image->paging_mem_size / FW_PAGING_SIZE;
111*4882a593Smuzhiyun 	fwrt->num_of_paging_blk =
112*4882a593Smuzhiyun 		DIV_ROUND_UP(num_of_pages, NUM_OF_PAGE_PER_GROUP);
113*4882a593Smuzhiyun 	fwrt->num_of_pages_in_last_blk =
114*4882a593Smuzhiyun 		num_of_pages -
115*4882a593Smuzhiyun 		NUM_OF_PAGE_PER_GROUP * (fwrt->num_of_paging_blk - 1);
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun 	IWL_DEBUG_FW(fwrt,
118*4882a593Smuzhiyun 		     "Paging: allocating mem for %d paging blocks, each block holds 8 pages, last block holds %d pages\n",
119*4882a593Smuzhiyun 		     fwrt->num_of_paging_blk,
120*4882a593Smuzhiyun 		     fwrt->num_of_pages_in_last_blk);
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	/*
123*4882a593Smuzhiyun 	 * Allocate CSS and paging blocks in dram.
124*4882a593Smuzhiyun 	 */
125*4882a593Smuzhiyun 	for (blk_idx = 0; blk_idx < fwrt->num_of_paging_blk + 1; blk_idx++) {
126*4882a593Smuzhiyun 		/* For CSS allocate 4KB, for others PAGING_BLOCK_SIZE (32K) */
127*4882a593Smuzhiyun 		size = blk_idx ? PAGING_BLOCK_SIZE : FW_PAGING_SIZE;
128*4882a593Smuzhiyun 		order = get_order(size);
129*4882a593Smuzhiyun 		block = alloc_pages(GFP_KERNEL, order);
130*4882a593Smuzhiyun 		if (!block) {
131*4882a593Smuzhiyun 			/* free all the previous pages since we failed */
132*4882a593Smuzhiyun 			iwl_free_fw_paging(fwrt);
133*4882a593Smuzhiyun 			return -ENOMEM;
134*4882a593Smuzhiyun 		}
135*4882a593Smuzhiyun 
136*4882a593Smuzhiyun 		fwrt->fw_paging_db[blk_idx].fw_paging_block = block;
137*4882a593Smuzhiyun 		fwrt->fw_paging_db[blk_idx].fw_paging_size = size;
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun 		phys = dma_map_page(fwrt->trans->dev, block, 0,
140*4882a593Smuzhiyun 				    PAGE_SIZE << order,
141*4882a593Smuzhiyun 				    DMA_BIDIRECTIONAL);
142*4882a593Smuzhiyun 		if (dma_mapping_error(fwrt->trans->dev, phys)) {
143*4882a593Smuzhiyun 			/*
144*4882a593Smuzhiyun 			 * free the previous pages and the current one
145*4882a593Smuzhiyun 			 * since we failed to map_page.
146*4882a593Smuzhiyun 			 */
147*4882a593Smuzhiyun 			iwl_free_fw_paging(fwrt);
148*4882a593Smuzhiyun 			return -ENOMEM;
149*4882a593Smuzhiyun 		}
150*4882a593Smuzhiyun 		fwrt->fw_paging_db[blk_idx].fw_paging_phys = phys;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 		if (!blk_idx)
153*4882a593Smuzhiyun 			IWL_DEBUG_FW(fwrt,
154*4882a593Smuzhiyun 				     "Paging: allocated 4K(CSS) bytes (order %d) for firmware paging.\n",
155*4882a593Smuzhiyun 				     order);
156*4882a593Smuzhiyun 		else
157*4882a593Smuzhiyun 			IWL_DEBUG_FW(fwrt,
158*4882a593Smuzhiyun 				     "Paging: allocated 32K bytes (order %d) for firmware paging.\n",
159*4882a593Smuzhiyun 				     order);
160*4882a593Smuzhiyun 	}
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	return 0;
163*4882a593Smuzhiyun }
164*4882a593Smuzhiyun 
iwl_fill_paging_mem(struct iwl_fw_runtime * fwrt,const struct fw_img * image)165*4882a593Smuzhiyun static int iwl_fill_paging_mem(struct iwl_fw_runtime *fwrt,
166*4882a593Smuzhiyun 			       const struct fw_img *image)
167*4882a593Smuzhiyun {
168*4882a593Smuzhiyun 	int sec_idx, idx, ret;
169*4882a593Smuzhiyun 	u32 offset = 0;
170*4882a593Smuzhiyun 
171*4882a593Smuzhiyun 	/*
172*4882a593Smuzhiyun 	 * find where is the paging image start point:
173*4882a593Smuzhiyun 	 * if CPU2 exist and it's in paging format, then the image looks like:
174*4882a593Smuzhiyun 	 * CPU1 sections (2 or more)
175*4882a593Smuzhiyun 	 * CPU1_CPU2_SEPARATOR_SECTION delimiter - separate between CPU1 to CPU2
176*4882a593Smuzhiyun 	 * CPU2 sections (not paged)
177*4882a593Smuzhiyun 	 * PAGING_SEPARATOR_SECTION delimiter - separate between CPU2
178*4882a593Smuzhiyun 	 * non paged to CPU2 paging sec
179*4882a593Smuzhiyun 	 * CPU2 paging CSS
180*4882a593Smuzhiyun 	 * CPU2 paging image (including instruction and data)
181*4882a593Smuzhiyun 	 */
182*4882a593Smuzhiyun 	for (sec_idx = 0; sec_idx < image->num_sec; sec_idx++) {
183*4882a593Smuzhiyun 		if (image->sec[sec_idx].offset == PAGING_SEPARATOR_SECTION) {
184*4882a593Smuzhiyun 			sec_idx++;
185*4882a593Smuzhiyun 			break;
186*4882a593Smuzhiyun 		}
187*4882a593Smuzhiyun 	}
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun 	/*
190*4882a593Smuzhiyun 	 * If paging is enabled there should be at least 2 more sections left
191*4882a593Smuzhiyun 	 * (one for CSS and one for Paging data)
192*4882a593Smuzhiyun 	 */
193*4882a593Smuzhiyun 	if (sec_idx >= image->num_sec - 1) {
194*4882a593Smuzhiyun 		IWL_ERR(fwrt, "Paging: Missing CSS and/or paging sections\n");
195*4882a593Smuzhiyun 		ret = -EINVAL;
196*4882a593Smuzhiyun 		goto err;
197*4882a593Smuzhiyun 	}
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun 	/* copy the CSS block to the dram */
200*4882a593Smuzhiyun 	IWL_DEBUG_FW(fwrt, "Paging: load paging CSS to FW, sec = %d\n",
201*4882a593Smuzhiyun 		     sec_idx);
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun 	if (image->sec[sec_idx].len > fwrt->fw_paging_db[0].fw_paging_size) {
204*4882a593Smuzhiyun 		IWL_ERR(fwrt, "CSS block is larger than paging size\n");
205*4882a593Smuzhiyun 		ret = -EINVAL;
206*4882a593Smuzhiyun 		goto err;
207*4882a593Smuzhiyun 	}
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun 	memcpy(page_address(fwrt->fw_paging_db[0].fw_paging_block),
210*4882a593Smuzhiyun 	       image->sec[sec_idx].data,
211*4882a593Smuzhiyun 	       image->sec[sec_idx].len);
212*4882a593Smuzhiyun 	dma_sync_single_for_device(fwrt->trans->dev,
213*4882a593Smuzhiyun 				   fwrt->fw_paging_db[0].fw_paging_phys,
214*4882a593Smuzhiyun 				   fwrt->fw_paging_db[0].fw_paging_size,
215*4882a593Smuzhiyun 				   DMA_BIDIRECTIONAL);
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun 	IWL_DEBUG_FW(fwrt,
218*4882a593Smuzhiyun 		     "Paging: copied %d CSS bytes to first block\n",
219*4882a593Smuzhiyun 		     fwrt->fw_paging_db[0].fw_paging_size);
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun 	sec_idx++;
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun 	/*
224*4882a593Smuzhiyun 	 * Copy the paging blocks to the dram.  The loop index starts
225*4882a593Smuzhiyun 	 * from 1 since the CSS block (index 0) was already copied to
226*4882a593Smuzhiyun 	 * dram.  We use num_of_paging_blk + 1 to account for that.
227*4882a593Smuzhiyun 	 */
228*4882a593Smuzhiyun 	for (idx = 1; idx < fwrt->num_of_paging_blk + 1; idx++) {
229*4882a593Smuzhiyun 		struct iwl_fw_paging *block = &fwrt->fw_paging_db[idx];
230*4882a593Smuzhiyun 		int remaining = image->sec[sec_idx].len - offset;
231*4882a593Smuzhiyun 		int len = block->fw_paging_size;
232*4882a593Smuzhiyun 
233*4882a593Smuzhiyun 		/*
234*4882a593Smuzhiyun 		 * For the last block, we copy all that is remaining,
235*4882a593Smuzhiyun 		 * for all other blocks, we copy fw_paging_size at a
236*4882a593Smuzhiyun 		 * time. */
237*4882a593Smuzhiyun 		if (idx == fwrt->num_of_paging_blk) {
238*4882a593Smuzhiyun 			len = remaining;
239*4882a593Smuzhiyun 			if (remaining !=
240*4882a593Smuzhiyun 			    fwrt->num_of_pages_in_last_blk * FW_PAGING_SIZE) {
241*4882a593Smuzhiyun 				IWL_ERR(fwrt,
242*4882a593Smuzhiyun 					"Paging: last block contains more data than expected %d\n",
243*4882a593Smuzhiyun 					remaining);
244*4882a593Smuzhiyun 				ret = -EINVAL;
245*4882a593Smuzhiyun 				goto err;
246*4882a593Smuzhiyun 			}
247*4882a593Smuzhiyun 		} else if (block->fw_paging_size > remaining) {
248*4882a593Smuzhiyun 			IWL_ERR(fwrt,
249*4882a593Smuzhiyun 				"Paging: not enough data in other in block %d (%d)\n",
250*4882a593Smuzhiyun 				idx, remaining);
251*4882a593Smuzhiyun 			ret = -EINVAL;
252*4882a593Smuzhiyun 			goto err;
253*4882a593Smuzhiyun 		}
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun 		memcpy(page_address(block->fw_paging_block),
256*4882a593Smuzhiyun 		       image->sec[sec_idx].data + offset, len);
257*4882a593Smuzhiyun 		dma_sync_single_for_device(fwrt->trans->dev,
258*4882a593Smuzhiyun 					   block->fw_paging_phys,
259*4882a593Smuzhiyun 					   block->fw_paging_size,
260*4882a593Smuzhiyun 					   DMA_BIDIRECTIONAL);
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun 		IWL_DEBUG_FW(fwrt,
263*4882a593Smuzhiyun 			     "Paging: copied %d paging bytes to block %d\n",
264*4882a593Smuzhiyun 			     len, idx);
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun 		offset += block->fw_paging_size;
267*4882a593Smuzhiyun 	}
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun 	return 0;
270*4882a593Smuzhiyun 
271*4882a593Smuzhiyun err:
272*4882a593Smuzhiyun 	iwl_free_fw_paging(fwrt);
273*4882a593Smuzhiyun 	return ret;
274*4882a593Smuzhiyun }
275*4882a593Smuzhiyun 
iwl_save_fw_paging(struct iwl_fw_runtime * fwrt,const struct fw_img * fw)276*4882a593Smuzhiyun static int iwl_save_fw_paging(struct iwl_fw_runtime *fwrt,
277*4882a593Smuzhiyun 			      const struct fw_img *fw)
278*4882a593Smuzhiyun {
279*4882a593Smuzhiyun 	int ret;
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun 	ret = iwl_alloc_fw_paging_mem(fwrt, fw);
282*4882a593Smuzhiyun 	if (ret)
283*4882a593Smuzhiyun 		return ret;
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun 	return iwl_fill_paging_mem(fwrt, fw);
286*4882a593Smuzhiyun }
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun /* send paging cmd to FW in case CPU2 has paging image */
iwl_send_paging_cmd(struct iwl_fw_runtime * fwrt,const struct fw_img * fw)289*4882a593Smuzhiyun static int iwl_send_paging_cmd(struct iwl_fw_runtime *fwrt,
290*4882a593Smuzhiyun 			       const struct fw_img *fw)
291*4882a593Smuzhiyun {
292*4882a593Smuzhiyun 	struct iwl_fw_paging_cmd paging_cmd = {
293*4882a593Smuzhiyun 		.flags = cpu_to_le32(PAGING_CMD_IS_SECURED |
294*4882a593Smuzhiyun 				     PAGING_CMD_IS_ENABLED |
295*4882a593Smuzhiyun 				     (fwrt->num_of_pages_in_last_blk <<
296*4882a593Smuzhiyun 				      PAGING_CMD_NUM_OF_PAGES_IN_LAST_GRP_POS)),
297*4882a593Smuzhiyun 		.block_size = cpu_to_le32(BLOCK_2_EXP_SIZE),
298*4882a593Smuzhiyun 		.block_num = cpu_to_le32(fwrt->num_of_paging_blk),
299*4882a593Smuzhiyun 	};
300*4882a593Smuzhiyun 	struct iwl_host_cmd hcmd = {
301*4882a593Smuzhiyun 		.id = iwl_cmd_id(FW_PAGING_BLOCK_CMD, IWL_ALWAYS_LONG_GROUP, 0),
302*4882a593Smuzhiyun 		.len = { sizeof(paging_cmd), },
303*4882a593Smuzhiyun 		.data = { &paging_cmd, },
304*4882a593Smuzhiyun 	};
305*4882a593Smuzhiyun 	int blk_idx;
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun 	/* loop for for all paging blocks + CSS block */
308*4882a593Smuzhiyun 	for (blk_idx = 0; blk_idx < fwrt->num_of_paging_blk + 1; blk_idx++) {
309*4882a593Smuzhiyun 		dma_addr_t addr = fwrt->fw_paging_db[blk_idx].fw_paging_phys;
310*4882a593Smuzhiyun 		__le32 phy_addr;
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun 		addr = addr >> PAGE_2_EXP_SIZE;
313*4882a593Smuzhiyun 		phy_addr = cpu_to_le32(addr);
314*4882a593Smuzhiyun 		paging_cmd.device_phy_addr[blk_idx] = phy_addr;
315*4882a593Smuzhiyun 	}
316*4882a593Smuzhiyun 
317*4882a593Smuzhiyun 	return iwl_trans_send_cmd(fwrt->trans, &hcmd);
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun 
iwl_init_paging(struct iwl_fw_runtime * fwrt,enum iwl_ucode_type type)320*4882a593Smuzhiyun int iwl_init_paging(struct iwl_fw_runtime *fwrt, enum iwl_ucode_type type)
321*4882a593Smuzhiyun {
322*4882a593Smuzhiyun 	const struct fw_img *fw = &fwrt->fw->img[type];
323*4882a593Smuzhiyun 	int ret;
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun 	if (fwrt->trans->trans_cfg->gen2)
326*4882a593Smuzhiyun 		return 0;
327*4882a593Smuzhiyun 
328*4882a593Smuzhiyun 	/*
329*4882a593Smuzhiyun 	 * Configure and operate fw paging mechanism.
330*4882a593Smuzhiyun 	 * The driver configures the paging flow only once.
331*4882a593Smuzhiyun 	 * The CPU2 paging image is included in the IWL_UCODE_INIT image.
332*4882a593Smuzhiyun 	 */
333*4882a593Smuzhiyun 	if (!fw->paging_mem_size)
334*4882a593Smuzhiyun 		return 0;
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun 	ret = iwl_save_fw_paging(fwrt, fw);
337*4882a593Smuzhiyun 	if (ret) {
338*4882a593Smuzhiyun 		IWL_ERR(fwrt, "failed to save the FW paging image\n");
339*4882a593Smuzhiyun 		return ret;
340*4882a593Smuzhiyun 	}
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun 	ret = iwl_send_paging_cmd(fwrt, fw);
343*4882a593Smuzhiyun 	if (ret) {
344*4882a593Smuzhiyun 		IWL_ERR(fwrt, "failed to send the paging cmd\n");
345*4882a593Smuzhiyun 		iwl_free_fw_paging(fwrt);
346*4882a593Smuzhiyun 		return ret;
347*4882a593Smuzhiyun 	}
348*4882a593Smuzhiyun 
349*4882a593Smuzhiyun 	return 0;
350*4882a593Smuzhiyun }
351*4882a593Smuzhiyun IWL_EXPORT_SYMBOL(iwl_init_paging);
352