xref: /freebsd/sys/dev/etherswitch/rtl8366/rtl8366rbvar.h (revision 718cf2ccb9956613756ab15d7a0e28f2c8e91cab)
1a043e8c7SAdrian Chadd /*-
2*718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*718cf2ccSPedro 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  * $FreeBSD$
30a043e8c7SAdrian Chadd  */
31a043e8c7SAdrian Chadd 
32a043e8c7SAdrian Chadd #ifndef _DEV_ETHERSWITCH_RTL8366RBVAR_H_
33a043e8c7SAdrian Chadd #define	_DEV_ETHERSWITCH_RTL8366RBVAR_H_
34a043e8c7SAdrian Chadd 
355a4380b5SMichael Zhilin #define	RTL8366RB		0
365a4380b5SMichael Zhilin #define	RTL8366SR		1
375a4380b5SMichael Zhilin 
38477e3effSMichael Zhilin #define RTL8366_IIC_ADDR	0xa8
39a043e8c7SAdrian Chadd #define RTL_IICBUS_TIMEOUT	100	/* us */
40a043e8c7SAdrian Chadd #define RTL_IICBUS_READ		1
41a043e8c7SAdrian Chadd #define	RTL_IICBUS_WRITE	0
42a043e8c7SAdrian Chadd /* number of times to try and select the chip on the I2C bus */
43a043e8c7SAdrian Chadd #define RTL_IICBUS_RETRIES	3
44a043e8c7SAdrian Chadd #define RTL_IICBUS_RETRY_SLEEP	(hz/1000)
45a043e8c7SAdrian Chadd 
46a043e8c7SAdrian Chadd /* Register definitions */
47a043e8c7SAdrian Chadd 
48a043e8c7SAdrian Chadd /* Switch Global Configuration */
49477e3effSMichael Zhilin #define RTL8366_SGCR				0x0000
50477e3effSMichael Zhilin #define RTL8366_SGCR_EN_BC_STORM_CTRL		0x0001
51477e3effSMichael Zhilin #define RTL8366_SGCR_MAX_LENGTH_MASK		0x0030
52477e3effSMichael Zhilin #define RTL8366_SGCR_MAX_LENGTH_1522		0x0000
53477e3effSMichael Zhilin #define RTL8366_SGCR_MAX_LENGTH_1536		0x0010
54477e3effSMichael Zhilin #define RTL8366_SGCR_MAX_LENGTH_1552		0x0020
55477e3effSMichael Zhilin #define RTL8366_SGCR_MAX_LENGTH_9216		0x0030
56477e3effSMichael Zhilin #define RTL8366_SGCR_EN_VLAN			0x2000
57477e3effSMichael Zhilin #define RTL8366_SGCR_EN_VLAN_4KTB		0x4000
58477e3effSMichael Zhilin #define RTL8366_SGCR_EN_QOS			0x8000
59a043e8c7SAdrian Chadd 
60a043e8c7SAdrian Chadd /* Port Enable Control: DISABLE_PORT[5:0] */
61477e3effSMichael Zhilin #define RTL8366_PECR				0x0001
62a043e8c7SAdrian Chadd 
63a043e8c7SAdrian Chadd /* Switch Security Control 0: DIS_LEARN[5:0] */
64477e3effSMichael Zhilin #define RTL8366_SSCR0				0x0002
65a043e8c7SAdrian Chadd 
66a043e8c7SAdrian Chadd /* Switch Security Control 1: DIS_AGE[5:0] */
67477e3effSMichael Zhilin #define RTL8366_SSCR1				0x0003
68a043e8c7SAdrian Chadd 
69a043e8c7SAdrian Chadd /* Switch Security Control 2 */
70477e3effSMichael Zhilin #define RTL8366_SSCR2				0x0004
71477e3effSMichael Zhilin #define RTL8366_SSCR2_DROP_UNKNOWN_DA		0x0001
72a043e8c7SAdrian Chadd 
73a043e8c7SAdrian Chadd /* Port Link Status: two ports per register */
74477e3effSMichael Zhilin #define RTL8366_PLSR_BASE			(sc->chip_type == 0 ? 0x0014 : 0x0060)
75477e3effSMichael Zhilin #define RTL8366_PLSR_SPEED_MASK	0x03
76477e3effSMichael Zhilin #define RTL8366_PLSR_SPEED_10		0x00
77477e3effSMichael Zhilin #define RTL8366_PLSR_SPEED_100	0x01
78477e3effSMichael Zhilin #define RTL8366_PLSR_SPEED_1000	0x02
79477e3effSMichael Zhilin #define RTL8366_PLSR_FULLDUPLEX	0x04
80477e3effSMichael Zhilin #define RTL8366_PLSR_LINK		0x10
81477e3effSMichael Zhilin #define RTL8366_PLSR_TXPAUSE		0x20
82477e3effSMichael Zhilin #define RTL8366_PLSR_RXPAUSE		0x40
83477e3effSMichael Zhilin #define RTL8366_PLSR_NO_AUTO		0x80
84a043e8c7SAdrian Chadd 
85477e3effSMichael Zhilin /* VLAN Member Configuration, 3 or 2 registers per VLAN */
86477e3effSMichael Zhilin #define RTL8366_VMCR_BASE			(sc->chip_type == 0 ? 0x0020 : 0x0016)
87477e3effSMichael Zhilin #define RTL8366_VMCR_MULT		(sc->chip_type == 0 ? 3 : 2)
88477e3effSMichael Zhilin #define RTL8366_VMCR_DOT1Q_REG	0
89477e3effSMichael Zhilin #define RTL8366_VMCR_DOT1Q_VID_SHIFT	0
90477e3effSMichael Zhilin #define RTL8366_VMCR_DOT1Q_VID_MASK	0x0fff
91477e3effSMichael Zhilin #define RTL8366_VMCR_DOT1Q_PCP_SHIFT	12
92477e3effSMichael Zhilin #define RTL8366_VMCR_DOT1Q_PCP_MASK	0x7000
93477e3effSMichael Zhilin #define RTL8366_VMCR_MU_REG		1
94477e3effSMichael Zhilin #define RTL8366_VMCR_MU_MEMBER_SHIFT	0
95477e3effSMichael Zhilin #define RTL8366_VMCR_MU_MEMBER_MASK	(sc->chip_type == 0 ? 0x00ff : 0x003f)
96477e3effSMichael Zhilin #define RTL8366_VMCR_MU_UNTAG_SHIFT	(sc->chip_type == 0 ? 8 : 6)
97477e3effSMichael Zhilin #define RTL8366_VMCR_MU_UNTAG_MASK	(sc->chip_type == 0 ? 0xff00 : 0x0fc0)
98477e3effSMichael Zhilin #define RTL8366_VMCR_FID_REG		(sc->chip_type == 0 ? 2 : 1)
99477e3effSMichael Zhilin #define RTL8366_VMCR_FID_FID_SHIFT	(sc->chip_type == 0 ? 0 : 12)
100477e3effSMichael Zhilin #define RTL8366_VMCR_FID_FID_MASK	(sc->chip_type == 0 ? 0x0007 : 0x7000)
101477e3effSMichael Zhilin #define RTL8366_VMCR(_reg, _vlan) \
102477e3effSMichael Zhilin 	(RTL8366_VMCR_BASE + _reg + _vlan * RTL8366_VMCR_MULT)
103a043e8c7SAdrian Chadd /* VLAN Identifier */
104477e3effSMichael Zhilin #define RTL8366_VMCR_VID(_r) \
105477e3effSMichael Zhilin 	(_r[RTL8366_VMCR_DOT1Q_REG] & RTL8366_VMCR_DOT1Q_VID_MASK)
106a043e8c7SAdrian Chadd /* Priority Code Point */
107477e3effSMichael Zhilin #define RTL8366_VMCR_PCP(_r) \
108477e3effSMichael Zhilin 	((_r[RTL8366_VMCR_DOT1Q_REG] & RTL8366_VMCR_DOT1Q_PCP_MASK) \
109477e3effSMichael Zhilin 	>> RTL8366_VMCR_DOT1Q_PCP_SHIFT)
110a043e8c7SAdrian Chadd /* Member ports */
111477e3effSMichael Zhilin #define RTL8366_VMCR_MEMBER(_r) \
112477e3effSMichael Zhilin 	(_r[RTL8366_VMCR_MU_REG] & RTL8366_VMCR_MU_MEMBER_MASK)
113a043e8c7SAdrian Chadd /* Untagged ports */
114477e3effSMichael Zhilin #define RTL8366_VMCR_UNTAG(_r) \
115477e3effSMichael Zhilin 	((_r[RTL8366_VMCR_MU_REG] & RTL8366_VMCR_MU_UNTAG_MASK) \
116477e3effSMichael Zhilin 	>> RTL8366_VMCR_MU_UNTAG_SHIFT)
117a043e8c7SAdrian Chadd /* Forwarding ID */
118477e3effSMichael Zhilin #define RTL8366_VMCR_FID(_r) \
119477e3effSMichael Zhilin 	(sc->chip_type == 0 ? (_r[RTL8366_VMCR_FID_REG] & RTL8366_VMCR_FID_FID_MASK) : \
120477e3effSMichael Zhilin 		((_r[RTL8366_VMCR_FID_REG] & RTL8366_VMCR_FID_FID_MASK) \
121477e3effSMichael Zhilin 		>> RTL8366_VMCR_FID_FID_SHIFT))
122a043e8c7SAdrian Chadd 
123a043e8c7SAdrian Chadd /*
124a043e8c7SAdrian Chadd  * Port VLAN Control, 4 ports per register
125a043e8c7SAdrian Chadd  * Determines the VID for untagged ingress frames through
126a043e8c7SAdrian Chadd  * index into VMC.
127a043e8c7SAdrian Chadd  */
128477e3effSMichael Zhilin #define RTL8366_PVCR_BASE			(sc->chip_type == 0 ? 0x0063 : 0x0058)
129477e3effSMichael Zhilin #define RTL8366_PVCR_PORT_SHIFT	4
130477e3effSMichael Zhilin #define RTL8366_PVCR_PORT_PERREG	(16 / RTL8366_PVCR_PORT_SHIFT)
131477e3effSMichael Zhilin #define RTL8366_PVCR_PORT_MASK	0x000f
132477e3effSMichael Zhilin #define RTL8366_PVCR_REG(_port) \
133477e3effSMichael Zhilin 	(RTL8366_PVCR_BASE + _port / (RTL8366_PVCR_PORT_PERREG))
134477e3effSMichael Zhilin #define RTL8366_PVCR_VAL(_port, _pvlan) \
135477e3effSMichael Zhilin 	((_pvlan & RTL8366_PVCR_PORT_MASK) << \
136477e3effSMichael Zhilin 	((_port % RTL8366_PVCR_PORT_PERREG) * RTL8366_PVCR_PORT_SHIFT))
137477e3effSMichael Zhilin #define RTL8366_PVCR_GET(_port, _val) \
138477e3effSMichael Zhilin 	(((_val) >> ((_port % RTL8366_PVCR_PORT_PERREG) * RTL8366_PVCR_PORT_SHIFT)) & RTL8366_PVCR_PORT_MASK)
139a043e8c7SAdrian Chadd 
140a043e8c7SAdrian Chadd /* Reset Control */
141477e3effSMichael Zhilin #define RTL8366_RCR				0x0100
142477e3effSMichael Zhilin #define RTL8366_RCR_HARD_RESET	0x0001
143477e3effSMichael Zhilin #define RTL8366_RCR_SOFT_RESET	0x0002
144a043e8c7SAdrian Chadd 
145a043e8c7SAdrian Chadd /* Chip Version Control: CHIP_VER[3:0] */
146477e3effSMichael Zhilin #define RTL8366_CVCR				(sc->chip_type == 0 ? 0x050A : 0x0104)
147a043e8c7SAdrian Chadd /* Chip Identifier */
148a043e8c7SAdrian Chadd #define RTL8366RB_CIR				0x0509
149a043e8c7SAdrian Chadd #define RTL8366RB_CIR_ID8366RB		0x5937
150477e3effSMichael Zhilin #define RTL8366SR_CIR				0x0105
151477e3effSMichael Zhilin #define RTL8366SR_CIR_ID8366SR		0x8366
152a043e8c7SAdrian Chadd 
153a043e8c7SAdrian Chadd /* VLAN Ingress Control 2: [5:0] */
154477e3effSMichael Zhilin #define RTL8366_VIC2R				0x037f
155a043e8c7SAdrian Chadd 
156a043e8c7SAdrian Chadd /* MIB registers */
157477e3effSMichael Zhilin #define RTL8366_MCNT_BASE			0x1000
158477e3effSMichael Zhilin #define RTL8366_MCTLR				(sc->chip_type == 0 ? 0x13f0 : 0x11F0)
159477e3effSMichael Zhilin #define RTL8366_MCTLR_BUSY		0x0001
160477e3effSMichael Zhilin #define RTL8366_MCTLR_RESET		0x0002
161477e3effSMichael Zhilin #define RTL8366_MCTLR_RESET_PORT_MASK	0x00fc
162477e3effSMichael Zhilin #define RTL8366_MCTLR_RESET_ALL	0x0800
163a043e8c7SAdrian Chadd 
164477e3effSMichael Zhilin #define RTL8366_MCNT(_port, _r) \
165477e3effSMichael Zhilin 	(RTL8366_MCNT_BASE + 0x50 * (_port) + (_r))
166477e3effSMichael Zhilin #define RTL8366_MCTLR_RESET_PORT(_p) \
167a043e8c7SAdrian Chadd 	(1 << ((_p) + 2))
168a043e8c7SAdrian Chadd 
169a043e8c7SAdrian Chadd /* PHY Access Control */
170477e3effSMichael Zhilin #define RTL8366_PACR				(sc->chip_type == 0 ? 0x8000 : 0x8028)
171477e3effSMichael Zhilin #define RTL8366_PACR_WRITE		0x0000
172477e3effSMichael Zhilin #define RTL8366_PACR_READ			0x0001
173a043e8c7SAdrian Chadd 
174a043e8c7SAdrian Chadd /* PHY Access Data */
175477e3effSMichael Zhilin #define	RTL8366_PADR				(sc->chip_type == 0 ? 0x8002 : 0x8029)
176a043e8c7SAdrian Chadd 
177477e3effSMichael Zhilin #define RTL8366_PHYREG(phy, page, reg) \
178477e3effSMichael Zhilin 	(0x8000 | (1 << (((phy) & 0x1f) + 9)) | (((page) & (sc->chip_type == 0 ? 0xf : 0x7)) << 5) | ((reg) & 0x1f))
179a043e8c7SAdrian Chadd 
180a043e8c7SAdrian Chadd /* general characteristics of the chip */
1815a4380b5SMichael Zhilin #define	RTL8366_NUM_PHYS			5
182477e3effSMichael Zhilin #define	RTL8366_NUM_VLANS			16
183477e3effSMichael Zhilin #define	RTL8366_NUM_PHY_REG			32
184a043e8c7SAdrian Chadd 
185a043e8c7SAdrian Chadd #endif
186