Lines Matching full:ppe

29 static void ppe_w32(struct mtk_ppe *ppe, u32 reg, u32 val)  in ppe_w32()  argument
31 writel(val, ppe->base + reg); in ppe_w32()
34 static u32 ppe_r32(struct mtk_ppe *ppe, u32 reg) in ppe_r32() argument
36 return readl(ppe->base + reg); in ppe_r32()
39 static u32 ppe_m32(struct mtk_ppe *ppe, u32 reg, u32 mask, u32 set) in ppe_m32() argument
43 val = ppe_r32(ppe, reg); in ppe_m32()
46 ppe_w32(ppe, reg, val); in ppe_m32()
51 static u32 ppe_set(struct mtk_ppe *ppe, u32 reg, u32 val) in ppe_set() argument
53 return ppe_m32(ppe, reg, 0, val); in ppe_set()
56 static u32 ppe_clear(struct mtk_ppe *ppe, u32 reg, u32 val) in ppe_clear() argument
58 return ppe_m32(ppe, reg, val, 0); in ppe_clear()
66 static int mtk_ppe_wait_busy(struct mtk_ppe *ppe) in mtk_ppe_wait_busy() argument
71 ret = readl_poll_timeout(ppe->base + MTK_PPE_GLO_CFG, val, in mtk_ppe_wait_busy()
76 dev_err(ppe->dev, "PPE table busy"); in mtk_ppe_wait_busy()
81 static int mtk_ppe_mib_wait_busy(struct mtk_ppe *ppe) in mtk_ppe_mib_wait_busy() argument
86 ret = readl_poll_timeout(ppe->base + MTK_PPE_MIB_SER_CR, val, in mtk_ppe_mib_wait_busy()
91 dev_err(ppe->dev, "MIB table busy"); in mtk_ppe_mib_wait_busy()
96 static int mtk_mib_entry_read(struct mtk_ppe *ppe, u16 index, u64 *bytes, u64 *packets) in mtk_mib_entry_read() argument
102 ppe_w32(ppe, MTK_PPE_MIB_SER_CR, val); in mtk_mib_entry_read()
104 ret = mtk_ppe_mib_wait_busy(ppe); in mtk_mib_entry_read()
108 cnt_r0 = readl(ppe->base + MTK_PPE_MIB_SER_R0); in mtk_mib_entry_read()
109 cnt_r1 = readl(ppe->base + MTK_PPE_MIB_SER_R1); in mtk_mib_entry_read()
110 cnt_r2 = readl(ppe->base + MTK_PPE_MIB_SER_R2); in mtk_mib_entry_read()
112 if (mtk_is_netsys_v3_or_greater(ppe->eth)) { in mtk_mib_entry_read()
114 u32 cnt_r3 = readl(ppe->base + MTK_PPE_MIB_SER_R3); in mtk_mib_entry_read()
130 static void mtk_ppe_cache_clear(struct mtk_ppe *ppe) in mtk_ppe_cache_clear() argument
132 ppe_set(ppe, MTK_PPE_CACHE_CTL, MTK_PPE_CACHE_CTL_CLEAR); in mtk_ppe_cache_clear()
133 ppe_clear(ppe, MTK_PPE_CACHE_CTL, MTK_PPE_CACHE_CTL_CLEAR); in mtk_ppe_cache_clear()
136 static void mtk_ppe_cache_enable(struct mtk_ppe *ppe, bool enable) in mtk_ppe_cache_enable() argument
138 mtk_ppe_cache_clear(ppe); in mtk_ppe_cache_enable()
140 ppe_m32(ppe, MTK_PPE_CACHE_CTL, MTK_PPE_CACHE_CTL_EN, in mtk_ppe_cache_enable()
501 __mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry) in __mtk_foe_entry_clear() argument
507 rhashtable_remove_fast(&ppe->l2_flows, &entry->l2_node, in __mtk_foe_entry_clear()
512 __mtk_foe_entry_clear(ppe, entry); in __mtk_foe_entry_clear()
518 struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, entry->hash); in __mtk_foe_entry_clear()
523 mtk_ppe_cache_clear(ppe); in __mtk_foe_entry_clear()
525 if (ppe->accounting) { in __mtk_foe_entry_clear()
528 acct = ppe->acct_table + entry->hash * sizeof(*acct); in __mtk_foe_entry_clear()
542 static int __mtk_foe_entry_idle_time(struct mtk_ppe *ppe, u32 ib1) in __mtk_foe_entry_idle_time() argument
544 u32 ib1_ts_mask = mtk_get_ib1_ts_mask(ppe->eth); in __mtk_foe_entry_idle_time()
545 u16 now = mtk_eth_timestamp(ppe->eth); in __mtk_foe_entry_idle_time()
555 mtk_flow_entry_update_l2(struct mtk_ppe *ppe, struct mtk_flow_entry *entry) in mtk_flow_entry_update_l2() argument
557 u32 ib1_ts_mask = mtk_get_ib1_ts_mask(ppe->eth); in mtk_flow_entry_update_l2()
563 idle = __mtk_foe_entry_idle_time(ppe, entry->data.ib1); in mtk_flow_entry_update_l2()
568 hwe = mtk_foe_get_entry(ppe, cur->hash); in mtk_flow_entry_update_l2()
573 __mtk_foe_entry_clear(ppe, cur); in mtk_flow_entry_update_l2()
577 cur_idle = __mtk_foe_entry_idle_time(ppe, ib1); in mtk_flow_entry_update_l2()
588 mtk_flow_entry_update(struct mtk_ppe *ppe, struct mtk_flow_entry *entry) in mtk_flow_entry_update() argument
596 mtk_flow_entry_update_l2(ppe, entry); in mtk_flow_entry_update()
603 hwe = mtk_foe_get_entry(ppe, entry->hash); in mtk_flow_entry_update()
604 memcpy(&foe, hwe, ppe->eth->soc->foe_entry_size); in mtk_flow_entry_update()
605 if (!mtk_flow_entry_match(ppe->eth, entry, &foe)) { in mtk_flow_entry_update()
617 __mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_foe_entry *entry, in __mtk_foe_entry_commit() argument
620 struct mtk_eth *eth = ppe->eth; in __mtk_foe_entry_commit()
635 hwe = mtk_foe_get_entry(ppe, hash); in __mtk_foe_entry_commit()
640 if (ppe->accounting) { in __mtk_foe_entry_commit()
650 mtk_ppe_cache_clear(ppe); in __mtk_foe_entry_commit()
653 void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry) in mtk_foe_entry_clear() argument
656 __mtk_foe_entry_clear(ppe, entry); in mtk_foe_entry_clear()
661 mtk_foe_entry_commit_l2(struct mtk_ppe *ppe, struct mtk_flow_entry *entry) in mtk_foe_entry_commit_l2() argument
667 prev = rhashtable_lookup_get_insert_fast(&ppe->l2_flows, &entry->l2_node, in mtk_foe_entry_commit_l2()
675 return rhashtable_replace_fast(&ppe->l2_flows, &prev->l2_node, in mtk_foe_entry_commit_l2()
679 int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry) in mtk_foe_entry_commit() argument
681 const struct mtk_soc_data *soc = ppe->eth->soc; in mtk_foe_entry_commit()
682 int type = mtk_get_ib1_pkt_type(ppe->eth, entry->data.ib1); in mtk_foe_entry_commit()
686 return mtk_foe_entry_commit_l2(ppe, entry); in mtk_foe_entry_commit()
688 hash = mtk_ppe_hash_entry(ppe->eth, &entry->data); in mtk_foe_entry_commit()
691 hlist_add_head(&entry->list, &ppe->foe_flow[hash / soc->hash_offset]); in mtk_foe_entry_commit()
698 mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry, in mtk_foe_entry_commit_subflow() argument
701 const struct mtk_soc_data *soc = ppe->eth->soc; in mtk_foe_entry_commit_subflow()
705 u32 ib1_mask = mtk_get_ib1_pkt_type_mask(ppe->eth) | MTK_FOE_IB1_UDP; in mtk_foe_entry_commit_subflow()
716 &ppe->foe_flow[hash / soc->hash_offset]); in mtk_foe_entry_commit_subflow()
719 hwe = mtk_foe_get_entry(ppe, hash); in mtk_foe_entry_commit_subflow()
724 l2 = mtk_foe_entry_l2(ppe->eth, &foe); in mtk_foe_entry_commit_subflow()
727 type = mtk_get_ib1_pkt_type(ppe->eth, foe.ib1); in mtk_foe_entry_commit_subflow()
733 *mtk_foe_entry_ib2(ppe->eth, &foe) = entry->data.bridge.ib2; in mtk_foe_entry_commit_subflow()
735 __mtk_foe_entry_commit(ppe, &foe, hash); in mtk_foe_entry_commit_subflow()
738 void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash) in __mtk_ppe_check_skb() argument
740 const struct mtk_soc_data *soc = ppe->eth->soc; in __mtk_ppe_check_skb()
741 struct hlist_head *head = &ppe->foe_flow[hash / soc->hash_offset]; in __mtk_ppe_check_skb()
742 struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, hash); in __mtk_ppe_check_skb()
762 __mtk_foe_entry_clear(ppe, entry); in __mtk_ppe_check_skb()
766 if (found || !mtk_flow_entry_match(ppe->eth, entry, hwe)) { in __mtk_ppe_check_skb()
773 __mtk_foe_entry_commit(ppe, &entry->data, hash); in __mtk_ppe_check_skb()
807 entry = rhashtable_lookup_fast(&ppe->l2_flows, &key, mtk_flow_l2_ht_params); in __mtk_ppe_check_skb()
811 mtk_foe_entry_commit_subflow(ppe, entry, hash); in __mtk_ppe_check_skb()
817 int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry) in mtk_foe_entry_idle_time() argument
819 mtk_flow_entry_update(ppe, entry); in mtk_foe_entry_idle_time()
821 return __mtk_foe_entry_idle_time(ppe, entry->data.ib1); in mtk_foe_entry_idle_time()
824 int mtk_ppe_prepare_reset(struct mtk_ppe *ppe) in mtk_ppe_prepare_reset() argument
826 if (!ppe) in mtk_ppe_prepare_reset()
830 ppe_clear(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_KEEPALIVE); in mtk_ppe_prepare_reset()
831 ppe_clear(ppe, MTK_PPE_BIND_LMT1, MTK_PPE_NTU_KEEPALIVE); in mtk_ppe_prepare_reset()
832 ppe_w32(ppe, MTK_PPE_KEEPALIVE, 0); in mtk_ppe_prepare_reset()
836 ppe_set(ppe, MTK_PPE_BIND_LMT1, MTK_PPE_NTU_KEEPALIVE); in mtk_ppe_prepare_reset()
837 ppe_w32(ppe, MTK_PPE_KEEPALIVE, 0xffffffff); in mtk_ppe_prepare_reset()
840 ppe_set(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_TICK_SEL); in mtk_ppe_prepare_reset()
841 ppe_set(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_KEEPALIVE); in mtk_ppe_prepare_reset()
845 ppe_clear(ppe, MTK_PPE_TB_CFG, MTK_PPE_TB_CFG_SCAN_MODE); in mtk_ppe_prepare_reset()
848 return mtk_ppe_wait_busy(ppe); in mtk_ppe_prepare_reset()
851 struct mtk_foe_accounting *mtk_foe_entry_get_mib(struct mtk_ppe *ppe, u32 index, in mtk_foe_entry_get_mib() argument
858 if (!ppe->accounting) in mtk_foe_entry_get_mib()
861 if (mtk_mib_entry_read(ppe, index, &bytes, &packets)) in mtk_foe_entry_get_mib()
864 acct = ppe->acct_table + index * size; in mtk_foe_entry_get_mib()
884 struct mtk_ppe *ppe; in mtk_ppe_init() local
888 ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL); in mtk_ppe_init()
889 if (!ppe) in mtk_ppe_init()
892 rhashtable_init(&ppe->l2_flows, &mtk_flow_l2_ht_params); in mtk_ppe_init()
894 /* need to allocate a separate device, since it PPE DMA access is in mtk_ppe_init()
897 ppe->base = base; in mtk_ppe_init()
898 ppe->eth = eth; in mtk_ppe_init()
899 ppe->dev = dev; in mtk_ppe_init()
900 ppe->version = eth->soc->offload_version; in mtk_ppe_init()
901 ppe->accounting = accounting; in mtk_ppe_init()
903 foe = dmam_alloc_coherent(ppe->dev, in mtk_ppe_init()
905 &ppe->foe_phys, GFP_KERNEL); in mtk_ppe_init()
909 ppe->foe_table = foe; in mtk_ppe_init()
912 sizeof(*ppe->foe_flow); in mtk_ppe_init()
913 ppe->foe_flow = devm_kzalloc(dev, foe_flow_size, GFP_KERNEL); in mtk_ppe_init()
914 if (!ppe->foe_flow) in mtk_ppe_init()
918 mib = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*mib), in mtk_ppe_init()
919 &ppe->mib_phys, GFP_KERNEL); in mtk_ppe_init()
923 ppe->mib_table = mib; in mtk_ppe_init()
931 ppe->acct_table = acct; in mtk_ppe_init()
934 mtk_ppe_debugfs_init(ppe, index); in mtk_ppe_init()
936 return ppe; in mtk_ppe_init()
939 rhashtable_destroy(&ppe->l2_flows); in mtk_ppe_init()
947 for (i = 0; i < ARRAY_SIZE(eth->ppe); i++) { in mtk_ppe_deinit()
948 if (!eth->ppe[i]) in mtk_ppe_deinit()
950 rhashtable_destroy(&eth->ppe[i]->l2_flows); in mtk_ppe_deinit()
954 static void mtk_ppe_init_foe_table(struct mtk_ppe *ppe) in mtk_ppe_init_foe_table() argument
959 memset(ppe->foe_table, 0, in mtk_ppe_init_foe_table()
960 MTK_PPE_ENTRIES * ppe->eth->soc->foe_entry_size); in mtk_ppe_init_foe_table()
970 hwe = mtk_foe_get_entry(ppe, i + skip[k]); in mtk_ppe_init_foe_table()
976 void mtk_ppe_start(struct mtk_ppe *ppe) in mtk_ppe_start() argument
980 if (!ppe) in mtk_ppe_start()
983 mtk_ppe_init_foe_table(ppe); in mtk_ppe_start()
984 ppe_w32(ppe, MTK_PPE_TB_BASE, ppe->foe_phys); in mtk_ppe_start()
1000 if (mtk_is_netsys_v2_or_greater(ppe->eth)) in mtk_ppe_start()
1002 if (!mtk_is_netsys_v3_or_greater(ppe->eth)) in mtk_ppe_start()
1004 ppe_w32(ppe, MTK_PPE_TB_CFG, val); in mtk_ppe_start()
1006 ppe_w32(ppe, MTK_PPE_IP_PROTO_CHK, in mtk_ppe_start()
1009 mtk_ppe_cache_enable(ppe, true); in mtk_ppe_start()
1018 if (mtk_is_netsys_v2_or_greater(ppe->eth)) in mtk_ppe_start()
1026 ppe_w32(ppe, MTK_PPE_FLOW_CFG, val); in mtk_ppe_start()
1030 ppe_w32(ppe, MTK_PPE_UNBIND_AGE, val); in mtk_ppe_start()
1034 ppe_w32(ppe, MTK_PPE_BIND_AGE0, val); in mtk_ppe_start()
1038 ppe_w32(ppe, MTK_PPE_BIND_AGE1, val); in mtk_ppe_start()
1041 ppe_w32(ppe, MTK_PPE_BIND_LIMIT0, val); in mtk_ppe_start()
1045 ppe_w32(ppe, MTK_PPE_BIND_LIMIT1, val); in mtk_ppe_start()
1049 ppe_w32(ppe, MTK_PPE_BIND_RATE, val); in mtk_ppe_start()
1051 /* enable PPE */ in mtk_ppe_start()
1056 ppe_w32(ppe, MTK_PPE_GLO_CFG, val); in mtk_ppe_start()
1058 ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT, 0); in mtk_ppe_start()
1060 if (mtk_is_netsys_v2_or_greater(ppe->eth)) { in mtk_ppe_start()
1061 ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT1, 0xcb777); in mtk_ppe_start()
1062 ppe_w32(ppe, MTK_PPE_SBW_CTRL, 0x7f); in mtk_ppe_start()
1065 if (ppe->accounting && ppe->mib_phys) { in mtk_ppe_start()
1066 ppe_w32(ppe, MTK_PPE_MIB_TB_BASE, ppe->mib_phys); in mtk_ppe_start()
1067 ppe_m32(ppe, MTK_PPE_MIB_CFG, MTK_PPE_MIB_CFG_EN, in mtk_ppe_start()
1069 ppe_m32(ppe, MTK_PPE_MIB_CFG, MTK_PPE_MIB_CFG_RD_CLR, in mtk_ppe_start()
1071 ppe_m32(ppe, MTK_PPE_MIB_CACHE_CTL, MTK_PPE_MIB_CACHE_CTL_EN, in mtk_ppe_start()
1076 int mtk_ppe_stop(struct mtk_ppe *ppe) in mtk_ppe_stop() argument
1081 if (!ppe) in mtk_ppe_stop()
1085 struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, i); in mtk_ppe_stop()
1091 mtk_ppe_cache_enable(ppe, false); in mtk_ppe_stop()
1100 ppe_clear(ppe, MTK_PPE_TB_CFG, val); in mtk_ppe_stop()
1102 if (mtk_ppe_wait_busy(ppe)) in mtk_ppe_stop()
1106 ppe_clear(ppe, MTK_PPE_GLO_CFG, MTK_PPE_GLO_CFG_EN); in mtk_ppe_stop()
1107 ppe_w32(ppe, MTK_PPE_FLOW_CFG, 0); in mtk_ppe_stop()