Skip to content

Commit 1953f13

Browse files
LorenzoBianconikuba-moo
authored andcommitted
net: ethernet: mtk_eth_soc: add NETSYS_V3 version support
Introduce NETSYS_V3 chipset version support. This is a preliminary patch to introduce support for MT7988 SoC. Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Daniel Golle <[email protected]> Link: https://lore.kernel.org/r/0db2260910755d76fa48e303b9f9bdf4e5a82340.1690246066.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e05fd62 commit 1953f13

File tree

2 files changed

+116
-37
lines changed

2 files changed

+116
-37
lines changed

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 77 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -876,17 +876,32 @@ void mtk_stats_update_mac(struct mtk_mac *mac)
876876
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x20 + offs);
877877
hw_stats->rx_flow_control_packets +=
878878
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x24 + offs);
879-
hw_stats->tx_skip +=
880-
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x28 + offs);
881-
hw_stats->tx_collisions +=
882-
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x2c + offs);
883-
hw_stats->tx_bytes +=
884-
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x30 + offs);
885-
stats = mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x34 + offs);
886-
if (stats)
887-
hw_stats->tx_bytes += (stats << 32);
888-
hw_stats->tx_packets +=
889-
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x38 + offs);
879+
880+
if (mtk_is_netsys_v3_or_greater(eth)) {
881+
hw_stats->tx_skip +=
882+
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x50 + offs);
883+
hw_stats->tx_collisions +=
884+
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x54 + offs);
885+
hw_stats->tx_bytes +=
886+
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x40 + offs);
887+
stats = mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x44 + offs);
888+
if (stats)
889+
hw_stats->tx_bytes += (stats << 32);
890+
hw_stats->tx_packets +=
891+
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x48 + offs);
892+
} else {
893+
hw_stats->tx_skip +=
894+
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x28 + offs);
895+
hw_stats->tx_collisions +=
896+
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x2c + offs);
897+
hw_stats->tx_bytes +=
898+
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x30 + offs);
899+
stats = mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x34 + offs);
900+
if (stats)
901+
hw_stats->tx_bytes += (stats << 32);
902+
hw_stats->tx_packets +=
903+
mtk_r32(mac->hw, reg_map->gdm1_cnt + 0x38 + offs);
904+
}
890905
}
891906

892907
u64_stats_update_end(&hw_stats->syncp);
@@ -1190,7 +1205,10 @@ static void mtk_tx_set_dma_desc_v2(struct net_device *dev, void *txd,
11901205
data |= TX_DMA_LS0;
11911206
WRITE_ONCE(desc->txd3, data);
11921207

1193-
data = (mac->id + 1) << TX_DMA_FPORT_SHIFT_V2; /* forward port */
1208+
if (mac->id == MTK_GMAC3_ID)
1209+
data = PSE_GDM3_PORT;
1210+
else
1211+
data = (mac->id + 1) << TX_DMA_FPORT_SHIFT_V2; /* forward port */
11941212
data |= TX_DMA_SWC_V2 | QID_BITS_V2(info->qid);
11951213
WRITE_ONCE(desc->txd4, data);
11961214

@@ -1201,6 +1219,8 @@ static void mtk_tx_set_dma_desc_v2(struct net_device *dev, void *txd,
12011219
/* tx checksum offload */
12021220
if (info->csum)
12031221
data |= TX_DMA_CHKSUM_V2;
1222+
if (mtk_is_netsys_v3_or_greater(eth) && netdev_uses_dsa(dev))
1223+
data |= TX_DMA_SPTAG_V3;
12041224
}
12051225
WRITE_ONCE(desc->txd5, data);
12061226

@@ -1266,8 +1286,7 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
12661286
mtk_tx_set_dma_desc(dev, itxd, &txd_info);
12671287

12681288
itx_buf->flags |= MTK_TX_FLAGS_SINGLE0;
1269-
itx_buf->flags |= (!mac->id) ? MTK_TX_FLAGS_FPORT0 :
1270-
MTK_TX_FLAGS_FPORT1;
1289+
itx_buf->mac_id = mac->id;
12711290
setup_tx_buf(eth, itx_buf, itxd_pdma, txd_info.addr, txd_info.size,
12721291
k++);
12731292

@@ -1315,8 +1334,7 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev,
13151334
memset(tx_buf, 0, sizeof(*tx_buf));
13161335
tx_buf->data = (void *)MTK_DMA_DUMMY_DESC;
13171336
tx_buf->flags |= MTK_TX_FLAGS_PAGE0;
1318-
tx_buf->flags |= (!mac->id) ? MTK_TX_FLAGS_FPORT0 :
1319-
MTK_TX_FLAGS_FPORT1;
1337+
tx_buf->mac_id = mac->id;
13201338

13211339
setup_tx_buf(eth, tx_buf, txd_pdma, txd_info.addr,
13221340
txd_info.size, k++);
@@ -1618,7 +1636,7 @@ static int mtk_xdp_frame_map(struct mtk_eth *eth, struct net_device *dev,
16181636
}
16191637
mtk_tx_set_dma_desc(dev, txd, txd_info);
16201638

1621-
tx_buf->flags |= !mac->id ? MTK_TX_FLAGS_FPORT0 : MTK_TX_FLAGS_FPORT1;
1639+
tx_buf->mac_id = mac->id;
16221640
tx_buf->type = dma_map ? MTK_TYPE_XDP_NDO : MTK_TYPE_XDP_TX;
16231641
tx_buf->data = (void *)MTK_DMA_DUMMY_DESC;
16241642

@@ -1868,11 +1886,24 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget,
18681886
break;
18691887

18701888
/* find out which mac the packet come from. values start at 1 */
1871-
if (mtk_is_netsys_v2_or_greater(eth))
1872-
mac = RX_DMA_GET_SPORT_V2(trxd.rxd5) - 1;
1873-
else if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628) &&
1874-
!(trxd.rxd4 & RX_DMA_SPECIAL_TAG))
1889+
if (mtk_is_netsys_v2_or_greater(eth)) {
1890+
u32 val = RX_DMA_GET_SPORT_V2(trxd.rxd5);
1891+
1892+
switch (val) {
1893+
case PSE_GDM1_PORT:
1894+
case PSE_GDM2_PORT:
1895+
mac = val - 1;
1896+
break;
1897+
case PSE_GDM3_PORT:
1898+
mac = MTK_GMAC3_ID;
1899+
break;
1900+
default:
1901+
break;
1902+
}
1903+
} else if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628) &&
1904+
!(trxd.rxd4 & RX_DMA_SPECIAL_TAG)) {
18751905
mac = RX_DMA_GET_SPORT(trxd.rxd4) - 1;
1906+
}
18761907

18771908
if (unlikely(mac < 0 || mac >= MTK_MAX_DEVS ||
18781909
!eth->netdev[mac]))
@@ -2094,23 +2125,20 @@ static int mtk_poll_tx_qdma(struct mtk_eth *eth, int budget,
20942125

20952126
while ((cpu != dma) && budget) {
20962127
u32 next_cpu = desc->txd2;
2097-
int mac = 0;
20982128

20992129
desc = mtk_qdma_phys_to_virt(ring, desc->txd2);
21002130
if ((desc->txd3 & TX_DMA_OWNER_CPU) == 0)
21012131
break;
21022132

21032133
tx_buf = mtk_desc_to_tx_buf(ring, desc,
21042134
eth->soc->txrx.txd_size);
2105-
if (tx_buf->flags & MTK_TX_FLAGS_FPORT1)
2106-
mac = 1;
2107-
21082135
if (!tx_buf->data)
21092136
break;
21102137

21112138
if (tx_buf->data != (void *)MTK_DMA_DUMMY_DESC) {
21122139
if (tx_buf->type == MTK_TYPE_SKB)
2113-
mtk_poll_tx_done(eth, state, mac, tx_buf->data);
2140+
mtk_poll_tx_done(eth, state, tx_buf->mac_id,
2141+
tx_buf->data);
21142142

21152143
budget--;
21162144
}
@@ -3721,7 +3749,24 @@ static int mtk_hw_init(struct mtk_eth *eth, bool reset)
37213749
mtk_w32(eth, eth->soc->txrx.rx_irq_done_mask, reg_map->qdma.int_grp + 4);
37223750
mtk_w32(eth, 0x21021000, MTK_FE_INT_GRP);
37233751

3724-
if (mtk_is_netsys_v2_or_greater(eth)) {
3752+
if (mtk_is_netsys_v3_or_greater(eth)) {
3753+
/* PSE should not drop port1, port8 and port9 packets */
3754+
mtk_w32(eth, 0x00000302, PSE_DROP_CFG);
3755+
3756+
/* GDM and CDM Threshold */
3757+
mtk_w32(eth, 0x00000707, MTK_CDMW0_THRES);
3758+
mtk_w32(eth, 0x00000077, MTK_CDMW1_THRES);
3759+
3760+
/* Disable GDM1 RX CRC stripping */
3761+
mtk_m32(eth, MTK_GDMA_STRP_CRC, 0, MTK_GDMA_FWD_CFG(0));
3762+
3763+
/* PSE GDM3 MIB counter has incorrect hw default values,
3764+
* so the driver ought to read clear the values beforehand
3765+
* in case ethtool retrieve wrong mib values.
3766+
*/
3767+
for (i = 0; i < 0x80; i += 0x4)
3768+
mtk_r32(eth, reg_map->gdm1_cnt + 0x100 + i);
3769+
} else if (!mtk_is_netsys_v1(eth)) {
37253770
/* PSE should not drop port8 and port9 packets from WDMA Tx */
37263771
mtk_w32(eth, 0x00000300, PSE_DROP_CFG);
37273772

@@ -4284,7 +4329,11 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
42844329
}
42854330
spin_lock_init(&mac->hw_stats->stats_lock);
42864331
u64_stats_init(&mac->hw_stats->syncp);
4287-
mac->hw_stats->reg_offset = id * MTK_STAT_OFFSET;
4332+
4333+
if (mtk_is_netsys_v3_or_greater(eth))
4334+
mac->hw_stats->reg_offset = id * 0x80;
4335+
else
4336+
mac->hw_stats->reg_offset = id * 0x40;
42884337

42894338
/* phylink create */
42904339
err = of_get_phy_mode(np, &phy_mode);

drivers/net/ethernet/mediatek/mtk_eth_soc.h

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
#define MTK_GDMA_ICS_EN BIT(22)
123123
#define MTK_GDMA_TCS_EN BIT(21)
124124
#define MTK_GDMA_UCS_EN BIT(20)
125+
#define MTK_GDMA_STRP_CRC BIT(16)
125126
#define MTK_GDMA_TO_PDMA 0x0
126127
#define MTK_GDMA_DROP_ALL 0x7777
127128

@@ -287,8 +288,6 @@
287288
/* QDMA Interrupt grouping registers */
288289
#define MTK_RLS_DONE_INT BIT(0)
289290

290-
#define MTK_STAT_OFFSET 0x40
291-
292291
/* QDMA TX NUM */
293292
#define QID_BITS_V2(x) (((x) & 0x3f) << 16)
294293
#define MTK_QDMA_GMAC2_QID 8
@@ -301,6 +300,8 @@
301300
#define TX_DMA_CHKSUM_V2 (0x7 << 28)
302301
#define TX_DMA_TSO_V2 BIT(31)
303302

303+
#define TX_DMA_SPTAG_V3 BIT(27)
304+
304305
/* QDMA V2 descriptor txd4 */
305306
#define TX_DMA_FPORT_SHIFT_V2 8
306307
#define TX_DMA_FPORT_MASK_V2 0xf
@@ -634,12 +635,6 @@ enum mtk_tx_flags {
634635
*/
635636
MTK_TX_FLAGS_SINGLE0 = 0x01,
636637
MTK_TX_FLAGS_PAGE0 = 0x02,
637-
638-
/* MTK_TX_FLAGS_FPORTx allows tracking which port the transmitted
639-
* SKB out instead of looking up through hardware TX descriptor.
640-
*/
641-
MTK_TX_FLAGS_FPORT0 = 0x04,
642-
MTK_TX_FLAGS_FPORT1 = 0x08,
643638
};
644639

645640
/* This enum allows us to identify how the clock is defined on the array of the
@@ -725,6 +720,35 @@ enum mtk_dev_state {
725720
MTK_RESETTING
726721
};
727722

723+
/* PSE Port Definition */
724+
enum mtk_pse_port {
725+
PSE_ADMA_PORT = 0,
726+
PSE_GDM1_PORT,
727+
PSE_GDM2_PORT,
728+
PSE_PPE0_PORT,
729+
PSE_PPE1_PORT,
730+
PSE_QDMA_TX_PORT,
731+
PSE_QDMA_RX_PORT,
732+
PSE_DROP_PORT,
733+
PSE_WDMA0_PORT,
734+
PSE_WDMA1_PORT,
735+
PSE_TDMA_PORT,
736+
PSE_NONE_PORT,
737+
PSE_PPE2_PORT,
738+
PSE_WDMA2_PORT,
739+
PSE_EIP197_PORT,
740+
PSE_GDM3_PORT,
741+
PSE_PORT_MAX
742+
};
743+
744+
/* GMAC Identifier */
745+
enum mtk_gmac_id {
746+
MTK_GMAC1_ID = 0,
747+
MTK_GMAC2_ID,
748+
MTK_GMAC3_ID,
749+
MTK_GMAC_ID_MAX
750+
};
751+
728752
enum mtk_tx_buf_type {
729753
MTK_TYPE_SKB,
730754
MTK_TYPE_XDP_TX,
@@ -743,7 +767,8 @@ struct mtk_tx_buf {
743767
enum mtk_tx_buf_type type;
744768
void *data;
745769

746-
u32 flags;
770+
u16 mac_id;
771+
u16 flags;
747772
DEFINE_DMA_UNMAP_ADDR(dma_addr0);
748773
DEFINE_DMA_UNMAP_LEN(dma_len0);
749774
DEFINE_DMA_UNMAP_ADDR(dma_addr1);
@@ -1192,6 +1217,11 @@ static inline bool mtk_is_netsys_v2_or_greater(struct mtk_eth *eth)
11921217
return eth->soc->version > 1;
11931218
}
11941219

1220+
static inline bool mtk_is_netsys_v3_or_greater(struct mtk_eth *eth)
1221+
{
1222+
return eth->soc->version > 2;
1223+
}
1224+
11951225
static inline struct mtk_foe_entry *
11961226
mtk_foe_get_entry(struct mtk_ppe *ppe, u16 hash)
11971227
{

0 commit comments

Comments
 (0)