From 0060af5a98bcad6cd5d6055fe53bcb94f32e6e4f Mon Sep 17 00:00:00 2001 From: Ghanim Fodi Date: Wed, 18 Dec 2019 19:14:38 +0200 Subject: [PATCH] msm: ipa: split quota stat memory between q6 and ap Q6 uses only 2 pipes for stats. Split the SRAM specific region between Q6 (2 entries) and AP (rest 3 entries). Change-Id: Ie9eac932a6547e03f76a2a294d69f90db1d1b190 Signed-off-by: Ghanim Fodi --- drivers/platform/msm/ipa/ipa_v3/ipa.c | 27 +++++----- .../platform/msm/ipa/ipa_v3/ipa_hw_stats.c | 33 +++++++++--- drivers/platform/msm/ipa/ipa_v3/ipa_i.h | 6 ++- .../platform/msm/ipa/ipa_v3/ipa_qmi_service.c | 6 +-- drivers/platform/msm/ipa/ipa_v3/ipa_utils.c | 52 +++++++++++++------ 5 files changed, 83 insertions(+), 41 deletions(-) diff --git a/drivers/platform/msm/ipa/ipa_v3/ipa.c b/drivers/platform/msm/ipa/ipa_v3/ipa.c index 21a97fc7d786..5aeaed624176 100644 --- a/drivers/platform/msm/ipa/ipa_v3/ipa.c +++ b/drivers/platform/msm/ipa/ipa_v3/ipa.c @@ -3862,22 +3862,23 @@ int _ipa_init_sram_v3(void) if (ipa_get_hw_type() >= IPA_HW_v4_5) { ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(nat_tbl_ofst) - 12); - ipa3_sram_set_canary(ipa_sram_mmio, - IPA_MEM_PART(nat_tbl_ofst) - 8); - ipa3_sram_set_canary(ipa_sram_mmio, - IPA_MEM_PART(nat_tbl_ofst) - 4); - ipa3_sram_set_canary(ipa_sram_mmio, IPA_MEM_PART(nat_tbl_ofst)); } if (ipa_get_hw_type() >= IPA_HW_v4_0) { - ipa3_sram_set_canary(ipa_sram_mmio, - IPA_MEM_PART(pdn_config_ofst) - 4); - ipa3_sram_set_canary(ipa_sram_mmio, - IPA_MEM_PART(pdn_config_ofst)); - ipa3_sram_set_canary(ipa_sram_mmio, - IPA_MEM_PART(stats_quota_ofst) - 4); - ipa3_sram_set_canary(ipa_sram_mmio, - IPA_MEM_PART(stats_quota_ofst)); + if (ipa_get_hw_type() < IPA_HW_v4_5) { + ipa3_sram_set_canary(ipa_sram_mmio, + IPA_MEM_PART(pdn_config_ofst) - 4); + ipa3_sram_set_canary(ipa_sram_mmio, + IPA_MEM_PART(pdn_config_ofst)); + ipa3_sram_set_canary(ipa_sram_mmio, + IPA_MEM_PART(stats_quota_q6_ofst) - 4); + ipa3_sram_set_canary(ipa_sram_mmio, + IPA_MEM_PART(stats_quota_q6_ofst)); + } else { + ipa3_sram_set_canary(ipa_sram_mmio, + IPA_MEM_PART(stats_quota_q6_ofst) - 12); + } } + if (ipa_get_hw_type() <= IPA_HW_v3_5 || ipa_get_hw_type() >= IPA_HW_v4_5) { ipa3_sram_set_canary(ipa_sram_mmio, diff --git a/drivers/platform/msm/ipa/ipa_v3/ipa_hw_stats.c b/drivers/platform/msm/ipa/ipa_v3/ipa_hw_stats.c index d12a1ea7b830..4587984fd843 100644 --- a/drivers/platform/msm/ipa/ipa_v3/ipa_hw_stats.c +++ b/drivers/platform/msm/ipa/ipa_v3/ipa_hw_stats.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved. */ #include @@ -271,6 +271,27 @@ static void ipa_close_coal_frame(struct ipahal_imm_cmd_pyld **coal_cmd_pyld) ®_write_coal_close, false); } +static bool ipa_validate_quota_stats_sram_size(u32 needed_len) +{ + u32 sram_size; + + /* Starting IPA4.5 Quota stats is split between Q6 and AP */ + + if (ipa3_ctx->ipa_hw_type < IPA_HW_v4_5) { + IPAERR("Not supported ipa_ver=%d\n", ipa3_ctx->ipa_hw_type); + return false; + } + + sram_size = IPA_MEM_PART(stats_quota_ap_size); + if (needed_len > sram_size) { + IPAERR("SRAM partition too small: %u needed %u\n", + sram_size, needed_len); + return false; + } + + return true; +} + int ipa_init_quota_stats(u32 pipe_bitmask) { struct ipahal_stats_init_pyld *pyld; @@ -301,9 +322,7 @@ int ipa_init_quota_stats(u32 pipe_bitmask) return -EPERM; } - if (pyld->len > IPA_MEM_PART(stats_quota_size)) { - IPAERR("SRAM partition too small: %d needed %d\n", - IPA_MEM_PART(stats_quota_size), pyld->len); + if (!ipa_validate_quota_stats_sram_size(pyld->len)) { ret = -EPERM; goto destroy_init_pyld; } @@ -356,7 +375,7 @@ int ipa_init_quota_stats(u32 pipe_bitmask) quota_base.offset = ipahal_get_reg_n_ofst(IPA_STAT_QUOTA_BASE_n, ipa3_ctx->ee); quota_base.value = ipa3_ctx->smem_restricted_bytes + - IPA_MEM_PART(stats_quota_ofst); + IPA_MEM_PART(stats_quota_ap_ofst); quota_base.value_mask = ~0; quota_base_pyld = ipahal_construct_imm_cmd(IPA_IMM_CMD_REGISTER_WRITE, "a_base, false); @@ -377,7 +396,7 @@ int ipa_init_quota_stats(u32 pipe_bitmask) cmd.size = pyld->len; cmd.system_addr = dma_address; cmd.local_addr = ipa3_ctx->smem_restricted_bytes + - IPA_MEM_PART(stats_quota_ofst); + IPA_MEM_PART(stats_quota_ap_ofst); cmd_pyld = ipahal_construct_imm_cmd( IPA_IMM_CMD_DMA_SHARED_MEM, &cmd, false); if (!cmd_pyld) { @@ -476,7 +495,7 @@ int ipa_get_quota_stats(struct ipa_quota_stats_all *out) cmd.size = mem.size; cmd.system_addr = mem.phys_base; cmd.local_addr = ipa3_ctx->smem_restricted_bytes + - IPA_MEM_PART(stats_quota_ofst) + offset.offset; + IPA_MEM_PART(stats_quota_ap_ofst) + offset.offset; cmd_pyld[num_cmd] = ipahal_construct_imm_cmd( IPA_IMM_CMD_DMA_SHARED_MEM, &cmd, false); if (!cmd_pyld[num_cmd]) { diff --git a/drivers/platform/msm/ipa/ipa_v3/ipa_i.h b/drivers/platform/msm/ipa/ipa_v3/ipa_i.h index dde7e7b80a34..af3590f90eac 100644 --- a/drivers/platform/msm/ipa/ipa_v3/ipa_i.h +++ b/drivers/platform/msm/ipa/ipa_v3/ipa_i.h @@ -2318,8 +2318,10 @@ struct ipa3_mem_partition { u32 uc_descriptor_ram_size; u32 pdn_config_ofst; u32 pdn_config_size; - u32 stats_quota_ofst; - u32 stats_quota_size; + u32 stats_quota_q6_ofst; + u32 stats_quota_q6_size; + u32 stats_quota_ap_ofst; + u32 stats_quota_ap_size; u32 stats_tethering_ofst; u32 stats_tethering_size; u32 stats_fnr_ofst; diff --git a/drivers/platform/msm/ipa/ipa_v3/ipa_qmi_service.c b/drivers/platform/msm/ipa/ipa_v3/ipa_qmi_service.c index a72a5b60fdaa..86b9fcfde5f7 100644 --- a/drivers/platform/msm/ipa/ipa_v3/ipa_qmi_service.c +++ b/drivers/platform/msm/ipa/ipa_v3/ipa_qmi_service.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2013-2019, The Linux Foundation. All rights reserved. + * Copyright (c) 2013-2020, The Linux Foundation. All rights reserved. */ #include @@ -589,10 +589,10 @@ static int ipa3_qmi_init_modem_send_sync_msg(void) } req.hw_stats_quota_base_addr_valid = true; req.hw_stats_quota_base_addr = - IPA_MEM_PART(stats_quota_ofst) + smem_restr_bytes; + IPA_MEM_PART(stats_quota_q6_ofst) + smem_restr_bytes; req.hw_stats_quota_size_valid = true; - req.hw_stats_quota_size = IPA_MEM_PART(stats_quota_size); + req.hw_stats_quota_size = IPA_MEM_PART(stats_quota_q6_size); req.hw_drop_stats_base_addr_valid = true; req.hw_drop_stats_base_addr = diff --git a/drivers/platform/msm/ipa/ipa_v3/ipa_utils.c b/drivers/platform/msm/ipa/ipa_v3/ipa_utils.c index d601277def63..17d3717352cb 100644 --- a/drivers/platform/msm/ipa/ipa_v3/ipa_utils.c +++ b/drivers/platform/msm/ipa/ipa_v3/ipa_utils.c @@ -3144,8 +3144,10 @@ static struct ipa3_mem_partition ipa_4_1_mem_part = { .uc_descriptor_ram_size = 0x400, .pdn_config_ofst = 0xbd8, .pdn_config_size = 0x50, - .stats_quota_ofst = 0xc30, - .stats_quota_size = 0x60, + .stats_quota_q6_ofst = 0xc30, + .stats_quota_q6_size = 0x60, + .stats_quota_ap_ofst = 0, + .stats_quota_ap_size = 0, .stats_tethering_ofst = 0xc90, .stats_tethering_size = 0x140, .stats_flt_v4_ofst = 0xdd0, @@ -3233,8 +3235,10 @@ static struct ipa3_mem_partition ipa_4_2_mem_part = { .uc_descriptor_ram_size = 0x0, .pdn_config_ofst = 0x9F8, .pdn_config_size = 0x50, - .stats_quota_ofst = 0xa50, - .stats_quota_size = 0x60, + .stats_quota_q6_ofst = 0xa50, + .stats_quota_q6_size = 0x60, + .stats_quota_ap_ofst = 0, + .stats_quota_ap_size = 0, .stats_tethering_ofst = 0xab0, .stats_tethering_size = 0x140, .stats_flt_v4_ofst = 0xbf0, @@ -3299,8 +3303,10 @@ static struct ipa3_mem_partition ipa_4_5_mem_part = { .apps_hdr_proc_ctx_size_ddr = 0x0, .nat_tbl_ofst = 0x1800, .nat_tbl_size = 0xd00, - .stats_quota_ofst = 0x2510, - .stats_quota_size = 0x78, + .stats_quota_q6_ofst = 0x2510, + .stats_quota_q6_size = 0x30, + .stats_quota_ap_ofst = 0x2540, + .stats_quota_ap_size = 0x48, .stats_tethering_ofst = 0x2588, .stats_tethering_size = 0x238, .stats_flt_v4_ofst = 0, @@ -3394,8 +3400,10 @@ static struct ipa3_mem_partition ipa_4_7_mem_part = { .nat_tbl_size = 0xd00, .pdn_config_ofst = 0x1be8, .pdn_config_size = 0x50, - .stats_quota_ofst = 0x1c40, - .stats_quota_size = 0x78, + .stats_quota_q6_ofst = 0x1c40, + .stats_quota_q6_size = 0x30, + .stats_quota_ap_ofst = 0x1c70, + .stats_quota_ap_size = 0x48, .stats_tethering_ofst = 0x1cb8, .stats_tethering_size = 0x238, .stats_flt_v4_ofst = 0, @@ -3485,8 +3493,10 @@ static struct ipa3_mem_partition ipa_4_9_mem_part = { .apps_hdr_proc_ctx_size_ddr = 0x0, .nat_tbl_ofst = 0x1800, .nat_tbl_size = 0xd00, - .stats_quota_ofst = 0x2510, - .stats_quota_size = 0x78, + .stats_quota_q6_ofst = 0x2510, + .stats_quota_q6_size = 0x30, + .stats_quota_ap_ofst = 0x2540, + .stats_quota_ap_size = 0x48, .stats_tethering_ofst = 0x2588, .stats_tethering_size = 0x238, .stats_flt_v4_ofst = 0, @@ -6131,13 +6141,23 @@ int ipa3_init_mem_partition(enum ipa_hw_type type) return -ENODEV; } - IPADBG("QUOTA STATS OFST 0x%x SIZE 0x%x\n", - IPA_MEM_PART(stats_quota_ofst), - IPA_MEM_PART(stats_quota_size)); + IPADBG("Q6 QUOTA STATS OFST 0x%x SIZE 0x%x\n", + IPA_MEM_PART(stats_quota_q6_ofst), + IPA_MEM_PART(stats_quota_q6_size)); - if (IPA_MEM_PART(stats_quota_ofst) & 7) { - IPAERR("QUOTA STATS OFST 0x%x is unaligned\n", - IPA_MEM_PART(stats_quota_ofst)); + if (IPA_MEM_PART(stats_quota_q6_ofst) & 7) { + IPAERR("Q6 QUOTA STATS OFST 0x%x is unaligned\n", + IPA_MEM_PART(stats_quota_q6_ofst)); + return -ENODEV; + } + + IPADBG("AP QUOTA STATS OFST 0x%x SIZE 0x%x\n", + IPA_MEM_PART(stats_quota_ap_ofst), + IPA_MEM_PART(stats_quota_ap_size)); + + if (IPA_MEM_PART(stats_quota_ap_ofst) & 7) { + IPAERR("AP QUOTA STATS OFST 0x%x is unaligned\n", + IPA_MEM_PART(stats_quota_ap_ofst)); return -ENODEV; }