5ac9d61ab424a761b123a0d319ce43e6a5e2b3bc
[openwrt/staging/jow.git] /
1 From 856be974290f28d7943be2ac5a382c4139486196 Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Tue, 25 Jul 2023 01:52:44 +0100
4 Subject: [PATCH 101/250] net: ethernet: mtk_eth_soc: rely on MTK_MAX_DEVS and
5 remove MTK_MAC_COUNT
6
7 Get rid of MTK_MAC_COUNT since it is a duplicated of MTK_MAX_DEVS.
8
9 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
10 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
11 Link: https://lore.kernel.org/r/1856f4266f2fc80677807b1bad867659e7b00c65.1690246066.git.daniel@makrotopia.org
12 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
13 ---
14 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 49 ++++++++++++---------
15 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 1 -
16 2 files changed, 27 insertions(+), 23 deletions(-)
17
18 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 @@ -882,7 +882,7 @@ static void mtk_stats_update(struct mtk_
21 {
22 int i;
23
24 - for (i = 0; i < MTK_MAC_COUNT; i++) {
25 + for (i = 0; i < MTK_MAX_DEVS; i++) {
26 if (!eth->mac[i] || !eth->mac[i]->hw_stats)
27 continue;
28 if (spin_trylock(&eth->mac[i]->hw_stats->stats_lock)) {
29 @@ -1387,7 +1387,7 @@ static int mtk_queue_stopped(struct mtk_
30 {
31 int i;
32
33 - for (i = 0; i < MTK_MAC_COUNT; i++) {
34 + for (i = 0; i < MTK_MAX_DEVS; i++) {
35 if (!eth->netdev[i])
36 continue;
37 if (netif_queue_stopped(eth->netdev[i]))
38 @@ -1401,7 +1401,7 @@ static void mtk_wake_queue(struct mtk_et
39 {
40 int i;
41
42 - for (i = 0; i < MTK_MAC_COUNT; i++) {
43 + for (i = 0; i < MTK_MAX_DEVS; i++) {
44 if (!eth->netdev[i])
45 continue;
46 netif_tx_wake_all_queues(eth->netdev[i]);
47 @@ -1860,7 +1860,7 @@ static int mtk_poll_rx(struct napi_struc
48 !(trxd.rxd4 & RX_DMA_SPECIAL_TAG))
49 mac = RX_DMA_GET_SPORT(trxd.rxd4) - 1;
50
51 - if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT ||
52 + if (unlikely(mac < 0 || mac >= MTK_MAX_DEVS ||
53 !eth->netdev[mac]))
54 goto release_desc;
55
56 @@ -2900,7 +2900,7 @@ static void mtk_dma_free(struct mtk_eth
57 const struct mtk_soc_data *soc = eth->soc;
58 int i;
59
60 - for (i = 0; i < MTK_MAC_COUNT; i++)
61 + for (i = 0; i < MTK_MAX_DEVS; i++)
62 if (eth->netdev[i])
63 netdev_reset_queue(eth->netdev[i]);
64 if (eth->scratch_ring) {
65 @@ -3054,8 +3054,13 @@ static void mtk_gdm_config(struct mtk_et
66 if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
67 return;
68
69 - for (i = 0; i < MTK_MAC_COUNT; i++) {
70 - u32 val = mtk_r32(eth, MTK_GDMA_FWD_CFG(i));
71 + for (i = 0; i < MTK_MAX_DEVS; i++) {
72 + u32 val;
73 +
74 + if (!eth->netdev[i])
75 + continue;
76 +
77 + val = mtk_r32(eth, MTK_GDMA_FWD_CFG(i));
78
79 /* default setup the forward port to send frame to PDMA */
80 val &= ~0xffff;
81 @@ -3065,7 +3070,7 @@ static void mtk_gdm_config(struct mtk_et
82
83 val |= config;
84
85 - if (eth->netdev[i] && netdev_uses_dsa(eth->netdev[i]))
86 + if (netdev_uses_dsa(eth->netdev[i]))
87 val |= MTK_GDMA_SPECIAL_TAG;
88
89 mtk_w32(eth, val, MTK_GDMA_FWD_CFG(i));
90 @@ -3662,15 +3667,15 @@ static int mtk_hw_init(struct mtk_eth *e
91 * up with the more appropriate value when mtk_mac_config call is being
92 * invoked.
93 */
94 - for (i = 0; i < MTK_MAC_COUNT; i++) {
95 + for (i = 0; i < MTK_MAX_DEVS; i++) {
96 struct net_device *dev = eth->netdev[i];
97
98 - mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
99 - if (dev) {
100 - struct mtk_mac *mac = netdev_priv(dev);
101 + if (!dev)
102 + continue;
103
104 - mtk_set_mcr_max_rx(mac, dev->mtu + MTK_RX_ETH_HLEN);
105 - }
106 + mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
107 + mtk_set_mcr_max_rx(netdev_priv(dev),
108 + dev->mtu + MTK_RX_ETH_HLEN);
109 }
110
111 /* Indicates CDM to parse the MTK special tag from CPU
112 @@ -3850,7 +3855,7 @@ static void mtk_pending_work(struct work
113 mtk_prepare_for_reset(eth);
114
115 /* stop all devices to make sure that dma is properly shut down */
116 - for (i = 0; i < MTK_MAC_COUNT; i++) {
117 + for (i = 0; i < MTK_MAX_DEVS; i++) {
118 if (!eth->netdev[i] || !netif_running(eth->netdev[i]))
119 continue;
120
121 @@ -3866,8 +3871,8 @@ static void mtk_pending_work(struct work
122 mtk_hw_init(eth, true);
123
124 /* restart DMA and enable IRQs */
125 - for (i = 0; i < MTK_MAC_COUNT; i++) {
126 - if (!test_bit(i, &restart))
127 + for (i = 0; i < MTK_MAX_DEVS; i++) {
128 + if (!eth->netdev[i] || !test_bit(i, &restart))
129 continue;
130
131 if (mtk_open(eth->netdev[i])) {
132 @@ -3894,7 +3899,7 @@ static int mtk_free_dev(struct mtk_eth *
133 {
134 int i;
135
136 - for (i = 0; i < MTK_MAC_COUNT; i++) {
137 + for (i = 0; i < MTK_MAX_DEVS; i++) {
138 if (!eth->netdev[i])
139 continue;
140 free_netdev(eth->netdev[i]);
141 @@ -3913,7 +3918,7 @@ static int mtk_unreg_dev(struct mtk_eth
142 {
143 int i;
144
145 - for (i = 0; i < MTK_MAC_COUNT; i++) {
146 + for (i = 0; i < MTK_MAX_DEVS; i++) {
147 struct mtk_mac *mac;
148 if (!eth->netdev[i])
149 continue;
150 @@ -4214,7 +4219,7 @@ static int mtk_add_mac(struct mtk_eth *e
151 }
152
153 id = be32_to_cpup(_id);
154 - if (id >= MTK_MAC_COUNT) {
155 + if (id >= MTK_MAX_DEVS) {
156 dev_err(eth->dev, "%d is not a valid mac id\n", id);
157 return -EINVAL;
158 }
159 @@ -4359,7 +4364,7 @@ void mtk_eth_set_dma_device(struct mtk_e
160
161 rtnl_lock();
162
163 - for (i = 0; i < MTK_MAC_COUNT; i++) {
164 + for (i = 0; i < MTK_MAX_DEVS; i++) {
165 dev = eth->netdev[i];
166
167 if (!dev || !(dev->flags & IFF_UP))
168 @@ -4665,7 +4670,7 @@ static int mtk_remove(struct platform_de
169 int i;
170
171 /* stop all devices to make sure that dma is properly shut down */
172 - for (i = 0; i < MTK_MAC_COUNT; i++) {
173 + for (i = 0; i < MTK_MAX_DEVS; i++) {
174 if (!eth->netdev[i])
175 continue;
176 mtk_stop(eth->netdev[i]);
177 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
178 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
179 @@ -33,7 +33,6 @@
180 #define MTK_TX_DMA_BUF_LEN_V2 0xffff
181 #define MTK_QDMA_RING_SIZE 2048
182 #define MTK_DMA_SIZE 512
183 -#define MTK_MAC_COUNT 2
184 #define MTK_RX_ETH_HLEN (VLAN_ETH_HLEN + ETH_FCS_LEN)
185 #define MTK_RX_HLEN (NET_SKB_PAD + MTK_RX_ETH_HLEN + NET_IP_ALIGN)
186 #define MTK_DMA_DUMMY_DESC 0xffffffff