1 From patchwork Thu Sep 8 19:33:39 2022
2 Content-Type: text/plain; charset="utf-8"
4 Content-Transfer-Encoding: 7bit
5 X-Patchwork-Submitter: Lorenzo Bianconi <lorenzo@kernel.org>
6 X-Patchwork-Id: 12970559
7 X-Patchwork-Delegate: kuba@kernel.org
8 Return-Path: <netdev-owner@kernel.org>
9 From: Lorenzo Bianconi <lorenzo@kernel.org>
10 To: netdev@vger.kernel.org
11 Cc: nbd@nbd.name, john@phrozen.org, sean.wang@mediatek.com,
12 Mark-MC.Lee@mediatek.com, davem@davemloft.net, edumazet@google.com,
13 kuba@kernel.org, pabeni@redhat.com, matthias.bgg@gmail.com,
14 linux-mediatek@lists.infradead.org, lorenzo.bianconi@redhat.com,
15 Bo.Jiao@mediatek.com, sujuan.chen@mediatek.com,
16 ryder.Lee@mediatek.com, evelyn.tsai@mediatek.com,
17 devicetree@vger.kernel.org, robh@kernel.org
18 Subject: [PATCH net-next 05/12] net: ethernet: mtk_eth_soc: add the capability
20 Date: Thu, 8 Sep 2022 21:33:39 +0200
22 <dd0254775390eb031c67c448df8b19e87df58558.1662661555.git.lorenzo@kernel.org>
23 X-Mailer: git-send-email 2.37.3
24 In-Reply-To: <cover.1662661555.git.lorenzo@kernel.org>
25 References: <cover.1662661555.git.lorenzo@kernel.org>
28 List-ID: <netdev.vger.kernel.org>
29 X-Mailing-List: netdev@vger.kernel.org
30 X-Patchwork-Delegate: kuba@kernel.org
32 mt7986 chipset support multiple packet engines for wlan <-> eth
35 Co-developed-by: Bo Jiao <Bo.Jiao@mediatek.com>
36 Signed-off-by: Bo Jiao <Bo.Jiao@mediatek.com>
37 Co-developed-by: Sujuan Chen <sujuan.chen@mediatek.com>
38 Signed-off-by: Sujuan Chen <sujuan.chen@mediatek.com>
39 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
41 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 35 ++++++++++++-------
42 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 2 +-
43 drivers/net/ethernet/mediatek/mtk_ppe.c | 14 +++++---
44 drivers/net/ethernet/mediatek/mtk_ppe.h | 9 +++--
45 .../net/ethernet/mediatek/mtk_ppe_debugfs.c | 8 ++---
46 .../net/ethernet/mediatek/mtk_ppe_offload.c | 13 +++----
47 6 files changed, 48 insertions(+), 33 deletions(-)
49 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
50 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
51 @@ -1871,7 +1871,7 @@ static int mtk_poll_rx(struct napi_struc
53 reason = FIELD_GET(MTK_RXD4_PPE_CPU_REASON, trxd.rxd4);
54 if (reason == MTK_PPE_CPU_REASON_HIT_UNBIND_RATE_REACHED)
55 - mtk_ppe_check_skb(eth->ppe, skb, hash);
56 + mtk_ppe_check_skb(eth->ppe[0], skb, hash);
58 if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) {
59 if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) {
60 @@ -2929,15 +2929,19 @@ static int mtk_open(struct net_device *d
61 /* we run 2 netdevs on the same dma ring so we only bring it up once */
62 if (!refcount_read(ð->dma_refcnt)) {
63 const struct mtk_soc_data *soc = eth->soc;
64 - u32 gdm_config = MTK_GDMA_TO_PDMA;
69 err = mtk_start_dma(eth);
73 - if (soc->offload_version && mtk_ppe_start(eth->ppe) == 0)
74 - gdm_config = soc->reg_map->gdma_to_ppe0;
75 + for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
76 + mtk_ppe_start(eth->ppe[i]);
78 + gdm_config = soc->offload_version ? soc->reg_map->gdma_to_ppe0
81 mtk_gdm_config(eth, gdm_config);
83 @@ -2982,6 +2986,7 @@ static int mtk_stop(struct net_device *d
85 struct mtk_mac *mac = netdev_priv(dev);
86 struct mtk_eth *eth = mac->hw;
89 phylink_stop(mac->phylink);
91 @@ -3009,8 +3014,8 @@ static int mtk_stop(struct net_device *d
95 - if (eth->soc->offload_version)
96 - mtk_ppe_stop(eth->ppe);
97 + for (i = 0; i < ARRAY_SIZE(eth->ppe); i++)
98 + mtk_ppe_stop(eth->ppe[i]);
102 @@ -4050,12 +4055,19 @@ static int mtk_probe(struct platform_dev
105 if (eth->soc->offload_version) {
106 - u32 ppe_addr = eth->soc->reg_map->ppe_base;
109 - eth->ppe = mtk_ppe_init(eth, eth->base + ppe_addr, 2);
113 + num_ppe = MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2) ? 2 : 1;
114 + num_ppe = min_t(u32, ARRAY_SIZE(eth->ppe), num_ppe);
115 + for (i = 0; i < num_ppe; i++) {
116 + u32 ppe_addr = eth->soc->reg_map->ppe_base + i * 0x400;
118 + eth->ppe[i] = mtk_ppe_init(eth, eth->base + ppe_addr,
119 + eth->soc->offload_version, i);
120 + if (!eth->ppe[i]) {
126 err = mtk_eth_offload_init(eth);
127 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
128 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
129 @@ -1111,7 +1111,7 @@ struct mtk_eth {
133 - struct mtk_ppe *ppe;
134 + struct mtk_ppe *ppe[2];
135 struct rhashtable flow_table;
137 struct bpf_prog __rcu *prog;
138 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
139 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
140 @@ -682,7 +682,7 @@ int mtk_foe_entry_idle_time(struct mtk_p
143 struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
145 + int version, int index)
147 const struct mtk_soc_data *soc = eth->soc;
148 struct device *dev = eth->dev;
149 @@ -717,7 +717,7 @@ struct mtk_ppe *mtk_ppe_init(struct mtk_
153 - mtk_ppe_debugfs_init(ppe);
154 + mtk_ppe_debugfs_init(ppe, index);
158 @@ -738,10 +738,13 @@ static void mtk_ppe_init_foe_table(struc
159 ppe->foe_table[i + skip[k]].ib1 |= MTK_FOE_IB1_STATIC;
162 -int mtk_ppe_start(struct mtk_ppe *ppe)
163 +void mtk_ppe_start(struct mtk_ppe *ppe)
170 mtk_ppe_init_foe_table(ppe);
171 ppe_w32(ppe, MTK_PPE_TB_BASE, ppe->foe_phys);
173 @@ -809,8 +812,6 @@ int mtk_ppe_start(struct mtk_ppe *ppe)
174 ppe_w32(ppe, MTK_PPE_GLO_CFG, val);
176 ppe_w32(ppe, MTK_PPE_DEFAULT_CPU_PORT, 0);
181 int mtk_ppe_stop(struct mtk_ppe *ppe)
182 @@ -818,6 +819,9 @@ int mtk_ppe_stop(struct mtk_ppe *ppe)
189 for (i = 0; i < MTK_PPE_ENTRIES; i++)
190 ppe->foe_table[i].ib1 = FIELD_PREP(MTK_FOE_IB1_STATE,
191 MTK_FOE_STATE_INVALID);
192 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
193 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
194 @@ -247,6 +247,7 @@ struct mtk_flow_entry {
201 struct mtk_foe_entry data;
202 @@ -265,6 +266,7 @@ struct mtk_ppe {
208 struct mtk_foe_entry *foe_table;
210 @@ -277,8 +279,9 @@ struct mtk_ppe {
214 -struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base, int version);
215 -int mtk_ppe_start(struct mtk_ppe *ppe);
216 +struct mtk_ppe *mtk_ppe_init(struct mtk_eth *eth, void __iomem *base,
217 + int version, int index);
218 +void mtk_ppe_start(struct mtk_ppe *ppe);
219 int mtk_ppe_stop(struct mtk_ppe *ppe);
221 void __mtk_ppe_check_skb(struct mtk_ppe *ppe, struct sk_buff *skb, u16 hash);
222 @@ -317,6 +320,6 @@ int mtk_foe_entry_set_wdma(struct mtk_fo
223 int mtk_foe_entry_commit(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
224 void mtk_foe_entry_clear(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
225 int mtk_foe_entry_idle_time(struct mtk_ppe *ppe, struct mtk_flow_entry *entry);
226 -int mtk_ppe_debugfs_init(struct mtk_ppe *ppe);
227 +int mtk_ppe_debugfs_init(struct mtk_ppe *ppe, int index);
230 --- a/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
231 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_debugfs.c
232 @@ -187,7 +187,7 @@ mtk_ppe_debugfs_foe_open_bind(struct ino
236 -int mtk_ppe_debugfs_init(struct mtk_ppe *ppe)
237 +int mtk_ppe_debugfs_init(struct mtk_ppe *ppe, int index)
239 static const struct file_operations fops_all = {
240 .open = mtk_ppe_debugfs_foe_open_all,
241 @@ -195,17 +195,17 @@ int mtk_ppe_debugfs_init(struct mtk_ppe
243 .release = single_release,
246 static const struct file_operations fops_bind = {
247 .open = mtk_ppe_debugfs_foe_open_bind,
250 .release = single_release,
255 - root = debugfs_create_dir("mtk_ppe", NULL);
256 + snprintf(ppe->dirname, sizeof(ppe->dirname), "ppe%d", index);
258 + root = debugfs_create_dir(ppe->dirname, NULL);
262 --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
263 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
264 @@ -434,7 +434,7 @@ mtk_flow_offload_replace(struct mtk_eth
265 memcpy(&entry->data, &foe, sizeof(entry->data));
266 entry->wed_index = wed_index;
268 - err = mtk_foe_entry_commit(eth->ppe, entry);
269 + err = mtk_foe_entry_commit(eth->ppe[entry->ppe_index], entry);
273 @@ -446,7 +446,7 @@ mtk_flow_offload_replace(struct mtk_eth
277 - mtk_foe_entry_clear(eth->ppe, entry);
278 + mtk_foe_entry_clear(eth->ppe[entry->ppe_index], entry);
282 @@ -464,7 +464,7 @@ mtk_flow_offload_destroy(struct mtk_eth
286 - mtk_foe_entry_clear(eth->ppe, entry);
287 + mtk_foe_entry_clear(eth->ppe[entry->ppe_index], entry);
288 rhashtable_remove_fast(ð->flow_table, &entry->node,
290 if (entry->wed_index >= 0)
291 @@ -485,7 +485,7 @@ mtk_flow_offload_stats(struct mtk_eth *e
295 - idle = mtk_foe_entry_idle_time(eth->ppe, entry);
296 + idle = mtk_foe_entry_idle_time(eth->ppe[entry->ppe_index], entry);
297 f->stats.lastused = jiffies - idle * HZ;
300 @@ -537,7 +537,7 @@ mtk_eth_setup_tc_block(struct net_device
301 struct flow_block_cb *block_cb;
304 - if (!eth->ppe || !eth->ppe->foe_table)
305 + if (!eth->soc->offload_version)
308 if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
309 @@ -589,8 +589,5 @@ int mtk_eth_setup_tc(struct net_device *
311 int mtk_eth_offload_init(struct mtk_eth *eth)
313 - if (!eth->ppe || !eth->ppe->foe_table)
316 return rhashtable_init(ð->flow_table, &mtk_flow_ht_params);