2bce63c4c01b13b4629ac2a5e4390d4d284cd7ec
[openwrt/staging/svanheule.git] /
1 From e3c27d869fccc1f2b8d0b4cde4763ab223874e8c Mon Sep 17 00:00:00 2001
2 Message-Id: <e3c27d869fccc1f2b8d0b4cde4763ab223874e8c.1662243796.git.lorenzo@kernel.org>
3 In-Reply-To: <43a21841ce0175d29f23c34a65ceaaf9dd7eb8b7.1662243796.git.lorenzo@kernel.org>
4 References: <43a21841ce0175d29f23c34a65ceaaf9dd7eb8b7.1662243796.git.lorenzo@kernel.org>
5 From: Lorenzo Bianconi <lorenzo@kernel.org>
6 Date: Sun, 21 Aug 2022 17:51:17 +0200
7 Subject: [PATCH net-next 3/4] net: ethernet: mtk_eth_soc: add foe_entry_size
8 to mtk_eth_soc
9
10 Introduce foe_entry_size to mtk_eth_soc data structure since mt7986
11 relies on a bigger mtk_foe_entry data structure.
12
13 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
14 ---
15 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 3 +
16 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 10 ++++
17 drivers/net/ethernet/mediatek/mtk_ppe.c | 55 +++++++++++--------
18 drivers/net/ethernet/mediatek/mtk_ppe.h | 2 +-
19 .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 2 +-
20 5 files changed, 48 insertions(+), 24 deletions(-)
21
22 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
23 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
24 @@ -4168,6 +4168,7 @@ static const struct mtk_soc_data mt7621_
25 .required_pctl = false,
26 .offload_version = 2,
27 .hash_offset = 2,
28 + .foe_entry_size = sizeof(struct mtk_foe_entry),
29 .txrx = {
30 .txd_size = sizeof(struct mtk_tx_dma),
31 .rxd_size = sizeof(struct mtk_rx_dma),
32 @@ -4187,6 +4188,7 @@ static const struct mtk_soc_data mt7622_
33 .required_pctl = false,
34 .offload_version = 2,
35 .hash_offset = 2,
36 + .foe_entry_size = sizeof(struct mtk_foe_entry),
37 .txrx = {
38 .txd_size = sizeof(struct mtk_tx_dma),
39 .rxd_size = sizeof(struct mtk_rx_dma),
40 @@ -4205,6 +4207,7 @@ static const struct mtk_soc_data mt7623_
41 .required_pctl = true,
42 .offload_version = 2,
43 .hash_offset = 2,
44 + .foe_entry_size = sizeof(struct mtk_foe_entry),
45 .txrx = {
46 .txd_size = sizeof(struct mtk_tx_dma),
47 .rxd_size = sizeof(struct mtk_rx_dma),
48 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
49 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
50 @@ -966,6 +966,7 @@ struct mtk_reg_map {
51 * @required_pctl A bool value to show whether the SoC requires
52 * the extra setup for those pins used by GMAC.
53 * @hash_offset Flow table hash offset.
54 + * @foe_entry_size Foe table entry size.
55 * @txd_size Tx DMA descriptor size.
56 * @rxd_size Rx DMA descriptor size.
57 * @rx_irq_done_mask Rx irq done register mask.
58 @@ -981,6 +982,7 @@ struct mtk_soc_data {
59 bool required_pctl;
60 u8 offload_version;
61 u8 hash_offset;
62 + u16 foe_entry_size;
63 netdev_features_t hw_features;
64 struct {
65 u32 txd_size;
66 @@ -1141,6 +1143,14 @@ struct mtk_mac {
67 /* the struct describing the SoC. these are declared in the soc_xyz.c files */
68 extern const struct of_device_id of_mtk_match[];
69
70 +static inline struct mtk_foe_entry *
71 +mtk_foe_get_entry(struct mtk_ppe *ppe, u16 hash)
72 +{
73 + const struct mtk_soc_data *soc = ppe->eth->soc;
74 +
75 + return ppe->foe_table + hash * soc->foe_entry_size;
76 +}
77 +
78 /* read the hardware status register */
79 void mtk_stats_update_mac(struct mtk_mac *mac);
80
81 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
82 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
83 @@ -410,9 +410,10 @@ __mtk_foe_entry_clear(struct mtk_ppe *pp
84
85 hlist_del_init(&entry->list);
86 if (entry->hash != 0xffff) {
87 - ppe->foe_table[entry->hash].ib1 &= ~MTK_FOE_IB1_STATE;
88 - ppe->foe_table[entry->hash].ib1 |= FIELD_PREP(MTK_FOE_IB1_STATE,
89 - MTK_FOE_STATE_BIND);
90 + struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, entry->hash);
91 +
92 + hwe->ib1 &= ~MTK_FOE_IB1_STATE;
93 + hwe->ib1 |= FIELD_PREP(MTK_FOE_IB1_STATE, MTK_FOE_STATE_BIND);
94 dma_wmb();
95 }
96 entry->hash = 0xffff;
97 @@ -451,7 +452,7 @@ mtk_flow_entry_update_l2(struct mtk_ppe
98 int cur_idle;
99 u32 ib1;
100
101 - hwe = &ppe->foe_table[cur->hash];
102 + hwe = mtk_foe_get_entry(ppe, cur->hash);
103 ib1 = READ_ONCE(hwe->ib1);
104
105 if (FIELD_GET(MTK_FOE_IB1_STATE, ib1) != MTK_FOE_STATE_BIND) {
106 @@ -473,8 +474,8 @@ mtk_flow_entry_update_l2(struct mtk_ppe
107 static void
108 mtk_flow_entry_update(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
109 {
110 + struct mtk_foe_entry foe = {};
111 struct mtk_foe_entry *hwe;
112 - struct mtk_foe_entry foe;
113
114 spin_lock_bh(&ppe_lock);
115
116 @@ -486,8 +487,8 @@ mtk_flow_entry_update(struct mtk_ppe *pp
117 if (entry->hash == 0xffff)
118 goto out;
119
120 - hwe = &ppe->foe_table[entry->hash];
121 - memcpy(&foe, hwe, sizeof(foe));
122 + hwe = mtk_foe_get_entry(ppe, entry->hash);
123 + memcpy(&foe, hwe, ppe->eth->soc->foe_entry_size);
124 if (!mtk_flow_entry_match(entry, &foe)) {
125 entry->hash = 0xffff;
126 goto out;
127 @@ -511,8 +512,8 @@ __mtk_foe_entry_commit(struct mtk_ppe *p
128 entry->ib1 &= ~MTK_FOE_IB1_BIND_TIMESTAMP;
129 entry->ib1 |= FIELD_PREP(MTK_FOE_IB1_BIND_TIMESTAMP, timestamp);
130
131 - hwe = &ppe->foe_table[hash];
132 - memcpy(&hwe->data, &entry->data, sizeof(hwe->data));
133 + hwe = mtk_foe_get_entry(ppe, hash);
134 + memcpy(&hwe->data, &entry->data, ppe->eth->soc->foe_entry_size);
135 wmb();
136 hwe->ib1 = entry->ib1;
137
138 @@ -561,7 +562,7 @@ mtk_foe_entry_commit_subflow(struct mtk_
139 {
140 const struct mtk_soc_data *soc = ppe->eth->soc;
141 struct mtk_flow_entry *flow_info;
142 - struct mtk_foe_entry foe, *hwe;
143 + struct mtk_foe_entry foe = {}, *hwe;
144 struct mtk_foe_mac_info *l2;
145 u32 ib1_mask = MTK_FOE_IB1_PACKET_TYPE | MTK_FOE_IB1_UDP;
146 int type;
147 @@ -578,8 +579,8 @@ mtk_foe_entry_commit_subflow(struct mtk_
148 &ppe->foe_flow[hash / soc->hash_offset]);
149 hlist_add_head(&flow_info->l2_data.list, &entry->l2_flows);
150
151 - hwe = &ppe->foe_table[hash];
152 - memcpy(&foe, hwe, sizeof(foe));
153 + hwe = mtk_foe_get_entry(ppe, hash);
154 + memcpy(&foe, hwe, soc->foe_entry_size);
155 foe.ib1 &= ib1_mask;
156 foe.ib1 |= entry->data.ib1 & ~ib1_mask;
157
158 @@ -601,7 +602,7 @@ void __mtk_ppe_check_skb(struct mtk_ppe
159 {
160 const struct mtk_soc_data *soc = ppe->eth->soc;
161 struct hlist_head *head = &ppe->foe_flow[hash / soc->hash_offset];
162 - struct mtk_foe_entry *hwe = &ppe->foe_table[hash];
163 + struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, hash);
164 struct mtk_flow_entry *entry;
165 struct mtk_foe_bridge key = {};
166 struct hlist_node *n;
167 @@ -686,9 +687,9 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_
168 {
169 const struct mtk_soc_data *soc = eth->soc;
170 struct device *dev = eth->dev;
171 - struct mtk_foe_entry *foe;
172 struct mtk_ppe *ppe;
173 u32 foe_flow_size;
174 + void *foe;
175
176 ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
177 if (!ppe)
178 @@ -704,7 +705,8 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_
179 ppe->dev = dev;
180 ppe->version = version;
181
182 - foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
183 + foe = dmam_alloc_coherent(ppe->dev,
184 + MTK_PPE_ENTRIES * soc->foe_entry_size,
185 &ppe->foe_phys, GFP_KERNEL);
186 if (!foe)
187 return NULL;
188 @@ -727,15 +729,21 @@ static void mtk_ppe_init_foe_table(struc
189 static const u8 skip[] = { 12, 25, 38, 51, 76, 89, 102 };
190 int i, k;
191
192 - memset(ppe->foe_table, 0, MTK_PPE_ENTRIES * sizeof(*ppe->foe_table));
193 + memset(ppe->foe_table, 0,
194 + MTK_PPE_ENTRIES * ppe->eth->soc->foe_entry_size);
195
196 if (!IS_ENABLED(CONFIG_SOC_MT7621))
197 return;
198
199 /* skip all entries that cross the 1024 byte boundary */
200 - for (i = 0; i < MTK_PPE_ENTRIES; i += 128)
201 - for (k = 0; k < ARRAY_SIZE(skip); k++)
202 - ppe->foe_table[i + skip[k]].ib1 |= MTK_FOE_IB1_STATIC;
203 + for (i = 0; i < MTK_PPE_ENTRIES; i += 128) {
204 + for (k = 0; k < ARRAY_SIZE(skip); k++) {
205 + struct mtk_foe_entry *hwe;
206 +
207 + hwe = mtk_foe_get_entry(ppe, i + skip[k]);
208 + hwe->ib1 |= MTK_FOE_IB1_STATIC;
209 + }
210 + }
211 }
212
213 void mtk_ppe_start(struct mtk_ppe *ppe)
214 @@ -822,9 +830,12 @@ int mtk_ppe_stop(struct mtk_ppe *ppe)
215 if (!ppe)
216 return 0;
217
218 - for (i = 0; i < MTK_PPE_ENTRIES; i++)
219 - ppe->foe_table[i].ib1 = FIELD_PREP(MTK_FOE_IB1_STATE,
220 - MTK_FOE_STATE_INVALID);
221 + for (i = 0; i < MTK_PPE_ENTRIES; i++) {
222 + struct mtk_foe_entry *hwe = mtk_foe_get_entry(ppe, i);
223 +
224 + hwe->ib1 = FIELD_PREP(MTK_FOE_IB1_STATE,
225 + MTK_FOE_STATE_INVALID);
226 + }
227
228 mtk_ppe_cache_enable(ppe, false);
229
230 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
231 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
232 @@ -268,7 +268,7 @@ struct mtk_ppe {
233 int version;
234 char dirname[5];
235
236 - struct mtk_foe_entry *foe_table;
237 + void *foe_table;
238 dma_addr_t foe_phys;
239
240 u16 foe_check_time[MTK_PPE_ENTRIES];
241 --- a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
242 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
243 @@ -79,7 +79,7 @@ mtk_ppe_debugfs_foe_show(struct seq_file
244 int i;
245
246 for (i = 0; i < MTK_PPE_ENTRIES; i++) {
247 - struct mtk_foe_entry *entry = &ppe->foe_table[i];
248 + struct mtk_foe_entry *entry = mtk_foe_get_entry(ppe, i);
249 struct mtk_foe_mac_info *l2;
250 struct mtk_flow_addr_info ai = {};
251 unsigned char h_source[ETH_ALEN];