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