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) 2018 - 2021 Intel Corporation
9*4882a593Smuzhiyun *
10*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify
11*4882a593Smuzhiyun * it under the terms of version 2 of the GNU General Public License as
12*4882a593Smuzhiyun * published by the Free Software Foundation.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, but
15*4882a593Smuzhiyun * WITHOUT ANY WARRANTY; without even the implied warranty of
16*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17*4882a593Smuzhiyun * General Public License for more details.
18*4882a593Smuzhiyun *
19*4882a593Smuzhiyun * BSD LICENSE
20*4882a593Smuzhiyun *
21*4882a593Smuzhiyun * Copyright(c) 2018 - 2020 Intel Corporation
22*4882a593Smuzhiyun * All rights reserved.
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
25*4882a593Smuzhiyun * modification, are permitted provided that the following conditions
26*4882a593Smuzhiyun * are met:
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun * * Redistributions of source code must retain the above copyright
29*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
30*4882a593Smuzhiyun * * Redistributions in binary form must reproduce the above copyright
31*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in
32*4882a593Smuzhiyun * the documentation and/or other materials provided with the
33*4882a593Smuzhiyun * distribution.
34*4882a593Smuzhiyun * * Neither the name Intel Corporation nor the names of its
35*4882a593Smuzhiyun * contributors may be used to endorse or promote products derived
36*4882a593Smuzhiyun * from this software without specific prior written permission.
37*4882a593Smuzhiyun *
38*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39*4882a593Smuzhiyun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40*4882a593Smuzhiyun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
41*4882a593Smuzhiyun * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
42*4882a593Smuzhiyun * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43*4882a593Smuzhiyun * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
44*4882a593Smuzhiyun * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45*4882a593Smuzhiyun * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46*4882a593Smuzhiyun * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
48*4882a593Smuzhiyun * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49*4882a593Smuzhiyun *
50*4882a593Smuzhiyun *****************************************************************************/
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun #include "iwl-trans.h"
53*4882a593Smuzhiyun #include "iwl-fh.h"
54*4882a593Smuzhiyun #include "iwl-context-info-gen3.h"
55*4882a593Smuzhiyun #include "internal.h"
56*4882a593Smuzhiyun #include "iwl-prph.h"
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun static void
iwl_pcie_ctxt_info_dbg_enable(struct iwl_trans * trans,struct iwl_prph_scratch_hwm_cfg * dbg_cfg,u32 * control_flags)59*4882a593Smuzhiyun iwl_pcie_ctxt_info_dbg_enable(struct iwl_trans *trans,
60*4882a593Smuzhiyun struct iwl_prph_scratch_hwm_cfg *dbg_cfg,
61*4882a593Smuzhiyun u32 *control_flags)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun enum iwl_fw_ini_allocation_id alloc_id = IWL_FW_INI_ALLOCATION_ID_DBGC1;
64*4882a593Smuzhiyun struct iwl_fw_ini_allocation_tlv *fw_mon_cfg;
65*4882a593Smuzhiyun u32 dbg_flags = 0;
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun if (!iwl_trans_dbg_ini_valid(trans)) {
68*4882a593Smuzhiyun struct iwl_dram_data *fw_mon = &trans->dbg.fw_mon;
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun iwl_pcie_alloc_fw_monitor(trans, 0);
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun if (fw_mon->size) {
73*4882a593Smuzhiyun dbg_flags |= IWL_PRPH_SCRATCH_EDBG_DEST_DRAM;
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun IWL_DEBUG_FW(trans,
76*4882a593Smuzhiyun "WRT: Applying DRAM buffer destination\n");
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun dbg_cfg->hwm_base_addr = cpu_to_le64(fw_mon->physical);
79*4882a593Smuzhiyun dbg_cfg->hwm_size = cpu_to_le32(fw_mon->size);
80*4882a593Smuzhiyun }
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun goto out;
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun fw_mon_cfg = &trans->dbg.fw_mon_cfg[alloc_id];
86*4882a593Smuzhiyun
87*4882a593Smuzhiyun switch (le32_to_cpu(fw_mon_cfg->buf_location)) {
88*4882a593Smuzhiyun case IWL_FW_INI_LOCATION_SRAM_PATH:
89*4882a593Smuzhiyun dbg_flags |= IWL_PRPH_SCRATCH_EDBG_DEST_INTERNAL;
90*4882a593Smuzhiyun IWL_DEBUG_FW(trans,
91*4882a593Smuzhiyun "WRT: Applying SMEM buffer destination\n");
92*4882a593Smuzhiyun break;
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun case IWL_FW_INI_LOCATION_NPK_PATH:
95*4882a593Smuzhiyun dbg_flags |= IWL_PRPH_SCRATCH_EDBG_DEST_TB22DTF;
96*4882a593Smuzhiyun IWL_DEBUG_FW(trans,
97*4882a593Smuzhiyun "WRT: Applying NPK buffer destination\n");
98*4882a593Smuzhiyun break;
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun case IWL_FW_INI_LOCATION_DRAM_PATH:
101*4882a593Smuzhiyun if (trans->dbg.fw_mon_ini[alloc_id].num_frags) {
102*4882a593Smuzhiyun struct iwl_dram_data *frag =
103*4882a593Smuzhiyun &trans->dbg.fw_mon_ini[alloc_id].frags[0];
104*4882a593Smuzhiyun dbg_flags |= IWL_PRPH_SCRATCH_EDBG_DEST_DRAM;
105*4882a593Smuzhiyun dbg_cfg->hwm_base_addr = cpu_to_le64(frag->physical);
106*4882a593Smuzhiyun dbg_cfg->hwm_size = cpu_to_le32(frag->size);
107*4882a593Smuzhiyun IWL_DEBUG_FW(trans,
108*4882a593Smuzhiyun "WRT: Applying DRAM destination (alloc_id=%u, num_frags=%u)\n",
109*4882a593Smuzhiyun alloc_id,
110*4882a593Smuzhiyun trans->dbg.fw_mon_ini[alloc_id].num_frags);
111*4882a593Smuzhiyun }
112*4882a593Smuzhiyun break;
113*4882a593Smuzhiyun default:
114*4882a593Smuzhiyun IWL_ERR(trans, "WRT: Invalid buffer destination\n");
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun out:
117*4882a593Smuzhiyun if (dbg_flags)
118*4882a593Smuzhiyun *control_flags |= IWL_PRPH_SCRATCH_EARLY_DEBUG_EN | dbg_flags;
119*4882a593Smuzhiyun }
120*4882a593Smuzhiyun
iwl_pcie_ctxt_info_gen3_init(struct iwl_trans * trans,const struct fw_img * fw)121*4882a593Smuzhiyun int iwl_pcie_ctxt_info_gen3_init(struct iwl_trans *trans,
122*4882a593Smuzhiyun const struct fw_img *fw)
123*4882a593Smuzhiyun {
124*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
125*4882a593Smuzhiyun struct iwl_context_info_gen3 *ctxt_info_gen3;
126*4882a593Smuzhiyun struct iwl_prph_scratch *prph_scratch;
127*4882a593Smuzhiyun struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl;
128*4882a593Smuzhiyun struct iwl_prph_info *prph_info;
129*4882a593Smuzhiyun u32 control_flags = 0;
130*4882a593Smuzhiyun int ret;
131*4882a593Smuzhiyun int cmdq_size = max_t(u32, IWL_CMD_QUEUE_SIZE,
132*4882a593Smuzhiyun trans->cfg->min_txq_size);
133*4882a593Smuzhiyun
134*4882a593Smuzhiyun switch (trans_pcie->rx_buf_size) {
135*4882a593Smuzhiyun case IWL_AMSDU_DEF:
136*4882a593Smuzhiyun return -EINVAL;
137*4882a593Smuzhiyun case IWL_AMSDU_2K:
138*4882a593Smuzhiyun break;
139*4882a593Smuzhiyun case IWL_AMSDU_4K:
140*4882a593Smuzhiyun control_flags |= IWL_PRPH_SCRATCH_RB_SIZE_4K;
141*4882a593Smuzhiyun break;
142*4882a593Smuzhiyun case IWL_AMSDU_8K:
143*4882a593Smuzhiyun control_flags |= IWL_PRPH_SCRATCH_RB_SIZE_4K;
144*4882a593Smuzhiyun /* if firmware supports the ext size, tell it */
145*4882a593Smuzhiyun control_flags |= IWL_PRPH_SCRATCH_RB_SIZE_EXT_8K;
146*4882a593Smuzhiyun break;
147*4882a593Smuzhiyun case IWL_AMSDU_12K:
148*4882a593Smuzhiyun control_flags |= IWL_PRPH_SCRATCH_RB_SIZE_4K;
149*4882a593Smuzhiyun /* if firmware supports the ext size, tell it */
150*4882a593Smuzhiyun control_flags |= IWL_PRPH_SCRATCH_RB_SIZE_EXT_12K;
151*4882a593Smuzhiyun break;
152*4882a593Smuzhiyun }
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun /* Allocate prph scratch */
155*4882a593Smuzhiyun prph_scratch = dma_alloc_coherent(trans->dev, sizeof(*prph_scratch),
156*4882a593Smuzhiyun &trans_pcie->prph_scratch_dma_addr,
157*4882a593Smuzhiyun GFP_KERNEL);
158*4882a593Smuzhiyun if (!prph_scratch)
159*4882a593Smuzhiyun return -ENOMEM;
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun prph_sc_ctrl = &prph_scratch->ctrl_cfg;
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun prph_sc_ctrl->version.version = 0;
164*4882a593Smuzhiyun prph_sc_ctrl->version.mac_id =
165*4882a593Smuzhiyun cpu_to_le16((u16)iwl_read32(trans, CSR_HW_REV));
166*4882a593Smuzhiyun prph_sc_ctrl->version.size = cpu_to_le16(sizeof(*prph_scratch) / 4);
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun control_flags |= IWL_PRPH_SCRATCH_MTR_MODE;
169*4882a593Smuzhiyun control_flags |= IWL_PRPH_MTR_FORMAT_256B & IWL_PRPH_SCRATCH_MTR_FORMAT;
170*4882a593Smuzhiyun
171*4882a593Smuzhiyun /* initialize RX default queue */
172*4882a593Smuzhiyun prph_sc_ctrl->rbd_cfg.free_rbd_addr =
173*4882a593Smuzhiyun cpu_to_le64(trans_pcie->rxq->bd_dma);
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun iwl_pcie_ctxt_info_dbg_enable(trans, &prph_sc_ctrl->hwm_cfg,
176*4882a593Smuzhiyun &control_flags);
177*4882a593Smuzhiyun prph_sc_ctrl->control.control_flags = cpu_to_le32(control_flags);
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun /* allocate ucode sections in dram and set addresses */
180*4882a593Smuzhiyun ret = iwl_pcie_init_fw_sec(trans, fw, &prph_scratch->dram);
181*4882a593Smuzhiyun if (ret)
182*4882a593Smuzhiyun goto err_free_prph_scratch;
183*4882a593Smuzhiyun
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun /* Allocate prph information
186*4882a593Smuzhiyun * currently we don't assign to the prph info anything, but it would get
187*4882a593Smuzhiyun * assigned later */
188*4882a593Smuzhiyun prph_info = dma_alloc_coherent(trans->dev, sizeof(*prph_info),
189*4882a593Smuzhiyun &trans_pcie->prph_info_dma_addr,
190*4882a593Smuzhiyun GFP_KERNEL);
191*4882a593Smuzhiyun if (!prph_info) {
192*4882a593Smuzhiyun ret = -ENOMEM;
193*4882a593Smuzhiyun goto err_free_prph_scratch;
194*4882a593Smuzhiyun }
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun /* Allocate context info */
197*4882a593Smuzhiyun ctxt_info_gen3 = dma_alloc_coherent(trans->dev,
198*4882a593Smuzhiyun sizeof(*ctxt_info_gen3),
199*4882a593Smuzhiyun &trans_pcie->ctxt_info_dma_addr,
200*4882a593Smuzhiyun GFP_KERNEL);
201*4882a593Smuzhiyun if (!ctxt_info_gen3) {
202*4882a593Smuzhiyun ret = -ENOMEM;
203*4882a593Smuzhiyun goto err_free_prph_info;
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun
206*4882a593Smuzhiyun ctxt_info_gen3->prph_info_base_addr =
207*4882a593Smuzhiyun cpu_to_le64(trans_pcie->prph_info_dma_addr);
208*4882a593Smuzhiyun ctxt_info_gen3->prph_scratch_base_addr =
209*4882a593Smuzhiyun cpu_to_le64(trans_pcie->prph_scratch_dma_addr);
210*4882a593Smuzhiyun ctxt_info_gen3->prph_scratch_size =
211*4882a593Smuzhiyun cpu_to_le32(sizeof(*prph_scratch));
212*4882a593Smuzhiyun ctxt_info_gen3->cr_head_idx_arr_base_addr =
213*4882a593Smuzhiyun cpu_to_le64(trans_pcie->rxq->rb_stts_dma);
214*4882a593Smuzhiyun ctxt_info_gen3->tr_tail_idx_arr_base_addr =
215*4882a593Smuzhiyun cpu_to_le64(trans_pcie->rxq->tr_tail_dma);
216*4882a593Smuzhiyun ctxt_info_gen3->cr_tail_idx_arr_base_addr =
217*4882a593Smuzhiyun cpu_to_le64(trans_pcie->rxq->cr_tail_dma);
218*4882a593Smuzhiyun ctxt_info_gen3->cr_idx_arr_size =
219*4882a593Smuzhiyun cpu_to_le16(IWL_NUM_OF_COMPLETION_RINGS);
220*4882a593Smuzhiyun ctxt_info_gen3->tr_idx_arr_size =
221*4882a593Smuzhiyun cpu_to_le16(IWL_NUM_OF_TRANSFER_RINGS);
222*4882a593Smuzhiyun ctxt_info_gen3->mtr_base_addr =
223*4882a593Smuzhiyun cpu_to_le64(trans->txqs.txq[trans->txqs.cmd.q_id]->dma_addr);
224*4882a593Smuzhiyun ctxt_info_gen3->mcr_base_addr =
225*4882a593Smuzhiyun cpu_to_le64(trans_pcie->rxq->used_bd_dma);
226*4882a593Smuzhiyun ctxt_info_gen3->mtr_size =
227*4882a593Smuzhiyun cpu_to_le16(TFD_QUEUE_CB_SIZE(cmdq_size));
228*4882a593Smuzhiyun ctxt_info_gen3->mcr_size =
229*4882a593Smuzhiyun cpu_to_le16(RX_QUEUE_CB_SIZE(trans->cfg->num_rbds));
230*4882a593Smuzhiyun
231*4882a593Smuzhiyun trans_pcie->ctxt_info_gen3 = ctxt_info_gen3;
232*4882a593Smuzhiyun trans_pcie->prph_info = prph_info;
233*4882a593Smuzhiyun trans_pcie->prph_scratch = prph_scratch;
234*4882a593Smuzhiyun
235*4882a593Smuzhiyun /* Allocate IML */
236*4882a593Smuzhiyun trans_pcie->iml = dma_alloc_coherent(trans->dev, trans->iml_len,
237*4882a593Smuzhiyun &trans_pcie->iml_dma_addr,
238*4882a593Smuzhiyun GFP_KERNEL);
239*4882a593Smuzhiyun if (!trans_pcie->iml) {
240*4882a593Smuzhiyun ret = -ENOMEM;
241*4882a593Smuzhiyun goto err_free_ctxt_info;
242*4882a593Smuzhiyun }
243*4882a593Smuzhiyun
244*4882a593Smuzhiyun memcpy(trans_pcie->iml, trans->iml, trans->iml_len);
245*4882a593Smuzhiyun
246*4882a593Smuzhiyun iwl_enable_fw_load_int_ctx_info(trans);
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun /* kick FW self load */
249*4882a593Smuzhiyun iwl_write64(trans, CSR_CTXT_INFO_ADDR,
250*4882a593Smuzhiyun trans_pcie->ctxt_info_dma_addr);
251*4882a593Smuzhiyun iwl_write64(trans, CSR_IML_DATA_ADDR,
252*4882a593Smuzhiyun trans_pcie->iml_dma_addr);
253*4882a593Smuzhiyun iwl_write32(trans, CSR_IML_SIZE_ADDR, trans->iml_len);
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun iwl_set_bit(trans, CSR_CTXT_INFO_BOOT_CTRL,
256*4882a593Smuzhiyun CSR_AUTO_FUNC_BOOT_ENA);
257*4882a593Smuzhiyun
258*4882a593Smuzhiyun return 0;
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun err_free_ctxt_info:
261*4882a593Smuzhiyun dma_free_coherent(trans->dev, sizeof(*trans_pcie->ctxt_info_gen3),
262*4882a593Smuzhiyun trans_pcie->ctxt_info_gen3,
263*4882a593Smuzhiyun trans_pcie->ctxt_info_dma_addr);
264*4882a593Smuzhiyun trans_pcie->ctxt_info_gen3 = NULL;
265*4882a593Smuzhiyun err_free_prph_info:
266*4882a593Smuzhiyun dma_free_coherent(trans->dev,
267*4882a593Smuzhiyun sizeof(*prph_info),
268*4882a593Smuzhiyun prph_info,
269*4882a593Smuzhiyun trans_pcie->prph_info_dma_addr);
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun err_free_prph_scratch:
272*4882a593Smuzhiyun dma_free_coherent(trans->dev,
273*4882a593Smuzhiyun sizeof(*prph_scratch),
274*4882a593Smuzhiyun prph_scratch,
275*4882a593Smuzhiyun trans_pcie->prph_scratch_dma_addr);
276*4882a593Smuzhiyun return ret;
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun }
279*4882a593Smuzhiyun
iwl_pcie_ctxt_info_gen3_free(struct iwl_trans * trans)280*4882a593Smuzhiyun void iwl_pcie_ctxt_info_gen3_free(struct iwl_trans *trans)
281*4882a593Smuzhiyun {
282*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun if (!trans_pcie->ctxt_info_gen3)
285*4882a593Smuzhiyun return;
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun dma_free_coherent(trans->dev, sizeof(*trans_pcie->ctxt_info_gen3),
288*4882a593Smuzhiyun trans_pcie->ctxt_info_gen3,
289*4882a593Smuzhiyun trans_pcie->ctxt_info_dma_addr);
290*4882a593Smuzhiyun trans_pcie->ctxt_info_dma_addr = 0;
291*4882a593Smuzhiyun trans_pcie->ctxt_info_gen3 = NULL;
292*4882a593Smuzhiyun
293*4882a593Smuzhiyun dma_free_coherent(trans->dev, trans->iml_len, trans_pcie->iml,
294*4882a593Smuzhiyun trans_pcie->iml_dma_addr);
295*4882a593Smuzhiyun trans_pcie->iml_dma_addr = 0;
296*4882a593Smuzhiyun trans_pcie->iml = NULL;
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun iwl_pcie_ctxt_info_free_fw_img(trans);
299*4882a593Smuzhiyun
300*4882a593Smuzhiyun dma_free_coherent(trans->dev, sizeof(*trans_pcie->prph_scratch),
301*4882a593Smuzhiyun trans_pcie->prph_scratch,
302*4882a593Smuzhiyun trans_pcie->prph_scratch_dma_addr);
303*4882a593Smuzhiyun trans_pcie->prph_scratch_dma_addr = 0;
304*4882a593Smuzhiyun trans_pcie->prph_scratch = NULL;
305*4882a593Smuzhiyun
306*4882a593Smuzhiyun dma_free_coherent(trans->dev, sizeof(*trans_pcie->prph_info),
307*4882a593Smuzhiyun trans_pcie->prph_info,
308*4882a593Smuzhiyun trans_pcie->prph_info_dma_addr);
309*4882a593Smuzhiyun trans_pcie->prph_info_dma_addr = 0;
310*4882a593Smuzhiyun trans_pcie->prph_info = NULL;
311*4882a593Smuzhiyun }
312*4882a593Smuzhiyun
iwl_trans_pcie_ctx_info_gen3_set_pnvm(struct iwl_trans * trans,const void * data,u32 len)313*4882a593Smuzhiyun int iwl_trans_pcie_ctx_info_gen3_set_pnvm(struct iwl_trans *trans,
314*4882a593Smuzhiyun const void *data, u32 len)
315*4882a593Smuzhiyun {
316*4882a593Smuzhiyun struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
317*4882a593Smuzhiyun struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl =
318*4882a593Smuzhiyun &trans_pcie->prph_scratch->ctrl_cfg;
319*4882a593Smuzhiyun int ret;
320*4882a593Smuzhiyun
321*4882a593Smuzhiyun if (trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_AX210)
322*4882a593Smuzhiyun return 0;
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun /* only allocate the DRAM if not allocated yet */
325*4882a593Smuzhiyun if (!trans->pnvm_loaded) {
326*4882a593Smuzhiyun if (WARN_ON(prph_sc_ctrl->pnvm_cfg.pnvm_size))
327*4882a593Smuzhiyun return -EBUSY;
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun ret = iwl_pcie_ctxt_info_alloc_dma(trans, data, len,
330*4882a593Smuzhiyun &trans_pcie->pnvm_dram);
331*4882a593Smuzhiyun if (ret < 0) {
332*4882a593Smuzhiyun IWL_DEBUG_FW(trans, "Failed to allocate PNVM DMA %d.\n",
333*4882a593Smuzhiyun ret);
334*4882a593Smuzhiyun return ret;
335*4882a593Smuzhiyun }
336*4882a593Smuzhiyun }
337*4882a593Smuzhiyun
338*4882a593Smuzhiyun prph_sc_ctrl->pnvm_cfg.pnvm_base_addr =
339*4882a593Smuzhiyun cpu_to_le64(trans_pcie->pnvm_dram.physical);
340*4882a593Smuzhiyun prph_sc_ctrl->pnvm_cfg.pnvm_size =
341*4882a593Smuzhiyun cpu_to_le32(trans_pcie->pnvm_dram.size);
342*4882a593Smuzhiyun
343*4882a593Smuzhiyun return 0;
344*4882a593Smuzhiyun }
345