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
10 Introduce foe_entry_size to mtk_eth_soc data structure since mt7986
11 relies on a bigger mtk_foe_entry data structure.
13 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
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(-)
22 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
23 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
24 @@ -4161,6 +4161,7 @@ static const struct mtk_soc_data mt7621_
25 .required_pctl = false,
28 + .foe_entry_size = sizeof(struct mtk_foe_entry),
30 .txd_size = sizeof(struct mtk_tx_dma),
31 .rxd_size = sizeof(struct mtk_rx_dma),
32 @@ -4180,6 +4181,7 @@ static const struct mtk_soc_data mt7622_
33 .required_pctl = false,
36 + .foe_entry_size = sizeof(struct mtk_foe_entry),
38 .txd_size = sizeof(struct mtk_tx_dma),
39 .rxd_size = sizeof(struct mtk_rx_dma),
40 @@ -4198,6 +4200,7 @@ static const struct mtk_soc_data mt7623_
41 .required_pctl = true,
44 + .foe_entry_size = sizeof(struct mtk_foe_entry),
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 {
63 netdev_features_t hw_features;
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[];
70 +static inline struct mtk_foe_entry *
71 +mtk_foe_get_entry(struct mtk_ppe *ppe, u16 hash)
73 + const struct mtk_soc_data *soc = ppe->eth->soc;
75 + return ppe->foe_table + hash * soc->foe_entry_size;
78 /* read the hardware status register */
79 void mtk_stats_update_mac(struct mtk_mac *mac);
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
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);
92 + hwe->ib1 &= ~MTK_FOE_IB1_STATE;
93 + hwe->ib1 |= FIELD_PREP(MTK_FOE_IB1_STATE, MTK_FOE_STATE_BIND);
97 @@ -451,7 +452,7 @@ mtk_flow_entry_update_l2(struct mtk_ppe
101 - hwe = &ppe->foe_table[cur->hash];
102 + hwe = mtk_foe_get_entry(ppe, cur->hash);
103 ib1 = READ_ONCE(hwe->ib1);
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
108 mtk_flow_entry_update(struct mtk_ppe *ppe, struct mtk_flow_entry *entry)
110 + struct mtk_foe_entry foe = {};
111 struct mtk_foe_entry *hwe;
112 - struct mtk_foe_entry foe;
114 spin_lock_bh(&ppe_lock);
116 @@ -486,8 +487,8 @@ mtk_flow_entry_update(struct mtk_ppe *pp
117 if (entry->hash == 0xffff)
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;
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);
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);
136 hwe->ib1 = entry->ib1;
138 @@ -561,7 +562,7 @@ mtk_foe_entry_commit_subflow(struct mtk_
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;
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);
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);
156 foe.ib1 |= entry->data.ib1 & ~ib1_mask;
158 @@ -601,7 +602,7 @@ void __mtk_ppe_check_skb(struct mtk_ppe
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_
169 const struct mtk_soc_data *soc = eth->soc;
170 struct device *dev = eth->dev;
171 - struct mtk_foe_entry *foe;
176 ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
178 @@ -704,7 +705,8 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_
180 ppe->version = version;
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);
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 };
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);
196 if (!IS_ENABLED(CONFIG_SOC_MT7621))
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;
207 + hwe = mtk_foe_get_entry(ppe, i + skip[k]);
208 + hwe->ib1 |= MTK_FOE_IB1_STATIC;
213 void mtk_ppe_start(struct mtk_ppe *ppe)
214 @@ -822,9 +830,12 @@ int mtk_ppe_stop(struct mtk_ppe *ppe)
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);
224 + hwe->ib1 = FIELD_PREP(MTK_FOE_IB1_STATE,
225 + MTK_FOE_STATE_INVALID);
228 mtk_ppe_cache_enable(ppe, false);
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 {
236 - struct mtk_foe_entry *foe_table;
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
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];