[ramips] fixes dma hangups in eth
[openwrt.git] / target / linux / ramips / files / arch / mips / include / asm / mach-ralink / eth.h
1 /*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
15 *
16 * based on Ralink SDK3.3
17 * Copyright (C) 2009 John Crispin <blogic@openwrt.org>
18 */
19
20 #ifndef RAMIPS_ETH_H
21 #define RAMIPS_ETH_H
22
23 #include <linux/mii.h>
24 #include <linux/interrupt.h>
25 #include <linux/netdevice.h>
26
27 #define NUM_RX_DESC 256
28 #define NUM_TX_DESC 256
29
30 #define RAMIPS_DELAY_EN_INT 0x80
31 #define RAMIPS_DELAY_MAX_INT 0x04
32 #define RAMIPS_DELAY_MAX_TOUT 0x04
33 #define RAMIPS_DELAY_CHAN (((RAMIPS_DELAY_EN_INT | RAMIPS_DELAY_MAX_INT) << 8) | RAMIPS_DELAY_MAX_TOUT)
34 #define RAMIPS_DELAY_INIT ((RAMIPS_DELAY_CHAN << 16) | RAMIPS_DELAY_CHAN)
35 #define RAMIPS_PSE_FQFC_CFG_INIT 0x80504000
36
37 #define RAMIPS_FE_RESET 0x34
38 #define RAMIPS_FE_RESET_BIT BIT(21)
39
40 /* interrupt bitd */
41 #define RAMIPS_CNT_PPE_AF BIT(31)
42 #define RAMIPS_CNT_GDM_AF BIT(29)
43 #define RAMIPS_PSE_P2_FC BIT(26)
44 #define RAMIPS_PSE_BUF_DROP BIT(24)
45 #define RAMIPS_GDM_OTHER_DROP BIT(23)
46 #define RAMIPS_PSE_P1_FC BIT(22)
47 #define RAMIPS_PSE_P0_FC BIT(21)
48 #define RAMIPS_PSE_FQ_EMPTY BIT(20)
49 #define RAMIPS_GE1_STA_CHG BIT(18)
50 #define RAMIPS_TX_COHERENT BIT(17)
51 #define RAMIPS_RX_COHERENT BIT(16)
52 #define RAMIPS_TX_DONE_INT3 BIT(11)
53 #define RAMIPS_TX_DONE_INT2 BIT(10)
54 #define RAMIPS_TX_DONE_INT1 BIT(9)
55 #define RAMIPS_TX_DONE_INT0 BIT(8)
56 #define RAMIPS_RX_DONE_INT0 BIT(2)
57 #define RAMIPS_TX_DLY_INT BIT(1)
58 #define RAMIPS_RX_DLY_INT BIT(0)
59
60 /* registers */
61 #define RAMIPS_FE_OFFSET 0x0000
62 #define RAMIPS_GDMA_OFFSET 0x0020
63 #define RAMIPS_PSE_OFFSET 0x0040
64 #define RAMIPS_GDMA2_OFFSET 0x0060
65 #define RAMIPS_CDMA_OFFSET 0x0080
66 #define RAMIPS_PDMA_OFFSET 0x0100
67 #define RAMIPS_PPE_OFFSET 0x0200
68 #define RAMIPS_CMTABLE_OFFSET 0x0400
69 #define RAMIPS_POLICYTABLE_OFFSET 0x1000
70
71 #define RAMIPS_MDIO_ACCESS (RAMIPS_FE_OFFSET + 0x00)
72 #define RAMIPS_MDIO_CFG (RAMIPS_FE_OFFSET + 0x04)
73 #define RAMIPS_FE_GLO_CFG (RAMIPS_FE_OFFSET + 0x08)
74 #define RAMIPS_FE_RST_GL (RAMIPS_FE_OFFSET + 0x0C)
75 #define RAMIPS_FE_INT_STATUS (RAMIPS_FE_OFFSET + 0x10)
76 #define RAMIPS_FE_INT_ENABLE (RAMIPS_FE_OFFSET + 0x14)
77 #define RAMIPS_MDIO_CFG2 (RAMIPS_FE_OFFSET + 0x18)
78 #define RAMIPS_FOC_TS_T (RAMIPS_FE_OFFSET + 0x1C)
79
80 #define RAMIPS_GDMA1_FWD_CFG (RAMIPS_GDMA_OFFSET + 0x00)
81 #define RAMIPS_GDMA1_SCH_CFG (RAMIPS_GDMA_OFFSET + 0x04)
82 #define RAMIPS_GDMA1_SHPR_CFG (RAMIPS_GDMA_OFFSET + 0x08)
83 #define RAMIPS_GDMA1_MAC_ADRL (RAMIPS_GDMA_OFFSET + 0x0C)
84 #define RAMIPS_GDMA1_MAC_ADRH (RAMIPS_GDMA_OFFSET + 0x10)
85
86 #define RAMIPS_GDMA2_FWD_CFG (RAMIPS_GDMA2_OFFSET + 0x00)
87 #define RAMIPS_GDMA2_SCH_CFG (RAMIPS_GDMA2_OFFSET + 0x04)
88 #define RAMIPS_GDMA2_SHPR_CFG (RAMIPS_GDMA2_OFFSET + 0x08)
89 #define RAMIPS_GDMA2_MAC_ADRL (RAMIPS_GDMA2_OFFSET + 0x0C)
90 #define RAMIPS_GDMA2_MAC_ADRH (RAMIPS_GDMA2_OFFSET + 0x10)
91
92 #define RAMIPS_PSE_FQ_CFG (RAMIPS_PSE_OFFSET + 0x00)
93 #define RAMIPS_CDMA_FC_CFG (RAMIPS_PSE_OFFSET + 0x04)
94 #define RAMIPS_GDMA1_FC_CFG (RAMIPS_PSE_OFFSET + 0x08)
95 #define RAMIPS_GDMA2_FC_CFG (RAMIPS_PSE_OFFSET + 0x0C)
96
97 #define RAMIPS_CDMA_CSG_CFG (RAMIPS_CDMA_OFFSET + 0x00)
98 #define RAMIPS_CDMA_SCH_CFG (RAMIPS_CDMA_OFFSET + 0x04)
99
100 #define RAMIPS_PDMA_GLO_CFG (RAMIPS_PDMA_OFFSET + 0x00)
101 #define RAMIPS_PDMA_RST_CFG (RAMIPS_PDMA_OFFSET + 0x04)
102 #define RAMIPS_PDMA_SCH_CFG (RAMIPS_PDMA_OFFSET + 0x08)
103 #define RAMIPS_DLY_INT_CFG (RAMIPS_PDMA_OFFSET + 0x0C)
104 #define RAMIPS_TX_BASE_PTR0 (RAMIPS_PDMA_OFFSET + 0x10)
105 #define RAMIPS_TX_MAX_CNT0 (RAMIPS_PDMA_OFFSET + 0x14)
106 #define RAMIPS_TX_CTX_IDX0 (RAMIPS_PDMA_OFFSET + 0x18)
107 #define RAMIPS_TX_DTX_IDX0 (RAMIPS_PDMA_OFFSET + 0x1C)
108 #define RAMIPS_TX_BASE_PTR1 (RAMIPS_PDMA_OFFSET + 0x20)
109 #define RAMIPS_TX_MAX_CNT1 (RAMIPS_PDMA_OFFSET + 0x24)
110 #define RAMIPS_TX_CTX_IDX1 (RAMIPS_PDMA_OFFSET + 0x28)
111 #define RAMIPS_TX_DTX_IDX1 (RAMIPS_PDMA_OFFSET + 0x2C)
112 #define RAMIPS_TX_BASE_PTR2 (RAMIPS_PDMA_OFFSET + 0x40)
113 #define RAMIPS_TX_MAX_CNT2 (RAMIPS_PDMA_OFFSET + 0x44)
114 #define RAMIPS_TX_CTX_IDX2 (RAMIPS_PDMA_OFFSET + 0x48)
115 #define RAMIPS_TX_DTX_IDX2 (RAMIPS_PDMA_OFFSET + 0x4C)
116 #define RAMIPS_TX_BASE_PTR3 (RAMIPS_PDMA_OFFSET + 0x50)
117 #define RAMIPS_TX_MAX_CNT3 (RAMIPS_PDMA_OFFSET + 0x54)
118 #define RAMIPS_TX_CTX_IDX3 (RAMIPS_PDMA_OFFSET + 0x58)
119 #define RAMIPS_TX_DTX_IDX3 (RAMIPS_PDMA_OFFSET + 0x5C)
120 #define RAMIPS_RX_BASE_PTR0 (RAMIPS_PDMA_OFFSET + 0x30)
121 #define RAMIPS_RX_MAX_CNT0 (RAMIPS_PDMA_OFFSET + 0x34)
122 #define RAMIPS_RX_CALC_IDX0 (RAMIPS_PDMA_OFFSET + 0x38)
123 #define RAMIPS_RX_DRX_IDX0 (RAMIPS_PDMA_OFFSET + 0x3C)
124 #define RAMIPS_RX_BASE_PTR1 (RAMIPS_PDMA_OFFSET + 0x40)
125 #define RAMIPS_RX_MAX_CNT1 (RAMIPS_PDMA_OFFSET + 0x44)
126 #define RAMIPS_RX_CALC_IDX1 (RAMIPS_PDMA_OFFSET + 0x48)
127 #define RAMIPS_RX_DRX_IDX1 (RAMIPS_PDMA_OFFSET + 0x4C)
128
129 /* uni-cast port */
130 #define RAMIPS_GDM1_ICS_EN (0x1 << 22)
131 #define RAMIPS_GDM1_TCS_EN (0x1 << 21)
132 #define RAMIPS_GDM1_UCS_EN (0x1 << 20)
133 #define RAMIPS_GDM1_JMB_EN (0x1 << 19)
134 #define RAMIPS_GDM1_STRPCRC (0x1 << 16)
135 #define RAMIPS_GDM1_UFRC_P_CPU (0 << 12)
136 #define RAMIPS_GDM1_UFRC_P_GDMA1 (1 << 12)
137 #define RAMIPS_GDM1_UFRC_P_PPE (6 << 12)
138
139 /* checksums */
140 #define RAMIPS_ICS_GEN_EN BIT(2)
141 #define RAMIPS_UCS_GEN_EN BIT(1)
142 #define RAMIPS_TCS_GEN_EN BIT(0)
143
144 /* dma rimg */
145 #define RAMIPS_PST_DRX_IDX0 BIT(16)
146 #define RAMIPS_PST_DTX_IDX3 BIT(3)
147 #define RAMIPS_PST_DTX_IDX2 BIT(2)
148 #define RAMIPS_PST_DTX_IDX1 BIT(1)
149 #define RAMIPS_PST_DTX_IDX0 BIT(0)
150
151 #define RAMIPS_TX_WB_DDONE BIT(6)
152 #define RAMIPS_RX_DMA_BUSY BIT(3)
153 #define RAMIPS_TX_DMA_BUSY BIT(1)
154 #define RAMIPS_RX_DMA_EN BIT(2)
155 #define RAMIPS_TX_DMA_EN BIT(0)
156
157 #define RAMIPS_PDMA_SIZE_4DWORDS (0<<4)
158 #define RAMIPS_PDMA_SIZE_8DWORDS (1<<4)
159 #define RAMIPS_PDMA_SIZE_16DWORDS (2<<4)
160
161 #define RAMIPS_US_CYC_CNT_MASK 0xff
162 #define RAMIPS_US_CYC_CNT_SHIFT 0x8
163 #define RAMIPS_US_CYC_CNT_DIVISOR 1000000
164
165 #define RX_DMA_PLEN0(x) ((x >> 16) & 0x3fff)
166 #define RX_DMA_LSO BIT(30)
167 #define RX_DMA_DONE BIT(31)
168 struct ramips_rx_dma {
169 unsigned int rxd1;
170 unsigned int rxd2;
171 unsigned int rxd3;
172 unsigned int rxd4;
173 };
174
175 #define TX_DMA_PLEN0_MASK ((0x3fff) << 16)
176 #define TX_DMA_PLEN0(x) ((x & 0x3fff) << 16)
177 #define TX_DMA_LSO BIT(30)
178 #define TX_DMA_DONE BIT(31)
179 #define TX_DMA_QN(x) (x << 16)
180 #define TX_DMA_PN(x) (x << 24)
181 #define TX_DMA_QN_MASK TX_DMA_QN(0x7)
182 #define TX_DMA_PN_MASK TX_DMA_PN(0x7)
183 struct ramips_tx_dma {
184 unsigned int txd1;
185 unsigned int txd2;
186 unsigned int txd3;
187 unsigned int txd4;
188 };
189
190 struct ramips_eth_platform_data
191 {
192 unsigned char mac[6];
193 unsigned int base_addr;
194 void (*reset_fe)(void);
195 int min_pkt_len;
196 int irq;
197 };
198
199 struct raeth_priv
200 {
201 unsigned int phy_rx;
202 struct tasklet_struct rx_tasklet;
203 struct ramips_rx_dma *rx;
204 struct sk_buff *rx_skb[NUM_RX_DESC];
205
206 unsigned int phy_tx;
207 struct tasklet_struct tx_housekeeping_tasklet;
208 struct ramips_tx_dma *tx;
209 struct sk_buff *tx_skb[NUM_RX_DESC];
210
211 unsigned int skb_free_idx;
212 struct net_device_stats stat;
213
214 struct ramips_eth_platform_data *plat;
215 };
216
217 #endif
This page took 0.051784 seconds and 5 git commands to generate.