mediatek: mt7622: add Linux 5.10 support
[openwrt/staging/chunkeey.git] / target / linux / mediatek / files-5.10 / drivers / net / phy / rtk / rtl8367c / cpu.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 : RTK switch high-level API for RTL8367/RTL8367C
14 * Feature : Here is a list of all functions and variables in CPU module.
15 *
16 */
17
18 #include <rtk_switch.h>
19 #include <rtk_error.h>
20 #include <cpu.h>
21 #include <string.h>
22
23 #include <rtl8367c_asicdrv.h>
24 #include <rtl8367c_asicdrv_cputag.h>
25
26 /* Function Name:
27 * rtk_cpu_enable_set
28 * Description:
29 * Set CPU port function enable/disable.
30 * Input:
31 * enable - CPU port function enable
32 * Output:
33 * None
34 * Return:
35 * RT_ERR_OK - OK
36 * RT_ERR_FAILED - Failed
37 * RT_ERR_SMI - SMI access error
38 * RT_ERR_INPUT - Invalid input parameter.
39 * RT_ERR_PORT_ID - Invalid port number.
40 * Note:
41 * The API can set CPU port function enable/disable.
42 */
43 rtk_api_ret_t rtk_cpu_enable_set(rtk_enable_t enable)
44 {
45 rtk_api_ret_t retVal;
46
47 /* Check initialization state */
48 RTK_CHK_INIT_STATE();
49
50 if (enable >= RTK_ENABLE_END)
51 return RT_ERR_ENABLE;
52
53 if ((retVal = rtl8367c_setAsicCputagEnable(enable)) != RT_ERR_OK)
54 return retVal;
55
56 if (DISABLED == enable)
57 {
58 if ((retVal = rtl8367c_setAsicCputagPortmask(0)) != RT_ERR_OK)
59 return retVal;
60 }
61
62 return RT_ERR_OK;
63 }
64
65 /* Function Name:
66 * rtk_cpu_enable_get
67 * Description:
68 * Get CPU port and its setting.
69 * Input:
70 * None
71 * Output:
72 * pEnable - CPU port function enable
73 * Return:
74 * RT_ERR_OK - OK
75 * RT_ERR_FAILED - Failed
76 * RT_ERR_SMI - SMI access error
77 * RT_ERR_INPUT - Invalid input parameters.
78 * RT_ERR_L2_NO_CPU_PORT - CPU port is not exist
79 * Note:
80 * The API can get CPU port function enable/disable.
81 */
82 rtk_api_ret_t rtk_cpu_enable_get(rtk_enable_t *pEnable)
83 {
84 rtk_api_ret_t retVal;
85
86 /* Check initialization state */
87 RTK_CHK_INIT_STATE();
88
89 if(NULL == pEnable)
90 return RT_ERR_NULL_POINTER;
91
92 if ((retVal = rtl8367c_getAsicCputagEnable(pEnable)) != RT_ERR_OK)
93 return retVal;
94
95 return RT_ERR_OK;
96 }
97
98 /* Function Name:
99 * rtk_cpu_tagPort_set
100 * Description:
101 * Set CPU port and CPU tag insert mode.
102 * Input:
103 * port - Port id.
104 * mode - CPU tag insert for packets egress from CPU port.
105 * Output:
106 * None
107 * Return:
108 * RT_ERR_OK - OK
109 * RT_ERR_FAILED - Failed
110 * RT_ERR_SMI - SMI access error
111 * RT_ERR_INPUT - Invalid input parameter.
112 * RT_ERR_PORT_ID - Invalid port number.
113 * Note:
114 * The API can set CPU port and inserting proprietary CPU tag mode (Length/Type 0x8899)
115 * to the frame that transmitting to CPU port.
116 * The inset cpu tag mode is as following:
117 * - CPU_INSERT_TO_ALL
118 * - CPU_INSERT_TO_TRAPPING
119 * - CPU_INSERT_TO_NONE
120 */
121 rtk_api_ret_t rtk_cpu_tagPort_set(rtk_port_t port, rtk_cpu_insert_t mode)
122 {
123 rtk_api_ret_t retVal;
124
125 /* Check initialization state */
126 RTK_CHK_INIT_STATE();
127
128 /* Check port Valid */
129 RTK_CHK_PORT_VALID(port);
130
131 if (mode >= CPU_INSERT_END)
132 return RT_ERR_INPUT;
133
134 if ((retVal = rtl8367c_setAsicCputagPortmask(1<<rtk_switch_port_L2P_get(port))) != RT_ERR_OK)
135 return retVal;
136
137 if ((retVal = rtl8367c_setAsicCputagTrapPort(rtk_switch_port_L2P_get(port))) != RT_ERR_OK)
138 return retVal;
139
140 if ((retVal = rtl8367c_setAsicCputagInsertMode(mode)) != RT_ERR_OK)
141 return retVal;
142
143 return RT_ERR_OK;
144 }
145
146 /* Function Name:
147 * rtk_cpu_tagPort_get
148 * Description:
149 * Get CPU port and CPU tag insert mode.
150 * Input:
151 * None
152 * Output:
153 * pPort - Port id.
154 * pMode - CPU tag insert for packets egress from CPU port, 0:all insert 1:Only for trapped packets 2:no insert.
155 * Return:
156 * RT_ERR_OK - OK
157 * RT_ERR_FAILED - Failed
158 * RT_ERR_SMI - SMI access error
159 * RT_ERR_INPUT - Invalid input parameters.
160 * RT_ERR_L2_NO_CPU_PORT - CPU port is not exist
161 * Note:
162 * The API can get configured CPU port and its setting.
163 * The inset cpu tag mode is as following:
164 * - CPU_INSERT_TO_ALL
165 * - CPU_INSERT_TO_TRAPPING
166 * - CPU_INSERT_TO_NONE
167 */
168 rtk_api_ret_t rtk_cpu_tagPort_get(rtk_port_t *pPort, rtk_cpu_insert_t *pMode)
169 {
170 rtk_api_ret_t retVal;
171 rtk_uint32 pmsk, port;
172
173 /* Check initialization state */
174 RTK_CHK_INIT_STATE();
175
176 if(NULL == pPort)
177 return RT_ERR_NULL_POINTER;
178
179 if(NULL == pMode)
180 return RT_ERR_NULL_POINTER;
181
182 if ((retVal = rtl8367c_getAsicCputagPortmask(&pmsk)) != RT_ERR_OK)
183 return retVal;
184
185 if ((retVal = rtl8367c_getAsicCputagTrapPort(&port)) != RT_ERR_OK)
186 return retVal;
187
188 *pPort = rtk_switch_port_P2L_get(port);
189
190 if ((retVal = rtl8367c_getAsicCputagInsertMode(pMode)) != RT_ERR_OK)
191 return retVal;
192
193 return RT_ERR_OK;
194 }
195
196
197 /* Function Name:
198 * rtk_cpu_awarePort_set
199 * Description:
200 * Set CPU aware port mask.
201 * Input:
202 * portmask - Port mask.
203 * Output:
204 * None
205 * Return:
206 * RT_ERR_OK - OK
207 * RT_ERR_FAILED - Failed
208 * RT_ERR_SMI - SMI access error
209 * RT_ERR_PORT_MASK - Invalid port mask.
210 * Note:
211 * The API can set configured CPU aware port mask.
212 */
213 rtk_api_ret_t rtk_cpu_awarePort_set(rtk_portmask_t *pPortmask)
214 {
215 rtk_api_ret_t retVal;
216 rtk_uint32 phyMbrPmask;
217
218 /* Check initialization state */
219 RTK_CHK_INIT_STATE();
220
221 /* Check Valid port mask */
222 if(NULL == pPortmask)
223 return RT_ERR_NULL_POINTER;
224
225 /* Check port mask valid */
226 RTK_CHK_PORTMASK_VALID(pPortmask);
227
228 if(rtk_switch_portmask_L2P_get(pPortmask, &phyMbrPmask) != RT_ERR_OK)
229 return RT_ERR_FAILED;
230
231 if ((retVal = rtl8367c_setAsicCputagPortmask(phyMbrPmask)) != RT_ERR_OK)
232 return retVal;
233
234 return RT_ERR_OK;
235 }
236
237 /* Function Name:
238 * rtk_cpu_awarePort_get
239 * Description:
240 * Get CPU aware port mask.
241 * Input:
242 * None
243 * Output:
244 * pPortmask - Port mask.
245 * Return:
246 * RT_ERR_OK - OK
247 * RT_ERR_FAILED - Failed
248 * RT_ERR_SMI - SMI access error
249 * Note:
250 * The API can get configured CPU aware port mask.
251 */
252 rtk_api_ret_t rtk_cpu_awarePort_get(rtk_portmask_t *pPortmask)
253 {
254 rtk_api_ret_t retVal;
255 rtk_uint32 pmsk;
256
257 /* Check initialization state */
258 RTK_CHK_INIT_STATE();
259
260 if(NULL == pPortmask)
261 return RT_ERR_NULL_POINTER;
262
263 if ((retVal = rtl8367c_getAsicCputagPortmask(&pmsk)) != RT_ERR_OK)
264 return retVal;
265
266 if(rtk_switch_portmask_P2L_get(pmsk, pPortmask) != RT_ERR_OK)
267 return RT_ERR_FAILED;
268
269 return RT_ERR_OK;
270 }
271
272 /* Function Name:
273 * rtk_cpu_tagPosition_set
274 * Description:
275 * Set CPU tag position.
276 * Input:
277 * position - CPU tag position.
278 * Output:
279 * None
280 * Return:
281 * RT_ERR_OK - OK
282 * RT_ERR_FAILED - Failed
283 * RT_ERR_SMI - SMI access error
284 * RT_ERR_INPUT - Invalid input.
285 * Note:
286 * The API can set CPU tag position.
287 */
288 rtk_api_ret_t rtk_cpu_tagPosition_set(rtk_cpu_position_t position)
289 {
290 rtk_api_ret_t retVal;
291
292 /* Check initialization state */
293 RTK_CHK_INIT_STATE();
294
295 if (position >= CPU_POS_END)
296 return RT_ERR_INPUT;
297
298 if ((retVal = rtl8367c_setAsicCputagPosition(position)) != RT_ERR_OK)
299 return retVal;
300
301 return RT_ERR_OK;
302 }
303
304 /* Function Name:
305 * rtk_cpu_tagPosition_get
306 * Description:
307 * Get CPU tag position.
308 * Input:
309 * None
310 * Output:
311 * pPosition - CPU tag position.
312 * Return:
313 * RT_ERR_OK - OK
314 * RT_ERR_FAILED - Failed
315 * RT_ERR_SMI - SMI access error
316 * RT_ERR_INPUT - Invalid input.
317 * Note:
318 * The API can get CPU tag position.
319 */
320 rtk_api_ret_t rtk_cpu_tagPosition_get(rtk_cpu_position_t *pPosition)
321 {
322 rtk_api_ret_t retVal;
323
324 /* Check initialization state */
325 RTK_CHK_INIT_STATE();
326
327 if(NULL == pPosition)
328 return RT_ERR_NULL_POINTER;
329
330 if ((retVal = rtl8367c_getAsicCputagPosition(pPosition)) != RT_ERR_OK)
331 return retVal;
332
333 return RT_ERR_OK;
334 }
335
336 /* Function Name:
337 * rtk_cpu_tagLength_set
338 * Description:
339 * Set CPU tag length.
340 * Input:
341 * length - CPU tag length.
342 * Output:
343 * None
344 * Return:
345 * RT_ERR_OK - OK
346 * RT_ERR_FAILED - Failed
347 * RT_ERR_SMI - SMI access error
348 * RT_ERR_INPUT - Invalid input.
349 * Note:
350 * The API can set CPU tag length.
351 */
352 rtk_api_ret_t rtk_cpu_tagLength_set(rtk_cpu_tag_length_t length)
353 {
354 rtk_api_ret_t retVal;
355
356 /* Check initialization state */
357 RTK_CHK_INIT_STATE();
358
359 if (length >= CPU_LEN_END)
360 return RT_ERR_INPUT;
361
362 if ((retVal = rtl8367c_setAsicCputagMode(length)) != RT_ERR_OK)
363 return retVal;
364
365 return RT_ERR_OK;
366 }
367
368 /* Function Name:
369 * rtk_cpu_tagLength_get
370 * Description:
371 * Get CPU tag length.
372 * Input:
373 * None
374 * Output:
375 * pLength - CPU tag length.
376 * Return:
377 * RT_ERR_OK - OK
378 * RT_ERR_FAILED - Failed
379 * RT_ERR_SMI - SMI access error
380 * RT_ERR_INPUT - Invalid input.
381 * Note:
382 * The API can get CPU tag length.
383 */
384 rtk_api_ret_t rtk_cpu_tagLength_get(rtk_cpu_tag_length_t *pLength)
385 {
386 rtk_api_ret_t retVal;
387
388 /* Check initialization state */
389 RTK_CHK_INIT_STATE();
390
391 if(NULL == pLength)
392 return RT_ERR_NULL_POINTER;
393
394 if ((retVal = rtl8367c_getAsicCputagMode(pLength)) != RT_ERR_OK)
395 return retVal;
396
397 return RT_ERR_OK;
398 }
399
400 /* Function Name:
401 * rtk_cpu_priRemap_set
402 * Description:
403 * Configure CPU priorities mapping to internal absolute priority.
404 * Input:
405 * int_pri - internal priority value.
406 * new_pri - new internal priority value.
407 * Output:
408 * None
409 * Return:
410 * RT_ERR_OK - OK
411 * RT_ERR_FAILED - Failed
412 * RT_ERR_SMI - SMI access error
413 * RT_ERR_INPUT - Invalid input parameters.
414 * RT_ERR_VLAN_PRIORITY - Invalid 1p priority.
415 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
416 * Note:
417 * Priority of CPU tag assignment for internal asic priority, and it is used for queue usage and packet scheduling.
418 */
419 rtk_api_ret_t rtk_cpu_priRemap_set(rtk_pri_t int_pri, rtk_pri_t new_pri)
420 {
421 rtk_api_ret_t retVal;
422
423 /* Check initialization state */
424 RTK_CHK_INIT_STATE();
425
426 if (new_pri > RTL8367C_PRIMAX || int_pri > RTL8367C_PRIMAX)
427 return RT_ERR_VLAN_PRIORITY;
428
429 if ((retVal = rtl8367c_setAsicCputagPriorityRemapping(int_pri, new_pri)) != RT_ERR_OK)
430 return retVal;
431
432 return RT_ERR_OK;
433 }
434
435 /* Function Name:
436 * rtk_cpu_priRemap_get
437 * Description:
438 * Configure CPU priorities mapping to internal absolute priority.
439 * Input:
440 * int_pri - internal priority value.
441 * Output:
442 * pNew_pri - new internal priority value.
443 * Return:
444 * RT_ERR_OK - OK
445 * RT_ERR_FAILED - Failed
446 * RT_ERR_SMI - SMI access error
447 * RT_ERR_INPUT - Invalid input parameters.
448 * RT_ERR_VLAN_PRIORITY - Invalid 1p priority.
449 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
450 * Note:
451 * Priority of CPU tag assignment for internal asic priority, and it is used for queue usage and packet scheduling.
452 */
453 rtk_api_ret_t rtk_cpu_priRemap_get(rtk_pri_t int_pri, rtk_pri_t *pNew_pri)
454 {
455 rtk_api_ret_t retVal;
456
457 /* Check initialization state */
458 RTK_CHK_INIT_STATE();
459
460 if(NULL == pNew_pri)
461 return RT_ERR_NULL_POINTER;
462
463 if (int_pri > RTL8367C_PRIMAX)
464 return RT_ERR_QOS_INT_PRIORITY;
465
466 if ((retVal = rtl8367c_getAsicCputagPriorityRemapping(int_pri, pNew_pri)) != RT_ERR_OK)
467 return retVal;
468
469 return RT_ERR_OK;
470 }
471
472 /* Function Name:
473 * rtk_cpu_acceptLength_set
474 * Description:
475 * Set CPU accept length.
476 * Input:
477 * length - CPU tag length.
478 * Output:
479 * None
480 * Return:
481 * RT_ERR_OK - OK
482 * RT_ERR_FAILED - Failed
483 * RT_ERR_SMI - SMI access error
484 * RT_ERR_INPUT - Invalid input.
485 * Note:
486 * The API can set CPU accept length.
487 */
488 rtk_api_ret_t rtk_cpu_acceptLength_set(rtk_cpu_rx_length_t length)
489 {
490 rtk_api_ret_t retVal;
491
492 /* Check initialization state */
493 RTK_CHK_INIT_STATE();
494
495 if (length >= CPU_RX_END)
496 return RT_ERR_INPUT;
497
498 if ((retVal = rtl8367c_setAsicCputagRxMinLength(length)) != RT_ERR_OK)
499 return retVal;
500
501 return RT_ERR_OK;
502 }
503
504 /* Function Name:
505 * rtk_cpu_acceptLength_get
506 * Description:
507 * Get CPU accept length.
508 * Input:
509 * None
510 * Output:
511 * pLength - CPU tag length.
512 * Return:
513 * RT_ERR_OK - OK
514 * RT_ERR_FAILED - Failed
515 * RT_ERR_SMI - SMI access error
516 * RT_ERR_INPUT - Invalid input.
517 * Note:
518 * The API can get CPU accept length.
519 */
520 rtk_api_ret_t rtk_cpu_acceptLength_get(rtk_cpu_rx_length_t *pLength)
521 {
522 rtk_api_ret_t retVal;
523
524 /* Check initialization state */
525 RTK_CHK_INIT_STATE();
526
527 if(NULL == pLength)
528 return RT_ERR_NULL_POINTER;
529
530 if ((retVal = rtl8367c_getAsicCputagRxMinLength(pLength)) != RT_ERR_OK)
531 return retVal;
532
533 return RT_ERR_OK;
534 }
535
536
537