diff options
author | qctecmdr <qctecmdr@localhost> | 2019-09-11 00:55:45 -0700 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2019-09-11 00:55:45 -0700 |
commit | 8896aca5917243cf1827dcf7eb9b4b5822141fe1 (patch) | |
tree | f61417e271258c8f36a6734d5cbb29b951d917af | |
parent | e6cb6dc5b42d18eeeaefe3df590f4b8d085cfbf0 (diff) | |
parent | 61ef3bf5fc87030a108ccd0631ccf183c52b1784 (diff) | |
download | android_vendor_qcom_opensource_data-ipa-cfg-mgr-8896aca5917243cf1827dcf7eb9b4b5822141fe1.tar.gz android_vendor_qcom_opensource_data-ipa-cfg-mgr-8896aca5917243cf1827dcf7eb9b4b5822141fe1.tar.bz2 android_vendor_qcom_opensource_data-ipa-cfg-mgr-8896aca5917243cf1827dcf7eb9b4b5822141fe1.zip |
Merge "ipacm: support hasting stats and quota"
-rw-r--r-- | ipacm/inc/IPACM_Config.h | 5 | ||||
-rw-r--r-- | ipacm/inc/IPACM_Filtering.h | 4 | ||||
-rw-r--r-- | ipacm/inc/IPACM_Routing.h | 4 | ||||
-rw-r--r-- | ipacm/src/IPACM_Config.cpp | 4 | ||||
-rw-r--r-- | ipacm/src/IPACM_Filtering.cpp | 236 | ||||
-rw-r--r-- | ipacm/src/IPACM_Iface.cpp | 36 | ||||
-rw-r--r-- | ipacm/src/IPACM_Lan.cpp | 160 | ||||
-rw-r--r-- | ipacm/src/IPACM_Main.cpp | 59 | ||||
-rw-r--r-- | ipacm/src/IPACM_Routing.cpp | 109 | ||||
-rw-r--r-- | ipacm/src/IPACM_Wan.cpp | 241 | ||||
-rw-r--r-- | ipacm/src/IPACM_Wlan.cpp | 31 |
11 files changed, 853 insertions, 36 deletions
diff --git a/ipacm/inc/IPACM_Config.h b/ipacm/inc/IPACM_Config.h index af1b616..9230f7d 100644 --- a/ipacm/inc/IPACM_Config.h +++ b/ipacm/inc/IPACM_Config.h @@ -147,6 +147,11 @@ public: bool isMCC_Mode; + /* IPA_HW_FNR_STATS */ + bool hw_fnr_stats_support; + int hw_counter_offset; + int sw_counter_offset; + /* To return the instance */ static IPACM_Config* GetInstance(); diff --git a/ipacm/inc/IPACM_Filtering.h b/ipacm/inc/IPACM_Filtering.h index 5ceab75..428c21a 100644 --- a/ipacm/inc/IPACM_Filtering.h +++ b/ipacm/inc/IPACM_Filtering.h @@ -56,6 +56,10 @@ public: ~IPACM_Filtering(); bool AddFilteringRule(struct ipa_ioc_add_flt_rule const *ruleTable); bool AddFilteringRuleAfter(struct ipa_ioc_add_flt_rule_after const *ruleTable); +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + bool AddFilteringRule_hw_index(struct ipa_ioc_add_flt_rule *ruleTable, int hw_counter_index); + bool AddFilteringRuleAfter_hw_index(struct ipa_ioc_add_flt_rule_after *ruleTable, int hw_counter_index); +#endif //IPA_IOCTL_SET_FNR_COUNTER_INFO bool DeleteFilteringRule(struct ipa_ioc_del_flt_rule *ruleTable); bool Commit(enum ipa_ip_type ip); bool Reset(enum ipa_ip_type ip); diff --git a/ipacm/inc/IPACM_Routing.h b/ipacm/inc/IPACM_Routing.h index b5ffabc..663076b 100644 --- a/ipacm/inc/IPACM_Routing.h +++ b/ipacm/inc/IPACM_Routing.h @@ -55,6 +55,10 @@ public: ~IPACM_Routing(); bool AddRoutingRule(struct ipa_ioc_add_rt_rule *ruleTable); + +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + bool AddRoutingRule_hw_index(struct ipa_ioc_add_rt_rule *ruleTable, int hw_counter_index); +#endif //IPA_IOCTL_SET_FNR_COUNTER_INFO bool DeleteRoutingRule(struct ipa_ioc_del_rt_rule *ruleTable); bool Commit(enum ipa_ip_type ip); diff --git a/ipacm/src/IPACM_Config.cpp b/ipacm/src/IPACM_Config.cpp index bfacd7c..781f1cb 100644 --- a/ipacm/src/IPACM_Config.cpp +++ b/ipacm/src/IPACM_Config.cpp @@ -143,6 +143,10 @@ IPACM_Config::IPACM_Config() ipa_bridge_enable = false; isMCC_Mode = false; ipa_max_valid_rm_entry = 0; + /* IPA_HW_FNR_STATS */ + hw_fnr_stats_support = false; + hw_counter_offset = 0; + sw_counter_offset = 0; memset(&rt_tbl_default_v4, 0, sizeof(rt_tbl_default_v4)); memset(&rt_tbl_lan_v4, 0, sizeof(rt_tbl_lan_v4)); diff --git a/ipacm/src/IPACM_Filtering.cpp b/ipacm/src/IPACM_Filtering.cpp index a5c2bf5..a158d74 100644 --- a/ipacm/src/IPACM_Filtering.cpp +++ b/ipacm/src/IPACM_Filtering.cpp @@ -116,6 +116,242 @@ bool IPACM_Filtering::AddFilteringRule(struct ipa_ioc_add_flt_rule const *ruleTa return true; } +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO +bool IPACM_Filtering::AddFilteringRule_hw_index(struct ipa_ioc_add_flt_rule *ruleTable, int hw_counter_index) +{ + int retval=0, cnt = 0, len = 0; + struct ipa_ioc_add_flt_rule_v2 *ruleTable_v2; + struct ipa_flt_rule_add_v2 flt_rule_entry; + bool ret = true; + + IPACMDBG("Printing filter add attributes\n"); + IPACMDBG("ip type: %d\n", ruleTable->ip); + IPACMDBG("Number of rules: %d\n", ruleTable->num_rules); + IPACMDBG("End point: %d and global value: %d\n", ruleTable->ep, ruleTable->global); + IPACMDBG("commit value: %d\n", ruleTable->commit); + + /* change to v2 format*/ + len = sizeof(struct ipa_ioc_add_flt_rule_v2); + ruleTable_v2 = (struct ipa_ioc_add_flt_rule_v2*)malloc(len); + if (ruleTable_v2 == NULL) + { + IPACMERR("Error Locate ipa_ioc_add_flt_rule_v2 memory...\n"); + return false; + } + memset(ruleTable_v2, 0, len); + ruleTable_v2->rules = (uint64_t)calloc(ruleTable->num_rules, sizeof(struct ipa_flt_rule_add_v2)); + if (!ruleTable_v2->rules) { + IPACMERR("Failed to allocate memory for filtering rules\n"); + ret = false; + goto fail_tbl; + } + + ruleTable_v2->commit = ruleTable->commit; + ruleTable_v2->ep = ruleTable->ep; + ruleTable_v2->global = ruleTable->global; + ruleTable_v2->ip = ruleTable->ip; + ruleTable_v2->num_rules = ruleTable->num_rules; + ruleTable_v2->flt_rule_size = sizeof(struct ipa_flt_rule_add_v2); + + for (cnt=0; cnt < ruleTable->num_rules; cnt++) + { + memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add_v2)); + flt_rule_entry.at_rear = ruleTable->rules[cnt].at_rear; + flt_rule_entry.rule.retain_hdr = ruleTable->rules[cnt].rule.retain_hdr; + flt_rule_entry.rule.to_uc = ruleTable->rules[cnt].rule.to_uc; + flt_rule_entry.rule.action = ruleTable->rules[cnt].rule.action; + flt_rule_entry.rule.rt_tbl_hdl = ruleTable->rules[cnt].rule.rt_tbl_hdl; + flt_rule_entry.rule.rt_tbl_idx = ruleTable->rules[cnt].rule.rt_tbl_idx; + flt_rule_entry.rule.eq_attrib_type = ruleTable->rules[cnt].rule.eq_attrib_type; + flt_rule_entry.rule.max_prio = ruleTable->rules[cnt].rule.max_prio; + flt_rule_entry.rule.hashable = ruleTable->rules[cnt].rule.hashable; + flt_rule_entry.rule.rule_id = ruleTable->rules[cnt].rule.rule_id; + flt_rule_entry.rule.set_metadata = ruleTable->rules[cnt].rule.set_metadata; + flt_rule_entry.rule.pdn_idx = ruleTable->rules[cnt].rule.pdn_idx; + memcpy(&flt_rule_entry.rule.eq_attrib, + &ruleTable->rules[cnt].rule.eq_attrib, + sizeof(flt_rule_entry.rule.eq_attrib)); + memcpy(&flt_rule_entry.rule.attrib, + &ruleTable->rules[cnt].rule.attrib, + sizeof(flt_rule_entry.rule.attrib)); + IPACMDBG("Filter rule:%d attrib mask: 0x%x\n", cnt, + ruleTable->rules[cnt].rule.attrib.attrib_mask); + /* 0 means disable hw-counter-sats */ + if (hw_counter_index != 0) + { + flt_rule_entry.rule.enable_stats = 1; + flt_rule_entry.rule.cnt_idx = hw_counter_index; + } + + /* copy to v2 table*/ + memcpy((void *)(ruleTable_v2->rules + (cnt * sizeof(struct ipa_flt_rule_add_v2))), + &flt_rule_entry, sizeof(flt_rule_entry)); + } + + retval = ioctl(fd, IPA_IOC_ADD_FLT_RULE_V2, ruleTable_v2); + if (retval != 0) + { + IPACMERR("Failed adding Filtering rule %pK\n", ruleTable_v2); + PERROR("unable to add filter rule:"); + + for (int cnt = 0; cnt < ruleTable_v2->num_rules; cnt++) + { + if (((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0) + { + IPACMERR("Adding Filter rule:%d failed with status:%d\n", + cnt, ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status); + } + } + ret = false; + goto fail_rule; + } + + /* copy results from v2 to v1 format */ + for (int cnt = 0; cnt < ruleTable->num_rules; cnt++) + { + /* copy status to v1 format */ + ruleTable->rules[cnt].status = ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status; + ruleTable->rules[cnt].flt_rule_hdl = ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].flt_rule_hdl; + + if(((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0) + { + IPACMERR("Adding Filter rule:%d failed with status:%d\n", + cnt, ((struct ipa_flt_rule_add_v2 *) ruleTable_v2->rules)[cnt].status); + } + } + + IPACMDBG("Added Filtering rule %pK\n", ruleTable_v2); + +fail_rule: + if((void *)ruleTable_v2->rules != NULL) + free((void *)ruleTable_v2->rules); +fail_tbl: + if (ruleTable_v2 != NULL) + free(ruleTable_v2); + return ret; +} + +bool IPACM_Filtering::AddFilteringRuleAfter_hw_index(struct ipa_ioc_add_flt_rule_after *ruleTable, int hw_counter_index) +{ + bool ret = true; +#ifdef FEATURE_IPA_V3 + int retval=0, cnt = 0, len = 0; + struct ipa_ioc_add_flt_rule_after_v2 *ruleTable_v2; + struct ipa_flt_rule_add_v2 flt_rule_entry; + + IPACMDBG("Printing filter add attributes\n"); + IPACMDBG("ep: %d\n", ruleTable->ep); + IPACMDBG("ip type: %d\n", ruleTable->ip); + IPACMDBG("Number of rules: %d\n", ruleTable->num_rules); + IPACMDBG("add_after_hdl: %d\n", ruleTable->add_after_hdl); + IPACMDBG("commit value: %d\n", ruleTable->commit); + + /* change to v2 format*/ + len = sizeof(struct ipa_ioc_add_flt_rule_after_v2); + ruleTable_v2 = (struct ipa_ioc_add_flt_rule_after_v2*)malloc(len); + if (ruleTable_v2 == NULL) + { + IPACMERR("Error Locate ipa_ioc_add_flt_rule_after_v2 memory...\n"); + return false; + } + memset(ruleTable_v2, 0, len); + ruleTable_v2->rules = (uint64_t)calloc(ruleTable->num_rules, sizeof(struct ipa_flt_rule_add_v2)); + if (!ruleTable_v2->rules) { + IPACMERR("Failed to allocate memory for filtering rules\n"); + ret = false; + goto fail_tbl; + } + + ruleTable_v2->commit = ruleTable->commit; + ruleTable_v2->ep = ruleTable->ep; + ruleTable_v2->ip = ruleTable->ip; + ruleTable_v2->num_rules = ruleTable->num_rules; + ruleTable_v2->add_after_hdl = ruleTable->add_after_hdl; + ruleTable_v2->flt_rule_size = sizeof(struct ipa_flt_rule_add_v2); + + for (cnt=0; cnt < ruleTable->num_rules; cnt++) + { + memset(&flt_rule_entry, 0, sizeof(struct ipa_flt_rule_add_v2)); + flt_rule_entry.at_rear = ruleTable->rules[cnt].at_rear; + flt_rule_entry.rule.retain_hdr = ruleTable->rules[cnt].rule.retain_hdr; + flt_rule_entry.rule.to_uc = ruleTable->rules[cnt].rule.to_uc; + flt_rule_entry.rule.action = ruleTable->rules[cnt].rule.action; + flt_rule_entry.rule.rt_tbl_hdl = ruleTable->rules[cnt].rule.rt_tbl_hdl; + flt_rule_entry.rule.rt_tbl_idx = ruleTable->rules[cnt].rule.rt_tbl_idx; + flt_rule_entry.rule.eq_attrib_type = ruleTable->rules[cnt].rule.eq_attrib_type; + flt_rule_entry.rule.max_prio = ruleTable->rules[cnt].rule.max_prio; + flt_rule_entry.rule.hashable = ruleTable->rules[cnt].rule.hashable; + flt_rule_entry.rule.rule_id = ruleTable->rules[cnt].rule.rule_id; + flt_rule_entry.rule.set_metadata = ruleTable->rules[cnt].rule.set_metadata; + flt_rule_entry.rule.pdn_idx = ruleTable->rules[cnt].rule.pdn_idx; + memcpy(&flt_rule_entry.rule.eq_attrib, + &ruleTable->rules[cnt].rule.eq_attrib, + sizeof(flt_rule_entry.rule.eq_attrib)); + memcpy(&flt_rule_entry.rule.attrib, + &ruleTable->rules[cnt].rule.attrib, + sizeof(flt_rule_entry.rule.attrib)); + IPACMDBG("Filter rule:%d attrib mask: 0x%x\n", cnt, + ruleTable->rules[cnt].rule.attrib.attrib_mask); + /* 0 means disable hw-counter-sats */ + if (hw_counter_index != 0) + { + flt_rule_entry.rule.enable_stats = 1; + flt_rule_entry.rule.cnt_idx = hw_counter_index; + } + + /* copy to v2 table*/ + memcpy((void *)(ruleTable_v2->rules + (cnt * sizeof(struct ipa_flt_rule_add_v2))), + &flt_rule_entry, sizeof(flt_rule_entry)); + } + + retval = ioctl(fd, IPA_IOC_ADD_FLT_RULE_AFTER_V2, ruleTable_v2); + if (retval != 0) + { + IPACMERR("Failed adding Filtering rule %pK\n", ruleTable_v2); + PERROR("unable to add filter rule:"); + + for (int cnt = 0; cnt < ruleTable_v2->num_rules; cnt++) + { + if (((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0) + { + IPACMERR("Adding Filter rule:%d failed with status:%d\n", + cnt, ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status); + } + } + ret = false; + goto fail_rule; + } + + /* copy results from v2 to v1 format */ + for (int cnt = 0; cnt < ruleTable->num_rules; cnt++) + { + /* copy status to v1 format */ + ruleTable->rules[cnt].status = ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status; + ruleTable->rules[cnt].flt_rule_hdl = ((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].flt_rule_hdl; + + if(((struct ipa_flt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0) + { + IPACMERR("Adding Filter rule:%d failed with status:%d\n", + cnt, ((struct ipa_flt_rule_add_v2 *) ruleTable_v2->rules)[cnt].status); + } + } + + IPACMDBG("Added Filtering rule %pK\n", ruleTable_v2); + +fail_rule: + if((void *)ruleTable_v2->rules != NULL) + free((void *)ruleTable_v2->rules); +fail_tbl: + if (ruleTable_v2 != NULL) + free(ruleTable_v2); +#else + if (ruleTable) + IPACMERR("Not support adding Filtering rule %pK\n", ruleTable); +#endif + return ret; +} +#endif //IPA_IOCTL_SET_FNR_COUNTER_INFO + bool IPACM_Filtering::AddFilteringRuleAfter(struct ipa_ioc_add_flt_rule_after const *ruleTable) { #ifdef FEATURE_IPA_V3 diff --git a/ipacm/src/IPACM_Iface.cpp b/ipacm/src/IPACM_Iface.cpp index 55e19ba..05dd6ca 100644 --- a/ipacm/src/IPACM_Iface.cpp +++ b/ipacm/src/IPACM_Iface.cpp @@ -639,6 +639,7 @@ int IPACM_Iface::init_fl_rule(ipa_ip_type iptype) int res = IPACM_SUCCESS, len = 0; struct ipa_flt_rule_add flt_rule_entry; ipa_ioc_add_flt_rule *m_pFilteringTable; + bool result; /* Adding this hack because WLAN may not registered for Rx-endpoint, other ifaces will always have*/ const char *dev_wlan0="wlan0"; @@ -745,7 +746,25 @@ int IPACM_Iface::init_fl_rule(ipa_ip_type iptype) #endif memcpy(&(m_pFilteringTable->rules[2]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + } else if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else + { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + + if (result == false) { IPACMERR("Error Adding Filtering rule, aborting...\n"); res = IPACM_FAILURE; @@ -927,7 +946,20 @@ int IPACM_Iface::init_fl_rule(ipa_ip_type iptype) memcpy(&(m_pFilteringTable->rules[7]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); #endif - if (m_filtering.AddFilteringRule(m_pFilteringTable) == false) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + + if (result == false) { IPACMERR("Error Adding Filtering rule, aborting...\n"); res = IPACM_FAILURE; diff --git a/ipacm/src/IPACM_Lan.cpp b/ipacm/src/IPACM_Lan.cpp index 9dfac2e..fd67ea4 100644 --- a/ipacm/src/IPACM_Lan.cpp +++ b/ipacm/src/IPACM_Lan.cpp @@ -1522,6 +1522,7 @@ int IPACM_Lan::handle_private_subnet(ipa_ip_type iptype) { struct ipa_flt_rule_add flt_rule_entry; int i; + bool result; ipa_ioc_add_flt_rule *m_pFilteringTable; @@ -1585,7 +1586,20 @@ int IPACM_Lan::handle_private_subnet(ipa_ip_type iptype) IPACMDBG_H("Loop %d 5\n", i); } - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + + if (result == false) { IPACMERR("Error Adding RuleTable(0) to Filtering, aborting...\n"); free(m_pFilteringTable); @@ -1614,6 +1628,7 @@ int IPACM_Lan::handle_wan_up(ipa_ip_type ip_type) struct ipa_flt_rule_add flt_rule_entry; int len = 0; ipa_ioc_add_flt_rule *m_pFilteringTable; + bool result; IPACMDBG_H("set WAN interface as default filter rule\n"); @@ -1688,7 +1703,20 @@ int IPACM_Lan::handle_wan_up(ipa_ip_type ip_type) flt_rule_entry.rule.attrib.u.v4.src_addr = prefix[IPA_IP_v4].v4Addr; #endif memcpy(&m_pFilteringTable->rules[0], &flt_rule_entry, sizeof(flt_rule_entry)); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) + +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + if (result == false) { IPACMERR("Error Adding RuleTable(0) to Filtering, aborting...\n"); free(m_pFilteringTable); @@ -1777,7 +1805,21 @@ int IPACM_Lan::handle_wan_up(ipa_ip_type ip_type) #endif memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) + +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + + if (result == false) { IPACMERR("Error Adding Filtering rule, aborting...\n"); free(m_pFilteringTable); @@ -3238,6 +3280,7 @@ int IPACM_Lan::handle_uplink_filter_rule(ipacm_ext_prop *prop, ipa_ip_type iptyp int i, index, eq_index; uint32_t value = 0; uint8_t qmap_id; + bool result; IPACMDBG_H("Set modem UL flt rules\n"); @@ -3522,7 +3565,20 @@ int IPACM_Lan::handle_uplink_filter_rule(ipacm_ext_prop *prop, ipa_ip_type iptyp goto fail; } - if(false == m_filtering.AddFilteringRule(pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRule_hw_index(pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else { + result = m_filtering.AddFilteringRule(pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(pFilteringTable); +#endif + + if(result == false) { IPACMERR("Error Adding RuleTable to Filtering, aborting...\n"); ret = IPACM_FAILURE; @@ -3818,6 +3874,7 @@ int IPACM_Lan::install_ipv4_icmp_flt_rule() int len; struct ipa_ioc_add_flt_rule* flt_rule; struct ipa_flt_rule_add flt_rule_entry; + bool result; if(rx_prop != NULL) { @@ -3854,7 +3911,20 @@ int IPACM_Lan::install_ipv4_icmp_flt_rule() flt_rule_entry.rule.attrib.u.v4.protocol = (uint8_t)IPACM_FIREWALL_IPPROTO_ICMP; memcpy(&(flt_rule->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (m_filtering.AddFilteringRule(flt_rule) == false) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRule_hw_index(flt_rule, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else { + result = m_filtering.AddFilteringRule(flt_rule); + } +#else + result = m_filtering.AddFilteringRule(flt_rule); +#endif + + if (result == false) { IPACMERR("Error Adding Filtering rule, aborting...\n"); free(flt_rule); @@ -3877,6 +3947,7 @@ int IPACM_Lan::install_ipv6_icmp_flt_rule() int len; struct ipa_ioc_add_flt_rule* flt_rule; struct ipa_flt_rule_add flt_rule_entry; + bool result; if(rx_prop != NULL) { @@ -3912,7 +3983,20 @@ int IPACM_Lan::install_ipv6_icmp_flt_rule() flt_rule_entry.rule.attrib.u.v6.next_hdr = (uint8_t)IPACM_FIREWALL_IPPROTO_ICMP6; memcpy(&(flt_rule->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (m_filtering.AddFilteringRule(flt_rule) == false) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRule_hw_index(flt_rule, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else { + result = m_filtering.AddFilteringRule(flt_rule); + } +#else + result = m_filtering.AddFilteringRule(flt_rule); +#endif + + if (result == false) { IPACMERR("Error Adding Filtering rule, aborting...\n"); free(flt_rule); @@ -3945,6 +4029,7 @@ int IPACM_Lan::add_dummy_private_subnet_flt_rule(ipa_ip_type iptype) int i, len, res = IPACM_SUCCESS; struct ipa_flt_rule_add flt_rule; ipa_ioc_add_flt_rule* pFilteringTable; + bool result; len = sizeof(struct ipa_ioc_add_flt_rule) + IPA_MAX_PRIVATE_SUBNET_ENTRIES * sizeof(struct ipa_flt_rule_add); @@ -3988,7 +4073,20 @@ int IPACM_Lan::add_dummy_private_subnet_flt_rule(ipa_ip_type iptype) memcpy(&(pFilteringTable->rules[i]), &flt_rule, sizeof(struct ipa_flt_rule_add)); } - if (false == m_filtering.AddFilteringRule(pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRule_hw_index(pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else { + result = m_filtering.AddFilteringRule(pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(pFilteringTable); +#endif + + if (result == false) { IPACMERR("Error adding dummy private subnet v4 flt rule\n"); res = IPACM_FAILURE; @@ -4113,6 +4211,7 @@ int IPACM_Lan::install_ipv6_prefix_flt_rule(uint32_t* prefix) int len; struct ipa_ioc_add_flt_rule* flt_rule; struct ipa_flt_rule_add flt_rule_entry; + bool result; if(rx_prop != NULL) { @@ -4155,7 +4254,20 @@ int IPACM_Lan::install_ipv6_prefix_flt_rule(uint32_t* prefix) flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[3] = 0x0; memcpy(&(flt_rule->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (m_filtering.AddFilteringRule(flt_rule) == false) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRule_hw_index(flt_rule, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else { + result = m_filtering.AddFilteringRule(flt_rule); + } +#else + result = m_filtering.AddFilteringRule(flt_rule); +#endif + + if (result == false) { IPACMERR("Error Adding Filtering rule, aborting...\n"); free(flt_rule); @@ -4998,6 +5110,7 @@ int IPACM_Lan::eth_bridge_add_flt_rule(uint8_t *mac, uint32_t rt_tbl_hdl, ipa_ip int len; struct ipa_flt_rule_add flt_rule_entry; struct ipa_ioc_add_flt_rule_after *pFilteringTable = NULL; + bool result; if (rx_prop == NULL || tx_prop == NULL) { @@ -5046,7 +5159,19 @@ int IPACM_Lan::eth_bridge_add_flt_rule(uint8_t *mac, uint32_t rt_tbl_hdl, ipa_ip memset(flt_rule_entry.rule.attrib.dst_mac_addr_mask, 0xFF, sizeof(flt_rule_entry.rule.attrib.dst_mac_addr_mask)); memcpy(&(pFilteringTable->rules[0]), &flt_rule_entry, sizeof(flt_rule_entry)); - if (false == m_filtering.AddFilteringRuleAfter(pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRuleAfter_hw_index(pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else { + result = m_filtering.AddFilteringRuleAfter(pFilteringTable); + } +#else + result = m_filtering.AddFilteringRuleAfter(pFilteringTable); +#endif + if (result == false) { IPACMERR("Failed to add client filtering rules.\n"); res = IPACM_FAILURE; @@ -5924,6 +6049,7 @@ int IPACM_Lan::add_tcp_syn_flt_rule(ipa_ip_type iptype) int len; struct ipa_flt_rule_add flt_rule_entry; ipa_ioc_add_flt_rule *m_pFilteringTable; + bool result; if(rx_prop == NULL) { @@ -5968,8 +6094,20 @@ int IPACM_Lan::add_tcp_syn_flt_rule(ipa_ip_type iptype) } memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(flt_rule_entry)); +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(ipa_if_cate == WLAN_IF && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif - if(false == m_filtering.AddFilteringRule(m_pFilteringTable)) + if(result == false) { IPACMERR("Error Adding RuleTable(0) to Filtering, aborting...\n"); free(m_pFilteringTable); @@ -6029,7 +6167,7 @@ int IPACM_Lan::add_tcp_syn_flt_rule_l2tp(ipa_ip_type inner_ip_type) } memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(flt_rule_entry)); - + /* no need for hw counters */ if(false == m_filtering.AddFilteringRule(m_pFilteringTable)) { IPACMERR("Error Adding RuleTable(0) to Filtering, aborting...\n"); diff --git a/ipacm/src/IPACM_Main.cpp b/ipacm/src/IPACM_Main.cpp index eef15d9..afdf26d 100644 --- a/ipacm/src/IPACM_Main.cpp +++ b/ipacm/src/IPACM_Main.cpp @@ -113,6 +113,12 @@ int ipa_reset(); int ipa_query_wlan_client(); #endif + +/* support ipa-hw-index-counters */ +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO +int ipa_reset_hw_index_counter(); +#endif + #ifdef FEATURE_IPACM_HAL IPACM_OffloadManager* OffloadMng; HAL *hal; @@ -932,6 +938,11 @@ int main(int argc, char **argv) ipa_reset(); #endif +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + IPACMDBG_H("Configure IPA-HW index-counter\n"); + ipa_reset_hw_index_counter(); +#endif + neigh = new IPACM_Neighbor(); ifacemgr = new IPACM_IfaceManager(); #ifdef FEATURE_IPACM_HAL @@ -1160,3 +1171,51 @@ int ipa_reset() return IPACM_SUCCESS; } #endif + +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO +int ipa_reset_hw_index_counter() +{ + int fd = -1; + struct ipa_ioc_flt_rt_counter_alloc fnr_counters; + struct ipa_ioc_fnr_index_info fnr_info; + + if ((fd = open(IPA_DEVICE_NAME, O_RDWR)) < 0) { + IPACMERR("Failed opening %s.\n", IPA_DEVICE_NAME); + return IPACM_FAILURE; + } + + memset(&fnr_counters, 0, sizeof(fnr_counters)); + fnr_counters.hw_counter.num_counters = 4; + fnr_counters.hw_counter.allow_less = false; + fnr_counters.sw_counter.num_counters = 4; + fnr_counters.sw_counter.allow_less = false; + IPACMDBG_H("Allocating %d hw counters and %d sw counters\n", + fnr_counters.hw_counter.num_counters, fnr_counters.sw_counter.num_counters); + + if (ioctl(fd, IPA_IOC_FNR_COUNTER_ALLOC, &fnr_counters) < 0) { + IPACMERR("IPA_IOC_FNR_COUNTER_ALLOC call failed: %s \n", strerror(errno)); + close(fd); + return IPACM_FAILURE; + } + + IPACMDBG_H("hw-counter start offset %d, sw-counter start offset %d\n", + fnr_counters.hw_counter.start_id, fnr_counters.sw_counter.start_id); + IPACM_Iface::ipacmcfg->hw_fnr_stats_support = true; + IPACM_Iface::ipacmcfg->hw_counter_offset = fnr_counters.hw_counter.start_id; + IPACM_Iface::ipacmcfg->sw_counter_offset = fnr_counters.sw_counter.start_id; + + /* set FNR counter info */ + memset(&fnr_info, 0, sizeof(fnr_info)); + fnr_info.hw_counter_offset = fnr_counters.hw_counter.start_id; + fnr_info.sw_counter_offset = fnr_counters.sw_counter.start_id; + + if (ioctl(fd, IPA_IOC_SET_FNR_COUNTER_INFO, &fnr_info) < 0) { + IPACMERR("IPA_IOC_SET_FNR_COUNTER_INFO call failed: %s \n", strerror(errno)); + close(fd); + return IPACM_FAILURE; + } + + close(fd); + return IPACM_SUCCESS; +} +#endif diff --git a/ipacm/src/IPACM_Routing.cpp b/ipacm/src/IPACM_Routing.cpp index 2a2555a..654a0f9 100644 --- a/ipacm/src/IPACM_Routing.cpp +++ b/ipacm/src/IPACM_Routing.cpp @@ -112,6 +112,115 @@ bool IPACM_Routing::AddRoutingRule(struct ipa_ioc_add_rt_rule *ruleTable) return true; } +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO +bool IPACM_Routing::AddRoutingRule_hw_index(struct ipa_ioc_add_rt_rule *ruleTable, int hw_counter_index) +{ + int retval = 0, cnt = 0, len = 0; + struct ipa_ioc_add_rt_rule_v2 *ruleTable_v2; + struct ipa_rt_rule_add_v2 rt_rule_entry; + bool ret = true; + + IPACMDBG("Printing routing add attributes\n"); + IPACMDBG("ip type: %d\n", ruleTable->ip); + IPACMDBG("rt tbl type: %s\n", ruleTable->rt_tbl_name); + IPACMDBG("Number of rules: %d\n", ruleTable->num_rules); + IPACMDBG("commit value: %d\n", ruleTable->commit); + + /* change to v2 format*/ + len = sizeof(struct ipa_ioc_add_rt_rule_v2); + ruleTable_v2 = (struct ipa_ioc_add_rt_rule_v2*)malloc(len); + if (ruleTable_v2 == NULL) + { + IPACMERR("Error Locate ipa_ioc_add_rt_rule_v2 memory...\n"); + return false; + } + memset(ruleTable_v2, 0, len); + ruleTable_v2->rules = (uint64_t)calloc(ruleTable->num_rules, sizeof(struct ipa_rt_rule_add_v2)); + if (!ruleTable_v2->rules) { + IPACMERR("Failed to allocate memory for routing rules\n"); + ret = false; + goto fail_tbl; + } + + ruleTable_v2->commit = ruleTable->commit; + ruleTable_v2->ip = ruleTable->ip; + ruleTable_v2->num_rules = ruleTable->num_rules; + ruleTable_v2->rule_add_size = sizeof(struct ipa_rt_rule_add_v2); + memcpy(ruleTable_v2->rt_tbl_name, + ruleTable->rt_tbl_name, + sizeof(ruleTable_v2->rt_tbl_name)); + + for (cnt=0; cnt < ruleTable->num_rules; cnt++) + { + memset(&rt_rule_entry, 0, sizeof(struct ipa_rt_rule_add_v2)); + rt_rule_entry.at_rear = ruleTable->rules[cnt].at_rear; + rt_rule_entry.rule.dst = ruleTable->rules[cnt].rule.dst; + rt_rule_entry.rule.hdr_hdl = ruleTable->rules[cnt].rule.hdr_hdl; + rt_rule_entry.rule.hdr_proc_ctx_hdl = ruleTable->rules[cnt].rule.hdr_proc_ctx_hdl; + rt_rule_entry.rule.max_prio = ruleTable->rules[cnt].rule.max_prio; + rt_rule_entry.rule.hashable = ruleTable->rules[cnt].rule.hashable; + rt_rule_entry.rule.retain_hdr = ruleTable->rules[cnt].rule.retain_hdr; + rt_rule_entry.rule.coalesce = ruleTable->rules[cnt].rule.coalesce; + memcpy(&rt_rule_entry.rule.attrib, + &ruleTable->rules[cnt].rule.attrib, + sizeof(rt_rule_entry.rule.attrib)); + IPACMDBG("RT rule:%d attrib mask: 0x%x\n", cnt, + ruleTable->rules[cnt].rule.attrib.attrib_mask); + /* 0 means disable hw-counter-sats */ + if (hw_counter_index != 0) + { + rt_rule_entry.rule.enable_stats = 1; + rt_rule_entry.rule.cnt_idx = hw_counter_index; + } + + /* copy to v2 table*/ + memcpy((void *)(ruleTable_v2->rules + (cnt * sizeof(struct ipa_rt_rule_add_v2))), + &rt_rule_entry, sizeof(rt_rule_entry)); + } + + retval = ioctl(m_fd, IPA_IOC_ADD_RT_RULE_V2, ruleTable_v2); + if (retval != 0) + { + IPACMERR("Failed adding Routing rule %pK\n", ruleTable_v2); + PERROR("unable to add routing rule:"); + + for (int cnt = 0; cnt < ruleTable_v2->num_rules; cnt++) + { + if (((struct ipa_rt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0) + { + IPACMERR("Adding Routing rule:%d failed with status:%d\n", + cnt, ((struct ipa_rt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status); + } + } + ret = false; + goto fail_rule; + } + + /* copy results from v2 to v1 format */ + for (int cnt = 0; cnt < ruleTable->num_rules; cnt++) + { + /* copy status to v1 format */ + ruleTable->rules[cnt].status = ((struct ipa_rt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status; + ruleTable->rules[cnt].rt_rule_hdl = ((struct ipa_rt_rule_add_v2 *)ruleTable_v2->rules)[cnt].rt_rule_hdl; + + if(((struct ipa_rt_rule_add_v2 *)ruleTable_v2->rules)[cnt].status != 0) + { + IPACMERR("Adding Routing rule:%d failed with status:%d\n", + cnt, ((struct ipa_rt_rule_add_v2 *) ruleTable_v2->rules)[cnt].status); + } + } + IPACMDBG("Added Routing rule %pK\n", ruleTable_v2); +fail_rule: + if((void *)ruleTable_v2->rules != NULL) + free((void *)ruleTable_v2->rules); +fail_tbl: + if (ruleTable_v2 != NULL) + free(ruleTable_v2); + return ret; +} +#endif //IPA_IOCTL_SET_FNR_COUNTER_INFO + + bool IPACM_Routing::DeleteRoutingRule(struct ipa_ioc_del_rt_rule *ruleTable) { int retval = 0; diff --git a/ipacm/src/IPACM_Wan.cpp b/ipacm/src/IPACM_Wan.cpp index 498f3b6..7638765 100644 --- a/ipacm/src/IPACM_Wan.cpp +++ b/ipacm/src/IPACM_Wan.cpp @@ -227,6 +227,7 @@ int IPACM_Wan::handle_addr_evt(ipacm_event_data_addr *data) struct ipa_ioc_add_flt_rule *flt_rule; struct ipa_flt_rule_add flt_rule_entry; struct ipa_ioc_get_hdr hdr; + bool result; const int NUM_RULES = 1; uint32_t num_ipv6_addr; @@ -498,8 +499,20 @@ int IPACM_Wan::handle_addr_evt(ipacm_event_data_addr *data) flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[2] = 0xFFFFFFFF; flt_rule_entry.rule.attrib.u.v6.dst_addr_mask[3] = 0xFFFFFFFF; memcpy(&(flt_rule->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(flt_rule, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(flt_rule); + } +#else + result = m_filtering.AddFilteringRule(flt_rule); +#endif - if (m_filtering.AddFilteringRule(flt_rule) == false) + if (result == false) { IPACMERR("Error Adding Filtering rule, aborting...\n"); free(flt_rule); @@ -1759,6 +1772,7 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) const int NUM = 1; ipacm_cmd_q_data evt_data; struct ipa_ioc_get_hdr hdr; + bool result; #ifdef WAN_IOC_NOTIFY_WAN_STATE //resolve compile issue on 4.9 kernel struct wan_ioctl_notify_wan_state wan_state; int fd_wwan_ioctl; @@ -1878,8 +1892,6 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) rt_rule->num_rules = (uint8_t)NUM; rt_rule->ip = iptype; - - IPACMDBG_H(" WAN table created %s \n", rt_rule->rt_tbl_name); rt_rule_entry = &rt_rule->rules[0]; rt_rule_entry->at_rear = true; @@ -1907,6 +1919,7 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) rt_rule_entry->rule.hdr_hdl = hdr_hdl_sta_v6; } + IPACMDBG_H(" WAN table created %s \n", rt_rule->rt_tbl_name); /* replace the hdr handle for q6_PCIE*/ if(m_is_sta_mode == Q6_MHI_WAN) { @@ -1945,10 +1958,21 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) rt_rule_entry->rule.attrib.u.v4.dst_addr = 0; rt_rule_entry->rule.attrib.u.v4.dst_addr_mask = 0; #ifdef FEATURE_IPA_V3 - rt_rule_entry->rule.hashable = true; #endif - if (false == m_routing.AddRoutingRule(rt_rule)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if((m_is_sta_mode == WLAN_WAN) && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_HW); + result = m_routing.AddRoutingRule_hw_index(rt_rule, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_HW); + } else { + result = m_routing.AddRoutingRule(rt_rule); + } +#else + result = m_routing.AddRoutingRule(rt_rule); +#endif + if (result == false) { IPACMERR("Routing rule addition failed!\n"); free(rt_rule); @@ -1973,7 +1997,19 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) #ifdef FEATURE_IPA_V3 rt_rule_entry->rule.hashable = true; #endif - if (false == m_routing.AddRoutingRule(rt_rule)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if((m_is_sta_mode == WLAN_WAN) && IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_HW); + result = m_routing.AddRoutingRule_hw_index(rt_rule, IPACM_Iface::ipacmcfg->hw_counter_offset + UL_HW); + } else { + result = m_routing.AddRoutingRule(rt_rule); + } +#else + result = m_routing.AddRoutingRule(rt_rule); +#endif + if (result == false) { IPACMERR("Routing rule addition failed!\n"); free(rt_rule); @@ -1993,6 +2029,7 @@ int IPACM_Wan::handle_route_add_evt(ipa_ip_type iptype) if (iptype == IPA_IP_v6 && m_is_sta_mode != Q6_MHI_WAN) { strlcpy(rt_rule->rt_tbl_name, IPACM_Iface::ipacmcfg->rt_tbl_wan_v6.name, sizeof(rt_rule->rt_tbl_name)); + IPACMDBG_H(" WAN table created %s \n", rt_rule->rt_tbl_name); memset(rt_rule_entry, 0, sizeof(struct ipa_rt_rule_add)); rt_rule_entry->at_rear = true; if(m_is_sta_mode == Q6_WAN) @@ -2454,6 +2491,7 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) { struct ipa_flt_rule_add flt_rule_entry; int i, rule_v4 = 0, rule_v6 = 0, len; + bool result; IPACMDBG_H("ip-family: %d; \n", iptype); @@ -2528,7 +2566,19 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) memcpy(&flt_rule_entry.rule.attrib, &rx_prop->rx[0].attrib, sizeof(struct ipa_rule_attrib)); flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_FRAGMENT; memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + if (false == result) { IPACMERR("Error Adding RuleTable(0) to Filtering, aborting...\n"); free(m_pFilteringTable); @@ -2621,8 +2671,19 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) } memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + if (false == result) { IPACMERR("Error Adding RuleTable(0) to Filtering, aborting...\n"); free(m_pFilteringTable); @@ -2709,7 +2770,20 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) IPACMDBG_H("Filter rule attrib mask: 0x%x\n", m_pFilteringTable->rules[0].rule.attrib.attrib_mask); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + + if (false == result) { IPACMERR("Error Adding RuleTable(0) to Filtering, aborting...\n"); free(m_pFilteringTable); @@ -2733,7 +2807,20 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) IPACMDBG_H("Filter rule attrib mask: 0x%x\n", m_pFilteringTable->rules[0].rule.attrib.attrib_mask); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + + if (false == result) { IPACMERR("Error Adding RuleTable(0) to Filtering, aborting...\n"); free(m_pFilteringTable); @@ -2757,7 +2844,20 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) IPACMDBG_H("Filter rule attrib mask: 0x%x\n", m_pFilteringTable->rules[0].rule.attrib.attrib_mask); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + + if (false == result) { IPACMERR("Error Adding RuleTable(0) to Filtering, aborting...\n"); free(m_pFilteringTable); @@ -2833,7 +2933,20 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) IPACMDBG_H("Filter rule attrib mask: 0x%x\n", m_pFilteringTable->rules[0].rule.attrib.attrib_mask); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + + if (false == result) { IPACMERR("Error Adding RuleTable(0) to Filtering, aborting...\n"); free(m_pFilteringTable); @@ -2881,7 +2994,20 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) flt_rule_entry.rule.attrib.attrib_mask |= IPA_FLT_NEXT_HDR; flt_rule_entry.rule.attrib.u.v6.next_hdr = (uint8_t)IPACM_FIREWALL_IPPROTO_ICMP6; memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + + if (false == result) { IPACMERR("Error Adding Filtering rules, aborting...\n"); free(m_pFilteringTable); @@ -2955,8 +3081,20 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) } memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) + if (false == result) { IPACMERR("Error Adding Filtering rules, aborting...\n"); free(m_pFilteringTable); @@ -3027,7 +3165,20 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) /* insert TCP rule*/ flt_rule_entry.rule.attrib.u.v6.next_hdr = IPACM_FIREWALL_IPPROTO_TCP; memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + + if (false == result) { IPACMERR("Error Adding Filtering rules, aborting...\n"); free(m_pFilteringTable); @@ -3046,7 +3197,19 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) /* insert UDP rule*/ flt_rule_entry.rule.attrib.u.v6.next_hdr = IPACM_FIREWALL_IPPROTO_UDP; memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + if (false == result) { IPACMERR("Error Adding Filtering rules, aborting...\n"); free(m_pFilteringTable); @@ -3065,7 +3228,20 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) else { memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) + +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + if (false == result) { IPACMERR("Error Adding Filtering rules, aborting...\n"); free(m_pFilteringTable); @@ -3103,7 +3279,19 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) flt_rule_entry.rule.attrib.u.v6.next_hdr = (uint8_t)IPACM_FIREWALL_IPPROTO_ICMP6; memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + if (result == false) { IPACMERR("Error Adding Filtering rules, aborting...\n"); free(m_pFilteringTable); @@ -3163,7 +3351,20 @@ int IPACM_Wan::config_dft_firewall_rules(ipa_ip_type iptype) memcpy(&(m_pFilteringTable->rules[0]), &flt_rule_entry, sizeof(struct ipa_flt_rule_add)); - if (false == m_filtering.AddFilteringRule(m_pFilteringTable)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_ALL); + result = m_filtering.AddFilteringRule_hw_index(m_pFilteringTable, IPACM_Iface::ipacmcfg->hw_counter_offset+ DL_ALL); + } else { + result = m_filtering.AddFilteringRule(m_pFilteringTable); + } +#else + result = m_filtering.AddFilteringRule(m_pFilteringTable); +#endif + + if (result == false) { IPACMERR("Error Adding Filtering rules, aborting...\n"); free(m_pFilteringTable); diff --git a/ipacm/src/IPACM_Wlan.cpp b/ipacm/src/IPACM_Wlan.cpp index b7fb9ff..f86dd1d 100644 --- a/ipacm/src/IPACM_Wlan.cpp +++ b/ipacm/src/IPACM_Wlan.cpp @@ -1456,6 +1456,7 @@ int IPACM_Wlan::handle_wlan_client_route_rule(uint8_t *mac_addr, ipa_ip_type ipt uint32_t tx_index; int wlan_index,v6_num; const int NUM = 1; + bool result; if(tx_prop == NULL) { @@ -1576,8 +1577,19 @@ int IPACM_Wlan::handle_wlan_client_route_rule(uint8_t *mac_addr, ipa_ip_type ipt { rt_rule_entry->rule.hashable = true; } - - if (false == m_routing.AddRoutingRule(rt_rule)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_HW); + result = m_routing.AddRoutingRule_hw_index(rt_rule, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_HW); + } else { + result = m_routing.AddRoutingRule(rt_rule); + } +#else + result = m_routing.AddRoutingRule(rt_rule); +#endif + if (result == false) { IPACMERR("Routing rule addition failed!\n"); free(rt_rule); @@ -1671,7 +1683,20 @@ int IPACM_Wlan::handle_wlan_client_route_rule(uint8_t *mac_addr, ipa_ip_type ipt #ifdef FEATURE_IPA_V3 rt_rule_entry->rule.hashable = true; #endif - if (false == m_routing.AddRoutingRule(rt_rule)) +#ifdef IPA_IOCTL_SET_FNR_COUNTER_INFO + /* use index hw-counter */ + if(IPACM_Iface::ipacmcfg->hw_fnr_stats_support) + { + IPACMDBG_H("hw-index-enable %d, counter %d\n", IPACM_Iface::ipacmcfg->hw_fnr_stats_support, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_HW); + result = m_routing.AddRoutingRule_hw_index(rt_rule, IPACM_Iface::ipacmcfg->hw_counter_offset + DL_HW); + } else { + result = m_routing.AddRoutingRule(rt_rule); + } +#else + result = m_routing.AddRoutingRule(rt_rule); +#endif + + if (result == false) { IPACMERR("Routing rule addition failed!\n"); free(rt_rule); |