xref: /freebsd/sys/dev/etherswitch/rtl8366/rtl8366rbvar.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1a043e8c7SAdrian Chadd /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni  *
4477e3effSMichael Zhilin  * Copyright (c) 2015-2016 Hiroki Mori.
5a043e8c7SAdrian Chadd  * Copyright (c) 2011-2012 Stefan Bethke.
6a043e8c7SAdrian Chadd  * All rights reserved.
7a043e8c7SAdrian Chadd  *
8a043e8c7SAdrian Chadd  * Redistribution and use in source and binary forms, with or without
9a043e8c7SAdrian Chadd  * modification, are permitted provided that the following conditions
10a043e8c7SAdrian Chadd  * are met:
11a043e8c7SAdrian Chadd  * 1. Redistributions of source code must retain the above copyright
12a043e8c7SAdrian Chadd  *    notice, this list of conditions and the following disclaimer.
13a043e8c7SAdrian Chadd  * 2. Redistributions in binary form must reproduce the above copyright
14a043e8c7SAdrian Chadd  *    notice, this list of conditions and the following disclaimer in the
15a043e8c7SAdrian Chadd  *    documentation and/or other materials provided with the distribution.
16a043e8c7SAdrian Chadd  *
17a043e8c7SAdrian Chadd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18a043e8c7SAdrian Chadd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19a043e8c7SAdrian Chadd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20a043e8c7SAdrian Chadd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21a043e8c7SAdrian Chadd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22a043e8c7SAdrian Chadd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23a043e8c7SAdrian Chadd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24a043e8c7SAdrian Chadd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25a043e8c7SAdrian Chadd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26a043e8c7SAdrian Chadd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27a043e8c7SAdrian Chadd  * SUCH DAMAGE.
28a043e8c7SAdrian Chadd  */
29a043e8c7SAdrian Chadd 
30a043e8c7SAdrian Chadd #ifndef _DEV_ETHERSWITCH_RTL8366RBVAR_H_
31a043e8c7SAdrian Chadd #define	_DEV_ETHERSWITCH_RTL8366RBVAR_H_
32a043e8c7SAdrian Chadd 
335a4380b5SMichael Zhilin #define	RTL8366RB		0
345a4380b5SMichael Zhilin #define	RTL8366SR		1
355a4380b5SMichael Zhilin 
36477e3effSMichael Zhilin #define RTL8366_IIC_ADDR	0xa8
37a043e8c7SAdrian Chadd #define RTL_IICBUS_TIMEOUT	100	/* us */
38a043e8c7SAdrian Chadd #define RTL_IICBUS_READ		1
39a043e8c7SAdrian Chadd #define	RTL_IICBUS_WRITE	0
40a043e8c7SAdrian Chadd /* number of times to try and select the chip on the I2C bus */
41a043e8c7SAdrian Chadd #define RTL_IICBUS_RETRIES	3
42a043e8c7SAdrian Chadd #define RTL_IICBUS_RETRY_SLEEP	(hz/1000)
43a043e8c7SAdrian Chadd 
44a043e8c7SAdrian Chadd /* Register definitions */
45a043e8c7SAdrian Chadd 
46a043e8c7SAdrian Chadd /* Switch Global Configuration */
47477e3effSMichael Zhilin #define RTL8366_SGCR				0x0000
48477e3effSMichael Zhilin #define RTL8366_SGCR_EN_BC_STORM_CTRL		0x0001
49477e3effSMichael Zhilin #define RTL8366_SGCR_MAX_LENGTH_MASK		0x0030
50477e3effSMichael Zhilin #define RTL8366_SGCR_MAX_LENGTH_1522		0x0000
51477e3effSMichael Zhilin #define RTL8366_SGCR_MAX_LENGTH_1536		0x0010
52477e3effSMichael Zhilin #define RTL8366_SGCR_MAX_LENGTH_1552		0x0020
53477e3effSMichael Zhilin #define RTL8366_SGCR_MAX_LENGTH_9216		0x0030
54477e3effSMichael Zhilin #define RTL8366_SGCR_EN_VLAN			0x2000
55477e3effSMichael Zhilin #define RTL8366_SGCR_EN_VLAN_4KTB		0x4000
56477e3effSMichael Zhilin #define RTL8366_SGCR_EN_QOS			0x8000
57a043e8c7SAdrian Chadd 
58a043e8c7SAdrian Chadd /* Port Enable Control: DISABLE_PORT[5:0] */
59477e3effSMichael Zhilin #define RTL8366_PECR				0x0001
60a043e8c7SAdrian Chadd 
61a043e8c7SAdrian Chadd /* Switch Security Control 0: DIS_LEARN[5:0] */
62477e3effSMichael Zhilin #define RTL8366_SSCR0				0x0002
63a043e8c7SAdrian Chadd 
64a043e8c7SAdrian Chadd /* Switch Security Control 1: DIS_AGE[5:0] */
65477e3effSMichael Zhilin #define RTL8366_SSCR1				0x0003
66a043e8c7SAdrian Chadd 
67a043e8c7SAdrian Chadd /* Switch Security Control 2 */
68477e3effSMichael Zhilin #define RTL8366_SSCR2				0x0004
69477e3effSMichael Zhilin #define RTL8366_SSCR2_DROP_UNKNOWN_DA		0x0001
70a043e8c7SAdrian Chadd 
71a043e8c7SAdrian Chadd /* Port Link Status: two ports per register */
72477e3effSMichael Zhilin #define RTL8366_PLSR_BASE			(sc->chip_type == 0 ? 0x0014 : 0x0060)
73477e3effSMichael Zhilin #define RTL8366_PLSR_SPEED_MASK	0x03
74477e3effSMichael Zhilin #define RTL8366_PLSR_SPEED_10		0x00
75477e3effSMichael Zhilin #define RTL8366_PLSR_SPEED_100	0x01
76477e3effSMichael Zhilin #define RTL8366_PLSR_SPEED_1000	0x02
77477e3effSMichael Zhilin #define RTL8366_PLSR_FULLDUPLEX	0x04
78477e3effSMichael Zhilin #define RTL8366_PLSR_LINK		0x10
79477e3effSMichael Zhilin #define RTL8366_PLSR_TXPAUSE		0x20
80477e3effSMichael Zhilin #define RTL8366_PLSR_RXPAUSE		0x40
81477e3effSMichael Zhilin #define RTL8366_PLSR_NO_AUTO		0x80
82a043e8c7SAdrian Chadd 
83477e3effSMichael Zhilin /* VLAN Member Configuration, 3 or 2 registers per VLAN */
84477e3effSMichael Zhilin #define RTL8366_VMCR_BASE			(sc->chip_type == 0 ? 0x0020 : 0x0016)
85477e3effSMichael Zhilin #define RTL8366_VMCR_MULT		(sc->chip_type == 0 ? 3 : 2)
86477e3effSMichael Zhilin #define RTL8366_VMCR_DOT1Q_REG	0
87477e3effSMichael Zhilin #define RTL8366_VMCR_DOT1Q_VID_SHIFT	0
88477e3effSMichael Zhilin #define RTL8366_VMCR_DOT1Q_VID_MASK	0x0fff
89477e3effSMichael Zhilin #define RTL8366_VMCR_DOT1Q_PCP_SHIFT	12
90477e3effSMichael Zhilin #define RTL8366_VMCR_DOT1Q_PCP_MASK	0x7000
91477e3effSMichael Zhilin #define RTL8366_VMCR_MU_REG		1
92477e3effSMichael Zhilin #define RTL8366_VMCR_MU_MEMBER_SHIFT	0
93477e3effSMichael Zhilin #define RTL8366_VMCR_MU_MEMBER_MASK	(sc->chip_type == 0 ? 0x00ff : 0x003f)
94477e3effSMichael Zhilin #define RTL8366_VMCR_MU_UNTAG_SHIFT	(sc->chip_type == 0 ? 8 : 6)
95477e3effSMichael Zhilin #define RTL8366_VMCR_MU_UNTAG_MASK	(sc->chip_type == 0 ? 0xff00 : 0x0fc0)
96477e3effSMichael Zhilin #define RTL8366_VMCR_FID_REG		(sc->chip_type == 0 ? 2 : 1)
97477e3effSMichael Zhilin #define RTL8366_VMCR_FID_FID_SHIFT	(sc->chip_type == 0 ? 0 : 12)
98477e3effSMichael Zhilin #define RTL8366_VMCR_FID_FID_MASK	(sc->chip_type == 0 ? 0x0007 : 0x7000)
99477e3effSMichael Zhilin #define RTL8366_VMCR(_reg, _vlan) \
100477e3effSMichael Zhilin 	(RTL8366_VMCR_BASE + _reg + _vlan * RTL8366_VMCR_MULT)
101a043e8c7SAdrian Chadd /* VLAN Identifier */
102477e3effSMichael Zhilin #define RTL8366_VMCR_VID(_r) \
103477e3effSMichael Zhilin 	(_r[RTL8366_VMCR_DOT1Q_REG] & RTL8366_VMCR_DOT1Q_VID_MASK)
104a043e8c7SAdrian Chadd /* Priority Code Point */
105477e3effSMichael Zhilin #define RTL8366_VMCR_PCP(_r) \
106477e3effSMichael Zhilin 	((_r[RTL8366_VMCR_DOT1Q_REG] & RTL8366_VMCR_DOT1Q_PCP_MASK) \
107477e3effSMichael Zhilin 	>> RTL8366_VMCR_DOT1Q_PCP_SHIFT)
108a043e8c7SAdrian Chadd /* Member ports */
109477e3effSMichael Zhilin #define RTL8366_VMCR_MEMBER(_r) \
110477e3effSMichael Zhilin 	(_r[RTL8366_VMCR_MU_REG] & RTL8366_VMCR_MU_MEMBER_MASK)
111a043e8c7SAdrian Chadd /* Untagged ports */
112477e3effSMichael Zhilin #define RTL8366_VMCR_UNTAG(_r) \
113477e3effSMichael Zhilin 	((_r[RTL8366_VMCR_MU_REG] & RTL8366_VMCR_MU_UNTAG_MASK) \
114477e3effSMichael Zhilin 	>> RTL8366_VMCR_MU_UNTAG_SHIFT)
115a043e8c7SAdrian Chadd /* Forwarding ID */
116477e3effSMichael Zhilin #define RTL8366_VMCR_FID(_r) \
117477e3effSMichael Zhilin 	(sc->chip_type == 0 ? (_r[RTL8366_VMCR_FID_REG] & RTL8366_VMCR_FID_FID_MASK) : \
118477e3effSMichael Zhilin 		((_r[RTL8366_VMCR_FID_REG] & RTL8366_VMCR_FID_FID_MASK) \
119477e3effSMichael Zhilin 		>> RTL8366_VMCR_FID_FID_SHIFT))
120a043e8c7SAdrian Chadd 
121a043e8c7SAdrian Chadd /*
122a043e8c7SAdrian Chadd  * Port VLAN Control, 4 ports per register
123a043e8c7SAdrian Chadd  * Determines the VID for untagged ingress frames through
124a043e8c7SAdrian Chadd  * index into VMC.
125a043e8c7SAdrian Chadd  */
126477e3effSMichael Zhilin #define RTL8366_PVCR_BASE			(sc->chip_type == 0 ? 0x0063 : 0x0058)
127477e3effSMichael Zhilin #define RTL8366_PVCR_PORT_SHIFT	4
128477e3effSMichael Zhilin #define RTL8366_PVCR_PORT_PERREG	(16 / RTL8366_PVCR_PORT_SHIFT)
129477e3effSMichael Zhilin #define RTL8366_PVCR_PORT_MASK	0x000f
130477e3effSMichael Zhilin #define RTL8366_PVCR_REG(_port) \
131477e3effSMichael Zhilin 	(RTL8366_PVCR_BASE + _port / (RTL8366_PVCR_PORT_PERREG))
132477e3effSMichael Zhilin #define RTL8366_PVCR_VAL(_port, _pvlan) \
133477e3effSMichael Zhilin 	((_pvlan & RTL8366_PVCR_PORT_MASK) << \
134477e3effSMichael Zhilin 	((_port % RTL8366_PVCR_PORT_PERREG) * RTL8366_PVCR_PORT_SHIFT))
135477e3effSMichael Zhilin #define RTL8366_PVCR_GET(_port, _val) \
136477e3effSMichael Zhilin 	(((_val) >> ((_port % RTL8366_PVCR_PORT_PERREG) * RTL8366_PVCR_PORT_SHIFT)) & RTL8366_PVCR_PORT_MASK)
137a043e8c7SAdrian Chadd 
138a043e8c7SAdrian Chadd /* Reset Control */
139477e3effSMichael Zhilin #define RTL8366_RCR				0x0100
140477e3effSMichael Zhilin #define RTL8366_RCR_HARD_RESET	0x0001
141477e3effSMichael Zhilin #define RTL8366_RCR_SOFT_RESET	0x0002
142a043e8c7SAdrian Chadd 
143a043e8c7SAdrian Chadd /* Chip Version Control: CHIP_VER[3:0] */
144477e3effSMichael Zhilin #define RTL8366_CVCR				(sc->chip_type == 0 ? 0x050A : 0x0104)
145a043e8c7SAdrian Chadd /* Chip Identifier */
146a043e8c7SAdrian Chadd #define RTL8366RB_CIR				0x0509
147a043e8c7SAdrian Chadd #define RTL8366RB_CIR_ID8366RB		0x5937
148477e3effSMichael Zhilin #define RTL8366SR_CIR				0x0105
149477e3effSMichael Zhilin #define RTL8366SR_CIR_ID8366SR		0x8366
150a043e8c7SAdrian Chadd 
151a043e8c7SAdrian Chadd /* VLAN Ingress Control 2: [5:0] */
152477e3effSMichael Zhilin #define RTL8366_VIC2R				0x037f
153a043e8c7SAdrian Chadd 
154a043e8c7SAdrian Chadd /* MIB registers */
155477e3effSMichael Zhilin #define RTL8366_MCNT_BASE			0x1000
156477e3effSMichael Zhilin #define RTL8366_MCTLR				(sc->chip_type == 0 ? 0x13f0 : 0x11F0)
157477e3effSMichael Zhilin #define RTL8366_MCTLR_BUSY		0x0001
158477e3effSMichael Zhilin #define RTL8366_MCTLR_RESET		0x0002
159477e3effSMichael Zhilin #define RTL8366_MCTLR_RESET_PORT_MASK	0x00fc
160477e3effSMichael Zhilin #define RTL8366_MCTLR_RESET_ALL	0x0800
161a043e8c7SAdrian Chadd 
162477e3effSMichael Zhilin #define RTL8366_MCNT(_port, _r) \
163477e3effSMichael Zhilin 	(RTL8366_MCNT_BASE + 0x50 * (_port) + (_r))
164477e3effSMichael Zhilin #define RTL8366_MCTLR_RESET_PORT(_p) \
165a043e8c7SAdrian Chadd 	(1 << ((_p) + 2))
166a043e8c7SAdrian Chadd 
167a043e8c7SAdrian Chadd /* PHY Access Control */
168477e3effSMichael Zhilin #define RTL8366_PACR				(sc->chip_type == 0 ? 0x8000 : 0x8028)
169477e3effSMichael Zhilin #define RTL8366_PACR_WRITE		0x0000
170477e3effSMichael Zhilin #define RTL8366_PACR_READ			0x0001
171a043e8c7SAdrian Chadd 
172a043e8c7SAdrian Chadd /* PHY Access Data */
173477e3effSMichael Zhilin #define	RTL8366_PADR				(sc->chip_type == 0 ? 0x8002 : 0x8029)
174a043e8c7SAdrian Chadd 
175477e3effSMichael Zhilin #define RTL8366_PHYREG(phy, page, reg) \
176477e3effSMichael Zhilin 	(0x8000 | (1 << (((phy) & 0x1f) + 9)) | (((page) & (sc->chip_type == 0 ? 0xf : 0x7)) << 5) | ((reg) & 0x1f))
177a043e8c7SAdrian Chadd 
178a043e8c7SAdrian Chadd /* general characteristics of the chip */
1795a4380b5SMichael Zhilin #define	RTL8366_NUM_PHYS			5
180477e3effSMichael Zhilin #define	RTL8366_NUM_VLANS			16
181477e3effSMichael Zhilin #define	RTL8366_NUM_PHY_REG			32
182a043e8c7SAdrian Chadd 
183a043e8c7SAdrian Chadd #endif
184