030a3346768afcba600e2870a93e321c7ef9cdc6
[openwrt/staging/pepe2k.git] /
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Mon, 21 Feb 2022 15:38:20 +0100
3 Subject: [PATCH] net: ethernet: mtk_eth_soc: allocate struct mtk_ppe
4 separately
5
6 Preparation for adding more data to it, which will increase its size.
7
8 Signed-off-by: Felix Fietkau <nbd@nbd.name>
9 ---
10
11 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
12 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
13 @@ -2338,7 +2338,7 @@ static int mtk_open(struct net_device *d
14 return err;
15 }
16
17 - if (eth->soc->offload_version && mtk_ppe_start(&eth->ppe) == 0)
18 + if (eth->soc->offload_version && mtk_ppe_start(eth->ppe) == 0)
19 gdm_config = MTK_GDMA_TO_PPE;
20
21 mtk_gdm_config(eth, gdm_config);
22 @@ -2412,7 +2412,7 @@ static int mtk_stop(struct net_device *d
23 mtk_dma_free(eth);
24
25 if (eth->soc->offload_version)
26 - mtk_ppe_stop(&eth->ppe);
27 + mtk_ppe_stop(eth->ppe);
28
29 return 0;
30 }
31 @@ -3297,10 +3297,11 @@ static int mtk_probe(struct platform_dev
32 }
33
34 if (eth->soc->offload_version) {
35 - err = mtk_ppe_init(&eth->ppe, eth->dev,
36 - eth->base + MTK_ETH_PPE_BASE, 2);
37 - if (err)
38 + eth->ppe = mtk_ppe_init(eth->dev, eth->base + MTK_ETH_PPE_BASE, 2);
39 + if (!eth->ppe) {
40 + err = -ENOMEM;
41 goto err_free_dev;
42 + }
43
44 err = mtk_eth_offload_init(eth);
45 if (err)
46 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
47 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
48 @@ -983,7 +983,7 @@ struct mtk_eth {
49 u32 rx_dma_l4_valid;
50 int ip_align;
51
52 - struct mtk_ppe ppe;
53 + struct mtk_ppe *ppe;
54 struct rhashtable flow_table;
55 };
56
57 --- a/drivers/net/ethernet/mediatek/mtk_ppe.c
58 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.c
59 @@ -384,10 +384,15 @@ int mtk_foe_entry_commit(struct mtk_ppe
60 return hash;
61 }
62
63 -int mtk_ppe_init(struct mtk_ppe *ppe, struct device *dev, void __iomem *base,
64 +struct mtk_ppe *mtk_ppe_init(struct device *dev, void __iomem *base,
65 int version)
66 {
67 struct mtk_foe_entry *foe;
68 + struct mtk_ppe *ppe;
69 +
70 + ppe = devm_kzalloc(dev, sizeof(*ppe), GFP_KERNEL);
71 + if (!ppe)
72 + return NULL;
73
74 /* need to allocate a separate device, since it PPE DMA access is
75 * not coherent.
76 @@ -399,13 +404,13 @@ int mtk_ppe_init(struct mtk_ppe *ppe, st
77 foe = dmam_alloc_coherent(ppe->dev, MTK_PPE_ENTRIES * sizeof(*foe),
78 &ppe->foe_phys, GFP_KERNEL);
79 if (!foe)
80 - return -ENOMEM;
81 + return NULL;
82
83 ppe->foe_table = foe;
84
85 mtk_ppe_debugfs_init(ppe);
86
87 - return 0;
88 + return ppe;
89 }
90
91 static void mtk_ppe_init_foe_table(struct mtk_ppe *ppe)
92 --- a/drivers/net/ethernet/mediatek/mtk_ppe.h
93 +++ b/drivers/net/ethernet/mediatek/mtk_ppe.h
94 @@ -246,8 +246,7 @@ struct mtk_ppe {
95 void *acct_table;
96 };
97
98 -int mtk_ppe_init(struct mtk_ppe *ppe, struct device *dev, void __iomem *base,
99 - int version);
100 +struct mtk_ppe *mtk_ppe_init(struct device *dev, void __iomem *base, int version);
101 int mtk_ppe_start(struct mtk_ppe *ppe);
102 int mtk_ppe_stop(struct mtk_ppe *ppe);
103
104 --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
105 +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c
106 @@ -411,7 +411,7 @@ mtk_flow_offload_replace(struct mtk_eth
107
108 entry->cookie = f->cookie;
109 timestamp = mtk_eth_timestamp(eth);
110 - hash = mtk_foe_entry_commit(&eth->ppe, &foe, timestamp);
111 + hash = mtk_foe_entry_commit(eth->ppe, &foe, timestamp);
112 if (hash < 0) {
113 err = hash;
114 goto free;
115 @@ -426,7 +426,7 @@ mtk_flow_offload_replace(struct mtk_eth
116
117 return 0;
118 clear_flow:
119 - mtk_foe_entry_clear(&eth->ppe, hash);
120 + mtk_foe_entry_clear(eth->ppe, hash);
121 free:
122 kfree(entry);
123 if (wed_index >= 0)
124 @@ -444,7 +444,7 @@ mtk_flow_offload_destroy(struct mtk_eth
125 if (!entry)
126 return -ENOENT;
127
128 - mtk_foe_entry_clear(&eth->ppe, entry->hash);
129 + mtk_foe_entry_clear(eth->ppe, entry->hash);
130 rhashtable_remove_fast(&eth->flow_table, &entry->node,
131 mtk_flow_ht_params);
132 if (entry->wed_index >= 0)
133 @@ -466,7 +466,7 @@ mtk_flow_offload_stats(struct mtk_eth *e
134 if (!entry)
135 return -ENOENT;
136
137 - timestamp = mtk_foe_entry_timestamp(&eth->ppe, entry->hash);
138 + timestamp = mtk_foe_entry_timestamp(eth->ppe, entry->hash);
139 if (timestamp < 0)
140 return -ETIMEDOUT;
141
142 @@ -522,7 +522,7 @@ mtk_eth_setup_tc_block(struct net_device
143 struct flow_block_cb *block_cb;
144 flow_setup_cb_t *cb;
145
146 - if (!eth->ppe.foe_table)
147 + if (!eth->ppe || !eth->ppe->foe_table)
148 return -EOPNOTSUPP;
149
150 if (f->binder_type != FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS)
151 @@ -575,7 +575,7 @@ int mtk_eth_setup_tc(struct net_device *
152
153 int mtk_eth_offload_init(struct mtk_eth *eth)
154 {
155 - if (!eth->ppe.foe_table)
156 + if (!eth->ppe || !eth->ppe->foe_table)
157 return 0;
158
159 return rhashtable_init(&eth->flow_table, &mtk_flow_ht_params);