18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) 2009-2016 John Crispin <blogic@openwrt.org> 58c2ecf20Sopenharmony_ci * Copyright (C) 2009-2016 Felix Fietkau <nbd@openwrt.org> 68c2ecf20Sopenharmony_ci * Copyright (C) 2013-2016 Michael Lee <igvtee@gmail.com> 78c2ecf20Sopenharmony_ci */ 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#ifndef MTK_ETH_H 108c2ecf20Sopenharmony_ci#define MTK_ETH_H 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/dma-mapping.h> 138c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 148c2ecf20Sopenharmony_ci#include <linux/of_net.h> 158c2ecf20Sopenharmony_ci#include <linux/u64_stats_sync.h> 168c2ecf20Sopenharmony_ci#include <linux/refcount.h> 178c2ecf20Sopenharmony_ci#include <linux/phylink.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci#define MTK_QDMA_PAGE_SIZE 2048 208c2ecf20Sopenharmony_ci#define MTK_MAX_RX_LENGTH 1536 218c2ecf20Sopenharmony_ci#define MTK_TX_DMA_BUF_LEN 0x3fff 228c2ecf20Sopenharmony_ci#define MTK_DMA_SIZE 256 238c2ecf20Sopenharmony_ci#define MTK_NAPI_WEIGHT 64 248c2ecf20Sopenharmony_ci#define MTK_MAC_COUNT 2 258c2ecf20Sopenharmony_ci#define MTK_RX_ETH_HLEN (VLAN_ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN) 268c2ecf20Sopenharmony_ci#define MTK_RX_HLEN (NET_SKB_PAD + MTK_RX_ETH_HLEN + NET_IP_ALIGN) 278c2ecf20Sopenharmony_ci#define MTK_DMA_DUMMY_DESC 0xffffffff 288c2ecf20Sopenharmony_ci#define MTK_DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | \ 298c2ecf20Sopenharmony_ci NETIF_MSG_PROBE | \ 308c2ecf20Sopenharmony_ci NETIF_MSG_LINK | \ 318c2ecf20Sopenharmony_ci NETIF_MSG_TIMER | \ 328c2ecf20Sopenharmony_ci NETIF_MSG_IFDOWN | \ 338c2ecf20Sopenharmony_ci NETIF_MSG_IFUP | \ 348c2ecf20Sopenharmony_ci NETIF_MSG_RX_ERR | \ 358c2ecf20Sopenharmony_ci NETIF_MSG_TX_ERR) 368c2ecf20Sopenharmony_ci#define MTK_HW_FEATURES (NETIF_F_IP_CSUM | \ 378c2ecf20Sopenharmony_ci NETIF_F_RXCSUM | \ 388c2ecf20Sopenharmony_ci NETIF_F_HW_VLAN_CTAG_TX | \ 398c2ecf20Sopenharmony_ci NETIF_F_HW_VLAN_CTAG_RX | \ 408c2ecf20Sopenharmony_ci NETIF_F_SG | NETIF_F_TSO | \ 418c2ecf20Sopenharmony_ci NETIF_F_TSO6 | \ 428c2ecf20Sopenharmony_ci NETIF_F_IPV6_CSUM) 438c2ecf20Sopenharmony_ci#define MTK_HW_FEATURES_MT7628 (NETIF_F_SG | NETIF_F_RXCSUM) 448c2ecf20Sopenharmony_ci#define NEXT_DESP_IDX(X, Y) (((X) + 1) & ((Y) - 1)) 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define MTK_MAX_RX_RING_NUM 4 478c2ecf20Sopenharmony_ci#define MTK_HW_LRO_DMA_SIZE 8 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define MTK_MAX_LRO_RX_LENGTH (4096 * 3) 508c2ecf20Sopenharmony_ci#define MTK_MAX_LRO_IP_CNT 2 518c2ecf20Sopenharmony_ci#define MTK_HW_LRO_TIMER_UNIT 1 /* 20 us */ 528c2ecf20Sopenharmony_ci#define MTK_HW_LRO_REFRESH_TIME 50000 /* 1 sec. */ 538c2ecf20Sopenharmony_ci#define MTK_HW_LRO_AGG_TIME 10 /* 200us */ 548c2ecf20Sopenharmony_ci#define MTK_HW_LRO_AGE_TIME 50 /* 1ms */ 558c2ecf20Sopenharmony_ci#define MTK_HW_LRO_MAX_AGG_CNT 64 568c2ecf20Sopenharmony_ci#define MTK_HW_LRO_BW_THRE 3000 578c2ecf20Sopenharmony_ci#define MTK_HW_LRO_REPLACE_DELTA 1000 588c2ecf20Sopenharmony_ci#define MTK_HW_LRO_SDL_REMAIN_ROOM 1522 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci/* Frame Engine Global Reset Register */ 618c2ecf20Sopenharmony_ci#define MTK_RST_GL 0x04 628c2ecf20Sopenharmony_ci#define RST_GL_PSE BIT(0) 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* Frame Engine Interrupt Status Register */ 658c2ecf20Sopenharmony_ci#define MTK_INT_STATUS2 0x08 668c2ecf20Sopenharmony_ci#define MTK_GDM1_AF BIT(28) 678c2ecf20Sopenharmony_ci#define MTK_GDM2_AF BIT(29) 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci/* PDMA HW LRO Alter Flow Timer Register */ 708c2ecf20Sopenharmony_ci#define MTK_PDMA_LRO_ALT_REFRESH_TIMER 0x1c 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci/* Frame Engine Interrupt Grouping Register */ 738c2ecf20Sopenharmony_ci#define MTK_FE_INT_GRP 0x20 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci/* CDMP Ingress Control Register */ 768c2ecf20Sopenharmony_ci#define MTK_CDMQ_IG_CTRL 0x1400 778c2ecf20Sopenharmony_ci#define MTK_CDMQ_STAG_EN BIT(0) 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci/* CDMP Exgress Control Register */ 808c2ecf20Sopenharmony_ci#define MTK_CDMP_EG_CTRL 0x404 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* GDM Exgress Control Register */ 838c2ecf20Sopenharmony_ci#define MTK_GDMA_FWD_CFG(x) (0x500 + (x * 0x1000)) 848c2ecf20Sopenharmony_ci#define MTK_GDMA_ICS_EN BIT(22) 858c2ecf20Sopenharmony_ci#define MTK_GDMA_TCS_EN BIT(21) 868c2ecf20Sopenharmony_ci#define MTK_GDMA_UCS_EN BIT(20) 878c2ecf20Sopenharmony_ci#define MTK_GDMA_TO_PDMA 0x0 888c2ecf20Sopenharmony_ci#define MTK_GDMA_DROP_ALL 0x7777 898c2ecf20Sopenharmony_ci 908c2ecf20Sopenharmony_ci/* Unicast Filter MAC Address Register - Low */ 918c2ecf20Sopenharmony_ci#define MTK_GDMA_MAC_ADRL(x) (0x508 + (x * 0x1000)) 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/* Unicast Filter MAC Address Register - High */ 948c2ecf20Sopenharmony_ci#define MTK_GDMA_MAC_ADRH(x) (0x50C + (x * 0x1000)) 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci/* PDMA RX Base Pointer Register */ 978c2ecf20Sopenharmony_ci#define MTK_PRX_BASE_PTR0 0x900 988c2ecf20Sopenharmony_ci#define MTK_PRX_BASE_PTR_CFG(x) (MTK_PRX_BASE_PTR0 + (x * 0x10)) 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/* PDMA RX Maximum Count Register */ 1018c2ecf20Sopenharmony_ci#define MTK_PRX_MAX_CNT0 0x904 1028c2ecf20Sopenharmony_ci#define MTK_PRX_MAX_CNT_CFG(x) (MTK_PRX_MAX_CNT0 + (x * 0x10)) 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* PDMA RX CPU Pointer Register */ 1058c2ecf20Sopenharmony_ci#define MTK_PRX_CRX_IDX0 0x908 1068c2ecf20Sopenharmony_ci#define MTK_PRX_CRX_IDX_CFG(x) (MTK_PRX_CRX_IDX0 + (x * 0x10)) 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci/* PDMA HW LRO Control Registers */ 1098c2ecf20Sopenharmony_ci#define MTK_PDMA_LRO_CTRL_DW0 0x980 1108c2ecf20Sopenharmony_ci#define MTK_LRO_EN BIT(0) 1118c2ecf20Sopenharmony_ci#define MTK_L3_CKS_UPD_EN BIT(7) 1128c2ecf20Sopenharmony_ci#define MTK_LRO_ALT_PKT_CNT_MODE BIT(21) 1138c2ecf20Sopenharmony_ci#define MTK_LRO_RING_RELINQUISH_REQ (0x7 << 26) 1148c2ecf20Sopenharmony_ci#define MTK_LRO_RING_RELINQUISH_DONE (0x7 << 29) 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ci#define MTK_PDMA_LRO_CTRL_DW1 0x984 1178c2ecf20Sopenharmony_ci#define MTK_PDMA_LRO_CTRL_DW2 0x988 1188c2ecf20Sopenharmony_ci#define MTK_PDMA_LRO_CTRL_DW3 0x98c 1198c2ecf20Sopenharmony_ci#define MTK_ADMA_MODE BIT(15) 1208c2ecf20Sopenharmony_ci#define MTK_LRO_MIN_RXD_SDL (MTK_HW_LRO_SDL_REMAIN_ROOM << 16) 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci/* PDMA Global Configuration Register */ 1238c2ecf20Sopenharmony_ci#define MTK_PDMA_GLO_CFG 0xa04 1248c2ecf20Sopenharmony_ci#define MTK_MULTI_EN BIT(10) 1258c2ecf20Sopenharmony_ci#define MTK_PDMA_SIZE_8DWORDS (1 << 4) 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci/* PDMA Reset Index Register */ 1288c2ecf20Sopenharmony_ci#define MTK_PDMA_RST_IDX 0xa08 1298c2ecf20Sopenharmony_ci#define MTK_PST_DRX_IDX0 BIT(16) 1308c2ecf20Sopenharmony_ci#define MTK_PST_DRX_IDX_CFG(x) (MTK_PST_DRX_IDX0 << (x)) 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci/* PDMA Delay Interrupt Register */ 1338c2ecf20Sopenharmony_ci#define MTK_PDMA_DELAY_INT 0xa0c 1348c2ecf20Sopenharmony_ci#define MTK_PDMA_DELAY_RX_EN BIT(15) 1358c2ecf20Sopenharmony_ci#define MTK_PDMA_DELAY_RX_PINT 4 1368c2ecf20Sopenharmony_ci#define MTK_PDMA_DELAY_RX_PINT_SHIFT 8 1378c2ecf20Sopenharmony_ci#define MTK_PDMA_DELAY_RX_PTIME 4 1388c2ecf20Sopenharmony_ci#define MTK_PDMA_DELAY_RX_DELAY \ 1398c2ecf20Sopenharmony_ci (MTK_PDMA_DELAY_RX_EN | MTK_PDMA_DELAY_RX_PTIME | \ 1408c2ecf20Sopenharmony_ci (MTK_PDMA_DELAY_RX_PINT << MTK_PDMA_DELAY_RX_PINT_SHIFT)) 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci/* PDMA Interrupt Status Register */ 1438c2ecf20Sopenharmony_ci#define MTK_PDMA_INT_STATUS 0xa20 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci/* PDMA Interrupt Mask Register */ 1468c2ecf20Sopenharmony_ci#define MTK_PDMA_INT_MASK 0xa28 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci/* PDMA HW LRO Alter Flow Delta Register */ 1498c2ecf20Sopenharmony_ci#define MTK_PDMA_LRO_ALT_SCORE_DELTA 0xa4c 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci/* PDMA Interrupt grouping registers */ 1528c2ecf20Sopenharmony_ci#define MTK_PDMA_INT_GRP1 0xa50 1538c2ecf20Sopenharmony_ci#define MTK_PDMA_INT_GRP2 0xa54 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci/* PDMA HW LRO IP Setting Registers */ 1568c2ecf20Sopenharmony_ci#define MTK_LRO_RX_RING0_DIP_DW0 0xb04 1578c2ecf20Sopenharmony_ci#define MTK_LRO_DIP_DW0_CFG(x) (MTK_LRO_RX_RING0_DIP_DW0 + (x * 0x40)) 1588c2ecf20Sopenharmony_ci#define MTK_RING_MYIP_VLD BIT(9) 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci/* PDMA HW LRO Ring Control Registers */ 1618c2ecf20Sopenharmony_ci#define MTK_LRO_RX_RING0_CTRL_DW1 0xb28 1628c2ecf20Sopenharmony_ci#define MTK_LRO_RX_RING0_CTRL_DW2 0xb2c 1638c2ecf20Sopenharmony_ci#define MTK_LRO_RX_RING0_CTRL_DW3 0xb30 1648c2ecf20Sopenharmony_ci#define MTK_LRO_CTRL_DW1_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW1 + (x * 0x40)) 1658c2ecf20Sopenharmony_ci#define MTK_LRO_CTRL_DW2_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW2 + (x * 0x40)) 1668c2ecf20Sopenharmony_ci#define MTK_LRO_CTRL_DW3_CFG(x) (MTK_LRO_RX_RING0_CTRL_DW3 + (x * 0x40)) 1678c2ecf20Sopenharmony_ci#define MTK_RING_AGE_TIME_L ((MTK_HW_LRO_AGE_TIME & 0x3ff) << 22) 1688c2ecf20Sopenharmony_ci#define MTK_RING_AGE_TIME_H ((MTK_HW_LRO_AGE_TIME >> 10) & 0x3f) 1698c2ecf20Sopenharmony_ci#define MTK_RING_AUTO_LERAN_MODE (3 << 6) 1708c2ecf20Sopenharmony_ci#define MTK_RING_VLD BIT(8) 1718c2ecf20Sopenharmony_ci#define MTK_RING_MAX_AGG_TIME ((MTK_HW_LRO_AGG_TIME & 0xffff) << 10) 1728c2ecf20Sopenharmony_ci#define MTK_RING_MAX_AGG_CNT_L ((MTK_HW_LRO_MAX_AGG_CNT & 0x3f) << 26) 1738c2ecf20Sopenharmony_ci#define MTK_RING_MAX_AGG_CNT_H ((MTK_HW_LRO_MAX_AGG_CNT >> 6) & 0x3) 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci/* QDMA TX Queue Configuration Registers */ 1768c2ecf20Sopenharmony_ci#define MTK_QTX_CFG(x) (0x1800 + (x * 0x10)) 1778c2ecf20Sopenharmony_ci#define QDMA_RES_THRES 4 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci/* QDMA TX Queue Scheduler Registers */ 1808c2ecf20Sopenharmony_ci#define MTK_QTX_SCH(x) (0x1804 + (x * 0x10)) 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci/* QDMA RX Base Pointer Register */ 1838c2ecf20Sopenharmony_ci#define MTK_QRX_BASE_PTR0 0x1900 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci/* QDMA RX Maximum Count Register */ 1868c2ecf20Sopenharmony_ci#define MTK_QRX_MAX_CNT0 0x1904 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci/* QDMA RX CPU Pointer Register */ 1898c2ecf20Sopenharmony_ci#define MTK_QRX_CRX_IDX0 0x1908 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci/* QDMA RX DMA Pointer Register */ 1928c2ecf20Sopenharmony_ci#define MTK_QRX_DRX_IDX0 0x190C 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci/* QDMA Global Configuration Register */ 1958c2ecf20Sopenharmony_ci#define MTK_QDMA_GLO_CFG 0x1A04 1968c2ecf20Sopenharmony_ci#define MTK_RX_2B_OFFSET BIT(31) 1978c2ecf20Sopenharmony_ci#define MTK_RX_BT_32DWORDS (3 << 11) 1988c2ecf20Sopenharmony_ci#define MTK_NDP_CO_PRO BIT(10) 1998c2ecf20Sopenharmony_ci#define MTK_TX_WB_DDONE BIT(6) 2008c2ecf20Sopenharmony_ci#define MTK_DMA_SIZE_16DWORDS (2 << 4) 2018c2ecf20Sopenharmony_ci#define MTK_RX_DMA_BUSY BIT(3) 2028c2ecf20Sopenharmony_ci#define MTK_TX_DMA_BUSY BIT(1) 2038c2ecf20Sopenharmony_ci#define MTK_RX_DMA_EN BIT(2) 2048c2ecf20Sopenharmony_ci#define MTK_TX_DMA_EN BIT(0) 2058c2ecf20Sopenharmony_ci#define MTK_DMA_BUSY_TIMEOUT HZ 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci/* QDMA Reset Index Register */ 2088c2ecf20Sopenharmony_ci#define MTK_QDMA_RST_IDX 0x1A08 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci/* QDMA Delay Interrupt Register */ 2118c2ecf20Sopenharmony_ci#define MTK_QDMA_DELAY_INT 0x1A0C 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci/* QDMA Flow Control Register */ 2148c2ecf20Sopenharmony_ci#define MTK_QDMA_FC_THRES 0x1A10 2158c2ecf20Sopenharmony_ci#define FC_THRES_DROP_MODE BIT(20) 2168c2ecf20Sopenharmony_ci#define FC_THRES_DROP_EN (7 << 16) 2178c2ecf20Sopenharmony_ci#define FC_THRES_MIN 0x4444 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci/* QDMA Interrupt Status Register */ 2208c2ecf20Sopenharmony_ci#define MTK_QDMA_INT_STATUS 0x1A18 2218c2ecf20Sopenharmony_ci#define MTK_RX_DONE_DLY BIT(30) 2228c2ecf20Sopenharmony_ci#define MTK_RX_DONE_INT3 BIT(19) 2238c2ecf20Sopenharmony_ci#define MTK_RX_DONE_INT2 BIT(18) 2248c2ecf20Sopenharmony_ci#define MTK_RX_DONE_INT1 BIT(17) 2258c2ecf20Sopenharmony_ci#define MTK_RX_DONE_INT0 BIT(16) 2268c2ecf20Sopenharmony_ci#define MTK_TX_DONE_INT3 BIT(3) 2278c2ecf20Sopenharmony_ci#define MTK_TX_DONE_INT2 BIT(2) 2288c2ecf20Sopenharmony_ci#define MTK_TX_DONE_INT1 BIT(1) 2298c2ecf20Sopenharmony_ci#define MTK_TX_DONE_INT0 BIT(0) 2308c2ecf20Sopenharmony_ci#define MTK_RX_DONE_INT MTK_RX_DONE_DLY 2318c2ecf20Sopenharmony_ci#define MTK_TX_DONE_INT (MTK_TX_DONE_INT0 | MTK_TX_DONE_INT1 | \ 2328c2ecf20Sopenharmony_ci MTK_TX_DONE_INT2 | MTK_TX_DONE_INT3) 2338c2ecf20Sopenharmony_ci 2348c2ecf20Sopenharmony_ci/* QDMA Interrupt grouping registers */ 2358c2ecf20Sopenharmony_ci#define MTK_QDMA_INT_GRP1 0x1a20 2368c2ecf20Sopenharmony_ci#define MTK_QDMA_INT_GRP2 0x1a24 2378c2ecf20Sopenharmony_ci#define MTK_RLS_DONE_INT BIT(0) 2388c2ecf20Sopenharmony_ci 2398c2ecf20Sopenharmony_ci/* QDMA Interrupt Status Register */ 2408c2ecf20Sopenharmony_ci#define MTK_QDMA_INT_MASK 0x1A1C 2418c2ecf20Sopenharmony_ci 2428c2ecf20Sopenharmony_ci/* QDMA Interrupt Mask Register */ 2438c2ecf20Sopenharmony_ci#define MTK_QDMA_HRED2 0x1A44 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci/* QDMA TX Forward CPU Pointer Register */ 2468c2ecf20Sopenharmony_ci#define MTK_QTX_CTX_PTR 0x1B00 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci/* QDMA TX Forward DMA Pointer Register */ 2498c2ecf20Sopenharmony_ci#define MTK_QTX_DTX_PTR 0x1B04 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci/* QDMA TX Release CPU Pointer Register */ 2528c2ecf20Sopenharmony_ci#define MTK_QTX_CRX_PTR 0x1B10 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci/* QDMA TX Release DMA Pointer Register */ 2558c2ecf20Sopenharmony_ci#define MTK_QTX_DRX_PTR 0x1B14 2568c2ecf20Sopenharmony_ci 2578c2ecf20Sopenharmony_ci/* QDMA FQ Head Pointer Register */ 2588c2ecf20Sopenharmony_ci#define MTK_QDMA_FQ_HEAD 0x1B20 2598c2ecf20Sopenharmony_ci 2608c2ecf20Sopenharmony_ci/* QDMA FQ Head Pointer Register */ 2618c2ecf20Sopenharmony_ci#define MTK_QDMA_FQ_TAIL 0x1B24 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_ci/* QDMA FQ Free Page Counter Register */ 2648c2ecf20Sopenharmony_ci#define MTK_QDMA_FQ_CNT 0x1B28 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci/* QDMA FQ Free Page Buffer Length Register */ 2678c2ecf20Sopenharmony_ci#define MTK_QDMA_FQ_BLEN 0x1B2C 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_ci/* GMA1 counter / statics register */ 2708c2ecf20Sopenharmony_ci#define MTK_GDM1_RX_GBCNT_L 0x2400 2718c2ecf20Sopenharmony_ci#define MTK_GDM1_RX_GBCNT_H 0x2404 2728c2ecf20Sopenharmony_ci#define MTK_GDM1_RX_GPCNT 0x2408 2738c2ecf20Sopenharmony_ci#define MTK_GDM1_RX_OERCNT 0x2410 2748c2ecf20Sopenharmony_ci#define MTK_GDM1_RX_FERCNT 0x2414 2758c2ecf20Sopenharmony_ci#define MTK_GDM1_RX_SERCNT 0x2418 2768c2ecf20Sopenharmony_ci#define MTK_GDM1_RX_LENCNT 0x241c 2778c2ecf20Sopenharmony_ci#define MTK_GDM1_RX_CERCNT 0x2420 2788c2ecf20Sopenharmony_ci#define MTK_GDM1_RX_FCCNT 0x2424 2798c2ecf20Sopenharmony_ci#define MTK_GDM1_TX_SKIPCNT 0x2428 2808c2ecf20Sopenharmony_ci#define MTK_GDM1_TX_COLCNT 0x242c 2818c2ecf20Sopenharmony_ci#define MTK_GDM1_TX_GBCNT_L 0x2430 2828c2ecf20Sopenharmony_ci#define MTK_GDM1_TX_GBCNT_H 0x2434 2838c2ecf20Sopenharmony_ci#define MTK_GDM1_TX_GPCNT 0x2438 2848c2ecf20Sopenharmony_ci#define MTK_STAT_OFFSET 0x40 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci/* QDMA descriptor txd4 */ 2878c2ecf20Sopenharmony_ci#define TX_DMA_CHKSUM (0x7 << 29) 2888c2ecf20Sopenharmony_ci#define TX_DMA_TSO BIT(28) 2898c2ecf20Sopenharmony_ci#define TX_DMA_FPORT_SHIFT 25 2908c2ecf20Sopenharmony_ci#define TX_DMA_FPORT_MASK 0x7 2918c2ecf20Sopenharmony_ci#define TX_DMA_INS_VLAN BIT(16) 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci/* QDMA descriptor txd3 */ 2948c2ecf20Sopenharmony_ci#define TX_DMA_OWNER_CPU BIT(31) 2958c2ecf20Sopenharmony_ci#define TX_DMA_LS0 BIT(30) 2968c2ecf20Sopenharmony_ci#define TX_DMA_PLEN0(_x) (((_x) & MTK_TX_DMA_BUF_LEN) << 16) 2978c2ecf20Sopenharmony_ci#define TX_DMA_PLEN1(_x) ((_x) & MTK_TX_DMA_BUF_LEN) 2988c2ecf20Sopenharmony_ci#define TX_DMA_SWC BIT(14) 2998c2ecf20Sopenharmony_ci#define TX_DMA_SDL(_x) (((_x) & 0x3fff) << 16) 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci/* PDMA on MT7628 */ 3028c2ecf20Sopenharmony_ci#define TX_DMA_DONE BIT(31) 3038c2ecf20Sopenharmony_ci#define TX_DMA_LS1 BIT(14) 3048c2ecf20Sopenharmony_ci#define TX_DMA_DESP2_DEF (TX_DMA_LS0 | TX_DMA_DONE) 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci/* QDMA descriptor rxd2 */ 3078c2ecf20Sopenharmony_ci#define RX_DMA_DONE BIT(31) 3088c2ecf20Sopenharmony_ci#define RX_DMA_LSO BIT(30) 3098c2ecf20Sopenharmony_ci#define RX_DMA_PLEN0(_x) (((_x) & 0x3fff) << 16) 3108c2ecf20Sopenharmony_ci#define RX_DMA_GET_PLEN0(_x) (((_x) >> 16) & 0x3fff) 3118c2ecf20Sopenharmony_ci#define RX_DMA_VTAG BIT(15) 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci/* QDMA descriptor rxd3 */ 3148c2ecf20Sopenharmony_ci#define RX_DMA_VID(_x) ((_x) & 0xfff) 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci/* QDMA descriptor rxd4 */ 3178c2ecf20Sopenharmony_ci#define RX_DMA_L4_VALID BIT(24) 3188c2ecf20Sopenharmony_ci#define RX_DMA_L4_VALID_PDMA BIT(30) /* when PDMA is used */ 3198c2ecf20Sopenharmony_ci#define RX_DMA_FPORT_SHIFT 19 3208c2ecf20Sopenharmony_ci#define RX_DMA_FPORT_MASK 0x7 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci/* PHY Indirect Access Control registers */ 3238c2ecf20Sopenharmony_ci#define MTK_PHY_IAC 0x10004 3248c2ecf20Sopenharmony_ci#define PHY_IAC_ACCESS BIT(31) 3258c2ecf20Sopenharmony_ci#define PHY_IAC_READ BIT(19) 3268c2ecf20Sopenharmony_ci#define PHY_IAC_WRITE BIT(18) 3278c2ecf20Sopenharmony_ci#define PHY_IAC_START BIT(16) 3288c2ecf20Sopenharmony_ci#define PHY_IAC_ADDR_SHIFT 20 3298c2ecf20Sopenharmony_ci#define PHY_IAC_REG_SHIFT 25 3308c2ecf20Sopenharmony_ci#define PHY_IAC_TIMEOUT HZ 3318c2ecf20Sopenharmony_ci 3328c2ecf20Sopenharmony_ci#define MTK_MAC_MISC 0x1000c 3338c2ecf20Sopenharmony_ci#define MTK_MUX_TO_ESW BIT(0) 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci/* Mac control registers */ 3368c2ecf20Sopenharmony_ci#define MTK_MAC_MCR(x) (0x10100 + (x * 0x100)) 3378c2ecf20Sopenharmony_ci#define MAC_MCR_MAX_RX_1536 BIT(24) 3388c2ecf20Sopenharmony_ci#define MAC_MCR_IPG_CFG (BIT(18) | BIT(16)) 3398c2ecf20Sopenharmony_ci#define MAC_MCR_FORCE_MODE BIT(15) 3408c2ecf20Sopenharmony_ci#define MAC_MCR_TX_EN BIT(14) 3418c2ecf20Sopenharmony_ci#define MAC_MCR_RX_EN BIT(13) 3428c2ecf20Sopenharmony_ci#define MAC_MCR_RX_FIFO_CLR_DIS BIT(12) 3438c2ecf20Sopenharmony_ci#define MAC_MCR_BACKOFF_EN BIT(9) 3448c2ecf20Sopenharmony_ci#define MAC_MCR_BACKPR_EN BIT(8) 3458c2ecf20Sopenharmony_ci#define MAC_MCR_FORCE_RX_FC BIT(5) 3468c2ecf20Sopenharmony_ci#define MAC_MCR_FORCE_TX_FC BIT(4) 3478c2ecf20Sopenharmony_ci#define MAC_MCR_SPEED_1000 BIT(3) 3488c2ecf20Sopenharmony_ci#define MAC_MCR_SPEED_100 BIT(2) 3498c2ecf20Sopenharmony_ci#define MAC_MCR_FORCE_DPX BIT(1) 3508c2ecf20Sopenharmony_ci#define MAC_MCR_FORCE_LINK BIT(0) 3518c2ecf20Sopenharmony_ci#define MAC_MCR_FORCE_LINK_DOWN (MAC_MCR_FORCE_MODE) 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_ci/* Mac status registers */ 3548c2ecf20Sopenharmony_ci#define MTK_MAC_MSR(x) (0x10108 + (x * 0x100)) 3558c2ecf20Sopenharmony_ci#define MAC_MSR_EEE1G BIT(7) 3568c2ecf20Sopenharmony_ci#define MAC_MSR_EEE100M BIT(6) 3578c2ecf20Sopenharmony_ci#define MAC_MSR_RX_FC BIT(5) 3588c2ecf20Sopenharmony_ci#define MAC_MSR_TX_FC BIT(4) 3598c2ecf20Sopenharmony_ci#define MAC_MSR_SPEED_1000 BIT(3) 3608c2ecf20Sopenharmony_ci#define MAC_MSR_SPEED_100 BIT(2) 3618c2ecf20Sopenharmony_ci#define MAC_MSR_SPEED_MASK (MAC_MSR_SPEED_1000 | MAC_MSR_SPEED_100) 3628c2ecf20Sopenharmony_ci#define MAC_MSR_DPX BIT(1) 3638c2ecf20Sopenharmony_ci#define MAC_MSR_LINK BIT(0) 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci/* TRGMII RXC control register */ 3668c2ecf20Sopenharmony_ci#define TRGMII_RCK_CTRL 0x10300 3678c2ecf20Sopenharmony_ci#define DQSI0(x) ((x << 0) & GENMASK(6, 0)) 3688c2ecf20Sopenharmony_ci#define DQSI1(x) ((x << 8) & GENMASK(14, 8)) 3698c2ecf20Sopenharmony_ci#define RXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16)) 3708c2ecf20Sopenharmony_ci#define RXC_RST BIT(31) 3718c2ecf20Sopenharmony_ci#define RXC_DQSISEL BIT(30) 3728c2ecf20Sopenharmony_ci#define RCK_CTRL_RGMII_1000 (RXC_DQSISEL | RXCTL_DMWTLAT(2) | DQSI1(16)) 3738c2ecf20Sopenharmony_ci#define RCK_CTRL_RGMII_10_100 RXCTL_DMWTLAT(2) 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci#define NUM_TRGMII_CTRL 5 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci/* TRGMII RXC control register */ 3788c2ecf20Sopenharmony_ci#define TRGMII_TCK_CTRL 0x10340 3798c2ecf20Sopenharmony_ci#define TXCTL_DMWTLAT(x) ((x << 16) & GENMASK(18, 16)) 3808c2ecf20Sopenharmony_ci#define TXC_INV BIT(30) 3818c2ecf20Sopenharmony_ci#define TCK_CTRL_RGMII_1000 TXCTL_DMWTLAT(2) 3828c2ecf20Sopenharmony_ci#define TCK_CTRL_RGMII_10_100 (TXC_INV | TXCTL_DMWTLAT(2)) 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci/* TRGMII TX Drive Strength */ 3858c2ecf20Sopenharmony_ci#define TRGMII_TD_ODT(i) (0x10354 + 8 * (i)) 3868c2ecf20Sopenharmony_ci#define TD_DM_DRVP(x) ((x) & 0xf) 3878c2ecf20Sopenharmony_ci#define TD_DM_DRVN(x) (((x) & 0xf) << 4) 3888c2ecf20Sopenharmony_ci 3898c2ecf20Sopenharmony_ci/* TRGMII Interface mode register */ 3908c2ecf20Sopenharmony_ci#define INTF_MODE 0x10390 3918c2ecf20Sopenharmony_ci#define TRGMII_INTF_DIS BIT(0) 3928c2ecf20Sopenharmony_ci#define TRGMII_MODE BIT(1) 3938c2ecf20Sopenharmony_ci#define TRGMII_CENTRAL_ALIGNED BIT(2) 3948c2ecf20Sopenharmony_ci#define INTF_MODE_RGMII_1000 (TRGMII_MODE | TRGMII_CENTRAL_ALIGNED) 3958c2ecf20Sopenharmony_ci#define INTF_MODE_RGMII_10_100 0 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci/* GPIO port control registers for GMAC 2*/ 3988c2ecf20Sopenharmony_ci#define GPIO_OD33_CTRL8 0x4c0 3998c2ecf20Sopenharmony_ci#define GPIO_BIAS_CTRL 0xed0 4008c2ecf20Sopenharmony_ci#define GPIO_DRV_SEL10 0xf00 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ci/* ethernet subsystem chip id register */ 4038c2ecf20Sopenharmony_ci#define ETHSYS_CHIPID0_3 0x0 4048c2ecf20Sopenharmony_ci#define ETHSYS_CHIPID4_7 0x4 4058c2ecf20Sopenharmony_ci#define MT7623_ETH 7623 4068c2ecf20Sopenharmony_ci#define MT7622_ETH 7622 4078c2ecf20Sopenharmony_ci#define MT7621_ETH 7621 4088c2ecf20Sopenharmony_ci 4098c2ecf20Sopenharmony_ci/* ethernet system control register */ 4108c2ecf20Sopenharmony_ci#define ETHSYS_SYSCFG 0x10 4118c2ecf20Sopenharmony_ci#define SYSCFG_DRAM_TYPE_DDR2 BIT(4) 4128c2ecf20Sopenharmony_ci 4138c2ecf20Sopenharmony_ci/* ethernet subsystem config register */ 4148c2ecf20Sopenharmony_ci#define ETHSYS_SYSCFG0 0x14 4158c2ecf20Sopenharmony_ci#define SYSCFG0_GE_MASK 0x3 4168c2ecf20Sopenharmony_ci#define SYSCFG0_GE_MODE(x, y) (x << (12 + (y * 2))) 4178c2ecf20Sopenharmony_ci#define SYSCFG0_SGMII_MASK GENMASK(9, 8) 4188c2ecf20Sopenharmony_ci#define SYSCFG0_SGMII_GMAC1 ((2 << 8) & SYSCFG0_SGMII_MASK) 4198c2ecf20Sopenharmony_ci#define SYSCFG0_SGMII_GMAC2 ((3 << 8) & SYSCFG0_SGMII_MASK) 4208c2ecf20Sopenharmony_ci#define SYSCFG0_SGMII_GMAC1_V2 BIT(9) 4218c2ecf20Sopenharmony_ci#define SYSCFG0_SGMII_GMAC2_V2 BIT(8) 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci/* ethernet subsystem clock register */ 4258c2ecf20Sopenharmony_ci#define ETHSYS_CLKCFG0 0x2c 4268c2ecf20Sopenharmony_ci#define ETHSYS_TRGMII_CLK_SEL362_5 BIT(11) 4278c2ecf20Sopenharmony_ci#define ETHSYS_TRGMII_MT7621_MASK (BIT(5) | BIT(6)) 4288c2ecf20Sopenharmony_ci#define ETHSYS_TRGMII_MT7621_APLL BIT(6) 4298c2ecf20Sopenharmony_ci#define ETHSYS_TRGMII_MT7621_DDR_PLL BIT(5) 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci/* ethernet reset control register */ 4328c2ecf20Sopenharmony_ci#define ETHSYS_RSTCTRL 0x34 4338c2ecf20Sopenharmony_ci#define RSTCTRL_FE BIT(6) 4348c2ecf20Sopenharmony_ci#define RSTCTRL_PPE BIT(31) 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci/* SGMII subsystem config registers */ 4378c2ecf20Sopenharmony_ci/* Register to auto-negotiation restart */ 4388c2ecf20Sopenharmony_ci#define SGMSYS_PCS_CONTROL_1 0x0 4398c2ecf20Sopenharmony_ci#define SGMII_AN_RESTART BIT(9) 4408c2ecf20Sopenharmony_ci#define SGMII_ISOLATE BIT(10) 4418c2ecf20Sopenharmony_ci#define SGMII_AN_ENABLE BIT(12) 4428c2ecf20Sopenharmony_ci#define SGMII_LINK_STATYS BIT(18) 4438c2ecf20Sopenharmony_ci#define SGMII_AN_ABILITY BIT(19) 4448c2ecf20Sopenharmony_ci#define SGMII_AN_COMPLETE BIT(21) 4458c2ecf20Sopenharmony_ci#define SGMII_PCS_FAULT BIT(23) 4468c2ecf20Sopenharmony_ci#define SGMII_AN_EXPANSION_CLR BIT(30) 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci/* Register to programmable link timer, the unit in 2 * 8ns */ 4498c2ecf20Sopenharmony_ci#define SGMSYS_PCS_LINK_TIMER 0x18 4508c2ecf20Sopenharmony_ci#define SGMII_LINK_TIMER_DEFAULT (0x186a0 & GENMASK(19, 0)) 4518c2ecf20Sopenharmony_ci 4528c2ecf20Sopenharmony_ci/* Register to control remote fault */ 4538c2ecf20Sopenharmony_ci#define SGMSYS_SGMII_MODE 0x20 4548c2ecf20Sopenharmony_ci#define SGMII_IF_MODE_BIT0 BIT(0) 4558c2ecf20Sopenharmony_ci#define SGMII_SPEED_DUPLEX_AN BIT(1) 4568c2ecf20Sopenharmony_ci#define SGMII_SPEED_10 0x0 4578c2ecf20Sopenharmony_ci#define SGMII_SPEED_100 BIT(2) 4588c2ecf20Sopenharmony_ci#define SGMII_SPEED_1000 BIT(3) 4598c2ecf20Sopenharmony_ci#define SGMII_DUPLEX_FULL BIT(4) 4608c2ecf20Sopenharmony_ci#define SGMII_IF_MODE_BIT5 BIT(5) 4618c2ecf20Sopenharmony_ci#define SGMII_REMOTE_FAULT_DIS BIT(8) 4628c2ecf20Sopenharmony_ci#define SGMII_CODE_SYNC_SET_VAL BIT(9) 4638c2ecf20Sopenharmony_ci#define SGMII_CODE_SYNC_SET_EN BIT(10) 4648c2ecf20Sopenharmony_ci#define SGMII_SEND_AN_ERROR_EN BIT(11) 4658c2ecf20Sopenharmony_ci#define SGMII_IF_MODE_MASK GENMASK(5, 1) 4668c2ecf20Sopenharmony_ci 4678c2ecf20Sopenharmony_ci/* Register to set SGMII speed, ANA RG_ Control Signals III*/ 4688c2ecf20Sopenharmony_ci#define SGMSYS_ANA_RG_CS3 0x2028 4698c2ecf20Sopenharmony_ci#define RG_PHY_SPEED_MASK (BIT(2) | BIT(3)) 4708c2ecf20Sopenharmony_ci#define RG_PHY_SPEED_1_25G 0x0 4718c2ecf20Sopenharmony_ci#define RG_PHY_SPEED_3_125G BIT(2) 4728c2ecf20Sopenharmony_ci 4738c2ecf20Sopenharmony_ci/* Register to power up QPHY */ 4748c2ecf20Sopenharmony_ci#define SGMSYS_QPHY_PWR_STATE_CTRL 0xe8 4758c2ecf20Sopenharmony_ci#define SGMII_PHYA_PWD BIT(4) 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci/* Infrasys subsystem config registers */ 4788c2ecf20Sopenharmony_ci#define INFRA_MISC2 0x70c 4798c2ecf20Sopenharmony_ci#define CO_QPHY_SEL BIT(0) 4808c2ecf20Sopenharmony_ci#define GEPHY_MAC_SEL BIT(1) 4818c2ecf20Sopenharmony_ci 4828c2ecf20Sopenharmony_ci/* MT7628/88 specific stuff */ 4838c2ecf20Sopenharmony_ci#define MT7628_PDMA_OFFSET 0x0800 4848c2ecf20Sopenharmony_ci#define MT7628_SDM_OFFSET 0x0c00 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ci#define MT7628_TX_BASE_PTR0 (MT7628_PDMA_OFFSET + 0x00) 4878c2ecf20Sopenharmony_ci#define MT7628_TX_MAX_CNT0 (MT7628_PDMA_OFFSET + 0x04) 4888c2ecf20Sopenharmony_ci#define MT7628_TX_CTX_IDX0 (MT7628_PDMA_OFFSET + 0x08) 4898c2ecf20Sopenharmony_ci#define MT7628_TX_DTX_IDX0 (MT7628_PDMA_OFFSET + 0x0c) 4908c2ecf20Sopenharmony_ci#define MT7628_PST_DTX_IDX0 BIT(0) 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci#define MT7628_SDM_MAC_ADRL (MT7628_SDM_OFFSET + 0x0c) 4938c2ecf20Sopenharmony_ci#define MT7628_SDM_MAC_ADRH (MT7628_SDM_OFFSET + 0x10) 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci/* Counter / stat register */ 4968c2ecf20Sopenharmony_ci#define MT7628_SDM_TPCNT (MT7628_SDM_OFFSET + 0x100) 4978c2ecf20Sopenharmony_ci#define MT7628_SDM_TBCNT (MT7628_SDM_OFFSET + 0x104) 4988c2ecf20Sopenharmony_ci#define MT7628_SDM_RPCNT (MT7628_SDM_OFFSET + 0x108) 4998c2ecf20Sopenharmony_ci#define MT7628_SDM_RBCNT (MT7628_SDM_OFFSET + 0x10c) 5008c2ecf20Sopenharmony_ci#define MT7628_SDM_CS_ERR (MT7628_SDM_OFFSET + 0x110) 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_cistruct mtk_rx_dma { 5038c2ecf20Sopenharmony_ci unsigned int rxd1; 5048c2ecf20Sopenharmony_ci unsigned int rxd2; 5058c2ecf20Sopenharmony_ci unsigned int rxd3; 5068c2ecf20Sopenharmony_ci unsigned int rxd4; 5078c2ecf20Sopenharmony_ci} __packed __aligned(4); 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_cistruct mtk_tx_dma { 5108c2ecf20Sopenharmony_ci unsigned int txd1; 5118c2ecf20Sopenharmony_ci unsigned int txd2; 5128c2ecf20Sopenharmony_ci unsigned int txd3; 5138c2ecf20Sopenharmony_ci unsigned int txd4; 5148c2ecf20Sopenharmony_ci} __packed __aligned(4); 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_cistruct mtk_eth; 5178c2ecf20Sopenharmony_cistruct mtk_mac; 5188c2ecf20Sopenharmony_ci 5198c2ecf20Sopenharmony_ci/* struct mtk_hw_stats - the structure that holds the traffic statistics. 5208c2ecf20Sopenharmony_ci * @stats_lock: make sure that stats operations are atomic 5218c2ecf20Sopenharmony_ci * @reg_offset: the status register offset of the SoC 5228c2ecf20Sopenharmony_ci * @syncp: the refcount 5238c2ecf20Sopenharmony_ci * 5248c2ecf20Sopenharmony_ci * All of the supported SoCs have hardware counters for traffic statistics. 5258c2ecf20Sopenharmony_ci * Whenever the status IRQ triggers we can read the latest stats from these 5268c2ecf20Sopenharmony_ci * counters and store them in this struct. 5278c2ecf20Sopenharmony_ci */ 5288c2ecf20Sopenharmony_cistruct mtk_hw_stats { 5298c2ecf20Sopenharmony_ci u64 tx_bytes; 5308c2ecf20Sopenharmony_ci u64 tx_packets; 5318c2ecf20Sopenharmony_ci u64 tx_skip; 5328c2ecf20Sopenharmony_ci u64 tx_collisions; 5338c2ecf20Sopenharmony_ci u64 rx_bytes; 5348c2ecf20Sopenharmony_ci u64 rx_packets; 5358c2ecf20Sopenharmony_ci u64 rx_overflow; 5368c2ecf20Sopenharmony_ci u64 rx_fcs_errors; 5378c2ecf20Sopenharmony_ci u64 rx_short_errors; 5388c2ecf20Sopenharmony_ci u64 rx_long_errors; 5398c2ecf20Sopenharmony_ci u64 rx_checksum_errors; 5408c2ecf20Sopenharmony_ci u64 rx_flow_control_packets; 5418c2ecf20Sopenharmony_ci 5428c2ecf20Sopenharmony_ci spinlock_t stats_lock; 5438c2ecf20Sopenharmony_ci u32 reg_offset; 5448c2ecf20Sopenharmony_ci struct u64_stats_sync syncp; 5458c2ecf20Sopenharmony_ci}; 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_cienum mtk_tx_flags { 5488c2ecf20Sopenharmony_ci /* PDMA descriptor can point at 1-2 segments. This enum allows us to 5498c2ecf20Sopenharmony_ci * track how memory was allocated so that it can be freed properly. 5508c2ecf20Sopenharmony_ci */ 5518c2ecf20Sopenharmony_ci MTK_TX_FLAGS_SINGLE0 = 0x01, 5528c2ecf20Sopenharmony_ci MTK_TX_FLAGS_PAGE0 = 0x02, 5538c2ecf20Sopenharmony_ci 5548c2ecf20Sopenharmony_ci /* MTK_TX_FLAGS_FPORTx allows tracking which port the transmitted 5558c2ecf20Sopenharmony_ci * SKB out instead of looking up through hardware TX descriptor. 5568c2ecf20Sopenharmony_ci */ 5578c2ecf20Sopenharmony_ci MTK_TX_FLAGS_FPORT0 = 0x04, 5588c2ecf20Sopenharmony_ci MTK_TX_FLAGS_FPORT1 = 0x08, 5598c2ecf20Sopenharmony_ci}; 5608c2ecf20Sopenharmony_ci 5618c2ecf20Sopenharmony_ci/* This enum allows us to identify how the clock is defined on the array of the 5628c2ecf20Sopenharmony_ci * clock in the order 5638c2ecf20Sopenharmony_ci */ 5648c2ecf20Sopenharmony_cienum mtk_clks_map { 5658c2ecf20Sopenharmony_ci MTK_CLK_ETHIF, 5668c2ecf20Sopenharmony_ci MTK_CLK_SGMIITOP, 5678c2ecf20Sopenharmony_ci MTK_CLK_ESW, 5688c2ecf20Sopenharmony_ci MTK_CLK_GP0, 5698c2ecf20Sopenharmony_ci MTK_CLK_GP1, 5708c2ecf20Sopenharmony_ci MTK_CLK_GP2, 5718c2ecf20Sopenharmony_ci MTK_CLK_FE, 5728c2ecf20Sopenharmony_ci MTK_CLK_TRGPLL, 5738c2ecf20Sopenharmony_ci MTK_CLK_SGMII_TX_250M, 5748c2ecf20Sopenharmony_ci MTK_CLK_SGMII_RX_250M, 5758c2ecf20Sopenharmony_ci MTK_CLK_SGMII_CDR_REF, 5768c2ecf20Sopenharmony_ci MTK_CLK_SGMII_CDR_FB, 5778c2ecf20Sopenharmony_ci MTK_CLK_SGMII2_TX_250M, 5788c2ecf20Sopenharmony_ci MTK_CLK_SGMII2_RX_250M, 5798c2ecf20Sopenharmony_ci MTK_CLK_SGMII2_CDR_REF, 5808c2ecf20Sopenharmony_ci MTK_CLK_SGMII2_CDR_FB, 5818c2ecf20Sopenharmony_ci MTK_CLK_SGMII_CK, 5828c2ecf20Sopenharmony_ci MTK_CLK_ETH2PLL, 5838c2ecf20Sopenharmony_ci MTK_CLK_MAX 5848c2ecf20Sopenharmony_ci}; 5858c2ecf20Sopenharmony_ci 5868c2ecf20Sopenharmony_ci#define MT7623_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \ 5878c2ecf20Sopenharmony_ci BIT(MTK_CLK_GP1) | BIT(MTK_CLK_GP2) | \ 5888c2ecf20Sopenharmony_ci BIT(MTK_CLK_TRGPLL)) 5898c2ecf20Sopenharmony_ci#define MT7622_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \ 5908c2ecf20Sopenharmony_ci BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \ 5918c2ecf20Sopenharmony_ci BIT(MTK_CLK_GP2) | \ 5928c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII_TX_250M) | \ 5938c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII_RX_250M) | \ 5948c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII_CDR_REF) | \ 5958c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII_CDR_FB) | \ 5968c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII_CK) | \ 5978c2ecf20Sopenharmony_ci BIT(MTK_CLK_ETH2PLL)) 5988c2ecf20Sopenharmony_ci#define MT7621_CLKS_BITMAP (0) 5998c2ecf20Sopenharmony_ci#define MT7628_CLKS_BITMAP (0) 6008c2ecf20Sopenharmony_ci#define MT7629_CLKS_BITMAP (BIT(MTK_CLK_ETHIF) | BIT(MTK_CLK_ESW) | \ 6018c2ecf20Sopenharmony_ci BIT(MTK_CLK_GP0) | BIT(MTK_CLK_GP1) | \ 6028c2ecf20Sopenharmony_ci BIT(MTK_CLK_GP2) | BIT(MTK_CLK_FE) | \ 6038c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII_TX_250M) | \ 6048c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII_RX_250M) | \ 6058c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII_CDR_REF) | \ 6068c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII_CDR_FB) | \ 6078c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII2_TX_250M) | \ 6088c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII2_RX_250M) | \ 6098c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII2_CDR_REF) | \ 6108c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII2_CDR_FB) | \ 6118c2ecf20Sopenharmony_ci BIT(MTK_CLK_SGMII_CK) | \ 6128c2ecf20Sopenharmony_ci BIT(MTK_CLK_ETH2PLL) | BIT(MTK_CLK_SGMIITOP)) 6138c2ecf20Sopenharmony_ci 6148c2ecf20Sopenharmony_cienum mtk_dev_state { 6158c2ecf20Sopenharmony_ci MTK_HW_INIT, 6168c2ecf20Sopenharmony_ci MTK_RESETTING 6178c2ecf20Sopenharmony_ci}; 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci/* struct mtk_tx_buf - This struct holds the pointers to the memory pointed at 6208c2ecf20Sopenharmony_ci * by the TX descriptor s 6218c2ecf20Sopenharmony_ci * @skb: The SKB pointer of the packet being sent 6228c2ecf20Sopenharmony_ci * @dma_addr0: The base addr of the first segment 6238c2ecf20Sopenharmony_ci * @dma_len0: The length of the first segment 6248c2ecf20Sopenharmony_ci * @dma_addr1: The base addr of the second segment 6258c2ecf20Sopenharmony_ci * @dma_len1: The length of the second segment 6268c2ecf20Sopenharmony_ci */ 6278c2ecf20Sopenharmony_cistruct mtk_tx_buf { 6288c2ecf20Sopenharmony_ci struct sk_buff *skb; 6298c2ecf20Sopenharmony_ci u32 flags; 6308c2ecf20Sopenharmony_ci DEFINE_DMA_UNMAP_ADDR(dma_addr0); 6318c2ecf20Sopenharmony_ci DEFINE_DMA_UNMAP_LEN(dma_len0); 6328c2ecf20Sopenharmony_ci DEFINE_DMA_UNMAP_ADDR(dma_addr1); 6338c2ecf20Sopenharmony_ci DEFINE_DMA_UNMAP_LEN(dma_len1); 6348c2ecf20Sopenharmony_ci}; 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci/* struct mtk_tx_ring - This struct holds info describing a TX ring 6378c2ecf20Sopenharmony_ci * @dma: The descriptor ring 6388c2ecf20Sopenharmony_ci * @buf: The memory pointed at by the ring 6398c2ecf20Sopenharmony_ci * @phys: The physical addr of tx_buf 6408c2ecf20Sopenharmony_ci * @next_free: Pointer to the next free descriptor 6418c2ecf20Sopenharmony_ci * @last_free: Pointer to the last free descriptor 6428c2ecf20Sopenharmony_ci * @thresh: The threshold of minimum amount of free descriptors 6438c2ecf20Sopenharmony_ci * @free_count: QDMA uses a linked list. Track how many free descriptors 6448c2ecf20Sopenharmony_ci * are present 6458c2ecf20Sopenharmony_ci */ 6468c2ecf20Sopenharmony_cistruct mtk_tx_ring { 6478c2ecf20Sopenharmony_ci struct mtk_tx_dma *dma; 6488c2ecf20Sopenharmony_ci struct mtk_tx_buf *buf; 6498c2ecf20Sopenharmony_ci dma_addr_t phys; 6508c2ecf20Sopenharmony_ci struct mtk_tx_dma *next_free; 6518c2ecf20Sopenharmony_ci struct mtk_tx_dma *last_free; 6528c2ecf20Sopenharmony_ci u16 thresh; 6538c2ecf20Sopenharmony_ci atomic_t free_count; 6548c2ecf20Sopenharmony_ci int dma_size; 6558c2ecf20Sopenharmony_ci struct mtk_tx_dma *dma_pdma; /* For MT7628/88 PDMA handling */ 6568c2ecf20Sopenharmony_ci dma_addr_t phys_pdma; 6578c2ecf20Sopenharmony_ci int cpu_idx; 6588c2ecf20Sopenharmony_ci}; 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci/* PDMA rx ring mode */ 6618c2ecf20Sopenharmony_cienum mtk_rx_flags { 6628c2ecf20Sopenharmony_ci MTK_RX_FLAGS_NORMAL = 0, 6638c2ecf20Sopenharmony_ci MTK_RX_FLAGS_HWLRO, 6648c2ecf20Sopenharmony_ci MTK_RX_FLAGS_QDMA, 6658c2ecf20Sopenharmony_ci}; 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci/* struct mtk_rx_ring - This struct holds info describing a RX ring 6688c2ecf20Sopenharmony_ci * @dma: The descriptor ring 6698c2ecf20Sopenharmony_ci * @data: The memory pointed at by the ring 6708c2ecf20Sopenharmony_ci * @phys: The physical addr of rx_buf 6718c2ecf20Sopenharmony_ci * @frag_size: How big can each fragment be 6728c2ecf20Sopenharmony_ci * @buf_size: The size of each packet buffer 6738c2ecf20Sopenharmony_ci * @calc_idx: The current head of ring 6748c2ecf20Sopenharmony_ci */ 6758c2ecf20Sopenharmony_cistruct mtk_rx_ring { 6768c2ecf20Sopenharmony_ci struct mtk_rx_dma *dma; 6778c2ecf20Sopenharmony_ci u8 **data; 6788c2ecf20Sopenharmony_ci dma_addr_t phys; 6798c2ecf20Sopenharmony_ci u16 frag_size; 6808c2ecf20Sopenharmony_ci u16 buf_size; 6818c2ecf20Sopenharmony_ci u16 dma_size; 6828c2ecf20Sopenharmony_ci bool calc_idx_update; 6838c2ecf20Sopenharmony_ci u16 calc_idx; 6848c2ecf20Sopenharmony_ci u32 crx_idx_reg; 6858c2ecf20Sopenharmony_ci}; 6868c2ecf20Sopenharmony_ci 6878c2ecf20Sopenharmony_cienum mkt_eth_capabilities { 6888c2ecf20Sopenharmony_ci MTK_RGMII_BIT = 0, 6898c2ecf20Sopenharmony_ci MTK_TRGMII_BIT, 6908c2ecf20Sopenharmony_ci MTK_SGMII_BIT, 6918c2ecf20Sopenharmony_ci MTK_ESW_BIT, 6928c2ecf20Sopenharmony_ci MTK_GEPHY_BIT, 6938c2ecf20Sopenharmony_ci MTK_MUX_BIT, 6948c2ecf20Sopenharmony_ci MTK_INFRA_BIT, 6958c2ecf20Sopenharmony_ci MTK_SHARED_SGMII_BIT, 6968c2ecf20Sopenharmony_ci MTK_HWLRO_BIT, 6978c2ecf20Sopenharmony_ci MTK_SHARED_INT_BIT, 6988c2ecf20Sopenharmony_ci MTK_TRGMII_MT7621_CLK_BIT, 6998c2ecf20Sopenharmony_ci MTK_QDMA_BIT, 7008c2ecf20Sopenharmony_ci MTK_SOC_MT7628_BIT, 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci /* MUX BITS*/ 7038c2ecf20Sopenharmony_ci MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT, 7048c2ecf20Sopenharmony_ci MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT, 7058c2ecf20Sopenharmony_ci MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT, 7068c2ecf20Sopenharmony_ci MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT, 7078c2ecf20Sopenharmony_ci MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT, 7088c2ecf20Sopenharmony_ci 7098c2ecf20Sopenharmony_ci /* PATH BITS */ 7108c2ecf20Sopenharmony_ci MTK_ETH_PATH_GMAC1_RGMII_BIT, 7118c2ecf20Sopenharmony_ci MTK_ETH_PATH_GMAC1_TRGMII_BIT, 7128c2ecf20Sopenharmony_ci MTK_ETH_PATH_GMAC1_SGMII_BIT, 7138c2ecf20Sopenharmony_ci MTK_ETH_PATH_GMAC2_RGMII_BIT, 7148c2ecf20Sopenharmony_ci MTK_ETH_PATH_GMAC2_SGMII_BIT, 7158c2ecf20Sopenharmony_ci MTK_ETH_PATH_GMAC2_GEPHY_BIT, 7168c2ecf20Sopenharmony_ci MTK_ETH_PATH_GDM1_ESW_BIT, 7178c2ecf20Sopenharmony_ci}; 7188c2ecf20Sopenharmony_ci 7198c2ecf20Sopenharmony_ci/* Supported hardware group on SoCs */ 7208c2ecf20Sopenharmony_ci#define MTK_RGMII BIT(MTK_RGMII_BIT) 7218c2ecf20Sopenharmony_ci#define MTK_TRGMII BIT(MTK_TRGMII_BIT) 7228c2ecf20Sopenharmony_ci#define MTK_SGMII BIT(MTK_SGMII_BIT) 7238c2ecf20Sopenharmony_ci#define MTK_ESW BIT(MTK_ESW_BIT) 7248c2ecf20Sopenharmony_ci#define MTK_GEPHY BIT(MTK_GEPHY_BIT) 7258c2ecf20Sopenharmony_ci#define MTK_MUX BIT(MTK_MUX_BIT) 7268c2ecf20Sopenharmony_ci#define MTK_INFRA BIT(MTK_INFRA_BIT) 7278c2ecf20Sopenharmony_ci#define MTK_SHARED_SGMII BIT(MTK_SHARED_SGMII_BIT) 7288c2ecf20Sopenharmony_ci#define MTK_HWLRO BIT(MTK_HWLRO_BIT) 7298c2ecf20Sopenharmony_ci#define MTK_SHARED_INT BIT(MTK_SHARED_INT_BIT) 7308c2ecf20Sopenharmony_ci#define MTK_TRGMII_MT7621_CLK BIT(MTK_TRGMII_MT7621_CLK_BIT) 7318c2ecf20Sopenharmony_ci#define MTK_QDMA BIT(MTK_QDMA_BIT) 7328c2ecf20Sopenharmony_ci#define MTK_SOC_MT7628 BIT(MTK_SOC_MT7628_BIT) 7338c2ecf20Sopenharmony_ci 7348c2ecf20Sopenharmony_ci#define MTK_ETH_MUX_GDM1_TO_GMAC1_ESW \ 7358c2ecf20Sopenharmony_ci BIT(MTK_ETH_MUX_GDM1_TO_GMAC1_ESW_BIT) 7368c2ecf20Sopenharmony_ci#define MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY \ 7378c2ecf20Sopenharmony_ci BIT(MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY_BIT) 7388c2ecf20Sopenharmony_ci#define MTK_ETH_MUX_U3_GMAC2_TO_QPHY \ 7398c2ecf20Sopenharmony_ci BIT(MTK_ETH_MUX_U3_GMAC2_TO_QPHY_BIT) 7408c2ecf20Sopenharmony_ci#define MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \ 7418c2ecf20Sopenharmony_ci BIT(MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII_BIT) 7428c2ecf20Sopenharmony_ci#define MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII \ 7438c2ecf20Sopenharmony_ci BIT(MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII_BIT) 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_ci/* Supported path present on SoCs */ 7468c2ecf20Sopenharmony_ci#define MTK_ETH_PATH_GMAC1_RGMII BIT(MTK_ETH_PATH_GMAC1_RGMII_BIT) 7478c2ecf20Sopenharmony_ci#define MTK_ETH_PATH_GMAC1_TRGMII BIT(MTK_ETH_PATH_GMAC1_TRGMII_BIT) 7488c2ecf20Sopenharmony_ci#define MTK_ETH_PATH_GMAC1_SGMII BIT(MTK_ETH_PATH_GMAC1_SGMII_BIT) 7498c2ecf20Sopenharmony_ci#define MTK_ETH_PATH_GMAC2_RGMII BIT(MTK_ETH_PATH_GMAC2_RGMII_BIT) 7508c2ecf20Sopenharmony_ci#define MTK_ETH_PATH_GMAC2_SGMII BIT(MTK_ETH_PATH_GMAC2_SGMII_BIT) 7518c2ecf20Sopenharmony_ci#define MTK_ETH_PATH_GMAC2_GEPHY BIT(MTK_ETH_PATH_GMAC2_GEPHY_BIT) 7528c2ecf20Sopenharmony_ci#define MTK_ETH_PATH_GDM1_ESW BIT(MTK_ETH_PATH_GDM1_ESW_BIT) 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ci#define MTK_GMAC1_RGMII (MTK_ETH_PATH_GMAC1_RGMII | MTK_RGMII) 7558c2ecf20Sopenharmony_ci#define MTK_GMAC1_TRGMII (MTK_ETH_PATH_GMAC1_TRGMII | MTK_TRGMII) 7568c2ecf20Sopenharmony_ci#define MTK_GMAC1_SGMII (MTK_ETH_PATH_GMAC1_SGMII | MTK_SGMII) 7578c2ecf20Sopenharmony_ci#define MTK_GMAC2_RGMII (MTK_ETH_PATH_GMAC2_RGMII | MTK_RGMII) 7588c2ecf20Sopenharmony_ci#define MTK_GMAC2_SGMII (MTK_ETH_PATH_GMAC2_SGMII | MTK_SGMII) 7598c2ecf20Sopenharmony_ci#define MTK_GMAC2_GEPHY (MTK_ETH_PATH_GMAC2_GEPHY | MTK_GEPHY) 7608c2ecf20Sopenharmony_ci#define MTK_GDM1_ESW (MTK_ETH_PATH_GDM1_ESW | MTK_ESW) 7618c2ecf20Sopenharmony_ci 7628c2ecf20Sopenharmony_ci/* MUXes present on SoCs */ 7638c2ecf20Sopenharmony_ci/* 0: GDM1 -> GMAC1, 1: GDM1 -> ESW */ 7648c2ecf20Sopenharmony_ci#define MTK_MUX_GDM1_TO_GMAC1_ESW (MTK_ETH_MUX_GDM1_TO_GMAC1_ESW | MTK_MUX) 7658c2ecf20Sopenharmony_ci 7668c2ecf20Sopenharmony_ci/* 0: GMAC2 -> GEPHY, 1: GMAC0 -> GePHY */ 7678c2ecf20Sopenharmony_ci#define MTK_MUX_GMAC2_GMAC0_TO_GEPHY \ 7688c2ecf20Sopenharmony_ci (MTK_ETH_MUX_GMAC2_GMAC0_TO_GEPHY | MTK_MUX | MTK_INFRA) 7698c2ecf20Sopenharmony_ci 7708c2ecf20Sopenharmony_ci/* 0: U3 -> QPHY, 1: GMAC2 -> QPHY */ 7718c2ecf20Sopenharmony_ci#define MTK_MUX_U3_GMAC2_TO_QPHY \ 7728c2ecf20Sopenharmony_ci (MTK_ETH_MUX_U3_GMAC2_TO_QPHY | MTK_MUX | MTK_INFRA) 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_ci/* 2: GMAC1 -> SGMII, 3: GMAC2 -> SGMII */ 7758c2ecf20Sopenharmony_ci#define MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII \ 7768c2ecf20Sopenharmony_ci (MTK_ETH_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_MUX | \ 7778c2ecf20Sopenharmony_ci MTK_SHARED_SGMII) 7788c2ecf20Sopenharmony_ci 7798c2ecf20Sopenharmony_ci/* 0: GMACx -> GEPHY, 1: GMACx -> SGMII where x is 1 or 2 */ 7808c2ecf20Sopenharmony_ci#define MTK_MUX_GMAC12_TO_GEPHY_SGMII \ 7818c2ecf20Sopenharmony_ci (MTK_ETH_MUX_GMAC12_TO_GEPHY_SGMII | MTK_MUX) 7828c2ecf20Sopenharmony_ci 7838c2ecf20Sopenharmony_ci#define MTK_HAS_CAPS(caps, _x) (((caps) & (_x)) == (_x)) 7848c2ecf20Sopenharmony_ci 7858c2ecf20Sopenharmony_ci#define MT7621_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | \ 7868c2ecf20Sopenharmony_ci MTK_GMAC2_RGMII | MTK_SHARED_INT | \ 7878c2ecf20Sopenharmony_ci MTK_TRGMII_MT7621_CLK | MTK_QDMA) 7888c2ecf20Sopenharmony_ci 7898c2ecf20Sopenharmony_ci#define MT7622_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_SGMII | MTK_GMAC2_RGMII | \ 7908c2ecf20Sopenharmony_ci MTK_GMAC2_SGMII | MTK_GDM1_ESW | \ 7918c2ecf20Sopenharmony_ci MTK_MUX_GDM1_TO_GMAC1_ESW | \ 7928c2ecf20Sopenharmony_ci MTK_MUX_GMAC1_GMAC2_TO_SGMII_RGMII | MTK_QDMA) 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci#define MT7623_CAPS (MTK_GMAC1_RGMII | MTK_GMAC1_TRGMII | MTK_GMAC2_RGMII | \ 7958c2ecf20Sopenharmony_ci MTK_QDMA) 7968c2ecf20Sopenharmony_ci 7978c2ecf20Sopenharmony_ci#define MT7628_CAPS (MTK_SHARED_INT | MTK_SOC_MT7628) 7988c2ecf20Sopenharmony_ci 7998c2ecf20Sopenharmony_ci#define MT7629_CAPS (MTK_GMAC1_SGMII | MTK_GMAC2_SGMII | MTK_GMAC2_GEPHY | \ 8008c2ecf20Sopenharmony_ci MTK_GDM1_ESW | MTK_MUX_GDM1_TO_GMAC1_ESW | \ 8018c2ecf20Sopenharmony_ci MTK_MUX_GMAC2_GMAC0_TO_GEPHY | \ 8028c2ecf20Sopenharmony_ci MTK_MUX_U3_GMAC2_TO_QPHY | \ 8038c2ecf20Sopenharmony_ci MTK_MUX_GMAC12_TO_GEPHY_SGMII | MTK_QDMA) 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci/* struct mtk_eth_data - This is the structure holding all differences 8068c2ecf20Sopenharmony_ci * among various plaforms 8078c2ecf20Sopenharmony_ci * @ana_rgc3: The offset for register ANA_RGC3 related to 8088c2ecf20Sopenharmony_ci * sgmiisys syscon 8098c2ecf20Sopenharmony_ci * @caps Flags shown the extra capability for the SoC 8108c2ecf20Sopenharmony_ci * @hw_features Flags shown HW features 8118c2ecf20Sopenharmony_ci * @required_clks Flags shown the bitmap for required clocks on 8128c2ecf20Sopenharmony_ci * the target SoC 8138c2ecf20Sopenharmony_ci * @required_pctl A bool value to show whether the SoC requires 8148c2ecf20Sopenharmony_ci * the extra setup for those pins used by GMAC. 8158c2ecf20Sopenharmony_ci */ 8168c2ecf20Sopenharmony_cistruct mtk_soc_data { 8178c2ecf20Sopenharmony_ci u32 ana_rgc3; 8188c2ecf20Sopenharmony_ci u32 caps; 8198c2ecf20Sopenharmony_ci u32 required_clks; 8208c2ecf20Sopenharmony_ci bool required_pctl; 8218c2ecf20Sopenharmony_ci netdev_features_t hw_features; 8228c2ecf20Sopenharmony_ci}; 8238c2ecf20Sopenharmony_ci 8248c2ecf20Sopenharmony_ci/* currently no SoC has more than 2 macs */ 8258c2ecf20Sopenharmony_ci#define MTK_MAX_DEVS 2 8268c2ecf20Sopenharmony_ci 8278c2ecf20Sopenharmony_ci#define MTK_SGMII_PHYSPEED_AN BIT(31) 8288c2ecf20Sopenharmony_ci#define MTK_SGMII_PHYSPEED_MASK GENMASK(2, 0) 8298c2ecf20Sopenharmony_ci#define MTK_SGMII_PHYSPEED_1000 BIT(0) 8308c2ecf20Sopenharmony_ci#define MTK_SGMII_PHYSPEED_2500 BIT(1) 8318c2ecf20Sopenharmony_ci#define MTK_HAS_FLAGS(flags, _x) (((flags) & (_x)) == (_x)) 8328c2ecf20Sopenharmony_ci 8338c2ecf20Sopenharmony_ci/* struct mtk_sgmii - This is the structure holding sgmii regmap and its 8348c2ecf20Sopenharmony_ci * characteristics 8358c2ecf20Sopenharmony_ci * @regmap: The register map pointing at the range used to setup 8368c2ecf20Sopenharmony_ci * SGMII modes 8378c2ecf20Sopenharmony_ci * @flags: The enum refers to which mode the sgmii wants to run on 8388c2ecf20Sopenharmony_ci * @ana_rgc3: The offset refers to register ANA_RGC3 related to regmap 8398c2ecf20Sopenharmony_ci */ 8408c2ecf20Sopenharmony_ci 8418c2ecf20Sopenharmony_cistruct mtk_sgmii { 8428c2ecf20Sopenharmony_ci struct regmap *regmap[MTK_MAX_DEVS]; 8438c2ecf20Sopenharmony_ci u32 flags[MTK_MAX_DEVS]; 8448c2ecf20Sopenharmony_ci u32 ana_rgc3; 8458c2ecf20Sopenharmony_ci}; 8468c2ecf20Sopenharmony_ci 8478c2ecf20Sopenharmony_ci/* struct mtk_eth - This is the main datasructure for holding the state 8488c2ecf20Sopenharmony_ci * of the driver 8498c2ecf20Sopenharmony_ci * @dev: The device pointer 8508c2ecf20Sopenharmony_ci * @base: The mapped register i/o base 8518c2ecf20Sopenharmony_ci * @page_lock: Make sure that register operations are atomic 8528c2ecf20Sopenharmony_ci * @tx_irq__lock: Make sure that IRQ register operations are atomic 8538c2ecf20Sopenharmony_ci * @rx_irq__lock: Make sure that IRQ register operations are atomic 8548c2ecf20Sopenharmony_ci * @dummy_dev: we run 2 netdevs on 1 physical DMA ring and need a 8558c2ecf20Sopenharmony_ci * dummy for NAPI to work 8568c2ecf20Sopenharmony_ci * @netdev: The netdev instances 8578c2ecf20Sopenharmony_ci * @mac: Each netdev is linked to a physical MAC 8588c2ecf20Sopenharmony_ci * @irq: The IRQ that we are using 8598c2ecf20Sopenharmony_ci * @msg_enable: Ethtool msg level 8608c2ecf20Sopenharmony_ci * @ethsys: The register map pointing at the range used to setup 8618c2ecf20Sopenharmony_ci * MII modes 8628c2ecf20Sopenharmony_ci * @infra: The register map pointing at the range used to setup 8638c2ecf20Sopenharmony_ci * SGMII and GePHY path 8648c2ecf20Sopenharmony_ci * @pctl: The register map pointing at the range used to setup 8658c2ecf20Sopenharmony_ci * GMAC port drive/slew values 8668c2ecf20Sopenharmony_ci * @dma_refcnt: track how many netdevs are using the DMA engine 8678c2ecf20Sopenharmony_ci * @tx_ring: Pointer to the memory holding info about the TX ring 8688c2ecf20Sopenharmony_ci * @rx_ring: Pointer to the memory holding info about the RX ring 8698c2ecf20Sopenharmony_ci * @rx_ring_qdma: Pointer to the memory holding info about the QDMA RX ring 8708c2ecf20Sopenharmony_ci * @tx_napi: The TX NAPI struct 8718c2ecf20Sopenharmony_ci * @rx_napi: The RX NAPI struct 8728c2ecf20Sopenharmony_ci * @scratch_ring: Newer SoCs need memory for a second HW managed TX ring 8738c2ecf20Sopenharmony_ci * @phy_scratch_ring: physical address of scratch_ring 8748c2ecf20Sopenharmony_ci * @scratch_head: The scratch memory that scratch_ring points to. 8758c2ecf20Sopenharmony_ci * @clks: clock array for all clocks required 8768c2ecf20Sopenharmony_ci * @mii_bus: If there is a bus we need to create an instance for it 8778c2ecf20Sopenharmony_ci * @pending_work: The workqueue used to reset the dma ring 8788c2ecf20Sopenharmony_ci * @state: Initialization and runtime state of the device 8798c2ecf20Sopenharmony_ci * @soc: Holding specific data among vaious SoCs 8808c2ecf20Sopenharmony_ci */ 8818c2ecf20Sopenharmony_ci 8828c2ecf20Sopenharmony_cistruct mtk_eth { 8838c2ecf20Sopenharmony_ci struct device *dev; 8848c2ecf20Sopenharmony_ci void __iomem *base; 8858c2ecf20Sopenharmony_ci spinlock_t page_lock; 8868c2ecf20Sopenharmony_ci spinlock_t tx_irq_lock; 8878c2ecf20Sopenharmony_ci spinlock_t rx_irq_lock; 8888c2ecf20Sopenharmony_ci struct net_device dummy_dev; 8898c2ecf20Sopenharmony_ci struct net_device *netdev[MTK_MAX_DEVS]; 8908c2ecf20Sopenharmony_ci struct mtk_mac *mac[MTK_MAX_DEVS]; 8918c2ecf20Sopenharmony_ci int irq[3]; 8928c2ecf20Sopenharmony_ci u32 msg_enable; 8938c2ecf20Sopenharmony_ci unsigned long sysclk; 8948c2ecf20Sopenharmony_ci struct regmap *ethsys; 8958c2ecf20Sopenharmony_ci struct regmap *infra; 8968c2ecf20Sopenharmony_ci struct mtk_sgmii *sgmii; 8978c2ecf20Sopenharmony_ci struct regmap *pctl; 8988c2ecf20Sopenharmony_ci bool hwlro; 8998c2ecf20Sopenharmony_ci refcount_t dma_refcnt; 9008c2ecf20Sopenharmony_ci struct mtk_tx_ring tx_ring; 9018c2ecf20Sopenharmony_ci struct mtk_rx_ring rx_ring[MTK_MAX_RX_RING_NUM]; 9028c2ecf20Sopenharmony_ci struct mtk_rx_ring rx_ring_qdma; 9038c2ecf20Sopenharmony_ci struct napi_struct tx_napi; 9048c2ecf20Sopenharmony_ci struct napi_struct rx_napi; 9058c2ecf20Sopenharmony_ci struct mtk_tx_dma *scratch_ring; 9068c2ecf20Sopenharmony_ci dma_addr_t phy_scratch_ring; 9078c2ecf20Sopenharmony_ci void *scratch_head; 9088c2ecf20Sopenharmony_ci struct clk *clks[MTK_CLK_MAX]; 9098c2ecf20Sopenharmony_ci 9108c2ecf20Sopenharmony_ci struct mii_bus *mii_bus; 9118c2ecf20Sopenharmony_ci struct work_struct pending_work; 9128c2ecf20Sopenharmony_ci unsigned long state; 9138c2ecf20Sopenharmony_ci 9148c2ecf20Sopenharmony_ci const struct mtk_soc_data *soc; 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_ci u32 tx_int_mask_reg; 9178c2ecf20Sopenharmony_ci u32 tx_int_status_reg; 9188c2ecf20Sopenharmony_ci u32 rx_dma_l4_valid; 9198c2ecf20Sopenharmony_ci int ip_align; 9208c2ecf20Sopenharmony_ci}; 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_ci/* struct mtk_mac - the structure that holds the info about the MACs of the 9238c2ecf20Sopenharmony_ci * SoC 9248c2ecf20Sopenharmony_ci * @id: The number of the MAC 9258c2ecf20Sopenharmony_ci * @interface: Interface mode kept for detecting change in hw settings 9268c2ecf20Sopenharmony_ci * @of_node: Our devicetree node 9278c2ecf20Sopenharmony_ci * @hw: Backpointer to our main datastruture 9288c2ecf20Sopenharmony_ci * @hw_stats: Packet statistics counter 9298c2ecf20Sopenharmony_ci */ 9308c2ecf20Sopenharmony_cistruct mtk_mac { 9318c2ecf20Sopenharmony_ci int id; 9328c2ecf20Sopenharmony_ci phy_interface_t interface; 9338c2ecf20Sopenharmony_ci unsigned int mode; 9348c2ecf20Sopenharmony_ci int speed; 9358c2ecf20Sopenharmony_ci struct device_node *of_node; 9368c2ecf20Sopenharmony_ci struct phylink *phylink; 9378c2ecf20Sopenharmony_ci struct phylink_config phylink_config; 9388c2ecf20Sopenharmony_ci struct mtk_eth *hw; 9398c2ecf20Sopenharmony_ci struct mtk_hw_stats *hw_stats; 9408c2ecf20Sopenharmony_ci __be32 hwlro_ip[MTK_MAX_LRO_IP_CNT]; 9418c2ecf20Sopenharmony_ci int hwlro_ip_cnt; 9428c2ecf20Sopenharmony_ci}; 9438c2ecf20Sopenharmony_ci 9448c2ecf20Sopenharmony_ci/* the struct describing the SoC. these are declared in the soc_xyz.c files */ 9458c2ecf20Sopenharmony_ciextern const struct of_device_id of_mtk_match[]; 9468c2ecf20Sopenharmony_ci 9478c2ecf20Sopenharmony_ci/* read the hardware status register */ 9488c2ecf20Sopenharmony_civoid mtk_stats_update_mac(struct mtk_mac *mac); 9498c2ecf20Sopenharmony_ci 9508c2ecf20Sopenharmony_civoid mtk_w32(struct mtk_eth *eth, u32 val, unsigned reg); 9518c2ecf20Sopenharmony_ciu32 mtk_r32(struct mtk_eth *eth, unsigned reg); 9528c2ecf20Sopenharmony_ci 9538c2ecf20Sopenharmony_ciint mtk_sgmii_init(struct mtk_sgmii *ss, struct device_node *np, 9548c2ecf20Sopenharmony_ci u32 ana_rgc3); 9558c2ecf20Sopenharmony_ciint mtk_sgmii_setup_mode_an(struct mtk_sgmii *ss, int id); 9568c2ecf20Sopenharmony_ciint mtk_sgmii_setup_mode_force(struct mtk_sgmii *ss, int id, 9578c2ecf20Sopenharmony_ci const struct phylink_link_state *state); 9588c2ecf20Sopenharmony_civoid mtk_sgmii_restart_an(struct mtk_eth *eth, int mac_id); 9598c2ecf20Sopenharmony_ci 9608c2ecf20Sopenharmony_ciint mtk_gmac_sgmii_path_setup(struct mtk_eth *eth, int mac_id); 9618c2ecf20Sopenharmony_ciint mtk_gmac_gephy_path_setup(struct mtk_eth *eth, int mac_id); 9628c2ecf20Sopenharmony_ciint mtk_gmac_rgmii_path_setup(struct mtk_eth *eth, int mac_id); 9638c2ecf20Sopenharmony_ci 9648c2ecf20Sopenharmony_ci#endif /* MTK_ETH_H */ 965