xref: /freebsd/sys/dev/etherswitch/mtkswitch/mtkswitch_mt7620.h (revision 1027d6d672d4cdeb771014c1c5e51abb058baab5)
1dfb5178fSStanislav Galabov /*-
2dfb5178fSStanislav Galabov  * Copyright (c) 2016 Stanislav Galabov.
3dfb5178fSStanislav Galabov  * All rights reserved.
4dfb5178fSStanislav Galabov  *
5dfb5178fSStanislav Galabov  * Redistribution and use in source and binary forms, with or without
6dfb5178fSStanislav Galabov  * modification, are permitted provided that the following conditions
7dfb5178fSStanislav Galabov  * are met:
8dfb5178fSStanislav Galabov  * 1. Redistributions of source code must retain the above copyright
9dfb5178fSStanislav Galabov  *    notice, this list of conditions and the following disclaimer.
10dfb5178fSStanislav Galabov  * 2. Redistributions in binary form must reproduce the above copyright
11dfb5178fSStanislav Galabov  *    notice, this list of conditions and the following disclaimer in the
12dfb5178fSStanislav Galabov  *    documentation and/or other materials provided with the distribution.
13dfb5178fSStanislav Galabov  *
14dfb5178fSStanislav Galabov  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15dfb5178fSStanislav Galabov  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16dfb5178fSStanislav Galabov  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17dfb5178fSStanislav Galabov  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18dfb5178fSStanislav Galabov  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19dfb5178fSStanislav Galabov  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20dfb5178fSStanislav Galabov  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21dfb5178fSStanislav Galabov  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22dfb5178fSStanislav Galabov  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23dfb5178fSStanislav Galabov  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24dfb5178fSStanislav Galabov  * SUCH DAMAGE.
25dfb5178fSStanislav Galabov  *
26dfb5178fSStanislav Galabov  * $FreeBSD$
27dfb5178fSStanislav Galabov  */
28dfb5178fSStanislav Galabov 
29dfb5178fSStanislav Galabov #ifndef	__MTKSWITCH_MT7620_H__
30dfb5178fSStanislav Galabov #define	__MTKSWITCH_MT7620_H__
31dfb5178fSStanislav Galabov 
32dfb5178fSStanislav Galabov #define	MTKSWITCH_ATC	0x0080
33dfb5178fSStanislav Galabov #define		ATC_BUSY		(1u<<15)
34dfb5178fSStanislav Galabov #define		ATC_AC_MAT_NON_STATIC_MACS	(4u<<8)
35dfb5178fSStanislav Galabov #define		ATC_AC_CMD_CLEAN	(2u<<0)
36dfb5178fSStanislav Galabov 
37dfb5178fSStanislav Galabov #define	MTKSWITCH_VTCR	0x0090
38dfb5178fSStanislav Galabov #define		VTCR_BUSY		(1u<<31)
39dfb5178fSStanislav Galabov #define		VTCR_FUNC_VID_READ	(0u<<12)
40dfb5178fSStanislav Galabov #define		VTCR_FUNC_VID_WRITE	(1u<<12)
41dfb5178fSStanislav Galabov #define		VTCR_FUNC_VID_INVALID	(2u<<12)
42dfb5178fSStanislav Galabov #define		VTCR_FUNC_VID_VALID	(3u<<12)
43dfb5178fSStanislav Galabov #define		VTCR_IDX_INVALID	(1u<<16)
44dfb5178fSStanislav Galabov #define		VTCR_VID_MASK		0xfff
45dfb5178fSStanislav Galabov 
46dfb5178fSStanislav Galabov #define	MTKSWITCH_VAWD1	0x0094
47dfb5178fSStanislav Galabov #define		VAWD1_IVL_MAC		(1u<<30)
48dfb5178fSStanislav Galabov #define		VAWD1_VTAG_EN		(1u<<28)
49dfb5178fSStanislav Galabov #define		VAWD1_PORT_MEMBER(p)	((1u<<16)<<(p))
50dfb5178fSStanislav Galabov #define		VAWD1_MEMBER_OFF	16
51dfb5178fSStanislav Galabov #define		VAWD1_MEMBER_MASK	0xff
52dfb5178fSStanislav Galabov #define		VAWD1_FID_OFFSET	1
53dfb5178fSStanislav Galabov #define		VAWD1_VALID		(1u<<0)
54dfb5178fSStanislav Galabov 
55dfb5178fSStanislav Galabov #define	MTKSWITCH_VAWD2	0x0098
56dfb5178fSStanislav Galabov #define		VAWD2_PORT_UNTAGGED(p)	(0u<<((p)*2))
57dfb5178fSStanislav Galabov #define		VAWD2_PORT_TAGGED(p)	(2u<<((p)*2))
58dfb5178fSStanislav Galabov #define		VAWD2_PORT_MASK(p)	(3u<<((p)*2))
59dfb5178fSStanislav Galabov 
60dfb5178fSStanislav Galabov #define	MTKSWITCH_VTIM(v)	((((v) >> 1) * 4) + 0x100)
61dfb5178fSStanislav Galabov #define		VTIM_OFF(v)	(((v) & 1) ? 12 : 0)
62dfb5178fSStanislav Galabov #define		VTIM_MASK	0xfff
63dfb5178fSStanislav Galabov 
64dfb5178fSStanislav Galabov #define	MTKSWITCH_PIAC	0x7004
65dfb5178fSStanislav Galabov #define		PIAC_PHY_ACS_ST		(1u<<31)
66dfb5178fSStanislav Galabov #define		PIAC_MDIO_REG_ADDR_OFF	25
67dfb5178fSStanislav Galabov #define		PIAC_MDIO_PHY_ADDR_OFF	20
68dfb5178fSStanislav Galabov #define		PIAC_MDIO_CMD_WRITE	(1u<<18)
69dfb5178fSStanislav Galabov #define		PIAC_MDIO_CMD_READ	(2u<<18)
70dfb5178fSStanislav Galabov #define		PIAC_MDIO_ST		(1u<<16)
71dfb5178fSStanislav Galabov #define		PIAC_MDIO_RW_DATA_MASK	0xffff
72dfb5178fSStanislav Galabov 
73dfb5178fSStanislav Galabov #define	MTKSWITCH_PORTREG(r, p)	((r) + ((p) * 0x100))
74dfb5178fSStanislav Galabov 
75dfb5178fSStanislav Galabov #define	MTKSWITCH_PCR(x)	MTKSWITCH_PORTREG(0x2004, (x))
76dfb5178fSStanislav Galabov #define		PCR_PORT_VLAN_SECURE	(3u<<0)
77dfb5178fSStanislav Galabov 
78dfb5178fSStanislav Galabov #define	MTKSWITCH_PVC(x)	MTKSWITCH_PORTREG(0x2010, (x))
79dfb5178fSStanislav Galabov #define		PVC_VLAN_ATTR_MASK	(3u<<6)
80dfb5178fSStanislav Galabov 
81dfb5178fSStanislav Galabov #define	MTKSWITCH_PPBV1(x)	MTKSWITCH_PORTREG(0x2014, (x))
82dfb5178fSStanislav Galabov #define	MTKSWITCH_PPBV2(x)	MTKSWITCH_PORTREG(0x2018, (x))
83dfb5178fSStanislav Galabov #define		PPBV_VID(v)		(((v)<<16) | (v))
84dfb5178fSStanislav Galabov #define		PPBV_VID_FROM_REG(x)	((x) & 0xfff)
85dfb5178fSStanislav Galabov #define		PPBV_VID_MASK		0xfff
86dfb5178fSStanislav Galabov 
87dfb5178fSStanislav Galabov #define	MTKSWITCH_PMCR(x)	MTKSWITCH_PORTREG(0x3000, (x))
88*1027d6d6SStanislav Galabov #define		PMCR_FORCE_LINK		(1u<<0)
89*1027d6d6SStanislav Galabov #define		PMCR_FORCE_DPX		(1u<<1)
90*1027d6d6SStanislav Galabov #define		PMCR_FORCE_SPD_1000	(2u<<2)
91*1027d6d6SStanislav Galabov #define		PMCR_FORCE_TX_FC	(1u<<4)
92*1027d6d6SStanislav Galabov #define		PMCR_FORCE_RX_FC	(1u<<5)
93dfb5178fSStanislav Galabov #define		PMCR_BACKPR_EN		(1u<<8)
94dfb5178fSStanislav Galabov #define		PMCR_BKOFF_EN		(1u<<9)
95dfb5178fSStanislav Galabov #define		PMCR_MAC_RX_EN		(1u<<13)
96dfb5178fSStanislav Galabov #define		PMCR_MAC_TX_EN		(1u<<14)
97*1027d6d6SStanislav Galabov #define		PMCR_FORCE_MODE		(1u<<15)
98*1027d6d6SStanislav Galabov #define		PMCR_RES_1		(1u<<16)
99dfb5178fSStanislav Galabov #define		PMCR_IPG_CFG_RND	(1u<<18)
100dfb5178fSStanislav Galabov #define		PMCR_CFG_DEFAULT	(PMCR_BACKPR_EN | PMCR_BKOFF_EN | \
101*1027d6d6SStanislav Galabov 		    PMCR_MAC_RX_EN | PMCR_MAC_TX_EN | PMCR_IPG_CFG_RND |  \
102*1027d6d6SStanislav Galabov 		    PMCR_FORCE_RX_FC | PMCR_FORCE_TX_FC | PMCR_RES_1)
103dfb5178fSStanislav Galabov 
104dfb5178fSStanislav Galabov #define	MTKSWITCH_PMSR(x)	MTKSWITCH_PORTREG(0x3008, (x))
105dfb5178fSStanislav Galabov #define		PMSR_MAC_LINK_STS	(1u<<0)
106dfb5178fSStanislav Galabov #define		PMSR_MAC_DPX_STS	(1u<<1)
107dfb5178fSStanislav Galabov #define		PMSR_MAC_SPD_STS	(3u<<2)
108dfb5178fSStanislav Galabov #define		PMSR_MAC_SPD(x)		(((x)>>2) & 0x3)
109dfb5178fSStanislav Galabov #define		PMSR_MAC_SPD_10		0
110dfb5178fSStanislav Galabov #define		PMSR_MAC_SPD_100	1
111dfb5178fSStanislav Galabov #define		PMSR_MAC_SPD_1000	2
112dfb5178fSStanislav Galabov #define		PMSR_TX_FC_STS		(1u<<4)
113dfb5178fSStanislav Galabov #define		PMSR_RX_FC_STS		(1u<<5)
114dfb5178fSStanislav Galabov 
115dfb5178fSStanislav Galabov #define	MTKSWITCH_REG_ADDR(r)	(((r) >> 6) & 0x3ff)
116dfb5178fSStanislav Galabov #define	MTKSWITCH_REG_LO(r)	(((r) >> 2) & 0xf)
117dfb5178fSStanislav Galabov #define	MTKSWITCH_REG_HI(r)	(1 << 4)
118dfb5178fSStanislav Galabov #define MTKSWITCH_VAL_LO(v)	((v) & 0xffff)
119dfb5178fSStanislav Galabov #define MTKSWITCH_VAL_HI(v)	(((v) >> 16) & 0xffff)
120dfb5178fSStanislav Galabov #define MTKSWITCH_GLOBAL_PHY	31
121dfb5178fSStanislav Galabov #define	MTKSWITCH_GLOBAL_REG	31
122dfb5178fSStanislav Galabov 
123dfb5178fSStanislav Galabov #define	MTKSWITCH_LAN_VID	0x001
124dfb5178fSStanislav Galabov #define	MTKSWITCH_WAN_VID	0x002
125dfb5178fSStanislav Galabov #define	MTKSWITCH_INVALID_VID	0xfff
126dfb5178fSStanislav Galabov 
127dfb5178fSStanislav Galabov #define	MTKSWITCH_LAN_FID	1
128dfb5178fSStanislav Galabov #define	MTKSWITCH_WAN_FID	2
129dfb5178fSStanislav Galabov 
130dfb5178fSStanislav Galabov #endif	/* __MTKSWITCH_MT7620_H__ */
131