Lines Matching defs:ppe
26 static void ppe_w32(struct mtk_ppe *ppe, u32 reg, u32 val)
28 writel(val, ppe->base + reg);
31 static u32 ppe_r32(struct mtk_ppe *ppe, u32 reg)
33 return readl(ppe->base + reg);
36 static u32 ppe_m32(struct mtk_ppe *ppe, u32 reg, u32 mask, u32 set)
40 val = ppe_r32(ppe, reg);
43 ppe_w32(ppe, reg, val);
48 static u32 ppe_set(struct mtk_ppe *ppe, u32 reg, u32 val)
50 return ppe_m32(ppe, reg, 0, val);
53 static u32 ppe_clear(struct mtk_ppe *ppe, u32 reg, u32 val)
55 return ppe_m32(ppe, reg, val, 0);
63 static int mtk_ppe_wait_busy(struct mtk_ppe *ppe)
68 ret = readl_poll_timeout(ppe->base + MTK_PPE_GLO_CFG, val,
73 dev_err(ppe->dev, "PPE table busy");
78 static int mtk_ppe_mib_wait_busy(struct mtk_ppe *ppe)
83 ret = readl_poll_timeout(ppe->base + MTK_PPE_MIB_SER_CR, val,
88 dev_err(ppe->dev, "MIB table busy");
93 static int mtk_mib_entry_read(struct mtk_ppe *ppe, u16 index, u64 *bytes, u64 *packets)
99 ppe_w32(ppe, MTK_PPE_MIB_SER_CR, val);
101 ret = mtk_ppe_mib_wait_busy(ppe);
105 cnt_r0 = readl(ppe->base + MTK_PPE_MIB_SER_R0);
106 cnt_r1 = readl(ppe->base + MTK_PPE_MIB_SER_R1);
107 cnt_r2 = readl(ppe->base + MTK_PPE_MIB_SER_R2);
109 if (mtk_is_netsys_v3_or_greater(ppe->eth)) {
111 u32 cnt_r3 = readl(ppe->base + MTK_PPE_MIB_SER_R3);
127 static void mtk_ppe_cache_clear(struct mtk_ppe *ppe)
129 ppe_set(ppe, MTK_PPE_CACHE_CTL, MTK_PPE_CACHE_CTL_CLEAR);
130 ppe_clear(ppe, MTK_PPE_CACHE_CTL, MTK_PPE_CACHE_CTL_CLEAR);
133 static void mtk_ppe_cache_enable(struct mtk_ppe *ppe, bool enable)
135 mtk_ppe_cache_clear(ppe);
137 ppe_m32(ppe, MTK_PPE_CACHE_CTL, MTK_PPE_CACHE_CTL_EN,
499 __mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
505 rhashtable_remove_fast(&ppe->l2_flows, &entry->l2_node,
510 __mtk_foe_entry_clear(ppe, entry);
516 struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, entry->hash);
521 mtk_ppe_cache_clear(ppe);
523 if (ppe->accounting) {
526 acct = ppe->acct_table + entry->hash * sizeof(*acct);
540 static int __mtk_foe_entry_idle_time(struct mtk_ppe *ppe, u32 ib1)
542 u32 ib1_ts_mask = mtk_get_ib1_ts_mask(ppe->eth);
543 u16 now = mtk_eth_timestamp(ppe->eth);
553 mtk_flow_entry_update_l2(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
555 u32 ib1_ts_mask = mtk_get_ib1_ts_mask(ppe->eth);
561 idle = __mtk_foe_entry_idle_time(ppe, entry->data.ib1);
566 hwe = mtk_foe_get_entry(ppe, cur->hash);
571 __mtk_foe_entry_clear(ppe, cur);
575 cur_idle = __mtk_foe_entry_idle_time(ppe, ib1);
586 mtk_flow_entry_update(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
594 mtk_flow_entry_update_l2(ppe, entry);
601 hwe = mtk_foe_get_entry(ppe, entry->hash);
602 memcpy(&foe, hwe, ppe->eth->soc->foe_entry_size);
603 if (!mtk_flow_entry_match(ppe->eth, entry, &foe)) {
615 __mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry,
618 struct mtk_eth *eth = ppe->eth;
633 hwe = mtk_foe_get_entry(ppe, hash);
638 if (ppe->accounting) {
648 mtk_ppe_cache_clear(ppe);
651 void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
654 __mtk_foe_entry_clear(ppe, entry);
659 mtk_foe_entry_commit_l2(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
665 prev = rhashtable_lookup_get_insert_fast(&ppe->l2_flows, &entry->l2_node,
673 return rhashtable_replace_fast(&ppe->l2_flows, &prev->l2_node,
677 int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
679 const struct mtk_soc_data *soc = ppe->eth->soc;
680 int type = mtk_get_ib1_pkt_type(ppe->eth, entry->data.ib1);
684 return mtk_foe_entry_commit_l2(ppe, entry);
686 hash = mtk_ppe_hash_entry(ppe->eth, &entry->data);
689 hlist_add_head(&entry->list, &ppe->foe_flow[hash / soc->hash_offset]);
696 mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
699 const struct mtk_soc_data *soc = ppe->eth->soc;
703 u32 ib1_mask = mtk_get_ib1_pkt_type_mask(ppe->eth) | MTK_FOE_IB1_UDP;
714 &ppe->foe_flow[hash / soc->hash_offset]);
717 hwe = mtk_foe_get_entry(ppe, hash);
722 l2 = mtk_foe_entry_l2(ppe->eth, &foe);
725 type = mtk_get_ib1_pkt_type(ppe->eth, foe.ib1);
731 *mtk_foe_entry_ib2(ppe->eth, &foe) = entry->data.bridge.ib2;
733 __mtk_foe_entry_commit(ppe, &foe, hash);
736 void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
738 const struct mtk_soc_data *soc = ppe->eth->soc;
739 struct hlist_head *head = &ppe->foe_flow[hash / soc->hash_offset];
740 struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, hash);
760 __mtk_foe_entry_clear(ppe, entry);
764 if (found || !mtk_flow_entry_match(ppe->eth, entry, hwe)) {
771 __mtk_foe_entry_commit(ppe, &entry->data, hash);
805 entry = rhashtable_lookup_fast(&ppe->l2_flows, &key, mtk_flow_l2_ht_params);
809 mtk_foe_entry_commit_subflow(ppe, entry, hash);
815 int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
817 mtk_flow_entry_update(ppe, entry);
819 return __mtk_foe_entry_idle_time(ppe, entry->data.ib1);
822 int mtk_ppe_prepare_reset(struct mtk_ppe *ppe)
824 if (!ppe)
828 ppe_clear(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_KEEPALIVE);
829 ppe_clear(ppe, MTK_PPE_BIND_LMT1, MTK_PPE_NTU_KEEPALIVE);
830 ppe_w32(ppe, MTK_PPE_KEEPALIVE, 0);
834 ppe_set(ppe, MTK_PPE_BIND_LMT1, MTK_PPE_NTU_KEEPALIVE);
835 ppe_w32(ppe, MTK_PPE_KEEPALIVE, 0xffffffff);
838 ppe_set(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_TICK_SEL);
839 ppe_set(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_KEEPALIVE);
843 ppe_clear(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_SCAN_MODE);
846 return mtk_ppe_wait_busy(ppe);
849 struct mtk_foe_accounting *mtk_foe_entry_get_mib(struct mtk_ppe *ppe, u32 index,
856 if (!ppe->accounting)
859 if (mtk_mib_entry_read(ppe, index, &bytes, &packets))
862 acct = ppe->acct_table + index * size;
882 struct mtk_ppe *ppe;
886 ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
887 if (!ppe)
890 rhashtable_init(&ppe->l2_flows, &mtk_flow_l2_ht_params);
895 ppe->base = base;
896 ppe->eth = eth;
897 ppe->dev = dev;
898 ppe->version = eth->soc->offload_version;
899 ppe->accounting = accounting;
901 foe = dmam_alloc_coherent(ppe->dev,
903 &ppe->foe_phys, GFP_KERNEL);
907 ppe->foe_table = foe;
910 sizeof(*ppe->foe_flow);
911 ppe->foe_flow = devm_kzalloc(dev, foe_flow_size, GFP_KERNEL);
912 if (!ppe->foe_flow)
916 mib = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*mib),
917 &ppe->mib_phys, GFP_KERNEL);
921 ppe->mib_table = mib;
929 ppe->acct_table = acct;
932 mtk_ppe_debugfs_init(ppe, index);
934 return ppe;
937 rhashtable_destroy(&ppe->l2_flows);
945 for (i = 0; i < ARRAY_SIZE(eth->ppe); i++) {
946 if (!eth->ppe[i])
948 rhashtable_destroy(ð->ppe[i]->l2_flows);
952 static void mtk_ppe_init_foe_table(struct mtk_ppe *ppe)
957 memset(ppe->foe_table, 0,
958 MTK_PPE_ENTRIES * ppe->eth->soc->foe_entry_size);
968 hwe = mtk_foe_get_entry(ppe, i + skip[k]);
974 void mtk_ppe_start(struct mtk_ppe *ppe)
978 if (!ppe)
981 mtk_ppe_init_foe_table(ppe);
982 ppe_w32(ppe, MTK_PPE_TB_BASE, ppe->foe_phys);
998 if (mtk_is_netsys_v2_or_greater(ppe->eth))
1000 if (!mtk_is_netsys_v3_or_greater(ppe->eth))
1002 ppe_w32(ppe, MTK_PPE_TB_CFG, val);
1004 ppe_w32(ppe, MTK_PPE_IP_PROTO_CHK,
1007 mtk_ppe_cache_enable(ppe, true);
1016 if (mtk_is_netsys_v2_or_greater(ppe->eth))
1024 ppe_w32(ppe, MTK_PPE_FLOW_CFG, val);
1028 ppe_w32(ppe, MTK_PPE_UNBIND_AGE, val);
1032 ppe_w32(ppe, MTK_PPE_BIND_AGE0, val);
1036 ppe_w32(ppe, MTK_PPE_BIND_AGE1, val);
1039 ppe_w32(ppe, MTK_PPE_BIND_LIMIT0, val);
1043 ppe_w32(ppe, MTK_PPE_BIND_LIMIT1, val);
1047 ppe_w32(ppe, MTK_PPE_BIND_RATE, val);
1054 ppe_w32(ppe, MTK_PPE_GLO_CFG, val);
1056 ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT, 0);
1058 if (mtk_is_netsys_v2_or_greater(ppe->eth)) {
1059 ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT1, 0xcb777);
1060 ppe_w32(ppe, MTK_PPE_SBW_CTRL, 0x7f);
1063 if (ppe->accounting && ppe->mib_phys) {
1064 ppe_w32(ppe, MTK_PPE_MIB_TB_BASE, ppe->mib_phys);
1065 ppe_m32(ppe, MTK_PPE_MIB_CFG, MTK_PPE_MIB_CFG_EN,
1067 ppe_m32(ppe, MTK_PPE_MIB_CFG, MTK_PPE_MIB_CFG_RD_CLR,
1069 ppe_m32(ppe, MTK_PPE_MIB_CACHE_CTL, MTK_PPE_MIB_CACHE_CTL_EN,
1074 int mtk_ppe_stop(struct mtk_ppe *ppe)
1079 if (!ppe)
1083 struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, i);
1089 mtk_ppe_cache_enable(ppe, false);
1098 ppe_clear(ppe, MTK_PPE_TB_CFG, val);
1100 if (mtk_ppe_wait_busy(ppe))
1104 ppe_clear(ppe, MTK_PPE_GLO_CFG, MTK_PPE_GLO_CFG_EN);
1105 ppe_w32(ppe, MTK_PPE_FLOW_CFG, 0);