18e99ea8dSJohannes Berg // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
28e99ea8dSJohannes Berg /*
3*1c4db761SMukesh Sisodiya  * Copyright (C) 2018-2022 Intel Corporation
48e99ea8dSJohannes Berg  */
52ee82402SGolan Ben Ami #include "iwl-trans.h"
62ee82402SGolan Ben Ami #include "iwl-fh.h"
72ee82402SGolan Ben Ami #include "iwl-context-info-gen3.h"
82ee82402SGolan Ben Ami #include "internal.h"
92ee82402SGolan Ben Ami #include "iwl-prph.h"
102ee82402SGolan Ben Ami 
11593fae3eSShahar S Matityahu static void
12593fae3eSShahar S Matityahu iwl_pcie_ctxt_info_dbg_enable(struct iwl_trans *trans,
13593fae3eSShahar S Matityahu 			      struct iwl_prph_scratch_hwm_cfg *dbg_cfg,
14593fae3eSShahar S Matityahu 			      u32 *control_flags)
15593fae3eSShahar S Matityahu {
16593fae3eSShahar S Matityahu 	enum iwl_fw_ini_allocation_id alloc_id = IWL_FW_INI_ALLOCATION_ID_DBGC1;
17593fae3eSShahar S Matityahu 	struct iwl_fw_ini_allocation_tlv *fw_mon_cfg;
18593fae3eSShahar S Matityahu 	u32 dbg_flags = 0;
19593fae3eSShahar S Matityahu 
20593fae3eSShahar S Matityahu 	if (!iwl_trans_dbg_ini_valid(trans)) {
21593fae3eSShahar S Matityahu 		struct iwl_dram_data *fw_mon = &trans->dbg.fw_mon;
22593fae3eSShahar S Matityahu 
23593fae3eSShahar S Matityahu 		iwl_pcie_alloc_fw_monitor(trans, 0);
24593fae3eSShahar S Matityahu 
25593fae3eSShahar S Matityahu 		if (fw_mon->size) {
26593fae3eSShahar S Matityahu 			dbg_flags |= IWL_PRPH_SCRATCH_EDBG_DEST_DRAM;
27593fae3eSShahar S Matityahu 
28593fae3eSShahar S Matityahu 			IWL_DEBUG_FW(trans,
29593fae3eSShahar S Matityahu 				     "WRT: Applying DRAM buffer destination\n");
30593fae3eSShahar S Matityahu 
31593fae3eSShahar S Matityahu 			dbg_cfg->hwm_base_addr = cpu_to_le64(fw_mon->physical);
32593fae3eSShahar S Matityahu 			dbg_cfg->hwm_size = cpu_to_le32(fw_mon->size);
33593fae3eSShahar S Matityahu 		}
34593fae3eSShahar S Matityahu 
35593fae3eSShahar S Matityahu 		goto out;
36593fae3eSShahar S Matityahu 	}
37593fae3eSShahar S Matityahu 
38593fae3eSShahar S Matityahu 	fw_mon_cfg = &trans->dbg.fw_mon_cfg[alloc_id];
39593fae3eSShahar S Matityahu 
40cbc63655SGil Adam 	switch (le32_to_cpu(fw_mon_cfg->buf_location)) {
41cbc63655SGil Adam 	case IWL_FW_INI_LOCATION_SRAM_PATH:
42593fae3eSShahar S Matityahu 		dbg_flags |= IWL_PRPH_SCRATCH_EDBG_DEST_INTERNAL;
43593fae3eSShahar S Matityahu 		IWL_DEBUG_FW(trans,
44593fae3eSShahar S Matityahu 				"WRT: Applying SMEM buffer destination\n");
45cbc63655SGil Adam 		break;
46593fae3eSShahar S Matityahu 
47cbc63655SGil Adam 	case IWL_FW_INI_LOCATION_NPK_PATH:
48cbc63655SGil Adam 		dbg_flags |= IWL_PRPH_SCRATCH_EDBG_DEST_TB22DTF;
49cbc63655SGil Adam 		IWL_DEBUG_FW(trans,
50cbc63655SGil Adam 			     "WRT: Applying NPK buffer destination\n");
51cbc63655SGil Adam 		break;
52593fae3eSShahar S Matityahu 
53cbc63655SGil Adam 	case IWL_FW_INI_LOCATION_DRAM_PATH:
54cbc63655SGil Adam 		if (trans->dbg.fw_mon_ini[alloc_id].num_frags) {
55593fae3eSShahar S Matityahu 			struct iwl_dram_data *frag =
56593fae3eSShahar S Matityahu 				&trans->dbg.fw_mon_ini[alloc_id].frags[0];
57593fae3eSShahar S Matityahu 			dbg_flags |= IWL_PRPH_SCRATCH_EDBG_DEST_DRAM;
58593fae3eSShahar S Matityahu 			dbg_cfg->hwm_base_addr = cpu_to_le64(frag->physical);
59593fae3eSShahar S Matityahu 			dbg_cfg->hwm_size = cpu_to_le32(frag->size);
60f21baf24SMukesh Sisodiya 			dbg_cfg->debug_token_config = cpu_to_le32(trans->dbg.ucode_preset);
61f21baf24SMukesh Sisodiya 			IWL_DEBUG_FW(trans,
62f21baf24SMukesh Sisodiya 				     "WRT: Applying DRAM destination (debug_token_config=%u)\n",
63f21baf24SMukesh Sisodiya 				     dbg_cfg->debug_token_config);
64cbc63655SGil Adam 			IWL_DEBUG_FW(trans,
65cbc63655SGil Adam 				     "WRT: Applying DRAM destination (alloc_id=%u, num_frags=%u)\n",
66cbc63655SGil Adam 				     alloc_id,
67cbc63655SGil Adam 				     trans->dbg.fw_mon_ini[alloc_id].num_frags);
68593fae3eSShahar S Matityahu 		}
69cbc63655SGil Adam 		break;
70cbc63655SGil Adam 	default:
71cbc63655SGil Adam 		IWL_ERR(trans, "WRT: Invalid buffer destination\n");
72cbc63655SGil Adam 	}
73593fae3eSShahar S Matityahu out:
74593fae3eSShahar S Matityahu 	if (dbg_flags)
75593fae3eSShahar S Matityahu 		*control_flags |= IWL_PRPH_SCRATCH_EARLY_DEBUG_EN | dbg_flags;
76593fae3eSShahar S Matityahu }
77593fae3eSShahar S Matityahu 
782ee82402SGolan Ben Ami int iwl_pcie_ctxt_info_gen3_init(struct iwl_trans *trans,
792ee82402SGolan Ben Ami 				 const struct fw_img *fw)
802ee82402SGolan Ben Ami {
812ee82402SGolan Ben Ami 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
822ee82402SGolan Ben Ami 	struct iwl_context_info_gen3 *ctxt_info_gen3;
832ee82402SGolan Ben Ami 	struct iwl_prph_scratch *prph_scratch;
842ee82402SGolan Ben Ami 	struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl;
852ee82402SGolan Ben Ami 	struct iwl_prph_info *prph_info;
862ee82402SGolan Ben Ami 	u32 control_flags = 0;
872ee82402SGolan Ben Ami 	int ret;
88718a8b23SShaul Triebitz 	int cmdq_size = max_t(u32, IWL_CMD_QUEUE_SIZE,
89718a8b23SShaul Triebitz 			      trans->cfg->min_txq_size);
902ee82402SGolan Ben Ami 
91d8d66397SJohannes Berg 	switch (trans_pcie->rx_buf_size) {
92d8d66397SJohannes Berg 	case IWL_AMSDU_DEF:
93d8d66397SJohannes Berg 		return -EINVAL;
94d8d66397SJohannes Berg 	case IWL_AMSDU_2K:
95d8d66397SJohannes Berg 		break;
96d8d66397SJohannes Berg 	case IWL_AMSDU_4K:
9761576240SJohannes Berg 		control_flags |= IWL_PRPH_SCRATCH_RB_SIZE_4K;
9861576240SJohannes Berg 		break;
99d8d66397SJohannes Berg 	case IWL_AMSDU_8K:
10061576240SJohannes Berg 		control_flags |= IWL_PRPH_SCRATCH_RB_SIZE_4K;
10161576240SJohannes Berg 		/* if firmware supports the ext size, tell it */
10261576240SJohannes Berg 		control_flags |= IWL_PRPH_SCRATCH_RB_SIZE_EXT_8K;
10361576240SJohannes Berg 		break;
104d8d66397SJohannes Berg 	case IWL_AMSDU_12K:
105d8d66397SJohannes Berg 		control_flags |= IWL_PRPH_SCRATCH_RB_SIZE_4K;
10661576240SJohannes Berg 		/* if firmware supports the ext size, tell it */
1073fa965c2SJohannes Berg 		control_flags |= IWL_PRPH_SCRATCH_RB_SIZE_EXT_16K;
108d8d66397SJohannes Berg 		break;
109d8d66397SJohannes Berg 	}
110d8d66397SJohannes Berg 
1112ee82402SGolan Ben Ami 	/* Allocate prph scratch */
1122ee82402SGolan Ben Ami 	prph_scratch = dma_alloc_coherent(trans->dev, sizeof(*prph_scratch),
1132ee82402SGolan Ben Ami 					  &trans_pcie->prph_scratch_dma_addr,
1142ee82402SGolan Ben Ami 					  GFP_KERNEL);
1152ee82402SGolan Ben Ami 	if (!prph_scratch)
1162ee82402SGolan Ben Ami 		return -ENOMEM;
1172ee82402SGolan Ben Ami 
1182ee82402SGolan Ben Ami 	prph_sc_ctrl = &prph_scratch->ctrl_cfg;
1192ee82402SGolan Ben Ami 
1202ee82402SGolan Ben Ami 	prph_sc_ctrl->version.version = 0;
1212ee82402SGolan Ben Ami 	prph_sc_ctrl->version.mac_id =
1222ee82402SGolan Ben Ami 		cpu_to_le16((u16)iwl_read32(trans, CSR_HW_REV));
1232ee82402SGolan Ben Ami 	prph_sc_ctrl->version.size = cpu_to_le16(sizeof(*prph_scratch) / 4);
1242ee82402SGolan Ben Ami 
125d8d66397SJohannes Berg 	control_flags |= IWL_PRPH_SCRATCH_MTR_MODE;
126d8d66397SJohannes Berg 	control_flags |= IWL_PRPH_MTR_FORMAT_256B & IWL_PRPH_SCRATCH_MTR_FORMAT;
1272ee82402SGolan Ben Ami 
128*1c4db761SMukesh Sisodiya 	if (trans->trans_cfg->imr_enabled)
129*1c4db761SMukesh Sisodiya 		control_flags |= IWL_PRPH_SCRATCH_IMR_DEBUG_EN;
130*1c4db761SMukesh Sisodiya 
1312ee82402SGolan Ben Ami 	/* initialize RX default queue */
1322ee82402SGolan Ben Ami 	prph_sc_ctrl->rbd_cfg.free_rbd_addr =
1332ee82402SGolan Ben Ami 		cpu_to_le64(trans_pcie->rxq->bd_dma);
1342ee82402SGolan Ben Ami 
135593fae3eSShahar S Matityahu 	iwl_pcie_ctxt_info_dbg_enable(trans, &prph_sc_ctrl->hwm_cfg,
136593fae3eSShahar S Matityahu 				      &control_flags);
137593fae3eSShahar S Matityahu 	prph_sc_ctrl->control.control_flags = cpu_to_le32(control_flags);
1389f358c17SGolan Ben Ami 
1392ee82402SGolan Ben Ami 	/* allocate ucode sections in dram and set addresses */
1402ee82402SGolan Ben Ami 	ret = iwl_pcie_init_fw_sec(trans, fw, &prph_scratch->dram);
1410f4f1994SNavid Emamdoost 	if (ret)
1420f4f1994SNavid Emamdoost 		goto err_free_prph_scratch;
1430f4f1994SNavid Emamdoost 
1442ee82402SGolan Ben Ami 
1452ee82402SGolan Ben Ami 	/* Allocate prph information
1462ee82402SGolan Ben Ami 	 * currently we don't assign to the prph info anything, but it would get
1478e08e191SJohannes Berg 	 * assigned later
1488e08e191SJohannes Berg 	 *
1498e08e191SJohannes Berg 	 * We also use the second half of this page to give the device some
1508e08e191SJohannes Berg 	 * dummy TR/CR tail pointers - which shouldn't be necessary as we don't
1518e08e191SJohannes Berg 	 * use this, but the hardware still reads/writes there and we can't let
1528e08e191SJohannes Berg 	 * it go do that with a NULL pointer.
1538e08e191SJohannes Berg 	 */
1548e08e191SJohannes Berg 	BUILD_BUG_ON(sizeof(*prph_info) > PAGE_SIZE / 2);
1558e08e191SJohannes Berg 	prph_info = dma_alloc_coherent(trans->dev, PAGE_SIZE,
1562ee82402SGolan Ben Ami 				       &trans_pcie->prph_info_dma_addr,
1572ee82402SGolan Ben Ami 				       GFP_KERNEL);
1580f4f1994SNavid Emamdoost 	if (!prph_info) {
1590f4f1994SNavid Emamdoost 		ret = -ENOMEM;
1600f4f1994SNavid Emamdoost 		goto err_free_prph_scratch;
1610f4f1994SNavid Emamdoost 	}
1622ee82402SGolan Ben Ami 
1632ee82402SGolan Ben Ami 	/* Allocate context info */
1642ee82402SGolan Ben Ami 	ctxt_info_gen3 = dma_alloc_coherent(trans->dev,
1652ee82402SGolan Ben Ami 					    sizeof(*ctxt_info_gen3),
1662ee82402SGolan Ben Ami 					    &trans_pcie->ctxt_info_dma_addr,
1672ee82402SGolan Ben Ami 					    GFP_KERNEL);
1680f4f1994SNavid Emamdoost 	if (!ctxt_info_gen3) {
1690f4f1994SNavid Emamdoost 		ret = -ENOMEM;
1700f4f1994SNavid Emamdoost 		goto err_free_prph_info;
1710f4f1994SNavid Emamdoost 	}
1722ee82402SGolan Ben Ami 
1732ee82402SGolan Ben Ami 	ctxt_info_gen3->prph_info_base_addr =
1742ee82402SGolan Ben Ami 		cpu_to_le64(trans_pcie->prph_info_dma_addr);
1752ee82402SGolan Ben Ami 	ctxt_info_gen3->prph_scratch_base_addr =
1762ee82402SGolan Ben Ami 		cpu_to_le64(trans_pcie->prph_scratch_dma_addr);
1772ee82402SGolan Ben Ami 	ctxt_info_gen3->prph_scratch_size =
1782ee82402SGolan Ben Ami 		cpu_to_le32(sizeof(*prph_scratch));
1792ee82402SGolan Ben Ami 	ctxt_info_gen3->cr_head_idx_arr_base_addr =
1802ee82402SGolan Ben Ami 		cpu_to_le64(trans_pcie->rxq->rb_stts_dma);
1812ee82402SGolan Ben Ami 	ctxt_info_gen3->tr_tail_idx_arr_base_addr =
1828e08e191SJohannes Berg 		cpu_to_le64(trans_pcie->prph_info_dma_addr + PAGE_SIZE / 2);
1832ee82402SGolan Ben Ami 	ctxt_info_gen3->cr_tail_idx_arr_base_addr =
1848e08e191SJohannes Berg 		cpu_to_le64(trans_pcie->prph_info_dma_addr + 3 * PAGE_SIZE / 4);
1852ee82402SGolan Ben Ami 	ctxt_info_gen3->mtr_base_addr =
1864f4822b7SMordechay Goodstein 		cpu_to_le64(trans->txqs.txq[trans->txqs.cmd.q_id]->dma_addr);
1872ee82402SGolan Ben Ami 	ctxt_info_gen3->mcr_base_addr =
1882ee82402SGolan Ben Ami 		cpu_to_le64(trans_pcie->rxq->used_bd_dma);
1892ee82402SGolan Ben Ami 	ctxt_info_gen3->mtr_size =
190ff911dcaSShaul Triebitz 		cpu_to_le16(TFD_QUEUE_CB_SIZE(cmdq_size));
1912ee82402SGolan Ben Ami 	ctxt_info_gen3->mcr_size =
192c042f0c7SJohannes Berg 		cpu_to_le16(RX_QUEUE_CB_SIZE(trans->cfg->num_rbds));
1932ee82402SGolan Ben Ami 
1942ee82402SGolan Ben Ami 	trans_pcie->ctxt_info_gen3 = ctxt_info_gen3;
1952ee82402SGolan Ben Ami 	trans_pcie->prph_info = prph_info;
1962ee82402SGolan Ben Ami 	trans_pcie->prph_scratch = prph_scratch;
1972ee82402SGolan Ben Ami 
1982ee82402SGolan Ben Ami 	/* Allocate IML */
199310f60f5SJohannes Berg 	trans_pcie->iml = dma_alloc_coherent(trans->dev, trans->iml_len,
200310f60f5SJohannes Berg 					     &trans_pcie->iml_dma_addr,
201310f60f5SJohannes Berg 					     GFP_KERNEL);
202310f60f5SJohannes Berg 	if (!trans_pcie->iml) {
2032d6bc752SJohannes Berg 		ret = -ENOMEM;
2042d6bc752SJohannes Berg 		goto err_free_ctxt_info;
2052d6bc752SJohannes Berg 	}
2062ee82402SGolan Ben Ami 
207310f60f5SJohannes Berg 	memcpy(trans_pcie->iml, trans->iml, trans->iml_len);
2082ee82402SGolan Ben Ami 
209ed3e4c6dSEmmanuel Grumbach 	iwl_enable_fw_load_int_ctx_info(trans);
2102ee82402SGolan Ben Ami 
2112ee82402SGolan Ben Ami 	/* kick FW self load */
2122ee82402SGolan Ben Ami 	iwl_write64(trans, CSR_CTXT_INFO_ADDR,
2132ee82402SGolan Ben Ami 		    trans_pcie->ctxt_info_dma_addr);
2142ee82402SGolan Ben Ami 	iwl_write64(trans, CSR_IML_DATA_ADDR,
2152ee82402SGolan Ben Ami 		    trans_pcie->iml_dma_addr);
2162ee82402SGolan Ben Ami 	iwl_write32(trans, CSR_IML_SIZE_ADDR, trans->iml_len);
217ff911dcaSShaul Triebitz 
218ff911dcaSShaul Triebitz 	iwl_set_bit(trans, CSR_CTXT_INFO_BOOT_CTRL,
219ff911dcaSShaul Triebitz 		    CSR_AUTO_FUNC_BOOT_ENA);
220edb62520SJohannes Berg 
2212ee82402SGolan Ben Ami 	return 0;
2220f4f1994SNavid Emamdoost 
2232d6bc752SJohannes Berg err_free_ctxt_info:
2242d6bc752SJohannes Berg 	dma_free_coherent(trans->dev, sizeof(*trans_pcie->ctxt_info_gen3),
2252d6bc752SJohannes Berg 			  trans_pcie->ctxt_info_gen3,
2262d6bc752SJohannes Berg 			  trans_pcie->ctxt_info_dma_addr);
2272d6bc752SJohannes Berg 	trans_pcie->ctxt_info_gen3 = NULL;
2280f4f1994SNavid Emamdoost err_free_prph_info:
2298e08e191SJohannes Berg 	dma_free_coherent(trans->dev, PAGE_SIZE, prph_info,
2300f4f1994SNavid Emamdoost 			  trans_pcie->prph_info_dma_addr);
2310f4f1994SNavid Emamdoost 
2320f4f1994SNavid Emamdoost err_free_prph_scratch:
2330f4f1994SNavid Emamdoost 	dma_free_coherent(trans->dev,
2340f4f1994SNavid Emamdoost 			  sizeof(*prph_scratch),
2350f4f1994SNavid Emamdoost 			prph_scratch,
2360f4f1994SNavid Emamdoost 			trans_pcie->prph_scratch_dma_addr);
2370f4f1994SNavid Emamdoost 	return ret;
2380f4f1994SNavid Emamdoost 
2392ee82402SGolan Ben Ami }
2402ee82402SGolan Ben Ami 
24194768975SJohannes Berg void iwl_pcie_ctxt_info_gen3_free(struct iwl_trans *trans, bool alive)
2422ee82402SGolan Ben Ami {
2432ee82402SGolan Ben Ami 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2442ee82402SGolan Ben Ami 
24594768975SJohannes Berg 	if (trans_pcie->iml) {
24694768975SJohannes Berg 		dma_free_coherent(trans->dev, trans->iml_len, trans_pcie->iml,
24794768975SJohannes Berg 				  trans_pcie->iml_dma_addr);
24894768975SJohannes Berg 		trans_pcie->iml_dma_addr = 0;
24994768975SJohannes Berg 		trans_pcie->iml = NULL;
25094768975SJohannes Berg 	}
25194768975SJohannes Berg 
25294768975SJohannes Berg 	iwl_pcie_ctxt_info_free_fw_img(trans);
25394768975SJohannes Berg 
25494768975SJohannes Berg 	if (alive)
25594768975SJohannes Berg 		return;
25694768975SJohannes Berg 
2572ee82402SGolan Ben Ami 	if (!trans_pcie->ctxt_info_gen3)
2582ee82402SGolan Ben Ami 		return;
2592ee82402SGolan Ben Ami 
26094768975SJohannes Berg 	/* ctxt_info_gen3 and prph_scratch are still needed for PNVM load */
2612ee82402SGolan Ben Ami 	dma_free_coherent(trans->dev, sizeof(*trans_pcie->ctxt_info_gen3),
2622ee82402SGolan Ben Ami 			  trans_pcie->ctxt_info_gen3,
2632ee82402SGolan Ben Ami 			  trans_pcie->ctxt_info_dma_addr);
2642ee82402SGolan Ben Ami 	trans_pcie->ctxt_info_dma_addr = 0;
2652ee82402SGolan Ben Ami 	trans_pcie->ctxt_info_gen3 = NULL;
2662ee82402SGolan Ben Ami 
2672ee82402SGolan Ben Ami 	dma_free_coherent(trans->dev, sizeof(*trans_pcie->prph_scratch),
2682ee82402SGolan Ben Ami 			  trans_pcie->prph_scratch,
2692ee82402SGolan Ben Ami 			  trans_pcie->prph_scratch_dma_addr);
2702ee82402SGolan Ben Ami 	trans_pcie->prph_scratch_dma_addr = 0;
2712ee82402SGolan Ben Ami 	trans_pcie->prph_scratch = NULL;
2722ee82402SGolan Ben Ami 
27394768975SJohannes Berg 	/* this is needed for the entire lifetime */
2748e08e191SJohannes Berg 	dma_free_coherent(trans->dev, PAGE_SIZE, trans_pcie->prph_info,
2752ee82402SGolan Ben Ami 			  trans_pcie->prph_info_dma_addr);
2762ee82402SGolan Ben Ami 	trans_pcie->prph_info_dma_addr = 0;
2772ee82402SGolan Ben Ami 	trans_pcie->prph_info = NULL;
2786654cd4eSLuca Coelho }
2796654cd4eSLuca Coelho 
2806654cd4eSLuca Coelho int iwl_trans_pcie_ctx_info_gen3_set_pnvm(struct iwl_trans *trans,
2816654cd4eSLuca Coelho 					  const void *data, u32 len)
2826654cd4eSLuca Coelho {
2836654cd4eSLuca Coelho 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
2846654cd4eSLuca Coelho 	struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl =
2856654cd4eSLuca Coelho 		&trans_pcie->prph_scratch->ctrl_cfg;
2866654cd4eSLuca Coelho 	int ret;
2876654cd4eSLuca Coelho 
2886654cd4eSLuca Coelho 	if (trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_AX210)
2896654cd4eSLuca Coelho 		return 0;
2906654cd4eSLuca Coelho 
2914a81598fSLuca Coelho 	/* only allocate the DRAM if not allocated yet */
2924a81598fSLuca Coelho 	if (!trans->pnvm_loaded) {
2934a81598fSLuca Coelho 		if (WARN_ON(prph_sc_ctrl->pnvm_cfg.pnvm_size))
2944a81598fSLuca Coelho 			return -EBUSY;
2954a81598fSLuca Coelho 
2966654cd4eSLuca Coelho 		ret = iwl_pcie_ctxt_info_alloc_dma(trans, data, len,
2976654cd4eSLuca Coelho 						   &trans_pcie->pnvm_dram);
2986654cd4eSLuca Coelho 		if (ret < 0) {
2996654cd4eSLuca Coelho 			IWL_DEBUG_FW(trans, "Failed to allocate PNVM DMA %d.\n",
3006654cd4eSLuca Coelho 				     ret);
3016654cd4eSLuca Coelho 			return ret;
3026654cd4eSLuca Coelho 		}
3034a81598fSLuca Coelho 	}
30434b9434cSJohannes Berg 
3056654cd4eSLuca Coelho 	prph_sc_ctrl->pnvm_cfg.pnvm_base_addr =
3066654cd4eSLuca Coelho 		cpu_to_le64(trans_pcie->pnvm_dram.physical);
3076654cd4eSLuca Coelho 	prph_sc_ctrl->pnvm_cfg.pnvm_size =
3086654cd4eSLuca Coelho 		cpu_to_le32(trans_pcie->pnvm_dram.size);
3096654cd4eSLuca Coelho 
3106654cd4eSLuca Coelho 	return 0;
3112ee82402SGolan Ben Ami }
3129dad325fSLuca Coelho 
3139dad325fSLuca Coelho int iwl_trans_pcie_ctx_info_gen3_set_reduce_power(struct iwl_trans *trans,
3149dad325fSLuca Coelho 						  const void *data, u32 len)
3159dad325fSLuca Coelho {
3169dad325fSLuca Coelho 	struct iwl_trans_pcie *trans_pcie = IWL_TRANS_GET_PCIE_TRANS(trans);
3179dad325fSLuca Coelho 	struct iwl_prph_scratch_ctrl_cfg *prph_sc_ctrl =
3189dad325fSLuca Coelho 		&trans_pcie->prph_scratch->ctrl_cfg;
3199dad325fSLuca Coelho 	int ret;
3209dad325fSLuca Coelho 
3219dad325fSLuca Coelho 	if (trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_AX210)
3229dad325fSLuca Coelho 		return 0;
3239dad325fSLuca Coelho 
3249dad325fSLuca Coelho 	/* only allocate the DRAM if not allocated yet */
3259dad325fSLuca Coelho 	if (!trans->reduce_power_loaded) {
3269dad325fSLuca Coelho 		if (WARN_ON(prph_sc_ctrl->reduce_power_cfg.size))
3279dad325fSLuca Coelho 			return -EBUSY;
3289dad325fSLuca Coelho 
3299dad325fSLuca Coelho 		ret = iwl_pcie_ctxt_info_alloc_dma(trans, data, len,
3309dad325fSLuca Coelho 					   &trans_pcie->reduce_power_dram);
3319dad325fSLuca Coelho 		if (ret < 0) {
3329dad325fSLuca Coelho 			IWL_DEBUG_FW(trans,
3339dad325fSLuca Coelho 				     "Failed to allocate reduce power DMA %d.\n",
3349dad325fSLuca Coelho 				     ret);
3359dad325fSLuca Coelho 			return ret;
3369dad325fSLuca Coelho 		}
3379dad325fSLuca Coelho 	}
3389dad325fSLuca Coelho 
3399dad325fSLuca Coelho 	prph_sc_ctrl->reduce_power_cfg.base_addr =
3409dad325fSLuca Coelho 		cpu_to_le64(trans_pcie->reduce_power_dram.physical);
3419dad325fSLuca Coelho 	prph_sc_ctrl->reduce_power_cfg.size =
3429dad325fSLuca Coelho 		cpu_to_le32(trans_pcie->reduce_power_dram.size);
3439dad325fSLuca Coelho 
3449dad325fSLuca Coelho 	return 0;
3459dad325fSLuca Coelho }
346