generic: ar8216: rename AR8216_*_STATS_* defines
[openwrt/openwrt.git] / target / linux / generic / files / drivers / net / phy / ar8216.h
1 /*
2 * ar8216.h: AR8216 switch driver
3 *
4 * Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17 #ifndef __AR8216_H
18 #define __AR8216_H
19
20 #define BITS(_s, _n) (((1UL << (_n)) - 1) << _s)
21
22 #define AR8216_PORT_CPU 0
23 #define AR8216_NUM_PORTS 6
24 #define AR8216_NUM_VLANS 16
25 #define AR8316_NUM_VLANS 4096
26
27 /* Atheros specific MII registers */
28 #define MII_ATH_MMD_ADDR 0x0d
29 #define MII_ATH_MMD_DATA 0x0e
30 #define MII_ATH_DBG_ADDR 0x1d
31 #define MII_ATH_DBG_DATA 0x1e
32
33 #define AR8216_REG_CTRL 0x0000
34 #define AR8216_CTRL_REVISION BITS(0, 8)
35 #define AR8216_CTRL_REVISION_S 0
36 #define AR8216_CTRL_VERSION BITS(8, 8)
37 #define AR8216_CTRL_VERSION_S 8
38 #define AR8216_CTRL_RESET BIT(31)
39
40 #define AR8216_REG_FLOOD_MASK 0x002C
41 #define AR8216_FM_UNI_DEST_PORTS BITS(0, 6)
42 #define AR8216_FM_MULTI_DEST_PORTS BITS(16, 6)
43
44 #define AR8216_REG_GLOBAL_CTRL 0x0030
45 #define AR8216_GCTRL_MTU BITS(0, 11)
46 #define AR8236_GCTRL_MTU BITS(0, 14)
47 #define AR8316_GCTRL_MTU BITS(0, 14)
48
49 #define AR8216_REG_VTU 0x0040
50 #define AR8216_VTU_OP BITS(0, 3)
51 #define AR8216_VTU_OP_NOOP 0x0
52 #define AR8216_VTU_OP_FLUSH 0x1
53 #define AR8216_VTU_OP_LOAD 0x2
54 #define AR8216_VTU_OP_PURGE 0x3
55 #define AR8216_VTU_OP_REMOVE_PORT 0x4
56 #define AR8216_VTU_ACTIVE BIT(3)
57 #define AR8216_VTU_FULL BIT(4)
58 #define AR8216_VTU_PORT BITS(8, 4)
59 #define AR8216_VTU_PORT_S 8
60 #define AR8216_VTU_VID BITS(16, 12)
61 #define AR8216_VTU_VID_S 16
62 #define AR8216_VTU_PRIO BITS(28, 3)
63 #define AR8216_VTU_PRIO_S 28
64 #define AR8216_VTU_PRIO_EN BIT(31)
65
66 #define AR8216_REG_VTU_DATA 0x0044
67 #define AR8216_VTUDATA_MEMBER BITS(0, 10)
68 #define AR8236_VTUDATA_MEMBER BITS(0, 7)
69 #define AR8216_VTUDATA_VALID BIT(11)
70
71 #define AR8216_REG_ATU 0x0050
72 #define AR8216_ATU_OP BITS(0, 3)
73 #define AR8216_ATU_OP_NOOP 0x0
74 #define AR8216_ATU_OP_FLUSH 0x1
75 #define AR8216_ATU_OP_LOAD 0x2
76 #define AR8216_ATU_OP_PURGE 0x3
77 #define AR8216_ATU_OP_FLUSH_LOCKED 0x4
78 #define AR8216_ATU_OP_FLUSH_UNICAST 0x5
79 #define AR8216_ATU_OP_GET_NEXT 0x6
80 #define AR8216_ATU_ACTIVE BIT(3)
81 #define AR8216_ATU_PORT_NUM BITS(8, 4)
82 #define AR8216_ATU_FULL_VIO BIT(12)
83 #define AR8216_ATU_ADDR4 BITS(16, 8)
84 #define AR8216_ATU_ADDR5 BITS(24, 8)
85
86 #define AR8216_REG_ATU_DATA 0x0054
87 #define AR8216_ATU_ADDR3 BITS(0, 8)
88 #define AR8216_ATU_ADDR2 BITS(8, 8)
89 #define AR8216_ATU_ADDR1 BITS(16, 8)
90 #define AR8216_ATU_ADDR0 BITS(24, 8)
91
92 #define AR8216_REG_ATU_CTRL 0x005C
93 #define AR8216_ATU_CTRL_AGE_EN BIT(17)
94 #define AR8216_ATU_CTRL_AGE_TIME BITS(0, 16)
95 #define AR8216_ATU_CTRL_AGE_TIME_S 0
96
97 #define AR8216_REG_MIB_FUNC 0x0080
98 #define AR8216_MIB_TIMER BITS(0, 16)
99 #define AR8216_MIB_AT_HALF_EN BIT(16)
100 #define AR8216_MIB_BUSY BIT(17)
101 #define AR8216_MIB_FUNC BITS(24, 3)
102 #define AR8216_MIB_FUNC_S 24
103 #define AR8216_MIB_FUNC_NO_OP 0x0
104 #define AR8216_MIB_FUNC_FLUSH 0x1
105 #define AR8216_MIB_FUNC_CAPTURE 0x3
106 #define AR8236_MIB_EN BIT(30)
107
108 #define AR8216_PORT_OFFSET(_i) (0x0100 * (_i + 1))
109 #define AR8216_REG_PORT_STATUS(_i) (AR8216_PORT_OFFSET(_i) + 0x0000)
110 #define AR8216_PORT_STATUS_SPEED BITS(0,2)
111 #define AR8216_PORT_STATUS_SPEED_S 0
112 #define AR8216_PORT_STATUS_TXMAC BIT(2)
113 #define AR8216_PORT_STATUS_RXMAC BIT(3)
114 #define AR8216_PORT_STATUS_TXFLOW BIT(4)
115 #define AR8216_PORT_STATUS_RXFLOW BIT(5)
116 #define AR8216_PORT_STATUS_DUPLEX BIT(6)
117 #define AR8216_PORT_STATUS_LINK_UP BIT(8)
118 #define AR8216_PORT_STATUS_LINK_AUTO BIT(9)
119 #define AR8216_PORT_STATUS_LINK_PAUSE BIT(10)
120
121 #define AR8216_REG_PORT_CTRL(_i) (AR8216_PORT_OFFSET(_i) + 0x0004)
122
123 /* port forwarding state */
124 #define AR8216_PORT_CTRL_STATE BITS(0, 3)
125 #define AR8216_PORT_CTRL_STATE_S 0
126
127 #define AR8216_PORT_CTRL_LEARN_LOCK BIT(7)
128
129 /* egress 802.1q mode */
130 #define AR8216_PORT_CTRL_VLAN_MODE BITS(8, 2)
131 #define AR8216_PORT_CTRL_VLAN_MODE_S 8
132
133 #define AR8216_PORT_CTRL_IGMP_SNOOP BIT(10)
134 #define AR8216_PORT_CTRL_HEADER BIT(11)
135 #define AR8216_PORT_CTRL_MAC_LOOP BIT(12)
136 #define AR8216_PORT_CTRL_SINGLE_VLAN BIT(13)
137 #define AR8216_PORT_CTRL_LEARN BIT(14)
138 #define AR8216_PORT_CTRL_MIRROR_TX BIT(16)
139 #define AR8216_PORT_CTRL_MIRROR_RX BIT(17)
140
141 #define AR8216_REG_PORT_VLAN(_i) (AR8216_PORT_OFFSET(_i) + 0x0008)
142
143 #define AR8216_PORT_VLAN_DEFAULT_ID BITS(0, 12)
144 #define AR8216_PORT_VLAN_DEFAULT_ID_S 0
145
146 #define AR8216_PORT_VLAN_DEST_PORTS BITS(16, 9)
147 #define AR8216_PORT_VLAN_DEST_PORTS_S 16
148
149 /* bit0 added to the priority field of egress frames */
150 #define AR8216_PORT_VLAN_TX_PRIO BIT(27)
151
152 /* port default priority */
153 #define AR8216_PORT_VLAN_PRIORITY BITS(28, 2)
154 #define AR8216_PORT_VLAN_PRIORITY_S 28
155
156 /* ingress 802.1q mode */
157 #define AR8216_PORT_VLAN_MODE BITS(30, 2)
158 #define AR8216_PORT_VLAN_MODE_S 30
159
160 #define AR8216_REG_PORT_RATE(_i) (AR8216_PORT_OFFSET(_i) + 0x000c)
161 #define AR8216_REG_PORT_PRIO(_i) (AR8216_PORT_OFFSET(_i) + 0x0010)
162
163 #define AR8236_REG_PORT_VLAN(_i) (AR8216_PORT_OFFSET((_i)) + 0x0008)
164 #define AR8236_PORT_VLAN_DEFAULT_ID BITS(16, 12)
165 #define AR8236_PORT_VLAN_DEFAULT_ID_S 16
166 #define AR8236_PORT_VLAN_PRIORITY BITS(29, 3)
167 #define AR8236_PORT_VLAN_PRIORITY_S 28
168
169 #define AR8236_REG_PORT_VLAN2(_i) (AR8216_PORT_OFFSET((_i)) + 0x000c)
170 #define AR8236_PORT_VLAN2_MEMBER BITS(16, 7)
171 #define AR8236_PORT_VLAN2_MEMBER_S 16
172 #define AR8236_PORT_VLAN2_TX_PRIO BIT(23)
173 #define AR8236_PORT_VLAN2_VLAN_MODE BITS(30, 2)
174 #define AR8236_PORT_VLAN2_VLAN_MODE_S 30
175
176 #define AR8236_REG_PORT_STATS_BASE(_i) (0x20000 + (_i) * 0x100)
177
178 #define AR8236_STATS_RXBROAD 0x00
179 #define AR8236_STATS_RXPAUSE 0x04
180 #define AR8236_STATS_RXMULTI 0x08
181 #define AR8236_STATS_RXFCSERR 0x0c
182 #define AR8236_STATS_RXALIGNERR 0x10
183 #define AR8236_STATS_RXRUNT 0x14
184 #define AR8236_STATS_RXFRAGMENT 0x18
185 #define AR8236_STATS_RX64BYTE 0x1c
186 #define AR8236_STATS_RX128BYTE 0x20
187 #define AR8236_STATS_RX256BYTE 0x24
188 #define AR8236_STATS_RX512BYTE 0x28
189 #define AR8236_STATS_RX1024BYTE 0x2c
190 #define AR8236_STATS_RX1518BYTE 0x30
191 #define AR8236_STATS_RXMAXBYTE 0x34
192 #define AR8236_STATS_RXTOOLONG 0x38
193 #define AR8236_STATS_RXGOODBYTE 0x3c
194 #define AR8236_STATS_RXBADBYTE 0x44
195 #define AR8236_STATS_RXOVERFLOW 0x4c
196 #define AR8236_STATS_FILTERED 0x50
197 #define AR8236_STATS_TXBROAD 0x54
198 #define AR8236_STATS_TXPAUSE 0x58
199 #define AR8236_STATS_TXMULTI 0x5c
200 #define AR8236_STATS_TXUNDERRUN 0x60
201 #define AR8236_STATS_TX64BYTE 0x64
202 #define AR8236_STATS_TX128BYTE 0x68
203 #define AR8236_STATS_TX256BYTE 0x6c
204 #define AR8236_STATS_TX512BYTE 0x70
205 #define AR8236_STATS_TX1024BYTE 0x74
206 #define AR8236_STATS_TX1518BYTE 0x78
207 #define AR8236_STATS_TXMAXBYTE 0x7c
208 #define AR8236_STATS_TXOVERSIZE 0x80
209 #define AR8236_STATS_TXBYTE 0x84
210 #define AR8236_STATS_TXCOLLISION 0x8c
211 #define AR8236_STATS_TXABORTCOL 0x90
212 #define AR8236_STATS_TXMULTICOL 0x94
213 #define AR8236_STATS_TXSINGLECOL 0x98
214 #define AR8236_STATS_TXEXCDEFER 0x9c
215 #define AR8236_STATS_TXDEFER 0xa0
216 #define AR8236_STATS_TXLATECOL 0xa4
217
218 #define AR8327_NUM_PORTS 7
219 #define AR8327_NUM_PHYS 5
220 #define AR8327_PORTS_ALL 0x7f
221
222 #define AR8327_REG_MASK 0x000
223
224 #define AR8327_REG_PAD0_MODE 0x004
225 #define AR8327_REG_PAD5_MODE 0x008
226 #define AR8327_REG_PAD6_MODE 0x00c
227 #define AR8327_PAD_MAC_MII_RXCLK_SEL BIT(0)
228 #define AR8327_PAD_MAC_MII_TXCLK_SEL BIT(1)
229 #define AR8327_PAD_MAC_MII_EN BIT(2)
230 #define AR8327_PAD_MAC_GMII_RXCLK_SEL BIT(4)
231 #define AR8327_PAD_MAC_GMII_TXCLK_SEL BIT(5)
232 #define AR8327_PAD_MAC_GMII_EN BIT(6)
233 #define AR8327_PAD_SGMII_EN BIT(7)
234 #define AR8327_PAD_PHY_MII_RXCLK_SEL BIT(8)
235 #define AR8327_PAD_PHY_MII_TXCLK_SEL BIT(9)
236 #define AR8327_PAD_PHY_MII_EN BIT(10)
237 #define AR8327_PAD_PHY_GMII_PIPE_RXCLK_SEL BIT(11)
238 #define AR8327_PAD_PHY_GMII_RXCLK_SEL BIT(12)
239 #define AR8327_PAD_PHY_GMII_TXCLK_SEL BIT(13)
240 #define AR8327_PAD_PHY_GMII_EN BIT(14)
241 #define AR8327_PAD_PHYX_GMII_EN BIT(16)
242 #define AR8327_PAD_PHYX_RGMII_EN BIT(17)
243 #define AR8327_PAD_PHYX_MII_EN BIT(18)
244 #define AR8327_PAD_RGMII_RXCLK_DELAY_SEL BITS(20, 2)
245 #define AR8327_PAD_RGMII_RXCLK_DELAY_SEL_S 20
246 #define AR8327_PAD_RGMII_TXCLK_DELAY_SEL BITS(22, 2)
247 #define AR8327_PAD_RGMII_TXCLK_DELAY_SEL_S 22
248 #define AR8327_PAD_RGMII_RXCLK_DELAY_EN BIT(24)
249 #define AR8327_PAD_RGMII_TXCLK_DELAY_EN BIT(25)
250 #define AR8327_PAD_RGMII_EN BIT(26)
251
252 #define AR8327_REG_POWER_ON_STRIP 0x010
253 #define AR8327_POWER_ON_STRIP_POWER_ON_SEL BIT(31)
254 #define AR8327_POWER_ON_STRIP_LED_OPEN_EN BIT(24)
255
256 #define AR8327_REG_INT_STATUS0 0x020
257 #define AR8327_INT0_VT_DONE BIT(20)
258
259 #define AR8327_REG_INT_STATUS1 0x024
260 #define AR8327_REG_INT_MASK0 0x028
261 #define AR8327_REG_INT_MASK1 0x02c
262
263 #define AR8327_REG_MODULE_EN 0x030
264 #define AR8327_MODULE_EN_MIB BIT(0)
265
266 #define AR8327_REG_MIB_FUNC 0x034
267 #define AR8327_MIB_CPU_KEEP BIT(20)
268
269 #define AR8327_REG_SERVICE_TAG 0x048
270 #define AR8327_REG_LED_CTRL0 0x050
271 #define AR8327_REG_LED_CTRL1 0x054
272 #define AR8327_REG_LED_CTRL2 0x058
273 #define AR8327_REG_LED_CTRL3 0x05c
274 #define AR8327_REG_MAC_ADDR0 0x060
275 #define AR8327_REG_MAC_ADDR1 0x064
276
277 #define AR8327_REG_MAX_FRAME_SIZE 0x078
278 #define AR8327_MAX_FRAME_SIZE_MTU BITS(0, 14)
279
280 #define AR8327_REG_PORT_STATUS(_i) (0x07c + (_i) * 4)
281
282 #define AR8327_REG_HEADER_CTRL 0x098
283 #define AR8327_REG_PORT_HEADER(_i) (0x09c + (_i) * 4)
284
285 #define AR8327_REG_PORT_VLAN0(_i) (0x420 + (_i) * 0x8)
286 #define AR8327_PORT_VLAN0_DEF_SVID BITS(0, 12)
287 #define AR8327_PORT_VLAN0_DEF_SVID_S 0
288 #define AR8327_PORT_VLAN0_DEF_CVID BITS(16, 12)
289 #define AR8327_PORT_VLAN0_DEF_CVID_S 16
290
291 #define AR8327_REG_PORT_VLAN1(_i) (0x424 + (_i) * 0x8)
292 #define AR8327_PORT_VLAN1_PORT_VLAN_PROP BIT(6)
293 #define AR8327_PORT_VLAN1_OUT_MODE BITS(12, 2)
294 #define AR8327_PORT_VLAN1_OUT_MODE_S 12
295 #define AR8327_PORT_VLAN1_OUT_MODE_UNMOD 0
296 #define AR8327_PORT_VLAN1_OUT_MODE_UNTAG 1
297 #define AR8327_PORT_VLAN1_OUT_MODE_TAG 2
298 #define AR8327_PORT_VLAN1_OUT_MODE_UNTOUCH 3
299
300 #define AR8327_REG_ATU_DATA0 0x600
301 #define AR8327_REG_ATU_DATA1 0x604
302 #define AR8327_REG_ATU_DATA2 0x608
303
304 #define AR8327_REG_ATU_FUNC 0x60c
305 #define AR8327_ATU_FUNC_OP BITS(0, 4)
306 #define AR8327_ATU_FUNC_OP_NOOP 0x0
307 #define AR8327_ATU_FUNC_OP_FLUSH 0x1
308 #define AR8327_ATU_FUNC_OP_LOAD 0x2
309 #define AR8327_ATU_FUNC_OP_PURGE 0x3
310 #define AR8327_ATU_FUNC_OP_FLUSH_LOCKED 0x4
311 #define AR8327_ATU_FUNC_OP_FLUSH_UNICAST 0x5
312 #define AR8327_ATU_FUNC_OP_GET_NEXT 0x6
313 #define AR8327_ATU_FUNC_OP_SEARCH_MAC 0x7
314 #define AR8327_ATU_FUNC_OP_CHANGE_TRUNK 0x8
315 #define AR8327_ATU_FUNC_BUSY BIT(31)
316
317 #define AR8327_REG_VTU_FUNC0 0x0610
318 #define AR8327_VTU_FUNC0_EG_MODE BITS(4, 14)
319 #define AR8327_VTU_FUNC0_EG_MODE_S(_i) (4 + (_i) * 2)
320 #define AR8327_VTU_FUNC0_EG_MODE_KEEP 0
321 #define AR8327_VTU_FUNC0_EG_MODE_UNTAG 1
322 #define AR8327_VTU_FUNC0_EG_MODE_TAG 2
323 #define AR8327_VTU_FUNC0_EG_MODE_NOT 3
324 #define AR8327_VTU_FUNC0_IVL BIT(19)
325 #define AR8327_VTU_FUNC0_VALID BIT(20)
326
327 #define AR8327_REG_VTU_FUNC1 0x0614
328 #define AR8327_VTU_FUNC1_OP BITS(0, 3)
329 #define AR8327_VTU_FUNC1_OP_NOOP 0
330 #define AR8327_VTU_FUNC1_OP_FLUSH 1
331 #define AR8327_VTU_FUNC1_OP_LOAD 2
332 #define AR8327_VTU_FUNC1_OP_PURGE 3
333 #define AR8327_VTU_FUNC1_OP_REMOVE_PORT 4
334 #define AR8327_VTU_FUNC1_OP_GET_NEXT 5
335 #define AR8327_VTU_FUNC1_OP_GET_ONE 6
336 #define AR8327_VTU_FUNC1_FULL BIT(4)
337 #define AR8327_VTU_FUNC1_PORT BIT(8, 4)
338 #define AR8327_VTU_FUNC1_PORT_S 8
339 #define AR8327_VTU_FUNC1_VID BIT(16, 12)
340 #define AR8327_VTU_FUNC1_VID_S 16
341 #define AR8327_VTU_FUNC1_BUSY BIT(31)
342
343 #define AR8327_REG_FWD_CTRL0 0x620
344 #define AR8327_FWD_CTRL0_CPU_PORT_EN BIT(10)
345 #define AR8327_FWD_CTRL0_MIRROR_PORT BITS(4, 4)
346 #define AR8327_FWD_CTRL0_MIRROR_PORT_S 4
347
348 #define AR8327_REG_FWD_CTRL1 0x624
349 #define AR8327_FWD_CTRL1_UC_FLOOD BITS(0, 7)
350 #define AR8327_FWD_CTRL1_UC_FLOOD_S 0
351 #define AR8327_FWD_CTRL1_MC_FLOOD BITS(8, 7)
352 #define AR8327_FWD_CTRL1_MC_FLOOD_S 8
353 #define AR8327_FWD_CTRL1_BC_FLOOD BITS(16, 7)
354 #define AR8327_FWD_CTRL1_BC_FLOOD_S 16
355 #define AR8327_FWD_CTRL1_IGMP BITS(24, 7)
356 #define AR8327_FWD_CTRL1_IGMP_S 24
357
358 #define AR8327_REG_PORT_LOOKUP(_i) (0x660 + (_i) * 0xc)
359 #define AR8327_PORT_LOOKUP_MEMBER BITS(0, 7)
360 #define AR8327_PORT_LOOKUP_IN_MODE BITS(8, 2)
361 #define AR8327_PORT_LOOKUP_IN_MODE_S 8
362 #define AR8327_PORT_LOOKUP_STATE BITS(16, 3)
363 #define AR8327_PORT_LOOKUP_STATE_S 16
364 #define AR8327_PORT_LOOKUP_LEARN BIT(20)
365
366 #define AR8327_REG_PORT_PRIO(_i) (0x664 + (_i) * 0xc)
367
368 #define AR8327_REG_PORT_STATS_BASE(_i) (0x1000 + (_i) * 0x100)
369
370 /* port speed */
371 enum {
372 AR8216_PORT_SPEED_10M = 0,
373 AR8216_PORT_SPEED_100M = 1,
374 AR8216_PORT_SPEED_1000M = 2,
375 AR8216_PORT_SPEED_ERR = 3,
376 };
377
378 /* ingress 802.1q mode */
379 enum {
380 AR8216_IN_PORT_ONLY = 0,
381 AR8216_IN_PORT_FALLBACK = 1,
382 AR8216_IN_VLAN_ONLY = 2,
383 AR8216_IN_SECURE = 3
384 };
385
386 /* egress 802.1q mode */
387 enum {
388 AR8216_OUT_KEEP = 0,
389 AR8216_OUT_STRIP_VLAN = 1,
390 AR8216_OUT_ADD_VLAN = 2
391 };
392
393 /* port forwarding state */
394 enum {
395 AR8216_PORT_STATE_DISABLED = 0,
396 AR8216_PORT_STATE_BLOCK = 1,
397 AR8216_PORT_STATE_LISTEN = 2,
398 AR8216_PORT_STATE_LEARN = 3,
399 AR8216_PORT_STATE_FORWARD = 4
400 };
401
402 #endif