be12aa5c06672ee214d5632d24b2cd8ce2ed1512
[openwrt/staging/hauke.git] / target / linux / generic / pending-6.1 / 737-03-net-ethernet-mtk_eth_soc-rely-on-num_devs-and-remove.patch
1 From 4e35e80750b33727e606be9e7ce447bde2e0deb7 Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Tue, 7 Mar 2023 15:55:35 +0000
4 Subject: [PATCH 3/7] net: ethernet: mtk_eth_soc: rely on num_devs and remove
5 MTK_MAC_COUNT
6
7 Get rid of MTK_MAC_COUNT since it is a duplicated of eth->soc->num_devs.
8
9 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
10 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
11 ---
12 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 30 ++++++++++-----------
13 drivers/net/ethernet/mediatek/mtk_eth_soc.h | 1 -
14 2 files changed, 15 insertions(+), 16 deletions(-)
15
16 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
17 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
18 @@ -944,7 +944,7 @@ static void mtk_stats_update(struct mtk_
19 {
20 int i;
21
22 - for (i = 0; i < MTK_MAC_COUNT; i++) {
23 + for (i = 0; i < eth->soc->num_devs; i++) {
24 if (!eth->mac[i] || !eth->mac[i]->hw_stats)
25 continue;
26 if (spin_trylock(&eth->mac[i]->hw_stats->stats_lock)) {
27 @@ -1449,7 +1449,7 @@ static int mtk_queue_stopped(struct mtk_
28 {
29 int i;
30
31 - for (i = 0; i < MTK_MAC_COUNT; i++) {
32 + for (i = 0; i < eth->soc->num_devs; i++) {
33 if (!eth->netdev[i])
34 continue;
35 if (netif_queue_stopped(eth->netdev[i]))
36 @@ -1463,7 +1463,7 @@ static void mtk_wake_queue(struct mtk_et
37 {
38 int i;
39
40 - for (i = 0; i < MTK_MAC_COUNT; i++) {
41 + for (i = 0; i < eth->soc->num_devs; i++) {
42 if (!eth->netdev[i])
43 continue;
44 netif_tx_wake_all_queues(eth->netdev[i]);
45 @@ -1956,7 +1956,7 @@ static int mtk_poll_rx(struct napi_struc
46 !(trxd.rxd4 & RX_DMA_SPECIAL_TAG))
47 mac = RX_DMA_GET_SPORT(trxd.rxd4) - 1;
48
49 - if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT ||
50 + if (unlikely(mac < 0 || mac >= eth->soc->num_devs ||
51 !eth->netdev[mac]))
52 goto release_desc;
53
54 @@ -2993,7 +2993,7 @@ static void mtk_dma_free(struct mtk_eth
55 const struct mtk_soc_data *soc = eth->soc;
56 int i;
57
58 - for (i = 0; i < MTK_MAC_COUNT; i++)
59 + for (i = 0; i < soc->num_devs; i++)
60 if (eth->netdev[i])
61 netdev_reset_queue(eth->netdev[i]);
62 if (eth->scratch_ring) {
63 @@ -3147,7 +3147,7 @@ static void mtk_gdm_config(struct mtk_et
64 if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
65 return;
66
67 - for (i = 0; i < MTK_MAC_COUNT; i++) {
68 + for (i = 0; i < eth->soc->num_devs; i++) {
69 u32 val = mtk_r32(eth, MTK_GDMA_FWD_CFG(i));
70
71 /* default setup the forward port to send frame to PDMA */
72 @@ -3758,7 +3758,7 @@ static int mtk_hw_init(struct mtk_eth *e
73 * up with the more appropriate value when mtk_mac_config call is being
74 * invoked.
75 */
76 - for (i = 0; i < MTK_MAC_COUNT; i++) {
77 + for (i = 0; i < eth->soc->num_devs; i++) {
78 struct net_device *dev = eth->netdev[i];
79
80 mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
81 @@ -3963,7 +3963,7 @@ static void mtk_pending_work(struct work
82 mtk_prepare_for_reset(eth);
83
84 /* stop all devices to make sure that dma is properly shut down */
85 - for (i = 0; i < MTK_MAC_COUNT; i++) {
86 + for (i = 0; i < eth->soc->num_devs; i++) {
87 if (!eth->netdev[i] || !netif_running(eth->netdev[i]))
88 continue;
89
90 @@ -3979,7 +3979,7 @@ static void mtk_pending_work(struct work
91 mtk_hw_init(eth, true);
92
93 /* restart DMA and enable IRQs */
94 - for (i = 0; i < MTK_MAC_COUNT; i++) {
95 + for (i = 0; i < eth->soc->num_devs; i++) {
96 if (!test_bit(i, &restart))
97 continue;
98
99 @@ -4007,7 +4007,7 @@ static int mtk_free_dev(struct mtk_eth *
100 {
101 int i;
102
103 - for (i = 0; i < MTK_MAC_COUNT; i++) {
104 + for (i = 0; i < eth->soc->num_devs; i++) {
105 if (!eth->netdev[i])
106 continue;
107 free_netdev(eth->netdev[i]);
108 @@ -4026,7 +4026,7 @@ static int mtk_unreg_dev(struct mtk_eth
109 {
110 int i;
111
112 - for (i = 0; i < MTK_MAC_COUNT; i++) {
113 + for (i = 0; i < eth->soc->num_devs; i++) {
114 struct mtk_mac *mac;
115 if (!eth->netdev[i])
116 continue;
117 @@ -4331,7 +4331,7 @@ static int mtk_add_mac(struct mtk_eth *e
118 }
119
120 id = be32_to_cpup(_id);
121 - if (id >= MTK_MAC_COUNT) {
122 + if (id >= eth->soc->num_devs) {
123 dev_err(eth->dev, "%d is not a valid mac id\n", id);
124 return -EINVAL;
125 }
126 @@ -4461,7 +4461,7 @@ void mtk_eth_set_dma_device(struct mtk_e
127
128 rtnl_lock();
129
130 - for (i = 0; i < MTK_MAC_COUNT; i++) {
131 + for (i = 0; i < eth->soc->num_devs; i++) {
132 dev = eth->netdev[i];
133
134 if (!dev || !(dev->flags & IFF_UP))
135 @@ -4787,7 +4787,7 @@ static int mtk_remove(struct platform_de
136 int i;
137
138 /* stop all devices to make sure that dma is properly shut down */
139 - for (i = 0; i < MTK_MAC_COUNT; i++) {
140 + for (i = 0; i < eth->soc->num_devs; i++) {
141 if (!eth->netdev[i])
142 continue;
143 mtk_stop(eth->netdev[i]);
144 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h
145 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h
146 @@ -33,7 +33,6 @@
147 #define MTK_TX_DMA_BUF_LEN_V2 0xffff
148 #define MTK_QDMA_RING_SIZE 2048
149 #define MTK_DMA_SIZE 512
150 -#define MTK_MAC_COUNT 2
151 #define MTK_RX_ETH_HLEN (VLAN_ETH_HLEN + ETH_FCS_LEN)
152 #define MTK_RX_HLEN (NET_SKB_PAD + MTK_RX_ETH_HLEN + NET_IP_ALIGN)
153 #define MTK_DMA_DUMMY_DESC 0xffffffff