xref: /freebsd/sys/contrib/dev/iwlwifi/fw/paging.c (revision d9836fb4b9380e2ed1c38455fb31a3832b452671)
1bfcc09ddSBjoern A. Zeeb // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2bfcc09ddSBjoern A. Zeeb /*
3bfcc09ddSBjoern A. Zeeb  * Copyright (C) 2012-2014, 2018-2019, 2021 Intel Corporation
4bfcc09ddSBjoern A. Zeeb  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5bfcc09ddSBjoern A. Zeeb  * Copyright (C) 2016-2017 Intel Deutschland GmbH
6bfcc09ddSBjoern A. Zeeb  */
7bfcc09ddSBjoern A. Zeeb #include "iwl-drv.h"
8bfcc09ddSBjoern A. Zeeb #include "runtime.h"
9bfcc09ddSBjoern A. Zeeb #include "fw/api/commands.h"
10bfcc09ddSBjoern A. Zeeb 
iwl_free_fw_paging(struct iwl_fw_runtime * fwrt)11bfcc09ddSBjoern A. Zeeb void iwl_free_fw_paging(struct iwl_fw_runtime *fwrt)
12bfcc09ddSBjoern A. Zeeb {
13bfcc09ddSBjoern A. Zeeb 	int i;
14bfcc09ddSBjoern A. Zeeb 
15bfcc09ddSBjoern A. Zeeb 	if (!fwrt->fw_paging_db[0].fw_paging_block)
16bfcc09ddSBjoern A. Zeeb 		return;
17bfcc09ddSBjoern A. Zeeb 
18bfcc09ddSBjoern A. Zeeb 	for (i = 0; i < NUM_OF_FW_PAGING_BLOCKS; i++) {
19bfcc09ddSBjoern A. Zeeb 		struct iwl_fw_paging *paging = &fwrt->fw_paging_db[i];
20bfcc09ddSBjoern A. Zeeb 
21bfcc09ddSBjoern A. Zeeb 		if (!paging->fw_paging_block) {
22bfcc09ddSBjoern A. Zeeb 			IWL_DEBUG_FW(fwrt,
23bfcc09ddSBjoern A. Zeeb 				     "Paging: block %d already freed, continue to next page\n",
24bfcc09ddSBjoern A. Zeeb 				     i);
25bfcc09ddSBjoern A. Zeeb 
26bfcc09ddSBjoern A. Zeeb 			continue;
27bfcc09ddSBjoern A. Zeeb 		}
28bfcc09ddSBjoern A. Zeeb 		dma_unmap_page(fwrt->trans->dev, paging->fw_paging_phys,
29bfcc09ddSBjoern A. Zeeb 			       paging->fw_paging_size, DMA_BIDIRECTIONAL);
30bfcc09ddSBjoern A. Zeeb 
31bfcc09ddSBjoern A. Zeeb 		__free_pages(paging->fw_paging_block,
32bfcc09ddSBjoern A. Zeeb 			     get_order(paging->fw_paging_size));
33bfcc09ddSBjoern A. Zeeb 		paging->fw_paging_block = NULL;
34bfcc09ddSBjoern A. Zeeb 	}
35bfcc09ddSBjoern A. Zeeb 
36bfcc09ddSBjoern A. Zeeb 	memset(fwrt->fw_paging_db, 0, sizeof(fwrt->fw_paging_db));
37bfcc09ddSBjoern A. Zeeb }
38bfcc09ddSBjoern A. Zeeb IWL_EXPORT_SYMBOL(iwl_free_fw_paging);
39bfcc09ddSBjoern A. Zeeb 
iwl_alloc_fw_paging_mem(struct iwl_fw_runtime * fwrt,const struct fw_img * image)40bfcc09ddSBjoern A. Zeeb static int iwl_alloc_fw_paging_mem(struct iwl_fw_runtime *fwrt,
41bfcc09ddSBjoern A. Zeeb 				   const struct fw_img *image)
42bfcc09ddSBjoern A. Zeeb {
43bfcc09ddSBjoern A. Zeeb 	struct page *block;
44bfcc09ddSBjoern A. Zeeb 	dma_addr_t phys = 0;
45bfcc09ddSBjoern A. Zeeb 	int blk_idx, order, num_of_pages, size;
46bfcc09ddSBjoern A. Zeeb 
47bfcc09ddSBjoern A. Zeeb 	if (fwrt->fw_paging_db[0].fw_paging_block)
48bfcc09ddSBjoern A. Zeeb 		return 0;
49bfcc09ddSBjoern A. Zeeb 
50bfcc09ddSBjoern A. Zeeb 	/* ensure BLOCK_2_EXP_SIZE is power of 2 of PAGING_BLOCK_SIZE */
51bfcc09ddSBjoern A. Zeeb 	BUILD_BUG_ON(BIT(BLOCK_2_EXP_SIZE) != PAGING_BLOCK_SIZE);
52bfcc09ddSBjoern A. Zeeb 
53bfcc09ddSBjoern A. Zeeb 	num_of_pages = image->paging_mem_size / FW_PAGING_SIZE;
54bfcc09ddSBjoern A. Zeeb 	fwrt->num_of_paging_blk =
55bfcc09ddSBjoern A. Zeeb 		DIV_ROUND_UP(num_of_pages, NUM_OF_PAGE_PER_GROUP);
56bfcc09ddSBjoern A. Zeeb 	fwrt->num_of_pages_in_last_blk =
57bfcc09ddSBjoern A. Zeeb 		num_of_pages -
58bfcc09ddSBjoern A. Zeeb 		NUM_OF_PAGE_PER_GROUP * (fwrt->num_of_paging_blk - 1);
59bfcc09ddSBjoern A. Zeeb 
60bfcc09ddSBjoern A. Zeeb 	IWL_DEBUG_FW(fwrt,
61bfcc09ddSBjoern A. Zeeb 		     "Paging: allocating mem for %d paging blocks, each block holds 8 pages, last block holds %d pages\n",
62bfcc09ddSBjoern A. Zeeb 		     fwrt->num_of_paging_blk,
63bfcc09ddSBjoern A. Zeeb 		     fwrt->num_of_pages_in_last_blk);
64bfcc09ddSBjoern A. Zeeb 
65bfcc09ddSBjoern A. Zeeb 	/*
66bfcc09ddSBjoern A. Zeeb 	 * Allocate CSS and paging blocks in dram.
67bfcc09ddSBjoern A. Zeeb 	 */
68bfcc09ddSBjoern A. Zeeb 	for (blk_idx = 0; blk_idx < fwrt->num_of_paging_blk + 1; blk_idx++) {
69bfcc09ddSBjoern A. Zeeb 		/* For CSS allocate 4KB, for others PAGING_BLOCK_SIZE (32K) */
70bfcc09ddSBjoern A. Zeeb 		size = blk_idx ? PAGING_BLOCK_SIZE : FW_PAGING_SIZE;
71bfcc09ddSBjoern A. Zeeb 		order = get_order(size);
72bfcc09ddSBjoern A. Zeeb 		block = alloc_pages(GFP_KERNEL, order);
73bfcc09ddSBjoern A. Zeeb 		if (!block) {
74bfcc09ddSBjoern A. Zeeb 			/* free all the previous pages since we failed */
75bfcc09ddSBjoern A. Zeeb 			iwl_free_fw_paging(fwrt);
76bfcc09ddSBjoern A. Zeeb 			return -ENOMEM;
77bfcc09ddSBjoern A. Zeeb 		}
78bfcc09ddSBjoern A. Zeeb 
79bfcc09ddSBjoern A. Zeeb 		fwrt->fw_paging_db[blk_idx].fw_paging_block = block;
80bfcc09ddSBjoern A. Zeeb 		fwrt->fw_paging_db[blk_idx].fw_paging_size = size;
81bfcc09ddSBjoern A. Zeeb 
82bfcc09ddSBjoern A. Zeeb 		phys = dma_map_page(fwrt->trans->dev, block, 0,
83bfcc09ddSBjoern A. Zeeb 				    PAGE_SIZE << order,
84bfcc09ddSBjoern A. Zeeb 				    DMA_BIDIRECTIONAL);
85bfcc09ddSBjoern A. Zeeb 		if (dma_mapping_error(fwrt->trans->dev, phys)) {
86bfcc09ddSBjoern A. Zeeb 			/*
87bfcc09ddSBjoern A. Zeeb 			 * free the previous pages and the current one
88bfcc09ddSBjoern A. Zeeb 			 * since we failed to map_page.
89bfcc09ddSBjoern A. Zeeb 			 */
90bfcc09ddSBjoern A. Zeeb 			iwl_free_fw_paging(fwrt);
91bfcc09ddSBjoern A. Zeeb 			return -ENOMEM;
92bfcc09ddSBjoern A. Zeeb 		}
93bfcc09ddSBjoern A. Zeeb 		fwrt->fw_paging_db[blk_idx].fw_paging_phys = phys;
94bfcc09ddSBjoern A. Zeeb 
95bfcc09ddSBjoern A. Zeeb 		if (!blk_idx)
96bfcc09ddSBjoern A. Zeeb 			IWL_DEBUG_FW(fwrt,
97bfcc09ddSBjoern A. Zeeb 				     "Paging: allocated 4K(CSS) bytes (order %d) for firmware paging.\n",
98bfcc09ddSBjoern A. Zeeb 				     order);
99bfcc09ddSBjoern A. Zeeb 		else
100bfcc09ddSBjoern A. Zeeb 			IWL_DEBUG_FW(fwrt,
101bfcc09ddSBjoern A. Zeeb 				     "Paging: allocated 32K bytes (order %d) for firmware paging.\n",
102bfcc09ddSBjoern A. Zeeb 				     order);
103bfcc09ddSBjoern A. Zeeb 	}
104bfcc09ddSBjoern A. Zeeb 
105bfcc09ddSBjoern A. Zeeb 	return 0;
106bfcc09ddSBjoern A. Zeeb }
107bfcc09ddSBjoern A. Zeeb 
iwl_fill_paging_mem(struct iwl_fw_runtime * fwrt,const struct fw_img * image)108bfcc09ddSBjoern A. Zeeb static int iwl_fill_paging_mem(struct iwl_fw_runtime *fwrt,
109bfcc09ddSBjoern A. Zeeb 			       const struct fw_img *image)
110bfcc09ddSBjoern A. Zeeb {
111bfcc09ddSBjoern A. Zeeb 	int sec_idx, idx, ret;
112bfcc09ddSBjoern A. Zeeb 	u32 offset = 0;
113bfcc09ddSBjoern A. Zeeb 
114bfcc09ddSBjoern A. Zeeb 	/*
115bfcc09ddSBjoern A. Zeeb 	 * find where is the paging image start point:
116bfcc09ddSBjoern A. Zeeb 	 * if CPU2 exist and it's in paging format, then the image looks like:
117bfcc09ddSBjoern A. Zeeb 	 * CPU1 sections (2 or more)
118bfcc09ddSBjoern A. Zeeb 	 * CPU1_CPU2_SEPARATOR_SECTION delimiter - separate between CPU1 to CPU2
119bfcc09ddSBjoern A. Zeeb 	 * CPU2 sections (not paged)
120bfcc09ddSBjoern A. Zeeb 	 * PAGING_SEPARATOR_SECTION delimiter - separate between CPU2
121bfcc09ddSBjoern A. Zeeb 	 * non paged to CPU2 paging sec
122bfcc09ddSBjoern A. Zeeb 	 * CPU2 paging CSS
123bfcc09ddSBjoern A. Zeeb 	 * CPU2 paging image (including instruction and data)
124bfcc09ddSBjoern A. Zeeb 	 */
125bfcc09ddSBjoern A. Zeeb 	for (sec_idx = 0; sec_idx < image->num_sec; sec_idx++) {
126bfcc09ddSBjoern A. Zeeb 		if (image->sec[sec_idx].offset == PAGING_SEPARATOR_SECTION) {
127bfcc09ddSBjoern A. Zeeb 			sec_idx++;
128bfcc09ddSBjoern A. Zeeb 			break;
129bfcc09ddSBjoern A. Zeeb 		}
130bfcc09ddSBjoern A. Zeeb 	}
131bfcc09ddSBjoern A. Zeeb 
132bfcc09ddSBjoern A. Zeeb 	/*
133bfcc09ddSBjoern A. Zeeb 	 * If paging is enabled there should be at least 2 more sections left
134bfcc09ddSBjoern A. Zeeb 	 * (one for CSS and one for Paging data)
135bfcc09ddSBjoern A. Zeeb 	 */
136bfcc09ddSBjoern A. Zeeb 	if (sec_idx >= image->num_sec - 1) {
137bfcc09ddSBjoern A. Zeeb 		IWL_ERR(fwrt, "Paging: Missing CSS and/or paging sections\n");
138bfcc09ddSBjoern A. Zeeb 		ret = -EINVAL;
139bfcc09ddSBjoern A. Zeeb 		goto err;
140bfcc09ddSBjoern A. Zeeb 	}
141bfcc09ddSBjoern A. Zeeb 
142bfcc09ddSBjoern A. Zeeb 	/* copy the CSS block to the dram */
143bfcc09ddSBjoern A. Zeeb 	IWL_DEBUG_FW(fwrt, "Paging: load paging CSS to FW, sec = %d\n",
144bfcc09ddSBjoern A. Zeeb 		     sec_idx);
145bfcc09ddSBjoern A. Zeeb 
146bfcc09ddSBjoern A. Zeeb 	if (image->sec[sec_idx].len > fwrt->fw_paging_db[0].fw_paging_size) {
147bfcc09ddSBjoern A. Zeeb 		IWL_ERR(fwrt, "CSS block is larger than paging size\n");
148bfcc09ddSBjoern A. Zeeb 		ret = -EINVAL;
149bfcc09ddSBjoern A. Zeeb 		goto err;
150bfcc09ddSBjoern A. Zeeb 	}
151bfcc09ddSBjoern A. Zeeb 
152bfcc09ddSBjoern A. Zeeb 	memcpy(page_address(fwrt->fw_paging_db[0].fw_paging_block),
153bfcc09ddSBjoern A. Zeeb 	       image->sec[sec_idx].data,
154bfcc09ddSBjoern A. Zeeb 	       image->sec[sec_idx].len);
155bfcc09ddSBjoern A. Zeeb 	fwrt->fw_paging_db[0].fw_offs = image->sec[sec_idx].offset;
156bfcc09ddSBjoern A. Zeeb 	dma_sync_single_for_device(fwrt->trans->dev,
157bfcc09ddSBjoern A. Zeeb 				   fwrt->fw_paging_db[0].fw_paging_phys,
158bfcc09ddSBjoern A. Zeeb 				   fwrt->fw_paging_db[0].fw_paging_size,
159bfcc09ddSBjoern A. Zeeb 				   DMA_BIDIRECTIONAL);
160bfcc09ddSBjoern A. Zeeb 
161bfcc09ddSBjoern A. Zeeb 	IWL_DEBUG_FW(fwrt,
162bfcc09ddSBjoern A. Zeeb 		     "Paging: copied %d CSS bytes to first block\n",
163bfcc09ddSBjoern A. Zeeb 		     fwrt->fw_paging_db[0].fw_paging_size);
164bfcc09ddSBjoern A. Zeeb 
165bfcc09ddSBjoern A. Zeeb 	sec_idx++;
166bfcc09ddSBjoern A. Zeeb 
167bfcc09ddSBjoern A. Zeeb 	/*
168bfcc09ddSBjoern A. Zeeb 	 * Copy the paging blocks to the dram.  The loop index starts
169bfcc09ddSBjoern A. Zeeb 	 * from 1 since the CSS block (index 0) was already copied to
170bfcc09ddSBjoern A. Zeeb 	 * dram.  We use num_of_paging_blk + 1 to account for that.
171bfcc09ddSBjoern A. Zeeb 	 */
172bfcc09ddSBjoern A. Zeeb 	for (idx = 1; idx < fwrt->num_of_paging_blk + 1; idx++) {
173bfcc09ddSBjoern A. Zeeb 		struct iwl_fw_paging *block = &fwrt->fw_paging_db[idx];
174bfcc09ddSBjoern A. Zeeb 		int remaining = image->sec[sec_idx].len - offset;
175bfcc09ddSBjoern A. Zeeb 		int len = block->fw_paging_size;
176bfcc09ddSBjoern A. Zeeb 
177bfcc09ddSBjoern A. Zeeb 		/*
178bfcc09ddSBjoern A. Zeeb 		 * For the last block, we copy all that is remaining,
179bfcc09ddSBjoern A. Zeeb 		 * for all other blocks, we copy fw_paging_size at a
180bfcc09ddSBjoern A. Zeeb 		 * time. */
181bfcc09ddSBjoern A. Zeeb 		if (idx == fwrt->num_of_paging_blk) {
182bfcc09ddSBjoern A. Zeeb 			len = remaining;
183bfcc09ddSBjoern A. Zeeb 			if (remaining !=
184bfcc09ddSBjoern A. Zeeb 			    fwrt->num_of_pages_in_last_blk * FW_PAGING_SIZE) {
185bfcc09ddSBjoern A. Zeeb 				IWL_ERR(fwrt,
186bfcc09ddSBjoern A. Zeeb 					"Paging: last block contains more data than expected %d\n",
187bfcc09ddSBjoern A. Zeeb 					remaining);
188bfcc09ddSBjoern A. Zeeb 				ret = -EINVAL;
189bfcc09ddSBjoern A. Zeeb 				goto err;
190bfcc09ddSBjoern A. Zeeb 			}
191bfcc09ddSBjoern A. Zeeb 		} else if (block->fw_paging_size > remaining) {
192bfcc09ddSBjoern A. Zeeb 			IWL_ERR(fwrt,
193bfcc09ddSBjoern A. Zeeb 				"Paging: not enough data in other in block %d (%d)\n",
194bfcc09ddSBjoern A. Zeeb 				idx, remaining);
195bfcc09ddSBjoern A. Zeeb 			ret = -EINVAL;
196bfcc09ddSBjoern A. Zeeb 			goto err;
197bfcc09ddSBjoern A. Zeeb 		}
198bfcc09ddSBjoern A. Zeeb 
199bfcc09ddSBjoern A. Zeeb 		memcpy(page_address(block->fw_paging_block),
200bfcc09ddSBjoern A. Zeeb 		       (const u8 *)image->sec[sec_idx].data + offset, len);
201bfcc09ddSBjoern A. Zeeb 		block->fw_offs = image->sec[sec_idx].offset + offset;
202bfcc09ddSBjoern A. Zeeb 		dma_sync_single_for_device(fwrt->trans->dev,
203bfcc09ddSBjoern A. Zeeb 					   block->fw_paging_phys,
204bfcc09ddSBjoern A. Zeeb 					   block->fw_paging_size,
205bfcc09ddSBjoern A. Zeeb 					   DMA_BIDIRECTIONAL);
206bfcc09ddSBjoern A. Zeeb 
207bfcc09ddSBjoern A. Zeeb 		IWL_DEBUG_FW(fwrt,
208bfcc09ddSBjoern A. Zeeb 			     "Paging: copied %d paging bytes to block %d\n",
209bfcc09ddSBjoern A. Zeeb 			     len, idx);
210bfcc09ddSBjoern A. Zeeb 
211bfcc09ddSBjoern A. Zeeb 		offset += block->fw_paging_size;
212bfcc09ddSBjoern A. Zeeb 	}
213bfcc09ddSBjoern A. Zeeb 
214bfcc09ddSBjoern A. Zeeb 	return 0;
215bfcc09ddSBjoern A. Zeeb 
216bfcc09ddSBjoern A. Zeeb err:
217bfcc09ddSBjoern A. Zeeb 	iwl_free_fw_paging(fwrt);
218bfcc09ddSBjoern A. Zeeb 	return ret;
219bfcc09ddSBjoern A. Zeeb }
220bfcc09ddSBjoern A. Zeeb 
iwl_save_fw_paging(struct iwl_fw_runtime * fwrt,const struct fw_img * fw)221bfcc09ddSBjoern A. Zeeb static int iwl_save_fw_paging(struct iwl_fw_runtime *fwrt,
222bfcc09ddSBjoern A. Zeeb 			      const struct fw_img *fw)
223bfcc09ddSBjoern A. Zeeb {
224bfcc09ddSBjoern A. Zeeb 	int ret;
225bfcc09ddSBjoern A. Zeeb 
226bfcc09ddSBjoern A. Zeeb 	ret = iwl_alloc_fw_paging_mem(fwrt, fw);
227bfcc09ddSBjoern A. Zeeb 	if (ret)
228bfcc09ddSBjoern A. Zeeb 		return ret;
229bfcc09ddSBjoern A. Zeeb 
230bfcc09ddSBjoern A. Zeeb 	return iwl_fill_paging_mem(fwrt, fw);
231bfcc09ddSBjoern A. Zeeb }
232bfcc09ddSBjoern A. Zeeb 
233bfcc09ddSBjoern A. Zeeb /* 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)234bfcc09ddSBjoern A. Zeeb static int iwl_send_paging_cmd(struct iwl_fw_runtime *fwrt,
235bfcc09ddSBjoern A. Zeeb 			       const struct fw_img *fw)
236bfcc09ddSBjoern A. Zeeb {
237bfcc09ddSBjoern A. Zeeb 	struct iwl_fw_paging_cmd paging_cmd = {
238bfcc09ddSBjoern A. Zeeb 		.flags = cpu_to_le32(PAGING_CMD_IS_SECURED |
239bfcc09ddSBjoern A. Zeeb 				     PAGING_CMD_IS_ENABLED |
240bfcc09ddSBjoern A. Zeeb 				     (fwrt->num_of_pages_in_last_blk <<
241bfcc09ddSBjoern A. Zeeb 				      PAGING_CMD_NUM_OF_PAGES_IN_LAST_GRP_POS)),
242bfcc09ddSBjoern A. Zeeb 		.block_size = cpu_to_le32(BLOCK_2_EXP_SIZE),
243bfcc09ddSBjoern A. Zeeb 		.block_num = cpu_to_le32(fwrt->num_of_paging_blk),
244bfcc09ddSBjoern A. Zeeb 	};
245bfcc09ddSBjoern A. Zeeb 	struct iwl_host_cmd hcmd = {
246*d9836fb4SBjoern A. Zeeb 		.id = WIDE_ID(IWL_ALWAYS_LONG_GROUP, FW_PAGING_BLOCK_CMD),
247bfcc09ddSBjoern A. Zeeb 		.len = { sizeof(paging_cmd), },
248bfcc09ddSBjoern A. Zeeb 		.data = { &paging_cmd, },
249bfcc09ddSBjoern A. Zeeb 	};
250bfcc09ddSBjoern A. Zeeb 	int blk_idx;
251bfcc09ddSBjoern A. Zeeb 
252bfcc09ddSBjoern A. Zeeb 	/* loop for for all paging blocks + CSS block */
253bfcc09ddSBjoern A. Zeeb 	for (blk_idx = 0; blk_idx < fwrt->num_of_paging_blk + 1; blk_idx++) {
254bfcc09ddSBjoern A. Zeeb 		dma_addr_t addr = fwrt->fw_paging_db[blk_idx].fw_paging_phys;
255bfcc09ddSBjoern A. Zeeb 		__le32 phy_addr;
256bfcc09ddSBjoern A. Zeeb 
257bfcc09ddSBjoern A. Zeeb 		addr = addr >> PAGE_2_EXP_SIZE;
258bfcc09ddSBjoern A. Zeeb 		phy_addr = cpu_to_le32(addr);
259bfcc09ddSBjoern A. Zeeb 		paging_cmd.device_phy_addr[blk_idx] = phy_addr;
260bfcc09ddSBjoern A. Zeeb 	}
261bfcc09ddSBjoern A. Zeeb 
262bfcc09ddSBjoern A. Zeeb 	return iwl_trans_send_cmd(fwrt->trans, &hcmd);
263bfcc09ddSBjoern A. Zeeb }
264bfcc09ddSBjoern A. Zeeb 
iwl_init_paging(struct iwl_fw_runtime * fwrt,enum iwl_ucode_type type)265bfcc09ddSBjoern A. Zeeb int iwl_init_paging(struct iwl_fw_runtime *fwrt, enum iwl_ucode_type type)
266bfcc09ddSBjoern A. Zeeb {
267bfcc09ddSBjoern A. Zeeb 	const struct fw_img *fw = &fwrt->fw->img[type];
268bfcc09ddSBjoern A. Zeeb 	int ret;
269bfcc09ddSBjoern A. Zeeb 
270bfcc09ddSBjoern A. Zeeb 	if (fwrt->trans->trans_cfg->gen2)
271bfcc09ddSBjoern A. Zeeb 		return 0;
272bfcc09ddSBjoern A. Zeeb 
273bfcc09ddSBjoern A. Zeeb 	/*
274bfcc09ddSBjoern A. Zeeb 	 * Configure and operate fw paging mechanism.
275bfcc09ddSBjoern A. Zeeb 	 * The driver configures the paging flow only once.
276bfcc09ddSBjoern A. Zeeb 	 * The CPU2 paging image is included in the IWL_UCODE_INIT image.
277bfcc09ddSBjoern A. Zeeb 	 */
278bfcc09ddSBjoern A. Zeeb 	if (!fw->paging_mem_size)
279bfcc09ddSBjoern A. Zeeb 		return 0;
280bfcc09ddSBjoern A. Zeeb 
281bfcc09ddSBjoern A. Zeeb 	ret = iwl_save_fw_paging(fwrt, fw);
282bfcc09ddSBjoern A. Zeeb 	if (ret) {
283bfcc09ddSBjoern A. Zeeb 		IWL_ERR(fwrt, "failed to save the FW paging image\n");
284bfcc09ddSBjoern A. Zeeb 		return ret;
285bfcc09ddSBjoern A. Zeeb 	}
286bfcc09ddSBjoern A. Zeeb 
287bfcc09ddSBjoern A. Zeeb 	ret = iwl_send_paging_cmd(fwrt, fw);
288bfcc09ddSBjoern A. Zeeb 	if (ret) {
289bfcc09ddSBjoern A. Zeeb 		IWL_ERR(fwrt, "failed to send the paging cmd\n");
290bfcc09ddSBjoern A. Zeeb 		iwl_free_fw_paging(fwrt);
291bfcc09ddSBjoern A. Zeeb 		return ret;
292bfcc09ddSBjoern A. Zeeb 	}
293bfcc09ddSBjoern A. Zeeb 
294bfcc09ddSBjoern A. Zeeb 	return 0;
295bfcc09ddSBjoern A. Zeeb }
296bfcc09ddSBjoern A. Zeeb IWL_EXPORT_SYMBOL(iwl_init_paging);
297