blob: d65563257512506004867fb4f2d451ad6fb19f5f [file] [log] [blame]
developerf4447452022-07-05 14:02:53 +08001diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
2index 2c54c9c..d3ba9eb 100644
3--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
4+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
5@@ -3814,7 +3814,8 @@ static int mtk_probe(struct platform_device *pdev)
6
7 for (i = 0; i < eth->ppe_num; i++) {
8 eth->ppe[i] = mtk_ppe_init(eth,
9- eth->base + MTK_ETH_PPE_BASE + i * 0x400, 2, i);
10+ eth->base + MTK_ETH_PPE_BASE + i * 0x400,
11+ 2, eth->soc->hash_way, i);
12 if (!eth->ppe[i]) {
13 err = -ENOMEM;
14 goto err_free_dev;
15@@ -3927,6 +3928,7 @@ static const struct mtk_soc_data mt2701_data = {
16 .required_clks = MT7623_CLKS_BITMAP,
17 .required_pctl = true,
18 .has_sram = false,
19+ .hash_way = 2,
20 .offload_version = 2,
21 };
22
23@@ -3936,6 +3938,7 @@ static const struct mtk_soc_data mt7621_data = {
24 .required_clks = MT7621_CLKS_BITMAP,
25 .required_pctl = false,
26 .has_sram = false,
27+ .hash_way = 2,
28 .offload_version = 2,
29 };
30
31@@ -3946,6 +3949,7 @@ static const struct mtk_soc_data mt7622_data = {
32 .required_clks = MT7622_CLKS_BITMAP,
33 .required_pctl = false,
34 .has_sram = false,
35+ .hash_way = 2,
36 .offload_version = 2,
37 };
38
39@@ -3955,6 +3959,7 @@ static const struct mtk_soc_data mt7623_data = {
40 .required_clks = MT7623_CLKS_BITMAP,
41 .required_pctl = true,
42 .has_sram = false,
43+ .hash_way = 2,
44 .offload_version = 2,
45 };
46
47@@ -3974,6 +3979,7 @@ static const struct mtk_soc_data mt7986_data = {
48 .required_clks = MT7986_CLKS_BITMAP,
49 .required_pctl = false,
50 .has_sram = true,
51+ .hash_way = 4,
52 .offload_version = 2,
53 };
54
55@@ -3984,6 +3990,8 @@ static const struct mtk_soc_data mt7981_data = {
56 .required_clks = MT7981_CLKS_BITMAP,
57 .required_pctl = false,
58 .has_sram = true,
59+ .hash_way = 4,
60+ .offload_version = 2,
61 };
62
63 static const struct mtk_soc_data rt5350_data = {
64diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
65index 4a69bd0..35a7543 100644
66--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
67+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
68@@ -1188,6 +1188,7 @@ struct mtk_soc_data {
69 u32 caps;
70 u32 required_clks;
71 bool required_pctl;
72+ u8 hash_way;
73 u8 offload_version;
74 netdev_features_t hw_features;
75 bool has_sram;
76diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.c b/drivers/net/ethernet/mediatek/mtk_ppe.c
77index e4d50eb..918aa22 100755
78--- a/drivers/net/ethernet/mediatek/mtk_ppe.c
79+++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
80@@ -88,7 +88,7 @@ static void mtk_ppe_cache_enable(struct mtk_ppe *ppe, bool enable)
81 enable * MTK_PPE_CACHE_CTL_EN);
82 }
83
84-static u32 mtk_ppe_hash_entry(struct mtk_foe_entry *e)
85+static u32 mtk_ppe_hash_entry(struct mtk_ppe *ppe, struct mtk_foe_entry *e)
86 {
87 u32 hv1, hv2, hv3;
88 u32 hash;
89@@ -122,7 +122,7 @@ static u32 mtk_ppe_hash_entry(struct mtk_foe_entry *e)
90 hash = (hash >> 24) | ((hash & 0xffffff) << 8);
91 hash ^= hv1 ^ hv2 ^ hv3;
92 hash ^= hash >> 16;
93- hash <<= 2;
94+ hash <<= (ffs(ppe->way) - 1);
95 hash &= MTK_PPE_ENTRIES - 1;
96
97 return hash;
98@@ -542,10 +542,10 @@ int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
99 if (type == MTK_PPE_PKT_TYPE_BRIDGE)
100 return mtk_foe_entry_commit_l2(ppe, entry);
101
102- hash = mtk_ppe_hash_entry(&entry->data);
103+ hash = mtk_ppe_hash_entry(ppe, &entry->data);
104 entry->hash = 0xffff;
105 spin_lock_bh(&ppe_lock);
106- hlist_add_head(&entry->list, &ppe->foe_flow[hash / 4]);
107+ hlist_add_head(&entry->list, &ppe->foe_flow[hash / ppe->way]);
108 spin_unlock_bh(&ppe_lock);
109
110 return 0;
111@@ -569,7 +569,7 @@ mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
112 flow_info->l2_data.base_flow = entry;
113 flow_info->type = MTK_FLOW_TYPE_L2_SUBFLOW;
114 flow_info->hash = hash;
115- hlist_add_head(&flow_info->list, &ppe->foe_flow[hash / 4]);
116+ hlist_add_head(&flow_info->list, &ppe->foe_flow[hash / ppe->way]);
117 hlist_add_head(&flow_info->l2_data.list, &entry->l2_flows);
118
119 hwe = &ppe->foe_table[hash];
120@@ -593,7 +593,7 @@ mtk_foe_entry_commit_subflow(struct mtk_ppe *ppe, struct mtk_flow_entry *entry,
121
122 void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash)
123 {
124- struct hlist_head *head = &ppe->foe_flow[hash / 4];
125+ struct hlist_head *head = &ppe->foe_flow[hash / ppe->way];
126 struct mtk_foe_entry *hwe = &ppe->foe_table[hash];
127 struct mtk_flow_entry *entry;
128 struct mtk_foe_bridge key = {};
129@@ -676,12 +676,12 @@ int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
130 return __mtk_foe_entry_idle_time(ppe, entry->data.ib1);
131 }
132
133-struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
134- int version, int id)
135+struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int way, int id)
136 {
137 struct device *dev = eth->dev;
138 struct mtk_foe_entry *foe;
139 struct mtk_ppe *ppe;
140+ struct hlist_head *flow;
141
142 ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
143 if (!ppe)
144@@ -695,6 +696,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int versio
145 ppe->eth = eth;
146 ppe->dev = dev;
147 ppe->version = version;
148+ ppe->way = way;
149 ppe->id = id;
150
151 foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
152@@ -704,6 +706,13 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int versio
153
154 ppe->foe_table = foe;
155
156+ flow = devm_kzalloc(dev, (MTK_PPE_ENTRIES / way) * sizeof(*flow),
157+ GFP_KERNEL);
158+ if (!flow)
159+ return NULL;
160+
161+ ppe->foe_flow = flow;
162+
163 return ppe;
164 }
165
166diff --git a/drivers/net/ethernet/mediatek/mtk_ppe.h b/drivers/net/ethernet/mediatek/mtk_ppe.h
167index 21cc551..3d6928c 100644
168--- a/drivers/net/ethernet/mediatek/mtk_ppe.h
169+++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
170@@ -276,19 +276,20 @@ struct mtk_ppe {
171 void __iomem *base;
172 int version;
173 int id;
174+ int way;
175
176 struct mtk_foe_entry *foe_table;
177 dma_addr_t foe_phys;
178
179 u16 foe_check_time[MTK_PPE_ENTRIES];
180- struct hlist_head foe_flow[MTK_PPE_ENTRIES / 2];
181+ struct hlist_head *foe_flow;
182
183 struct rhashtable l2_flows;
184
185 void *acct_table;
186 };
187
188-struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int id);
189+struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version, int way, int id);
190 int mtk_ppe_start(struct mtk_ppe *ppe);
191 int mtk_ppe_stop(struct mtk_ppe *ppe);
192