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
7 Get rid of MTK_MAC_COUNT since it is a duplicated of MTK_MAX_DEVS.
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>
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(-)
18 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
19 +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
20 @@ -837,7 +837,7 @@ static void mtk_stats_update(struct mtk_
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)
28 if (spin_trylock(ð->mac[i]->hw_stats->stats_lock)) {
29 @@ -1340,7 +1340,7 @@ static int mtk_queue_stopped(struct mtk_
33 - for (i = 0; i < MTK_MAC_COUNT; i++) {
34 + for (i = 0; i < MTK_MAX_DEVS; i++) {
37 if (netif_queue_stopped(eth->netdev[i]))
38 @@ -1354,7 +1354,7 @@ static void mtk_wake_queue(struct mtk_et
42 - for (i = 0; i < MTK_MAC_COUNT; i++) {
43 + for (i = 0; i < MTK_MAX_DEVS; i++) {
46 netif_tx_wake_all_queues(eth->netdev[i]);
47 @@ -1811,7 +1811,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;
51 - if (unlikely(mac < 0 || mac >= MTK_MAC_COUNT ||
52 + if (unlikely(mac < 0 || mac >= MTK_MAX_DEVS ||
56 @@ -2843,7 +2843,7 @@ static void mtk_dma_free(struct mtk_eth
57 const struct mtk_soc_data *soc = eth->soc;
60 - for (i = 0; i < MTK_MAC_COUNT; i++)
61 + for (i = 0; i < MTK_MAX_DEVS; i++)
63 netdev_reset_queue(eth->netdev[i]);
64 if (eth->scratch_ring) {
65 @@ -2997,8 +2997,13 @@ static void mtk_gdm_config(struct mtk_et
66 if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628))
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++) {
74 + if (!eth->netdev[i])
77 + val = mtk_r32(eth, MTK_GDMA_FWD_CFG(i));
79 /* default setup the forward port to send frame to PDMA */
81 @@ -3008,7 +3013,7 @@ static void mtk_gdm_config(struct mtk_et
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;
89 mtk_w32(eth, val, MTK_GDMA_FWD_CFG(i));
90 @@ -3607,15 +3612,15 @@ static int mtk_hw_init(struct mtk_eth *e
91 * up with the more appropriate value when mtk_mac_config call is being
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];
98 - mtk_w32(eth, MAC_MCR_FORCE_LINK_DOWN, MTK_MAC_MCR(i));
100 - struct mtk_mac *mac = netdev_priv(dev);
104 - mtk_set_mcr_max_rx(mac, dev->mtu + MTK_RX_ETH_HLEN);
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);
111 /* Indicates CDM to parse the MTK special tag from CPU
112 @@ -3795,7 +3800,7 @@ static void mtk_pending_work(struct work
113 mtk_prepare_for_reset(eth);
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]))
121 @@ -3811,8 +3816,8 @@ static void mtk_pending_work(struct work
122 mtk_hw_init(eth, true);
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))
131 if (mtk_open(eth->netdev[i])) {
132 @@ -3839,7 +3844,7 @@ static int mtk_free_dev(struct mtk_eth *
136 - for (i = 0; i < MTK_MAC_COUNT; i++) {
137 + for (i = 0; i < MTK_MAX_DEVS; i++) {
140 free_netdev(eth->netdev[i]);
141 @@ -3858,7 +3863,7 @@ static int mtk_unreg_dev(struct mtk_eth
145 - for (i = 0; i < MTK_MAC_COUNT; i++) {
146 + for (i = 0; i < MTK_MAX_DEVS; i++) {
150 @@ -4159,7 +4164,7 @@ static int mtk_add_mac(struct mtk_eth *e
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);
159 @@ -4304,7 +4309,7 @@ void mtk_eth_set_dma_device(struct mtk_e
163 - for (i = 0; i < MTK_MAC_COUNT; i++) {
164 + for (i = 0; i < MTK_MAX_DEVS; i++) {
165 dev = eth->netdev[i];
167 if (!dev || !(dev->flags & IFF_UP))
168 @@ -4612,7 +4617,7 @@ static int mtk_remove(struct platform_de
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++) {
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
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