mediatek: add support for rtl8367c
[openwrt/staging/rmilecki.git] / target / linux / mediatek / files-5.4 / drivers / net / phy / rtk / rtl8367c / rtl8367c_asicdrv_cputag.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: 76306 $
11 * $Date: 2017-03-08 15:13:58 +0800 (週三, 08 三月 2017) $
12 *
13 * Purpose : RTL8367C switch high-level API for RTL8367C
14 * Feature : Proprietary CPU-tag related function drivers
15 *
16 */
17 #include <rtl8367c_asicdrv_cputag.h>
18 /* Function Name:
19 * rtl8367c_setAsicCputagEnable
20 * Description:
21 * Set cpu tag function enable/disable
22 * Input:
23 * enabled - 1: enabled, 0: disabled
24 * Output:
25 * None
26 * Return:
27 * RT_ERR_OK - Success
28 * RT_ERR_SMI - SMI access error
29 * RT_ERR_ENABLE - Invalid enable/disable input
30 * Note:
31 * If CPU tag function is disabled, CPU tag will not be added to frame
32 * forwarded to CPU port, and all ports cannot parse CPU tag.
33 */
34 ret_t rtl8367c_setAsicCputagEnable(rtk_uint32 enabled)
35 {
36 if(enabled > 1)
37 return RT_ERR_ENABLE;
38
39 return rtl8367c_setAsicRegBit(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_EN_OFFSET, enabled);
40 }
41 /* Function Name:
42 * rtl8367c_getAsicCputagEnable
43 * Description:
44 * Get cpu tag function enable/disable
45 * Input:
46 * pEnabled - 1: enabled, 0: disabled
47 * Output:
48 * None
49 * Return:
50 * RT_ERR_OK - Success
51 * RT_ERR_SMI - SMI access error
52 * Note:
53 * None
54 */
55 ret_t rtl8367c_getAsicCputagEnable(rtk_uint32 *pEnabled)
56 {
57 return rtl8367c_getAsicRegBit(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_EN_OFFSET, pEnabled);
58 }
59 /* Function Name:
60 * rtl8367c_setAsicCputagTrapPort
61 * Description:
62 * Set cpu tag trap port
63 * Input:
64 * port - port number
65 * Output:
66 * None
67 * Return:
68 * RT_ERR_OK - Success
69 * RT_ERR_SMI - SMI access error
70 * RT_ERR_PORT_ID - Invalid port number
71 * Note:
72 * API can set destination port of trapping frame
73 */
74 ret_t rtl8367c_setAsicCputagTrapPort(rtk_uint32 port)
75 {
76 ret_t retVal;
77
78 if(port >= RTL8367C_PORTNO)
79 return RT_ERR_PORT_ID;
80
81 retVal = rtl8367c_setAsicRegBits(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_TRAP_PORT_MASK, port & 7);
82 if(retVal != RT_ERR_OK)
83 return retVal;
84
85 retVal = rtl8367c_setAsicRegBits(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_TRAP_PORT_EXT_MASK, (port>>3) & 1);
86 if(retVal != RT_ERR_OK)
87 return retVal;
88
89 return RT_ERR_OK;
90 }
91 /* Function Name:
92 * rtl8367c_getAsicCputagTrapPort
93 * Description:
94 * Get cpu tag trap port
95 * Input:
96 * pPort - port number
97 * Output:
98 * None
99 * Return:
100 * RT_ERR_OK - Success
101 * RT_ERR_SMI - SMI access error
102 * Note:
103 * None
104 */
105 ret_t rtl8367c_getAsicCputagTrapPort(rtk_uint32 *pPort)
106 {
107 ret_t retVal;
108 rtk_uint32 tmpPort;
109
110 retVal = rtl8367c_getAsicRegBits(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_TRAP_PORT_MASK, &tmpPort);
111 if(retVal != RT_ERR_OK)
112 return retVal;
113 *pPort = tmpPort;
114
115 retVal = rtl8367c_getAsicRegBits(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_TRAP_PORT_EXT_MASK, &tmpPort);
116 if(retVal != RT_ERR_OK)
117 return retVal;
118 *pPort |= (tmpPort & 1) << 3;
119
120 return RT_ERR_OK;
121 }
122 /* Function Name:
123 * rtl8367c_setAsicCputagPortmask
124 * Description:
125 * Set ports that can parse CPU tag
126 * Input:
127 * portmask - port mask
128 * Output:
129 * None
130 * Return:
131 * RT_ERR_OK - Success
132 * RT_ERR_SMI - SMI access error
133 * RT_ERR_PORT_MASK - Invalid portmask
134 * Note:
135 * None
136 */
137 ret_t rtl8367c_setAsicCputagPortmask(rtk_uint32 portmask)
138 {
139 if(portmask > RTL8367C_PORTMASK)
140 return RT_ERR_PORT_MASK;
141
142 return rtl8367c_setAsicReg(RTL8367C_CPU_PORT_MASK_REG, portmask);
143 }
144 /* Function Name:
145 * rtl8367c_getAsicCputagPortmask
146 * Description:
147 * Get ports that can parse CPU tag
148 * Input:
149 * pPortmask - port mask
150 * Output:
151 * None
152 * Return:
153 * RT_ERR_OK - Success
154 * RT_ERR_SMI - SMI access error
155 * Note:
156 * None
157 */
158 ret_t rtl8367c_getAsicCputagPortmask(rtk_uint32 *pPortmask)
159 {
160 return rtl8367c_getAsicReg(RTL8367C_CPU_PORT_MASK_REG, pPortmask);
161 }
162 /* Function Name:
163 * rtl8367c_setAsicCputagInsertMode
164 * Description:
165 * Set CPU-tag insert mode
166 * Input:
167 * mode - 0: insert to all packets; 1: insert to trapped packets; 2: don't insert
168 * Output:
169 * None
170 * Return:
171 * RT_ERR_OK - Success
172 * RT_ERR_SMI - SMI access error
173 * RT_ERR_NOT_ALLOWED - Actions not allowed by the function
174 * Note:
175 * None
176 */
177 ret_t rtl8367c_setAsicCputagInsertMode(rtk_uint32 mode)
178 {
179 if(mode >= CPUTAG_INSERT_END)
180 return RT_ERR_NOT_ALLOWED;
181
182 return rtl8367c_setAsicRegBits(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_INSERTMODE_MASK, mode);
183 }
184 /* Function Name:
185 * rtl8367c_getAsicCputagInsertMode
186 * Description:
187 * Get CPU-tag insert mode
188 * Input:
189 * pMode - 0: insert to all packets; 1: insert to trapped packets; 2: don't insert
190 * Output:
191 * None
192 * Return:
193 * RT_ERR_OK - Success
194 * RT_ERR_SMI - SMI access error
195 * Note:
196 * None
197 */
198 ret_t rtl8367c_getAsicCputagInsertMode(rtk_uint32 *pMode)
199 {
200 return rtl8367c_getAsicRegBits(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_INSERTMODE_MASK, pMode);
201 }
202 /* Function Name:
203 * rtl8367c_setAsicCputagPriorityRemapping
204 * Description:
205 * Set queue assignment of CPU port
206 * Input:
207 * srcPri - internal priority (0~7)
208 * newPri - internal priority after remapping (0~7)
209 * Output:
210 * None
211 * Return:
212 * RT_ERR_OK - Success
213 * RT_ERR_SMI - SMI access error
214 * RT_ERR_QOS_INT_PRIORITY - Invalid priority
215 * Note:
216 * None
217 */
218 ret_t rtl8367c_setAsicCputagPriorityRemapping(rtk_uint32 srcPri, rtk_uint32 newPri)
219 {
220 if((srcPri > RTL8367C_PRIMAX) || (newPri > RTL8367C_PRIMAX))
221 return RT_ERR_QOS_INT_PRIORITY;
222
223 return rtl8367c_setAsicRegBits(RTL8367C_QOS_PRIPORITY_REMAPPING_IN_CPU_REG(srcPri), RTL8367C_QOS_PRIPORITY_REMAPPING_IN_CPU_MASK(srcPri), newPri);
224 }
225 /* Function Name:
226 * rtl8367c_getAsicCputagPriorityRemapping
227 * Description:
228 * Get queue assignment of CPU port
229 * Input:
230 * srcPri - internal priority (0~7)
231 * pNewPri - internal priority after remapping (0~7)
232 * Output:
233 * None
234 * Return:
235 * RT_ERR_OK - Success
236 * RT_ERR_SMI - SMI access error
237 * RT_ERR_QOS_INT_PRIORITY - Invalid priority
238 * Note:
239 * None
240 */
241 ret_t rtl8367c_getAsicCputagPriorityRemapping(rtk_uint32 srcPri, rtk_uint32 *pNewPri)
242 {
243 if(srcPri > RTL8367C_PRIMAX)
244 return RT_ERR_QOS_INT_PRIORITY;
245
246 return rtl8367c_getAsicRegBits(RTL8367C_QOS_PRIPORITY_REMAPPING_IN_CPU_REG(srcPri), RTL8367C_QOS_PRIPORITY_REMAPPING_IN_CPU_MASK(srcPri), pNewPri);
247 }
248 /* Function Name:
249 * rtl8367c_setAsicCputagPosition
250 * Description:
251 * Set cpu tag insert position
252 * Input:
253 * postion - 1: After entire packet(before CRC field), 0: After MAC_SA (Default)
254 * Output:
255 * None
256 * Return:
257 * RT_ERR_OK - Success
258 * RT_ERR_SMI - SMI access error
259 * Note:
260 * None
261 */
262 ret_t rtl8367c_setAsicCputagPosition(rtk_uint32 postion)
263 {
264 return rtl8367c_setAsicRegBit(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_TAG_POSITION_OFFSET, postion);
265 }
266 /* Function Name:
267 * rtl8367c_getAsicCputagPosition
268 * Description:
269 * Get cpu tag insert position
270 * Input:
271 * pPostion - 1: After entire packet(before CRC field), 0: After MAC_SA (Default)
272 * Output:
273 * None
274 * Return:
275 * RT_ERR_OK - Success
276 * RT_ERR_SMI - SMI access error
277 * Note:
278 * None
279 */
280 ret_t rtl8367c_getAsicCputagPosition(rtk_uint32* pPostion)
281 {
282 return rtl8367c_getAsicRegBit(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_TAG_POSITION_OFFSET, pPostion);
283 }
284
285 /* Function Name:
286 * rtl8367c_setAsicCputagMode
287 * Description:
288 * Set cpu tag mode
289 * Input:
290 * mode - 1: 4bytes mode, 0: 8bytes mode
291 * Output:
292 * None
293 * Return:
294 * RT_ERR_OK - Success
295 * RT_ERR_SMI - SMI access error
296 * RT_ERR_INPUT - Invalid input parameters
297 * Note:
298 * If CPU tag function is disabled, CPU tag will not be added to frame
299 * forwarded to CPU port, and all ports cannot parse CPU tag.
300 */
301 ret_t rtl8367c_setAsicCputagMode(rtk_uint32 mode)
302 {
303 if(mode > 1)
304 return RT_ERR_INPUT;
305
306 return rtl8367c_setAsicRegBit(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_TAG_FORMAT_OFFSET, mode);
307 }
308 /* Function Name:
309 * rtl8367c_getAsicCputagMode
310 * Description:
311 * Get cpu tag mode
312 * Input:
313 * pMode - 1: 4bytes mode, 0: 8bytes mode
314 * Output:
315 * None
316 * Return:
317 * RT_ERR_OK - Success
318 * RT_ERR_SMI - SMI access error
319 * Note:
320 * None
321 */
322 ret_t rtl8367c_getAsicCputagMode(rtk_uint32 *pMode)
323 {
324 return rtl8367c_getAsicRegBit(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_TAG_FORMAT_OFFSET, pMode);
325 }
326 /* Function Name:
327 * rtl8367c_setAsicCputagRxMinLength
328 * Description:
329 * Set cpu tag mode
330 * Input:
331 * mode - 1: 64bytes, 0: 72bytes
332 * Output:
333 * None
334 * Return:
335 * RT_ERR_OK - Success
336 * RT_ERR_SMI - SMI access error
337 * RT_ERR_INPUT - Invalid input parameters
338 * Note:
339 * If CPU tag function is disabled, CPU tag will not be added to frame
340 * forwarded to CPU port, and all ports cannot parse CPU tag.
341 */
342 ret_t rtl8367c_setAsicCputagRxMinLength(rtk_uint32 mode)
343 {
344 if(mode > 1)
345 return RT_ERR_INPUT;
346
347 return rtl8367c_setAsicRegBit(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_TAG_RXBYTECOUNT_OFFSET, mode);
348 }
349 /* Function Name:
350 * rtl8367c_getAsicCputagRxMinLength
351 * Description:
352 * Get cpu tag mode
353 * Input:
354 * pMode - 1: 64bytes, 0: 72bytes
355 * Output:
356 * None
357 * Return:
358 * RT_ERR_OK - Success
359 * RT_ERR_SMI - SMI access error
360 * Note:
361 * None
362 */
363 ret_t rtl8367c_getAsicCputagRxMinLength(rtk_uint32 *pMode)
364 {
365 return rtl8367c_getAsicRegBit(RTL8367C_REG_CPU_CTRL, RTL8367C_CPU_TAG_RXBYTECOUNT_OFFSET, pMode);
366 }
367
368
369