The RT3883 frame engine is PDMA only like RT5350/MT7628, but it is the older one, shared with RT2880 and RT305x: - different register offsets - the descriptors carry the GDMA port in txd4/rxd4 - the GMAC link is forced through MDIO_CFG RT3883 also has two RGMII GMACs. Add support for this RT2880 family, the way MT7628 is supported. Tested on an ASUS RT-N56U (RT3883). Signed-off-by: Ho Jie Feng --- drivers/net/ethernet/mediatek/Kconfig | 3 +- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 255 +++++++++++++++++--- drivers/net/ethernet/mediatek/mtk_eth_soc.h | 57 +++++ 3 files changed, 285 insertions(+), 30 deletions(-) diff --git a/drivers/net/ethernet/mediatek/Kconfig b/drivers/net/ethernet/mediatek/Kconfig index 2ba361f8ce..0f9fd3659b 100644 --- a/drivers/net/ethernet/mediatek/Kconfig +++ b/drivers/net/ethernet/mediatek/Kconfig @@ -1,7 +1,8 @@ # SPDX-License-Identifier: GPL-2.0-only config NET_VENDOR_MEDIATEK bool "MediaTek devices" - depends on ARCH_MEDIATEK || ARCH_AIROHA || SOC_MT7621 || SOC_MT7620 || COMPILE_TEST + depends on ARCH_MEDIATEK || ARCH_AIROHA || SOC_MT7621 || SOC_MT7620 || \ + SOC_RT3883 || COMPILE_TEST help If you have a Mediatek SoC with ethernet, say Y. diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index 83a829bfa0..33750f6b54 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "mtk_eth_soc.h" #include "mtk_wed.h" @@ -218,6 +219,26 @@ static const struct mtk_reg_map mt7988_reg_map = { .pse_oq_sta = 0x01a0, }; +static const struct mtk_reg_map rt2880_reg_map = { + .tx_irq_mask = 0x0014, + .tx_irq_status = 0x0010, + .pdma = { + .tx_ptr = 0x0110, + .tx_cnt_cfg = 0x0114, + .pctx_ptr = 0x0118, + .pdtx_ptr = 0x011c, + .rx_ptr = 0x0130, + .rx_cnt_cfg = 0x0134, + .pcrx_ptr = 0x0138, + .glo_cfg = 0x0100, + .rst_idx = 0x0104, + .delay_irq = 0x010c, + .irq_status = 0x0010, + .irq_mask = 0x0014, + }, + .gdm1_cnt = 0x0700, +}; + /* strings used by ethtool */ static const struct mtk_ethtool_stats { char str[ETH_GSTRING_LEN]; @@ -983,6 +1004,59 @@ static const struct phylink_mac_ops rt5350_phylink_ops = { .mac_link_up = rt5350_mac_link_up, }; +static void rt2880_mac_link_down(struct phylink_config *config, + unsigned int mode, phy_interface_t interface) +{ + struct mtk_mac *mac = container_of(config, struct mtk_mac, + phylink_config); + + mtk_m32(mac->hw, 0, RT_MDIO_LNK_DWN, RT_MDIO_CFG(mac->id)); +} + +static void rt2880_mac_link_up(struct phylink_config *config, + struct phy_device *phy, + unsigned int mode, phy_interface_t interface, + int speed, int duplex, bool tx_pause, bool rx_pause) +{ + struct mtk_mac *mac = container_of(config, struct mtk_mac, + phylink_config); + u32 val; + + /* 200 ps RGMII clock skew, as set by the OpenWrt driver */ + val = RT_MDIO_FRC_EN | FIELD_PREP(RT_MDIO_RX_SKEW, 1) | + FIELD_PREP(RT_MDIO_TX_SKEW, 1); + + switch (speed) { + case SPEED_1000: + val |= FIELD_PREP(RT_MDIO_SPEED, RT_MDIO_SPEED_1000); + break; + case SPEED_100: + val |= FIELD_PREP(RT_MDIO_SPEED, RT_MDIO_SPEED_100); + break; + default: + val |= FIELD_PREP(RT_MDIO_SPEED, RT_MDIO_SPEED_10); + break; + } + + if (duplex == DUPLEX_FULL) + val |= RT_MDIO_DUPLEX; + if (tx_pause) + val |= RT_MDIO_FC_TX; + if (rx_pause) + val |= RT_MDIO_FC_RX; + + mtk_m32(mac->hw, RT_MDIO_FRC_EN | RT_MDIO_SPEED | RT_MDIO_DUPLEX | + RT_MDIO_FC_TX | RT_MDIO_FC_RX | RT_MDIO_LNK_DWN | + RT_MDIO_RX_SKEW | RT_MDIO_TX_SKEW, val, RT_MDIO_CFG(mac->id)); +} + +/* RT2880 family GMACs force the link through MDIO_CFG */ +static const struct phylink_mac_ops rt2880_phylink_ops = { + .mac_config = rt5350_mac_config, + .mac_link_down = rt2880_mac_link_down, + .mac_link_up = rt2880_mac_link_up, +}; + static void mtk_mdio_config(struct mtk_eth *eth) { u32 val; @@ -1104,6 +1178,7 @@ static int mtk_set_mac_address(struct net_device *dev, void *p) struct mtk_mac *mac = netdev_priv(dev); struct mtk_eth *eth = mac->hw; const char *macaddr = dev->dev_addr; + u32 adrh, adrl; if (ret) return ret; @@ -1111,20 +1186,21 @@ static int mtk_set_mac_address(struct net_device *dev, void *p) if (unlikely(test_bit(MTK_RESETTING, &mac->hw->state))) return -EBUSY; - spin_lock_bh(&mac->hw->page_lock); if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) { - mtk_w32(mac->hw, (macaddr[0] << 8) | macaddr[1], - MT7628_SDM_MAC_ADRH); - mtk_w32(mac->hw, (macaddr[2] << 24) | (macaddr[3] << 16) | - (macaddr[4] << 8) | macaddr[5], - MT7628_SDM_MAC_ADRL); + adrh = MT7628_SDM_MAC_ADRH; + adrl = MT7628_SDM_MAC_ADRL; + } else if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) { + adrh = RT_GDMA_MAC_ADRH(mac->id); + adrl = RT_GDMA_MAC_ADRL(mac->id); } else { - mtk_w32(mac->hw, (macaddr[0] << 8) | macaddr[1], - MTK_GDMA_MAC_ADRH(mac->id)); - mtk_w32(mac->hw, (macaddr[2] << 24) | (macaddr[3] << 16) | - (macaddr[4] << 8) | macaddr[5], - MTK_GDMA_MAC_ADRL(mac->id)); + adrh = MTK_GDMA_MAC_ADRH(mac->id); + adrl = MTK_GDMA_MAC_ADRL(mac->id); } + + spin_lock_bh(&mac->hw->page_lock); + mtk_w32(mac->hw, (macaddr[0] << 8) | macaddr[1], adrh); + mtk_w32(mac->hw, (macaddr[2] << 24) | (macaddr[3] << 16) | + (macaddr[4] << 8) | macaddr[5], adrl); spin_unlock_bh(&mac->hw->page_lock); return 0; @@ -1144,6 +1220,23 @@ void mtk_stats_update_mac(struct mtk_mac *mac) hw_stats->rx_bytes += mtk_r32(mac->hw, MT7628_SDM_RBCNT); hw_stats->rx_checksum_errors += mtk_r32(mac->hw, MT7628_SDM_CS_ERR); + } else if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) { + u32 base = eth->soc->reg_map->gdm1_cnt + hw_stats->reg_offset; + + hw_stats->tx_bytes += mtk_r32(mac->hw, base); + hw_stats->tx_packets += mtk_r32(mac->hw, base + 0x04); + hw_stats->tx_skip += mtk_r32(mac->hw, base + 0x08); + hw_stats->tx_collisions += mtk_r32(mac->hw, base + 0x0c); + hw_stats->rx_bytes += mtk_r32(mac->hw, base + 0x20); + hw_stats->rx_packets += mtk_r32(mac->hw, base + 0x24); + hw_stats->rx_overflow += mtk_r32(mac->hw, base + 0x28); + hw_stats->rx_fcs_errors += mtk_r32(mac->hw, base + 0x2c); + hw_stats->rx_short_errors += mtk_r32(mac->hw, base + 0x30); + hw_stats->rx_long_errors += mtk_r32(mac->hw, base + 0x34); + hw_stats->rx_checksum_errors += + mtk_r32(mac->hw, base + 0x38); + hw_stats->rx_flow_control_packets += + mtk_r32(mac->hw, base + 0x3c); } else { const struct mtk_reg_map *reg_map = eth->soc->reg_map; unsigned int offs = hw_stats->reg_offset; @@ -1480,6 +1573,11 @@ static void setup_tx_buf(struct mtk_eth *eth, struct mtk_tx_buf *tx_buf, tx_buf->data = (void *)MTK_DMA_DUMMY_DESC; txd->txd1 = mapped_addr; txd->txd2 = TX_DMA_PLEN0(size); + /* GDMA port, on queue 3 like the vendor driver */ + if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) + txd->txd4 = FIELD_PREP(RT_TX_DMA_QN, 3) | + FIELD_PREP(RT_TX_DMA_PN, + tx_buf->mac_id + 1); dma_unmap_addr_set(tx_buf, dma_addr0, mapped_addr); dma_unmap_len_set(tx_buf, dma_len0, size); } @@ -1628,6 +1726,8 @@ static int mtk_tx_map(struct sk_buff *skb, struct net_device *dev, itx_buf->mac_id = mac->id; setup_tx_buf(eth, itx_buf, itxd_pdma, txd_info.addr, txd_info.size, k++); + if (MTK_HAS_CAPS(soc->caps, MTK_SOC_RT2880) && txd_info.csum) + itxd_pdma->txd4 |= TX_DMA_CHKSUM; /* TX SG offload */ txd = itxd; @@ -1795,6 +1895,11 @@ static netdev_tx_t mtk_start_xmit(struct sk_buff *skb, struct net_device *dev) goto dropped; } + /* RT2880 family pads to 60 bytes including the VLAN tag */ + if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880) && + eth_type_vlan(skb->protocol) && skb_put_padto(skb, VLAN_ETH_ZLEN)) + goto dropped; + /* normally we can rely on the stack not calling this more than once, * however we have 2 queues running on the same ring so we need to lock * the ring access @@ -2249,6 +2354,8 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, default: break; } + } else if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) { + mac = (int)FIELD_GET(RT_RX_DMA_SPORT, trxd.rxd4) - 1; } else if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628) && !(trxd.rxd4 & RX_DMA_SPECIAL_TAG)) { mac = RX_DMA_GET_SPORT(trxd.rxd4) - 1; @@ -2403,7 +2510,7 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, addr64 = RX_DMA_PREP_ADDR64(dma_addr); } - if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) + if (mtk_is_ralink(eth)) rxd->rxd2 = RX_DMA_LSO; else rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size) | addr64; @@ -2874,7 +2981,7 @@ static int mtk_rx_alloc(struct mtk_eth *eth, int ring_no, int rx_flag) rxd->rxd1 = (unsigned int)dma_addr; ring->data[i] = data; - if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) + if (mtk_is_ralink(eth)) rxd->rxd2 = RX_DMA_LSO; else rxd->rxd2 = RX_DMA_PREP_PLEN0(ring->buf_size); @@ -3205,6 +3312,22 @@ static int mtk_hwlro_get_fdir_all(struct net_device *dev, return 0; } +static netdev_features_t mtk_features_check(struct sk_buff *skb, + struct net_device *dev, + netdev_features_t features) +{ + struct mtk_mac *mac = netdev_priv(dev); + __be16 proto = skb_vlan_tag_present(skb) ? skb->vlan_proto : + skb->protocol; + + /* the RT2880 family checksum offload can't parse DSA or 802.1ad tags */ + if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_SOC_RT2880) && + (netdev_uses_dsa(dev) || proto == htons(ETH_P_8021AD))) + features &= ~NETIF_F_CSUM_MASK; + + return vlan_features_check(skb, features); +} + static netdev_features_t mtk_fix_features(struct net_device *dev, netdev_features_t features) { @@ -3349,7 +3472,13 @@ static void mtk_dma_free(struct mtk_eth *eth) static bool mtk_hw_reset_check(struct mtk_eth *eth) { - u32 val = mtk_r32(eth, MTK_INT_STATUS2); + u32 val; + + /* no INT_STATUS2 and no reset recovery on the RT2880 family */ + if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) + return false; + + val = mtk_r32(eth, MTK_INT_STATUS2); return (val & MTK_FE_INT_FQ_EMPTY) || (val & MTK_FE_INT_RFIFO_UF) || (val & MTK_FE_INT_RFIFO_OV) || (val & MTK_FE_INT_TSO_FAIL) || @@ -3512,9 +3641,11 @@ static int mtk_start_dma(struct mtk_eth *eth) MTK_RX_BT_32DWORDS | MTK_MULTI_EN, reg_map->pdma.glo_cfg); } else { - mtk_w32(eth, MTK_TX_WB_DDONE | MTK_TX_DMA_EN | MTK_RX_DMA_EN | - MTK_MULTI_EN | MTK_PDMA_SIZE_8DWORDS, - reg_map->pdma.glo_cfg); + val = MTK_TX_WB_DDONE | MTK_TX_DMA_EN | MTK_RX_DMA_EN | + MTK_PDMA_SIZE_8DWORDS; + if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) + val |= MTK_MULTI_EN; + mtk_w32(eth, val, reg_map->pdma.glo_cfg); } return 0; @@ -3522,25 +3653,41 @@ static int mtk_start_dma(struct mtk_eth *eth) static void mtk_gdm_config(struct mtk_eth *eth, u32 id, u32 config) { - u32 val; + u32 reg, val; if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) return; - val = mtk_r32(eth, MTK_GDMA_FWD_CFG(id)); + if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) { + /* not every GDMA exists, only touch those with a MAC */ + if (!eth->netdev[id]) + return; + reg = RT_GDMA_FWD_CFG(id); + } else { + reg = MTK_GDMA_FWD_CFG(id); + } + + val = mtk_r32(eth, reg); /* default setup the forward port to send frame to PDMA */ val &= ~0xffff; + /* take frames up to 2 KB, the RX buffer size */ + if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) { + val &= ~RT_GDMA_JMB_LEN; + val |= RT_GDMA_JMB_EN | FIELD_PREP(RT_GDMA_JMB_LEN, 2); + } + /* Enable RX checksum */ val |= MTK_GDMA_ICS_EN | MTK_GDMA_TCS_EN | MTK_GDMA_UCS_EN; val |= config; - if (eth->netdev[id] && netdev_uses_dsa(eth->netdev[id])) + if (eth->netdev[id] && netdev_uses_dsa(eth->netdev[id]) && + !MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) val |= MTK_GDMA_SPECIAL_TAG; - mtk_w32(eth, val, MTK_GDMA_FWD_CFG(id)); + mtk_w32(eth, val, reg); } @@ -3675,7 +3822,8 @@ static int mtk_open(struct net_device *dev) phylink_start(mac->phylink); netif_tx_start_all_queues(dev); - if (mtk_is_netsys_v2_or_greater(eth)) + if (mtk_is_netsys_v2_or_greater(eth) || + MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) return 0; if (mtk_uses_dsa(dev) && !eth->prog) { @@ -3928,7 +4076,7 @@ static void mtk_set_mcr_max_rx(struct mtk_mac *mac, u32 val) struct mtk_eth *eth = mac->hw; u32 mcr_cur, mcr_new; - if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) + if (mtk_is_ralink(eth)) return; mcr_cur = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id)); @@ -4048,7 +4196,7 @@ static bool mtk_hw_check_dma_hang(struct mtk_eth *eth) bool qfsm_hang, qfwd_hang; bool ret = false; - if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) + if (mtk_is_ralink(eth)) return false; /* WDMA sanity checks */ @@ -4134,6 +4282,23 @@ static void mtk_hw_reset_monitor_work(struct work_struct *work) MTK_DMA_MONITOR_TIMEOUT); } +static void rt2880_hw_init(struct mtk_eth *eth) +{ + struct clk *clk = eth->clks[MTK_CLK_FE]; + + mtk_m32(eth, RT_US_CYC_CNT, + FIELD_PREP(RT_US_CYC_CNT, clk_get_rate(clk) / HZ_PER_MHZ), + RT_FE_GLO_CFG); + + mtk_w32(eth, eth->soc->pse_fq_cfg, RT_PSE_FQ_CFG); + + mtk_m32(eth, 0, RT_CSG_ICS_GEN_EN | RT_CSG_UCS_GEN_EN | + RT_CSG_TCS_GEN_EN, RT_CDMA_CSG_CFG); + + mtk_w32(eth, RT_PSE_RESET, RT_FE_RST_GL); + mtk_w32(eth, 0, RT_FE_RST_GL); +} + static int mtk_hw_init(struct mtk_eth *eth, bool reset) { u32 dma_mask = ETHSYS_DMA_AG_MAP_PDMA | ETHSYS_DMA_AG_MAP_QDMA | @@ -4157,13 +4322,16 @@ static int mtk_hw_init(struct mtk_eth *eth, bool reset) regmap_update_bits(eth->ethsys, ETHSYS_DMA_AG_MAP, dma_mask, of_dma_is_coherent(eth->dma_dev->of_node) * dma_mask); - if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) { + if (mtk_is_ralink(eth)) { ret = device_reset(eth->dev); if (ret) { dev_err(eth->dev, "MAC reset failed!\n"); goto err_disable_pm; } + if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) + rt2880_hw_init(eth); + /* set interrupt delays based on current Net DIM sample */ mtk_dim_rx(ð->rx_dim.work); mtk_dim_tx(ð->tx_dim.work); @@ -4815,6 +4983,7 @@ static const struct net_device_ops mtk_netdev_ops = { .ndo_open = mtk_open, .ndo_stop = mtk_stop, .ndo_start_xmit = mtk_start_xmit, + .ndo_features_check = mtk_features_check, .ndo_set_mac_address = mtk_set_mac_address, .ndo_validate_addr = eth_validate_addr, .ndo_eth_ioctl = mtk_do_ioctl, @@ -4969,6 +5138,8 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np) if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) mac_ops = &rt5350_phylink_ops; + else if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880)) + mac_ops = &rt2880_phylink_ops; if (MTK_HAS_CAPS(mac->hw->soc->caps, MTK_2P5GPHY) && id == MTK_GMAC2_ID) @@ -5137,7 +5308,7 @@ static int mtk_probe(struct platform_device *pdev) if (IS_ERR(eth->base)) return PTR_ERR(eth->base); - if (MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) + if (mtk_is_ralink(eth)) eth->ip_align = NET_IP_ALIGN; if (MTK_HAS_CAPS(eth->soc->caps, MTK_36BIT_DMA)) { @@ -5163,7 +5334,7 @@ static int mtk_probe(struct platform_device *pdev) eth->tx_dim.mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE; INIT_WORK(ð->tx_dim.work, mtk_dim_tx); - if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) { + if (!mtk_is_ralink(eth)) { eth->ethsys = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "mediatek,ethsys"); if (IS_ERR(eth->ethsys)) { @@ -5318,8 +5489,8 @@ static int mtk_probe(struct platform_device *pdev) if (err) goto err_free_dev; - /* No MT7628/88 support yet */ - if (!MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628)) { + /* No MT7628/88 or RT2880 family support yet */ + if (!mtk_is_ralink(eth)) { err = mtk_mdio_init(eth); if (err) goto err_free_dev; @@ -5669,6 +5840,31 @@ static const struct mtk_soc_data mt7988_data = { }, }; +static const struct mtk_soc_data rt3883_data = { + .reg_map = &rt2880_reg_map, + .caps = RT3883_CAPS, + .hw_features = MTK_HW_FEATURES_RT3883, + .required_clks = RT3883_CLKS_BITMAP, + .required_pctl = false, + .pse_fq_cfg = RT3883_PSE_FQ_256Q, + .version = 1, + .tx = { + .desc_size = sizeof(struct mtk_tx_dma), + .irq_done_mask = RT_INT_TX_DLY, + .dma_max_len = MTK_TX_DMA_BUF_LEN, + .dma_len_offset = 16, + .dma_size = MTK_DMA_SIZE(2K), + }, + .rx = { + .desc_size = sizeof(struct mtk_rx_dma), + .irq_done_mask = RT_INT_RX_DLY, + .dma_l4_valid = RX_DMA_L4_VALID_PDMA, + .dma_max_len = MTK_TX_DMA_BUF_LEN, + .dma_len_offset = 16, + .dma_size = MTK_DMA_SIZE(2K), + }, +}; + static const struct mtk_soc_data rt5350_data = { .reg_map = &mt7628_reg_map, .caps = MT7628_CAPS, @@ -5702,6 +5898,7 @@ const struct of_device_id of_mtk_match[] = { { .compatible = "mediatek,mt7981-eth", .data = &mt7981_data }, { .compatible = "mediatek,mt7986-eth", .data = &mt7986_data }, { .compatible = "mediatek,mt7988-eth", .data = &mt7988_data }, + { .compatible = "ralink,rt3883-eth", .data = &rt3883_data }, { .compatible = "ralink,rt5350-eth", .data = &rt5350_data }, {}, }; diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/drivers/net/ethernet/mediatek/mtk_eth_soc.h index 9b20b39eae..72d0a9566e 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.h +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.h @@ -54,6 +54,7 @@ NETIF_F_IPV6_CSUM |\ NETIF_F_HW_TC) #define MTK_HW_FEATURES_MT7628 (NETIF_F_SG | NETIF_F_RXCSUM) +#define MTK_HW_FEATURES_RT3883 (NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_RXCSUM) #define NEXT_DESP_IDX(X, Y) (((X) + 1) & ((Y) - 1)) #define MTK_PP_HEADROOM XDP_PACKET_HEADROOM @@ -633,6 +634,48 @@ #define MT7628_SDM_RBCNT (MT7628_SDM_OFFSET + 0x10c) #define MT7628_SDM_CS_ERR (MT7628_SDM_OFFSET + 0x110) +/* RT2880 family (RT2880, RT305x, RT3883) specific stuff */ +#define RT_MDIO_CFG(x) ((x) ? 0x18 : 0x04) +#define RT_MDIO_FRC_EN BIT(15) +#define RT_MDIO_SPEED GENMASK(14, 13) +#define RT_MDIO_SPEED_10 0 +#define RT_MDIO_SPEED_100 1 +#define RT_MDIO_SPEED_1000 2 +#define RT_MDIO_DUPLEX BIT(12) +#define RT_MDIO_FC_TX BIT(11) +#define RT_MDIO_FC_RX BIT(10) +#define RT_MDIO_LNK_DWN BIT(9) +#define RT_MDIO_RX_SKEW GENMASK(3, 2) +#define RT_MDIO_TX_SKEW GENMASK(1, 0) + +#define RT_FE_GLO_CFG 0x08 +#define RT_US_CYC_CNT GENMASK(15, 8) + +#define RT_FE_RST_GL 0x0c +#define RT_PSE_RESET BIT(0) + +#define RT_INT_TX_DLY BIT(1) +#define RT_INT_RX_DLY BIT(0) + +#define RT_GDMA_FWD_CFG(x) (0x20 + (x) * 0x40) +#define RT_GDMA_JMB_EN BIT(19) +#define RT_GDMA_JMB_LEN GENMASK(31, 28) +#define RT_GDMA_MAC_ADRL(x) (0x2c + (x) * 0x40) +#define RT_GDMA_MAC_ADRH(x) (0x30 + (x) * 0x40) + +#define RT_PSE_FQ_CFG 0x40 +#define RT3883_PSE_FQ_256Q 0xff908000 + +#define RT_CDMA_CSG_CFG 0x80 +#define RT_CSG_ICS_GEN_EN BIT(2) +#define RT_CSG_UCS_GEN_EN BIT(1) +#define RT_CSG_TCS_GEN_EN BIT(0) + +/* PDMA descriptor fields */ +#define RT_TX_DMA_PN GENMASK(26, 24) +#define RT_TX_DMA_QN GENMASK(18, 16) +#define RT_RX_DMA_SPORT GENMASK(26, 24) + #define MTK_FE_CDM1_FSM 0x220 #define MTK_FE_CDM2_FSM 0x224 #define MTK_FE_CDM3_FSM 0x238 @@ -857,6 +900,7 @@ enum mtk_clks_map { BIT_ULL(MTK_CLK_TOP_NETSYS_SYNC_250M_SEL) | \ BIT_ULL(MTK_CLK_TOP_NETSYS_PPEFB_250M_SEL) | \ BIT_ULL(MTK_CLK_TOP_NETSYS_WARP_SEL)) +#define RT3883_CLKS_BITMAP (BIT_ULL(MTK_CLK_FE)) enum mtk_dev_state { MTK_HW_INIT, @@ -995,6 +1039,7 @@ enum mkt_eth_capabilities { MTK_SRAM_BIT, MTK_36BIT_DMA_BIT, MTK_GMAC_EEE_BIT, + MTK_SOC_RT2880_BIT, /* MUX BITS*/ MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT, @@ -1036,6 +1081,7 @@ enum mkt_eth_capabilities { #define MTK_SRAM BIT_ULL(MTK_SRAM_BIT) #define MTK_36BIT_DMA BIT_ULL(MTK_36BIT_DMA_BIT) #define MTK_GMAC_EEE BIT_ULL(MTK_GMAC_EEE_BIT) +#define MTK_SOC_RT2880 BIT_ULL(MTK_SOC_RT2880_BIT) #define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW \ BIT_ULL(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT) @@ -1129,6 +1175,8 @@ enum mkt_eth_capabilities { MTK_MUX_GMAC2_TO_2P5GPHY | MTK_QDMA | MTK_RSTCTRL_PPE1 | \ MTK_RSTCTRL_PPE2 | MTK_SRAM) +#define RT3883_CAPS (MTK_RGMII | MTK_SHARED_INT | MTK_SOC_RT2880) + struct mtk_tx_dma_desc_info { dma_addr_t addr; u32 size; @@ -1206,6 +1254,7 @@ struct mtk_reg_map { * @foe_entry_size Foe table entry size. * @has_accounting Bool indicating support for accounting of * offloaded flows. + * @pse_fq_cfg PSE free queue config of the RT2880 family. * @desc_size Tx/Rx DMA descriptor size. * @irq_done_mask Tx/Rx irq done register mask. * @dma_l4_valid Rx DMA valid register mask. @@ -1226,6 +1275,7 @@ struct mtk_soc_data { netdev_features_t hw_features; bool has_accounting; bool disable_pll_modes; + u32 pse_fq_cfg; struct { u32 desc_size; u32 irq_done_mask; @@ -1390,6 +1440,13 @@ struct mtk_mac { /* the struct describing the SoC. these are declared in the soc_xyz.c files */ extern const struct of_device_id of_mtk_match[]; +/* Ralink frame engine: PDMA only, no NETSYS MAC or MDIO */ +static inline bool mtk_is_ralink(struct mtk_eth *eth) +{ + return MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_MT7628) || + MTK_HAS_CAPS(eth->soc->caps, MTK_SOC_RT2880); +} + static inline bool mtk_is_netsys_v1(struct mtk_eth *eth) { return eth->soc->version == 1; -- 2.53.0