mediatek: mt7622: add Linux 5.10 support
[openwrt/staging/rmilecki.git] / target / linux / mediatek / files-5.10 / drivers / net / phy / rtk / rtl8367c / rtl8367c_asicdrv_oam.c
1 /*
2 * Copyright (C) 2013 Realtek Semiconductor Corp.
3 * All Rights Reserved.
4 *
5 * Unless you and Realtek execute a separate written software license
6 * agreement governing use of this software, this software is licensed
7 * to you under the terms of the GNU General Public License version 2,
8 * available at https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
9 *
10 * $Revision: 42321 $
11 * $Date: 2013-08-26 13:51:29 +0800 (週一, 26 八月 2013) $
12 *
13 * Purpose : RTL8367C switch high-level API for RTL8367C
14 * Feature : OAM related functions
15 *
16 */
17
18 #include <rtl8367c_asicdrv_oam.h>
19 /* Function Name:
20 * rtl8367c_setAsicOamParser
21 * Description:
22 * Set OAM parser state
23 * Input:
24 * port - Physical port number (0~7)
25 * parser - Per-Port OAM parser state
26 * Output:
27 * None
28 * Return:
29 * RT_ERR_OK - Success
30 * RT_ERR_SMI - SMI access error
31 * RT_ERR_PORT_ID - Invalid port number
32 * RT_ERR_NOT_ALLOWED - Invalid paser state
33 * Note:
34 * None
35 */
36 ret_t rtl8367c_setAsicOamParser(rtk_uint32 port, rtk_uint32 parser)
37 {
38 if(port >= RTL8367C_PORTNO)
39 return RT_ERR_PORT_ID;
40
41 if(parser > OAM_PARFWDCPU)
42 return RT_ERR_NOT_ALLOWED;
43
44 return rtl8367c_setAsicRegBits(RTL8367C_REG_OAM_PARSER_CTRL0 + port/8, RTL8367C_OAM_PARSER_MASK(port % 8), parser);
45 }
46 /* Function Name:
47 * rtl8367c_getAsicOamParser
48 * Description:
49 * Get OAM parser state
50 * Input:
51 * port - Physical port number (0~7)
52 * pParser - Per-Port OAM parser state
53 * Output:
54 * None
55 * Return:
56 * RT_ERR_OK - Success
57 * RT_ERR_SMI - SMI access error
58 * RT_ERR_PORT_ID - Invalid port number
59 * Note:
60 * None
61 */
62 ret_t rtl8367c_getAsicOamParser(rtk_uint32 port, rtk_uint32* pParser)
63 {
64 if(port >= RTL8367C_PORTNO)
65 return RT_ERR_PORT_ID;
66
67 return rtl8367c_getAsicRegBits(RTL8367C_REG_OAM_PARSER_CTRL0 + port/8, RTL8367C_OAM_PARSER_MASK(port%8), pParser);
68 }
69 /* Function Name:
70 * rtl8367c_setAsicOamMultiplexer
71 * Description:
72 * Set OAM multiplexer state
73 * Input:
74 * port - Physical port number (0~7)
75 * multiplexer - Per-Port OAM multiplexer state
76 * Output:
77 * None
78 * Return:
79 * RT_ERR_OK - Success
80 * RT_ERR_SMI - SMI access error
81 * RT_ERR_PORT_ID - Invalid port number
82 * RT_ERR_NOT_ALLOWED - Invalid multiplexer state
83 * Note:
84 * None
85 */
86 ret_t rtl8367c_setAsicOamMultiplexer(rtk_uint32 port, rtk_uint32 multiplexer)
87 {
88 if(port >= RTL8367C_PORTNO)
89 return RT_ERR_PORT_ID;
90
91 if(multiplexer > OAM_MULCPU)
92 return RT_ERR_NOT_ALLOWED;
93
94 return rtl8367c_setAsicRegBits(RTL8367C_REG_OAM_MULTIPLEXER_CTRL0 + port/8, RTL8367C_OAM_MULTIPLEXER_MASK(port%8), multiplexer);
95 }
96 /* Function Name:
97 * rtl8367c_getAsicOamMultiplexer
98 * Description:
99 * Get OAM multiplexer state
100 * Input:
101 * port - Physical port number (0~7)
102 * pMultiplexer - Per-Port OAM multiplexer state
103 * Output:
104 * None
105 * Return:
106 * RT_ERR_OK - Success
107 * RT_ERR_SMI - SMI access error
108 * RT_ERR_PORT_ID - Invalid port number
109 * Note:
110 * None
111 */
112 ret_t rtl8367c_getAsicOamMultiplexer(rtk_uint32 port, rtk_uint32* pMultiplexer)
113 {
114 if(port >= RTL8367C_PORTNO)
115 return RT_ERR_PORT_ID;
116
117 return rtl8367c_getAsicRegBits(RTL8367C_REG_OAM_MULTIPLEXER_CTRL0 + port/8, RTL8367C_OAM_MULTIPLEXER_MASK(port%8), pMultiplexer);
118 }
119 /* Function Name:
120 * rtl8367c_setAsicOamCpuPri
121 * Description:
122 * Set trap priority for OAM packet
123 * Input:
124 * priority - priority (0~7)
125 * Output:
126 * None
127 * Return:
128 * RT_ERR_OK - Success
129 * RT_ERR_SMI - SMI access error
130 * RT_ERR_QOS_INT_PRIORITY - Invalid priority
131 * Note:
132 * None
133 */
134 ret_t rtl8367c_setAsicOamCpuPri(rtk_uint32 priority)
135 {
136 if(priority > RTL8367C_PRIMAX)
137 return RT_ERR_QOS_INT_PRIORITY;
138
139 return rtl8367c_setAsicRegBits(RTL8367C_REG_QOS_TRAP_PRIORITY0, RTL8367C_OAM_PRIOIRTY_MASK, priority);
140 }
141 /* Function Name:
142 * rtl8367c_getAsicOamCpuPri
143 * Description:
144 * Get trap priority for OAM packet
145 * Input:
146 * pPriority - priority (0~7)
147 * Output:
148 * None
149 * Return:
150 * RT_ERR_OK - Success
151 * RT_ERR_SMI - SMI access error
152 * Note:
153 * None
154 */
155 ret_t rtl8367c_getAsicOamCpuPri(rtk_uint32 *pPriority)
156 {
157 return rtl8367c_getAsicRegBits(RTL8367C_REG_QOS_TRAP_PRIORITY0, RTL8367C_OAM_PRIOIRTY_MASK, pPriority);
158 }
159 /* Function Name:
160 * rtl8367c_setAsicOamEnable
161 * Description:
162 * Set OAM function state
163 * Input:
164 * enabled - OAM function usage 1:enable, 0:disabled
165 * Output:
166 * None
167 * Return:
168 * RT_ERR_OK - Success
169 * RT_ERR_SMI - SMI access error
170 * Note:
171 * None
172 */
173 ret_t rtl8367c_setAsicOamEnable(rtk_uint32 enabled)
174 {
175 return rtl8367c_setAsicRegBit(RTL8367C_REG_OAM_CTRL, RTL8367C_OAM_CTRL_OFFSET, enabled);
176 }
177 /* Function Name:
178 * rtl8367c_getAsicOamEnable
179 * Description:
180 * Get OAM function state
181 * Input:
182 * pEnabled - OAM function usage 1:enable, 0:disabled
183 * Output:
184 * None
185 * Return:
186 * RT_ERR_OK - Success
187 * RT_ERR_SMI - SMI access error
188 * Note:
189 * None
190 */
191 ret_t rtl8367c_getAsicOamEnable(rtk_uint32 *pEnabled)
192 {
193 return rtl8367c_getAsicRegBit(RTL8367C_REG_OAM_CTRL, RTL8367C_OAM_CTRL_OFFSET, pEnabled);
194 }