soc_rt3050.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 <asm/mach-ralink/ralink_regs.h>
  16. #include "mtk_eth_soc.h"
  17. #include "esw_rt3050.h"
  18. #include "mdio_rt2880.h"
  19. static const u16 rt5350_reg_table[FE_REG_COUNT] = {
  20. [FE_REG_PDMA_GLO_CFG] = RT5350_PDMA_GLO_CFG,
  21. [FE_REG_PDMA_RST_CFG] = RT5350_PDMA_RST_CFG,
  22. [FE_REG_DLY_INT_CFG] = RT5350_DLY_INT_CFG,
  23. [FE_REG_TX_BASE_PTR0] = RT5350_TX_BASE_PTR0,
  24. [FE_REG_TX_MAX_CNT0] = RT5350_TX_MAX_CNT0,
  25. [FE_REG_TX_CTX_IDX0] = RT5350_TX_CTX_IDX0,
  26. [FE_REG_TX_DTX_IDX0] = RT5350_TX_DTX_IDX0,
  27. [FE_REG_RX_BASE_PTR0] = RT5350_RX_BASE_PTR0,
  28. [FE_REG_RX_MAX_CNT0] = RT5350_RX_MAX_CNT0,
  29. [FE_REG_RX_CALC_IDX0] = RT5350_RX_CALC_IDX0,
  30. [FE_REG_RX_DRX_IDX0] = RT5350_RX_DRX_IDX0,
  31. [FE_REG_FE_INT_ENABLE] = RT5350_FE_INT_ENABLE,
  32. [FE_REG_FE_INT_STATUS] = RT5350_FE_INT_STATUS,
  33. [FE_REG_FE_RST_GL] = 0,
  34. [FE_REG_FE_DMA_VID_BASE] = 0,
  35. };
  36. static void rt305x_init_data(struct fe_soc_data *data,
  37. struct net_device *netdev)
  38. {
  39. struct fe_priv *priv = netdev_priv(netdev);
  40. priv->flags = FE_FLAG_PADDING_64B | FE_FLAG_PADDING_BUG |
  41. FE_FLAG_CALIBRATE_CLK | FE_FLAG_HAS_SWITCH;
  42. netdev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM |
  43. NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX;
  44. }
  45. static int rt3050_fwd_config(struct fe_priv *priv)
  46. {
  47. int ret;
  48. if (ralink_soc != RT305X_SOC_RT3052) {
  49. ret = fe_set_clock_cycle(priv);
  50. if (ret)
  51. return ret;
  52. }
  53. fe_fwd_config(priv);
  54. if (ralink_soc != RT305X_SOC_RT3352)
  55. fe_w32(FE_PSE_FQFC_CFG_INIT, FE_PSE_FQ_CFG);
  56. fe_csum_config(priv);
  57. return 0;
  58. }
  59. static void rt5350_init_data(struct fe_soc_data *data,
  60. struct net_device *netdev)
  61. {
  62. struct fe_priv *priv = netdev_priv(netdev);
  63. priv->flags = FE_FLAG_HAS_SWITCH;
  64. netdev->hw_features = NETIF_F_SG | NETIF_F_RXCSUM;
  65. }
  66. static void rt5350_set_mac(struct fe_priv *priv, const unsigned char *mac)
  67. {
  68. unsigned long flags;
  69. spin_lock_irqsave(&priv->page_lock, flags);
  70. fe_w32((mac[0] << 8) | mac[1], RT5350_SDM_MAC_ADRH);
  71. fe_w32((mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5],
  72. RT5350_SDM_MAC_ADRL);
  73. spin_unlock_irqrestore(&priv->page_lock, flags);
  74. }
  75. static void rt5350_rxcsum_config(bool enable)
  76. {
  77. if (enable)
  78. fe_w32(fe_r32(RT5350_SDM_CFG) | (RT5350_SDM_ICS_EN |
  79. RT5350_SDM_TCS_EN | RT5350_SDM_UCS_EN),
  80. RT5350_SDM_CFG);
  81. else
  82. fe_w32(fe_r32(RT5350_SDM_CFG) & ~(RT5350_SDM_ICS_EN |
  83. RT5350_SDM_TCS_EN | RT5350_SDM_UCS_EN),
  84. RT5350_SDM_CFG);
  85. }
  86. static int rt5350_fwd_config(struct fe_priv *priv)
  87. {
  88. struct net_device *dev = priv_netdev(priv);
  89. rt5350_rxcsum_config((dev->features & NETIF_F_RXCSUM));
  90. return 0;
  91. }
  92. static void rt5350_tx_dma(struct fe_tx_dma *txd)
  93. {
  94. txd->txd4 = 0;
  95. }
  96. static struct fe_soc_data rt3050_data = {
  97. .init_data = rt305x_init_data,
  98. .fwd_config = rt3050_fwd_config,
  99. .switch_init = rt3050_esw_init,
  100. .pdma_glo_cfg = FE_PDMA_SIZE_8DWORDS,
  101. .checksum_bit = RX_DMA_L4VALID,
  102. .rx_int = FE_RX_DONE_INT,
  103. .tx_int = FE_TX_DONE_INT,
  104. .status_int = FE_CNT_GDM_AF,
  105. };
  106. static struct fe_soc_data rt5350_data = {
  107. .init_data = rt5350_init_data,
  108. .reg_table = rt5350_reg_table,
  109. .set_mac = rt5350_set_mac,
  110. .fwd_config = rt5350_fwd_config,
  111. .switch_init = rt3050_esw_init,
  112. .tx_dma = rt5350_tx_dma,
  113. .pdma_glo_cfg = FE_PDMA_SIZE_8DWORDS,
  114. .checksum_bit = RX_DMA_L4VALID,
  115. .rx_int = RT5350_RX_DONE_INT,
  116. .tx_int = RT5350_TX_DONE_INT,
  117. };
  118. const struct of_device_id of_fe_match[] = {
  119. { .compatible = "ralink,rt3050-eth", .data = &rt3050_data },
  120. { .compatible = "ralink,rt5350-eth", .data = &rt5350_data },
  121. {},
  122. };
  123. MODULE_DEVICE_TABLE(of, of_fe_match);