soc_mt7621.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* This program is free software; you can redistribute it and/or modify
  2. * it under the terms of the GNU General Public License as published by
  3. * the Free Software Foundation; version 2 of the License
  4. *
  5. * This program is distributed in the hope that it will be useful,
  6. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. * GNU General Public License for more details.
  9. *
  10. * Copyright (C) 2009-2015 John Crispin <[email protected]>
  11. * Copyright (C) 2009-2015 Felix Fietkau <[email protected]>
  12. * Copyright (C) 2013-2015 Michael Lee <[email protected]>
  13. */
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/if_vlan.h>
  17. #include <linux/of_net.h>
  18. #include <asm/mach-ralink/ralink_regs.h>
  19. #include "mtk_eth_soc.h"
  20. #include "gsw_mt7620.h"
  21. #include "mt7530.h"
  22. #include "mdio.h"
  23. #define MT7620A_CDMA_CSG_CFG 0x400
  24. #define MT7621_CDMP_IG_CTRL (MT7620A_CDMA_CSG_CFG + 0x00)
  25. #define MT7621_CDMP_EG_CTRL (MT7620A_CDMA_CSG_CFG + 0x04)
  26. #define MT7621_RESET_FE BIT(6)
  27. #define MT7621_L4_VALID BIT(24)
  28. #define MT7621_TX_DMA_UDF BIT(19)
  29. #define MT7621_TX_DMA_FPORT BIT(25)
  30. #define CDMA_ICS_EN BIT(2)
  31. #define CDMA_UCS_EN BIT(1)
  32. #define CDMA_TCS_EN BIT(0)
  33. #define GDMA_ICS_EN BIT(22)
  34. #define GDMA_TCS_EN BIT(21)
  35. #define GDMA_UCS_EN BIT(20)
  36. /* frame engine counters */
  37. #define MT7621_REG_MIB_OFFSET 0x2000
  38. #define MT7621_PPE_AC_BCNT0 (MT7621_REG_MIB_OFFSET + 0x00)
  39. #define MT7621_GDM1_TX_GBCNT (MT7621_REG_MIB_OFFSET + 0x400)
  40. #define MT7621_GDM2_TX_GBCNT (MT7621_GDM1_TX_GBCNT + 0x40)
  41. #define GSW_REG_GDMA1_MAC_ADRL 0x508
  42. #define GSW_REG_GDMA1_MAC_ADRH 0x50C
  43. #define MT7621_FE_RST_GL (FE_FE_OFFSET + 0x04)
  44. #define MT7620_FE_INT_STATUS2 (FE_FE_OFFSET + 0x08)
  45. /* FE_INT_STATUS reg on mt7620 define CNT_GDM1_AF at BIT(29)
  46. * but after test it should be BIT(13).
  47. */
  48. #define MT7620_FE_GDM1_AF BIT(13)
  49. #define MT7621_FE_GDM1_AF BIT(28)
  50. #define MT7621_FE_GDM2_AF BIT(29)
  51. static const u16 mt7621_reg_table[FE_REG_COUNT] = {
  52. [FE_REG_PDMA_GLO_CFG] = RT5350_PDMA_GLO_CFG,
  53. [FE_REG_PDMA_RST_CFG] = RT5350_PDMA_RST_CFG,
  54. [FE_REG_DLY_INT_CFG] = RT5350_DLY_INT_CFG,
  55. [FE_REG_TX_BASE_PTR0] = RT5350_TX_BASE_PTR0,
  56. [FE_REG_TX_MAX_CNT0] = RT5350_TX_MAX_CNT0,
  57. [FE_REG_TX_CTX_IDX0] = RT5350_TX_CTX_IDX0,
  58. [FE_REG_TX_DTX_IDX0] = RT5350_TX_DTX_IDX0,
  59. [FE_REG_RX_BASE_PTR0] = RT5350_RX_BASE_PTR0,
  60. [FE_REG_RX_MAX_CNT0] = RT5350_RX_MAX_CNT0,
  61. [FE_REG_RX_CALC_IDX0] = RT5350_RX_CALC_IDX0,
  62. [FE_REG_RX_DRX_IDX0] = RT5350_RX_DRX_IDX0,
  63. [FE_REG_FE_INT_ENABLE] = RT5350_FE_INT_ENABLE,
  64. [FE_REG_FE_INT_STATUS] = RT5350_FE_INT_STATUS,
  65. [FE_REG_FE_DMA_VID_BASE] = 0,
  66. [FE_REG_FE_COUNTER_BASE] = MT7621_GDM1_TX_GBCNT,
  67. [FE_REG_FE_RST_GL] = MT7621_FE_RST_GL,
  68. [FE_REG_FE_INT_STATUS2] = MT7620_FE_INT_STATUS2,
  69. };
  70. static int mt7621_gsw_config(struct fe_priv *priv)
  71. {
  72. if (priv->mii_bus && mdiobus_get_phy(priv->mii_bus, 0x1f))
  73. mt7530_probe(priv->device, NULL, priv->mii_bus, 1);
  74. return 0;
  75. }
  76. static void mt7621_fe_reset(void)
  77. {
  78. fe_reset(MT7621_RESET_FE);
  79. }
  80. static void mt7621_rxcsum_config(bool enable)
  81. {
  82. if (enable)
  83. fe_w32(fe_r32(MT7620A_GDMA1_FWD_CFG) | (GDMA_ICS_EN |
  84. GDMA_TCS_EN | GDMA_UCS_EN),
  85. MT7620A_GDMA1_FWD_CFG);
  86. else
  87. fe_w32(fe_r32(MT7620A_GDMA1_FWD_CFG) & ~(GDMA_ICS_EN |
  88. GDMA_TCS_EN | GDMA_UCS_EN),
  89. MT7620A_GDMA1_FWD_CFG);
  90. }
  91. static void mt7621_rxvlan_config(bool enable)
  92. {
  93. if (enable)
  94. fe_w32(1, MT7621_CDMP_EG_CTRL);
  95. else
  96. fe_w32(0, MT7621_CDMP_EG_CTRL);
  97. }
  98. static int mt7621_fwd_config(struct fe_priv *priv)
  99. {
  100. struct net_device *dev = priv_netdev(priv);
  101. fe_w32(fe_r32(MT7620A_GDMA1_FWD_CFG) & ~0xffff,
  102. MT7620A_GDMA1_FWD_CFG);
  103. /* mt7621 doesn't have txcsum config */
  104. mt7621_rxcsum_config((dev->features & NETIF_F_RXCSUM));
  105. mt7621_rxvlan_config(priv->flags & FE_FLAG_RX_VLAN_CTAG);
  106. return 0;
  107. }
  108. static void mt7621_tx_dma(struct fe_tx_dma *txd)
  109. {
  110. txd->txd4 = MT7621_TX_DMA_FPORT;
  111. }
  112. static void mt7621_init_data(struct fe_soc_data *data,
  113. struct net_device *netdev)
  114. {
  115. struct fe_priv *priv = netdev_priv(netdev);
  116. priv->flags = FE_FLAG_PADDING_64B | FE_FLAG_RX_2B_OFFSET |
  117. FE_FLAG_RX_SG_DMA | FE_FLAG_NAPI_WEIGHT |
  118. FE_FLAG_HAS_SWITCH;
  119. netdev->hw_features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
  120. NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_SG | NETIF_F_TSO |
  121. NETIF_F_TSO6 | NETIF_F_IPV6_CSUM;
  122. }
  123. static void mt7621_set_mac(struct fe_priv *priv, unsigned char *mac)
  124. {
  125. unsigned long flags;
  126. spin_lock_irqsave(&priv->page_lock, flags);
  127. fe_w32((mac[0] << 8) | mac[1], GSW_REG_GDMA1_MAC_ADRH);
  128. fe_w32((mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5],
  129. GSW_REG_GDMA1_MAC_ADRL);
  130. spin_unlock_irqrestore(&priv->page_lock, flags);
  131. }
  132. static struct fe_soc_data mt7621_data = {
  133. .init_data = mt7621_init_data,
  134. .reset_fe = mt7621_fe_reset,
  135. .set_mac = mt7621_set_mac,
  136. .fwd_config = mt7621_fwd_config,
  137. .tx_dma = mt7621_tx_dma,
  138. .switch_init = mtk_gsw_init,
  139. .switch_config = mt7621_gsw_config,
  140. .reg_table = mt7621_reg_table,
  141. .pdma_glo_cfg = FE_PDMA_SIZE_16DWORDS,
  142. .rx_int = RT5350_RX_DONE_INT,
  143. .tx_int = RT5350_TX_DONE_INT,
  144. .status_int = (MT7621_FE_GDM1_AF | MT7621_FE_GDM2_AF),
  145. .checksum_bit = MT7621_L4_VALID,
  146. .has_carrier = mt7620_has_carrier,
  147. .mdio_read = mt7620_mdio_read,
  148. .mdio_write = mt7620_mdio_write,
  149. .mdio_adjust_link = mt7620_mdio_link_adjust,
  150. };
  151. const struct of_device_id of_fe_match[] = {
  152. { .compatible = "mediatek,mt7621-eth", .data = &mt7621_data },
  153. {},
  154. };
  155. MODULE_DEVICE_TABLE(of, of_fe_match);