mediatek: add patches for 5.15 and kernel config for mt7622
[openwrt/openwrt.git] / target / linux / mediatek / files / drivers / net / phy / rtk / rtl8367c / qos.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 QoS module.
15 *
16 */
17
18 #include <rtk_switch.h>
19 #include <rtk_error.h>
20 #include <qos.h>
21 #include <string.h>
22
23 #include <rtl8367c_asicdrv.h>
24 #include <rtl8367c_asicdrv_qos.h>
25 #include <rtl8367c_asicdrv_fc.h>
26 #include <rtl8367c_asicdrv_scheduling.h>
27
28 /* Function Name:
29 * rtk_qos_init
30 * Description:
31 * Configure Qos default settings with queue number assigment to each port.
32 * Input:
33 * queueNum - Queue number of each port.
34 * Output:
35 * None
36 * Return:
37 * RT_ERR_OK - OK
38 * RT_ERR_FAILED - Failed
39 * RT_ERR_SMI - SMI access error
40 * RT_ERR_QUEUE_NUM - Invalid queue number.
41 * RT_ERR_INPUT - Invalid input parameters.
42 * Note:
43 * This API will initialize related Qos setting with queue number assigment.
44 * The queue number is from 1 to 8.
45 */
46 rtk_api_ret_t rtk_qos_init(rtk_queue_num_t queueNum)
47 {
48 CONST_T rtk_uint16 g_prioritytToQid[8][8]= {
49 {0, 0,0,0,0,0,0,0},
50 {0, 0,0,0,7,7,7,7},
51 {0, 0,0,0,1,1,7,7},
52 {0, 0,1,1,2,2,7,7},
53 {0, 0,1,1,2,3,7,7},
54 {0, 0,1,2,3,4,7,7},
55 {0, 0,1,2,3,4,5,7},
56 {0,1,2,3,4,5,6,7}
57 };
58
59 CONST_T rtk_uint32 g_priorityDecision[8] = {0x01, 0x80,0x04,0x02,0x20,0x40,0x10,0x08};
60 CONST_T rtk_uint32 g_prioritytRemap[8] = {0,1,2,3,4,5,6,7};
61
62 rtk_api_ret_t retVal;
63 rtk_uint32 qmapidx;
64 rtk_uint32 priority;
65 rtk_uint32 priDec;
66 rtk_uint32 port;
67 rtk_uint32 dscp;
68
69 /* Check initialization state */
70 RTK_CHK_INIT_STATE();
71
72 if (queueNum <= 0 || queueNum > RTK_MAX_NUM_OF_QUEUE)
73 return RT_ERR_QUEUE_NUM;
74
75 /*Set Output Queue Number*/
76 if (RTK_MAX_NUM_OF_QUEUE == queueNum)
77 qmapidx = 0;
78 else
79 qmapidx = queueNum;
80
81 RTK_SCAN_ALL_PHY_PORTMASK(port)
82 {
83 if ((retVal = rtl8367c_setAsicOutputQueueMappingIndex(port, qmapidx)) != RT_ERR_OK)
84 return retVal;
85 }
86
87 /*Set Priority to Qid*/
88 for (priority = 0; priority <= RTK_PRIMAX; priority++)
89 {
90 if ((retVal = rtl8367c_setAsicPriorityToQIDMappingTable(queueNum - 1, priority, g_prioritytToQid[queueNum - 1][priority])) != RT_ERR_OK)
91 return retVal;
92 }
93
94 /*Set Flow Control Type to Ingress Flow Control*/
95 if ((retVal = rtl8367c_setAsicFlowControlSelect(FC_INGRESS)) != RT_ERR_OK)
96 return retVal;
97
98
99 /*Priority Decision Order*/
100 for (priDec = 0;priDec < PRIDEC_END;priDec++)
101 {
102 if ((retVal = rtl8367c_setAsicPriorityDecision(PRIDECTBL_IDX0, priDec, g_priorityDecision[priDec])) != RT_ERR_OK)
103 return retVal;
104 if ((retVal = rtl8367c_setAsicPriorityDecision(PRIDECTBL_IDX1, priDec, g_priorityDecision[priDec])) != RT_ERR_OK)
105 return retVal;
106 }
107
108 /*Set Port-based Priority to 0*/
109 RTK_SCAN_ALL_PHY_PORTMASK(port)
110 {
111 if ((retVal = rtl8367c_setAsicPriorityPortBased(port, 0)) != RT_ERR_OK)
112 return retVal;
113 }
114
115 /*Disable 1p Remarking*/
116 RTK_SCAN_ALL_PHY_PORTMASK(port)
117 {
118 if ((retVal = rtl8367c_setAsicRemarkingDot1pAbility(port, DISABLED)) != RT_ERR_OK)
119 return retVal;
120 }
121
122 /*Disable DSCP Remarking*/
123 if ((retVal = rtl8367c_setAsicRemarkingDscpAbility(DISABLED)) != RT_ERR_OK)
124 return retVal;
125
126 /*Set 1p & DSCP Priority Remapping & Remarking*/
127 for (priority = 0; priority <= RTL8367C_PRIMAX; priority++)
128 {
129 if ((retVal = rtl8367c_setAsicPriorityDot1qRemapping(priority, g_prioritytRemap[priority])) != RT_ERR_OK)
130 return retVal;
131
132 if ((retVal = rtl8367c_setAsicRemarkingDot1pParameter(priority, 0)) != RT_ERR_OK)
133 return retVal;
134
135 if ((retVal = rtl8367c_setAsicRemarkingDscpParameter(priority, 0)) != RT_ERR_OK)
136 return retVal;
137 }
138
139 /*Set DSCP Priority*/
140 for (dscp = 0; dscp <= 63; dscp++)
141 {
142 if ((retVal = rtl8367c_setAsicPriorityDscpBased(dscp, 0)) != RT_ERR_OK)
143 return retVal;
144 }
145
146 /* Finetune B/T value */
147 if((retVal = rtl8367c_setAsicReg(0x1722, 0x1158)) != RT_ERR_OK)
148 return retVal;
149
150 return RT_ERR_OK;
151 }
152
153 /* Function Name:
154 * rtk_qos_priSel_set
155 * Description:
156 * Configure the priority order among different priority mechanism.
157 * Input:
158 * index - Priority decision table index (0~1)
159 * pPriDec - Priority assign for port, dscp, 802.1p, cvlan, svlan, acl based priority decision.
160 * Output:
161 * None
162 * Return:
163 * RT_ERR_OK - OK
164 * RT_ERR_FAILED - Failed
165 * RT_ERR_SMI - SMI access error
166 * RT_ERR_QOS_SEL_PRI_SOURCE - Invalid priority decision source parameter.
167 * Note:
168 * ASIC will follow user priority setting of mechanisms to select mapped queue priority for receiving frame.
169 * If two priority mechanisms are the same, the ASIC will chose the highest priority from mechanisms to
170 * assign queue priority to receiving frame.
171 * The priority sources are:
172 * - PRIDEC_PORT
173 * - PRIDEC_ACL
174 * - PRIDEC_DSCP
175 * - PRIDEC_1Q
176 * - PRIDEC_1AD
177 * - PRIDEC_CVLAN
178 * - PRIDEC_DA
179 * - PRIDEC_SA
180 */
181 rtk_api_ret_t rtk_qos_priSel_set(rtk_qos_priDecTbl_t index, rtk_priority_select_t *pPriDec)
182 {
183 rtk_api_ret_t retVal;
184 rtk_uint32 port_pow;
185 rtk_uint32 dot1q_pow;
186 rtk_uint32 dscp_pow;
187 rtk_uint32 acl_pow;
188 rtk_uint32 svlan_pow;
189 rtk_uint32 cvlan_pow;
190 rtk_uint32 smac_pow;
191 rtk_uint32 dmac_pow;
192 rtk_uint32 i;
193
194 /* Check initialization state */
195 RTK_CHK_INIT_STATE();
196
197 if (index < 0 || index >= PRIDECTBL_END)
198 return RT_ERR_ENTRY_INDEX;
199
200 if (pPriDec->port_pri >= 8 || pPriDec->dot1q_pri >= 8 || pPriDec->acl_pri >= 8 || pPriDec->dscp_pri >= 8 ||
201 pPriDec->cvlan_pri >= 8 || pPriDec->svlan_pri >= 8 || pPriDec->dmac_pri >= 8 || pPriDec->smac_pri >= 8)
202 return RT_ERR_QOS_SEL_PRI_SOURCE;
203
204 port_pow = 1;
205 for (i = pPriDec->port_pri; i > 0; i--)
206 port_pow = (port_pow)*2;
207
208 dot1q_pow = 1;
209 for (i = pPriDec->dot1q_pri; i > 0; i--)
210 dot1q_pow = (dot1q_pow)*2;
211
212 acl_pow = 1;
213 for (i = pPriDec->acl_pri; i > 0; i--)
214 acl_pow = (acl_pow)*2;
215
216 dscp_pow = 1;
217 for (i = pPriDec->dscp_pri; i > 0; i--)
218 dscp_pow = (dscp_pow)*2;
219
220 svlan_pow = 1;
221 for (i = pPriDec->svlan_pri; i > 0; i--)
222 svlan_pow = (svlan_pow)*2;
223
224 cvlan_pow = 1;
225 for (i = pPriDec->cvlan_pri; i > 0; i--)
226 cvlan_pow = (cvlan_pow)*2;
227
228 dmac_pow = 1;
229 for (i = pPriDec->dmac_pri; i > 0; i--)
230 dmac_pow = (dmac_pow)*2;
231
232 smac_pow = 1;
233 for (i = pPriDec->smac_pri; i > 0; i--)
234 smac_pow = (smac_pow)*2;
235
236 if ((retVal = rtl8367c_setAsicPriorityDecision(index, PRIDEC_PORT, port_pow)) != RT_ERR_OK)
237 return retVal;
238
239 if ((retVal = rtl8367c_setAsicPriorityDecision(index, PRIDEC_ACL, acl_pow)) != RT_ERR_OK)
240 return retVal;
241
242 if ((retVal = rtl8367c_setAsicPriorityDecision(index, PRIDEC_DSCP, dscp_pow)) != RT_ERR_OK)
243 return retVal;
244
245 if ((retVal = rtl8367c_setAsicPriorityDecision(index, PRIDEC_1Q, dot1q_pow)) != RT_ERR_OK)
246 return retVal;
247
248 if ((retVal = rtl8367c_setAsicPriorityDecision(index, PRIDEC_1AD, svlan_pow)) != RT_ERR_OK)
249 return retVal;
250
251 if ((retVal = rtl8367c_setAsicPriorityDecision(index, PRIDEC_CVLAN, cvlan_pow)) != RT_ERR_OK)
252 return retVal;
253
254 if ((retVal = rtl8367c_setAsicPriorityDecision(index, PRIDEC_DA, dmac_pow)) != RT_ERR_OK)
255 return retVal;
256
257 if ((retVal = rtl8367c_setAsicPriorityDecision(index, PRIDEC_SA, smac_pow)) != RT_ERR_OK)
258 return retVal;
259
260 return RT_ERR_OK;
261 }
262
263 /* Function Name:
264 * rtk_qos_priSel_get
265 * Description:
266 * Get the priority order configuration among different priority mechanism.
267 * Input:
268 * index - Priority decision table index (0~1)
269 * Output:
270 * pPriDec - Priority assign for port, dscp, 802.1p, cvlan, svlan, acl based priority decision .
271 * Return:
272 * RT_ERR_OK - OK
273 * RT_ERR_FAILED - Failed
274 * RT_ERR_SMI - SMI access error
275 * Note:
276 * ASIC will follow user priority setting of mechanisms to select mapped queue priority for receiving frame.
277 * If two priority mechanisms are the same, the ASIC will chose the highest priority from mechanisms to
278 * assign queue priority to receiving frame.
279 * The priority sources are:
280 * - PRIDEC_PORT,
281 * - PRIDEC_ACL,
282 * - PRIDEC_DSCP,
283 * - PRIDEC_1Q,
284 * - PRIDEC_1AD,
285 * - PRIDEC_CVLAN,
286 * - PRIDEC_DA,
287 * - PRIDEC_SA,
288 */
289 rtk_api_ret_t rtk_qos_priSel_get(rtk_qos_priDecTbl_t index, rtk_priority_select_t *pPriDec)
290 {
291
292 rtk_api_ret_t retVal;
293 rtk_int32 i;
294 rtk_uint32 port_pow;
295 rtk_uint32 dot1q_pow;
296 rtk_uint32 dscp_pow;
297 rtk_uint32 acl_pow;
298 rtk_uint32 svlan_pow;
299 rtk_uint32 cvlan_pow;
300 rtk_uint32 smac_pow;
301 rtk_uint32 dmac_pow;
302
303 /* Check initialization state */
304 RTK_CHK_INIT_STATE();
305
306 if (index < 0 || index >= PRIDECTBL_END)
307 return RT_ERR_ENTRY_INDEX;
308
309 if ((retVal = rtl8367c_getAsicPriorityDecision(index, PRIDEC_PORT, &port_pow)) != RT_ERR_OK)
310 return retVal;
311
312 if ((retVal = rtl8367c_getAsicPriorityDecision(index, PRIDEC_ACL, &acl_pow)) != RT_ERR_OK)
313 return retVal;
314
315 if ((retVal = rtl8367c_getAsicPriorityDecision(index, PRIDEC_DSCP, &dscp_pow)) != RT_ERR_OK)
316 return retVal;
317
318 if ((retVal = rtl8367c_getAsicPriorityDecision(index, PRIDEC_1Q, &dot1q_pow)) != RT_ERR_OK)
319 return retVal;
320
321 if ((retVal = rtl8367c_getAsicPriorityDecision(index, PRIDEC_1AD, &svlan_pow)) != RT_ERR_OK)
322 return retVal;
323
324 if ((retVal = rtl8367c_getAsicPriorityDecision(index, PRIDEC_CVLAN, &cvlan_pow)) != RT_ERR_OK)
325 return retVal;
326
327 if ((retVal = rtl8367c_getAsicPriorityDecision(index, PRIDEC_DA, &dmac_pow)) != RT_ERR_OK)
328 return retVal;
329
330 if ((retVal = rtl8367c_getAsicPriorityDecision(index, PRIDEC_SA, &smac_pow)) != RT_ERR_OK)
331 return retVal;
332
333 for (i = 31; i >= 0; i--)
334 {
335 if (port_pow & (1 << i))
336 {
337 pPriDec->port_pri = i;
338 break;
339 }
340 }
341
342 for (i = 31; i >= 0; i--)
343 {
344 if (dot1q_pow & (1 << i))
345 {
346 pPriDec->dot1q_pri = i;
347 break;
348 }
349 }
350
351 for (i = 31; i >= 0; i--)
352 {
353 if (acl_pow & (1 << i))
354 {
355 pPriDec->acl_pri = i;
356 break;
357 }
358 }
359
360 for (i = 31; i >= 0; i--)
361 {
362 if (dscp_pow & (1 << i))
363 {
364 pPriDec->dscp_pri = i;
365 break;
366 }
367 }
368
369 for (i = 31; i >= 0; i--)
370 {
371 if (svlan_pow & (1 << i))
372 {
373 pPriDec->svlan_pri = i;
374 break;
375 }
376 }
377
378 for (i = 31;i >= 0; i--)
379 {
380 if (cvlan_pow & (1 << i))
381 {
382 pPriDec->cvlan_pri = i;
383 break;
384 }
385 }
386
387 for (i = 31; i >= 0; i--)
388 {
389 if (dmac_pow&(1<<i))
390 {
391 pPriDec->dmac_pri = i;
392 break;
393 }
394 }
395
396 for (i = 31; i >= 0; i--)
397 {
398 if (smac_pow & (1 << i))
399 {
400 pPriDec->smac_pri = i;
401 break;
402 }
403 }
404
405 return RT_ERR_OK;
406 }
407
408 /* Function Name:
409 * rtk_qos_1pPriRemap_set
410 * Description:
411 * Configure 1Q priorities mapping to internal absolute priority.
412 * Input:
413 * dot1p_pri - 802.1p priority value.
414 * int_pri - internal priority value.
415 * Output:
416 * None
417 * Return:
418 * RT_ERR_OK - OK
419 * RT_ERR_FAILED - Failed
420 * RT_ERR_SMI - SMI access error
421 * RT_ERR_INPUT - Invalid input parameters.
422 * RT_ERR_VLAN_PRIORITY - Invalid 1p priority.
423 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
424 * Note:
425 * Priority of 802.1Q assignment for internal asic priority, and it is used for queue usage and packet scheduling.
426 */
427 rtk_api_ret_t rtk_qos_1pPriRemap_set(rtk_pri_t dot1p_pri, rtk_pri_t int_pri)
428 {
429 rtk_api_ret_t retVal;
430
431 /* Check initialization state */
432 RTK_CHK_INIT_STATE();
433
434 if (dot1p_pri > RTL8367C_PRIMAX || int_pri > RTL8367C_PRIMAX)
435 return RT_ERR_VLAN_PRIORITY;
436
437 if ((retVal = rtl8367c_setAsicPriorityDot1qRemapping(dot1p_pri, int_pri)) != RT_ERR_OK)
438 return retVal;
439
440 return RT_ERR_OK;
441 }
442
443 /* Function Name:
444 * rtk_qos_1pPriRemap_get
445 * Description:
446 * Get 1Q priorities mapping to internal absolute priority.
447 * Input:
448 * dot1p_pri - 802.1p priority value .
449 * Output:
450 * pInt_pri - internal priority value.
451 * Return:
452 * RT_ERR_OK - OK
453 * RT_ERR_FAILED - Failed
454 * RT_ERR_SMI - SMI access error
455 * RT_ERR_VLAN_PRIORITY - Invalid priority.
456 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
457 * Note:
458 * Priority of 802.1Q assigment for internal asic priority, and it is uesed for queue usage and packet scheduling.
459 */
460 rtk_api_ret_t rtk_qos_1pPriRemap_get(rtk_pri_t dot1p_pri, rtk_pri_t *pInt_pri)
461 {
462 rtk_api_ret_t retVal;
463
464 /* Check initialization state */
465 RTK_CHK_INIT_STATE();
466
467 if (dot1p_pri > RTL8367C_PRIMAX)
468 return RT_ERR_QOS_INT_PRIORITY;
469
470 if ((retVal = rtl8367c_getAsicPriorityDot1qRemapping(dot1p_pri, pInt_pri)) != RT_ERR_OK)
471 return retVal;
472
473 return RT_ERR_OK;
474 }
475
476 /* Function Name:
477 * rtk_qos_dscpPriRemap_set
478 * Description:
479 * Map dscp value to internal priority.
480 * Input:
481 * dscp - Dscp value of receiving frame
482 * int_pri - internal priority value .
483 * Output:
484 * None
485 * Return:
486 * RT_ERR_OK - OK
487 * RT_ERR_FAILED - Failed
488 * RT_ERR_SMI - SMI access error
489 * RT_ERR_INPUT - Invalid input parameters.
490 * RT_ERR_QOS_DSCP_VALUE - Invalid DSCP value.
491 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
492 * Note:
493 * The Differentiated Service Code Point is a selector for router's per-hop behaviors. As a selector, there is no implication that a numerically
494 * greater DSCP implies a better network service. As can be seen, the DSCP totally overlaps the old precedence field of TOS. So if values of
495 * DSCP are carefully chosen then backward compatibility can be achieved.
496 */
497 rtk_api_ret_t rtk_qos_dscpPriRemap_set(rtk_dscp_t dscp, rtk_pri_t int_pri)
498 {
499 rtk_api_ret_t retVal;
500
501 /* Check initialization state */
502 RTK_CHK_INIT_STATE();
503
504 if (int_pri > RTL8367C_PRIMAX )
505 return RT_ERR_QOS_INT_PRIORITY;
506
507 if (dscp > RTL8367C_DSCPMAX)
508 return RT_ERR_QOS_DSCP_VALUE;
509
510 if ((retVal = rtl8367c_setAsicPriorityDscpBased(dscp, int_pri)) != RT_ERR_OK)
511 return retVal;
512
513 return RT_ERR_OK;
514 }
515
516 /* Function Name:
517 * rtk_qos_dscpPriRemap_get
518 * Description:
519 * Get dscp value to internal priority.
520 * Input:
521 * dscp - Dscp value of receiving frame
522 * Output:
523 * pInt_pri - internal priority value.
524 * Return:
525 * RT_ERR_OK - OK
526 * RT_ERR_FAILED - Failed
527 * RT_ERR_SMI - SMI access error
528 * RT_ERR_QOS_DSCP_VALUE - Invalid DSCP value.
529 * Note:
530 * The Differentiated Service Code Point is a selector for router's per-hop behaviors. As a selector, there is no implication that a numerically
531 * greater DSCP implies a better network service. As can be seen, the DSCP totally overlaps the old precedence field of TOS. So if values of
532 * DSCP are carefully chosen then backward compatibility can be achieved.
533 */
534 rtk_api_ret_t rtk_qos_dscpPriRemap_get(rtk_dscp_t dscp, rtk_pri_t *pInt_pri)
535 {
536 rtk_api_ret_t retVal;
537
538 /* Check initialization state */
539 RTK_CHK_INIT_STATE();
540
541 if (dscp > RTL8367C_DSCPMAX)
542 return RT_ERR_QOS_DSCP_VALUE;
543
544 if ((retVal = rtl8367c_getAsicPriorityDscpBased(dscp, pInt_pri)) != RT_ERR_OK)
545 return retVal;
546
547 return RT_ERR_OK;
548 }
549
550 /* Function Name:
551 * rtk_qos_portPri_set
552 * Description:
553 * Configure priority usage to each port.
554 * Input:
555 * port - Port id.
556 * int_pri - internal priority value.
557 * Output:
558 * None
559 * Return:
560 * RT_ERR_OK - OK
561 * RT_ERR_FAILED - Failed
562 * RT_ERR_SMI - SMI access error
563 * RT_ERR_PORT_ID - Invalid port number.
564 * RT_ERR_QOS_SEL_PORT_PRI - Invalid port priority.
565 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
566 * Note:
567 * The API can set priority of port assignments for queue usage and packet scheduling.
568 */
569 rtk_api_ret_t rtk_qos_portPri_set(rtk_port_t port, rtk_pri_t int_pri)
570 {
571 rtk_api_ret_t retVal;
572
573 /* Check initialization state */
574 RTK_CHK_INIT_STATE();
575
576 /* Check Port Valid */
577 RTK_CHK_PORT_VALID(port);
578
579 if (int_pri > RTL8367C_PRIMAX )
580 return RT_ERR_QOS_INT_PRIORITY;
581
582 if ((retVal = rtl8367c_setAsicPriorityPortBased(rtk_switch_port_L2P_get(port), int_pri)) != RT_ERR_OK)
583 return retVal;
584
585 return RT_ERR_OK;
586 }
587
588 /* Function Name:
589 * rtk_qos_portPri_get
590 * Description:
591 * Get priority usage to each port.
592 * Input:
593 * port - Port id.
594 * Output:
595 * pInt_pri - internal priority value.
596 * Return:
597 * RT_ERR_OK - OK
598 * RT_ERR_FAILED - Failed
599 * RT_ERR_SMI - SMI access error
600 * RT_ERR_PORT_ID - Invalid port number.
601 * RT_ERR_INPUT - Invalid input parameters.
602 * Note:
603 * The API can get priority of port assignments for queue usage and packet scheduling.
604 */
605 rtk_api_ret_t rtk_qos_portPri_get(rtk_port_t port, rtk_pri_t *pInt_pri)
606 {
607 rtk_api_ret_t retVal;
608
609 /* Check initialization state */
610 RTK_CHK_INIT_STATE();
611
612 /* Check Port Valid */
613 RTK_CHK_PORT_VALID(port);
614
615 if ((retVal = rtl8367c_getAsicPriorityPortBased(rtk_switch_port_L2P_get(port), pInt_pri)) != RT_ERR_OK)
616 return retVal;
617
618
619 return RT_ERR_OK;
620 }
621
622 /* Function Name:
623 * rtk_qos_queueNum_set
624 * Description:
625 * Set output queue number for each port.
626 * Input:
627 * port - Port id.
628 * index - Mapping queue number (1~8)
629 * Output:
630 * None
631 * Return:
632 * RT_ERR_OK - OK
633 * RT_ERR_FAILED - Failed
634 * RT_ERR_SMI - SMI access error
635 * RT_ERR_PORT_ID - Invalid port number.
636 * RT_ERR_QUEUE_NUM - Invalid queue number.
637 * Note:
638 * The API can set the output queue number of the specified port. The queue number is from 1 to 8.
639 */
640 rtk_api_ret_t rtk_qos_queueNum_set(rtk_port_t port, rtk_queue_num_t queue_num)
641 {
642 rtk_api_ret_t retVal;
643
644 /* Check initialization state */
645 RTK_CHK_INIT_STATE();
646
647 /* Check Port Valid */
648 RTK_CHK_PORT_VALID(port);
649
650 if ((0 == queue_num) || (queue_num > RTK_MAX_NUM_OF_QUEUE))
651 return RT_ERR_FAILED;
652
653 if (RTK_MAX_NUM_OF_QUEUE == queue_num)
654 queue_num = 0;
655
656 if ((retVal = rtl8367c_setAsicOutputQueueMappingIndex(rtk_switch_port_L2P_get(port), queue_num)) != RT_ERR_OK)
657 return retVal;
658
659 return RT_ERR_OK;
660 }
661
662 /* Function Name:
663 * rtk_qos_queueNum_get
664 * Description:
665 * Get output queue number.
666 * Input:
667 * port - Port id.
668 * Output:
669 * pQueue_num - Mapping queue number
670 * Return:
671 * RT_ERR_OK - OK
672 * RT_ERR_FAILED - Failed
673 * RT_ERR_SMI - SMI access error
674 * RT_ERR_PORT_ID - Invalid port number.
675 * Note:
676 * The API will return the output queue number of the specified port. The queue number is from 1 to 8.
677 */
678 rtk_api_ret_t rtk_qos_queueNum_get(rtk_port_t port, rtk_queue_num_t *pQueue_num)
679 {
680 rtk_api_ret_t retVal;
681 rtk_uint32 qidx;
682
683 /* Check initialization state */
684 RTK_CHK_INIT_STATE();
685
686 /* Check Port Valid */
687 RTK_CHK_PORT_VALID(port);
688
689 if ((retVal = rtl8367c_getAsicOutputQueueMappingIndex(rtk_switch_port_L2P_get(port), &qidx)) != RT_ERR_OK)
690 return retVal;
691
692 if (0 == qidx)
693 *pQueue_num = 8;
694 else
695 *pQueue_num = qidx;
696
697 return RT_ERR_OK;
698 }
699
700 /* Function Name:
701 * rtk_qos_priMap_set
702 * Description:
703 * Set output queue number for each port.
704 * Input:
705 * queue_num - Queue number usage.
706 * pPri2qid - Priority mapping to queue ID.
707 * Output:
708 * None
709 * Return:
710 * RT_ERR_OK - OK
711 * RT_ERR_FAILED - Failed
712 * RT_ERR_SMI - SMI access error
713 * RT_ERR_INPUT - Invalid input parameters.
714 * RT_ERR_QUEUE_NUM - Invalid queue number.
715 * RT_ERR_QUEUE_ID - Invalid queue id.
716 * RT_ERR_PORT_ID - Invalid port number.
717 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
718 * Note:
719 * ASIC supports priority mapping to queue with different queue number from 1 to 8.
720 * For different queue numbers usage, ASIC supports different internal available queue IDs.
721 */
722 rtk_api_ret_t rtk_qos_priMap_set(rtk_queue_num_t queue_num, rtk_qos_pri2queue_t *pPri2qid)
723 {
724 rtk_api_ret_t retVal;
725 rtk_uint32 pri;
726
727 /* Check initialization state */
728 RTK_CHK_INIT_STATE();
729
730 if ((0 == queue_num) || (queue_num > RTK_MAX_NUM_OF_QUEUE))
731 return RT_ERR_QUEUE_NUM;
732
733 for (pri = 0; pri <= RTK_PRIMAX; pri++)
734 {
735 if (pPri2qid->pri2queue[pri] > RTK_QIDMAX)
736 return RT_ERR_QUEUE_ID;
737
738 if ((retVal = rtl8367c_setAsicPriorityToQIDMappingTable(queue_num - 1, pri, pPri2qid->pri2queue[pri])) != RT_ERR_OK)
739 return retVal;
740 }
741
742 return RT_ERR_OK;
743 }
744
745 /* Function Name:
746 * rtk_qos_priMap_get
747 * Description:
748 * Get priority to queue ID mapping table parameters.
749 * Input:
750 * queue_num - Queue number usage.
751 * Output:
752 * pPri2qid - Priority mapping to queue ID.
753 * Return:
754 * RT_ERR_OK - OK
755 * RT_ERR_FAILED - Failed
756 * RT_ERR_SMI - SMI access error
757 * RT_ERR_INPUT - Invalid input parameters.
758 * RT_ERR_QUEUE_NUM - Invalid queue number.
759 * Note:
760 * The API can return the mapping queue id of the specified priority and queue number.
761 * The queue number is from 1 to 8.
762 */
763 rtk_api_ret_t rtk_qos_priMap_get(rtk_queue_num_t queue_num, rtk_qos_pri2queue_t *pPri2qid)
764 {
765 rtk_api_ret_t retVal;
766 rtk_uint32 pri;
767
768 /* Check initialization state */
769 RTK_CHK_INIT_STATE();
770
771 if ((0 == queue_num) || (queue_num > RTK_MAX_NUM_OF_QUEUE))
772 return RT_ERR_QUEUE_NUM;
773
774 for (pri = 0; pri <= RTK_PRIMAX; pri++)
775 {
776 if ((retVal = rtl8367c_getAsicPriorityToQIDMappingTable(queue_num-1, pri, &pPri2qid->pri2queue[pri])) != RT_ERR_OK)
777 return retVal;
778 }
779
780 return RT_ERR_OK;
781 }
782
783 /* Function Name:
784 * rtk_qos_schedulingQueue_set
785 * Description:
786 * Set weight and type of queues in dedicated port.
787 * Input:
788 * port - Port id.
789 * pQweights - The array of weights for WRR/WFQ queue (0 for STRICT_PRIORITY queue).
790 * Output:
791 * None
792 * Return:
793 * RT_ERR_OK - OK
794 * RT_ERR_FAILED - Failed
795 * RT_ERR_SMI - SMI access error
796 * RT_ERR_PORT_ID - Invalid port number.
797 * RT_ERR_QOS_QUEUE_WEIGHT - Invalid queue weight.
798 * Note:
799 * The API can set weight and type, strict priority or weight fair queue (WFQ) for
800 * dedicated port for using queues. If queue id is not included in queue usage,
801 * then its type and weight setting in dummy for setting. There are priorities
802 * as queue id in strict queues. It means strict queue id 5 carrying higher priority
803 * than strict queue id 4. The WFQ queue weight is from 1 to 127, and weight 0 is
804 * for strict priority queue type.
805 */
806 rtk_api_ret_t rtk_qos_schedulingQueue_set(rtk_port_t port, rtk_qos_queue_weights_t *pQweights)
807 {
808 rtk_api_ret_t retVal;
809 rtk_uint32 qid;
810
811 /* Check initialization state */
812 RTK_CHK_INIT_STATE();
813
814 /* Check Port Valid */
815 RTK_CHK_PORT_VALID(port);
816
817 for (qid = 0; qid < RTL8367C_QUEUENO; qid ++)
818 {
819
820 if (pQweights->weights[qid] > QOS_WEIGHT_MAX)
821 return RT_ERR_QOS_QUEUE_WEIGHT;
822
823 if (0 == pQweights->weights[qid])
824 {
825 if ((retVal = rtl8367c_setAsicQueueType(rtk_switch_port_L2P_get(port), qid, QTYPE_STRICT)) != RT_ERR_OK)
826 return retVal;
827 }
828 else
829 {
830 if ((retVal = rtl8367c_setAsicQueueType(rtk_switch_port_L2P_get(port), qid, QTYPE_WFQ)) != RT_ERR_OK)
831 return retVal;
832
833 if ((retVal = rtl8367c_setAsicWFQWeight(rtk_switch_port_L2P_get(port),qid, pQweights->weights[qid])) != RT_ERR_OK)
834 return retVal;
835 }
836 }
837
838 return RT_ERR_OK;
839 }
840
841 /* Function Name:
842 * rtk_qos_schedulingQueue_get
843 * Description:
844 * Get weight and type of queues in dedicated port.
845 * Input:
846 * port - Port id.
847 * Output:
848 * pQweights - The array of weights for WRR/WFQ queue (0 for STRICT_PRIORITY queue).
849 * Return:
850 * RT_ERR_OK - OK
851 * RT_ERR_FAILED - Failed
852 * RT_ERR_SMI - SMI access error
853 * RT_ERR_INPUT - Invalid input parameters.
854 * RT_ERR_PORT_ID - Invalid port number.
855 * Note:
856 * The API can get weight and type, strict priority or weight fair queue (WFQ) for dedicated port for using queues.
857 * The WFQ queue weight is from 1 to 127, and weight 0 is for strict priority queue type.
858 */
859 rtk_api_ret_t rtk_qos_schedulingQueue_get(rtk_port_t port, rtk_qos_queue_weights_t *pQweights)
860 {
861 rtk_api_ret_t retVal;
862 rtk_uint32 qid,qtype,qweight;
863
864 /* Check initialization state */
865 RTK_CHK_INIT_STATE();
866
867 /* Check Port Valid */
868 RTK_CHK_PORT_VALID(port);
869
870 for (qid = 0; qid < RTL8367C_QUEUENO; qid++)
871 {
872 if ((retVal = rtl8367c_getAsicQueueType(rtk_switch_port_L2P_get(port), qid, &qtype)) != RT_ERR_OK)
873 return retVal;
874
875 if (QTYPE_STRICT == qtype)
876 {
877 pQweights->weights[qid] = 0;
878 }
879 else if (QTYPE_WFQ == qtype)
880 {
881 if ((retVal = rtl8367c_getAsicWFQWeight(rtk_switch_port_L2P_get(port), qid, &qweight)) != RT_ERR_OK)
882 return retVal;
883 pQweights->weights[qid] = qweight;
884 }
885 }
886 return RT_ERR_OK;
887 }
888
889 /* Function Name:
890 * rtk_qos_1pRemarkEnable_set
891 * Description:
892 * Set 1p Remarking state
893 * Input:
894 * port - Port id.
895 * enable - State of per-port 1p Remarking
896 * Output:
897 * None
898 * Return:
899 * RT_ERR_OK - OK
900 * RT_ERR_FAILED - Failed
901 * RT_ERR_SMI - SMI access error
902 * RT_ERR_PORT_ID - Invalid port number.
903 * RT_ERR_ENABLE - Invalid enable parameter.
904 * Note:
905 * The API can enable or disable 802.1p remarking ability for whole system.
906 * The status of 802.1p remark:
907 * - DISABLED
908 * - ENABLED
909 */
910 rtk_api_ret_t rtk_qos_1pRemarkEnable_set(rtk_port_t port, rtk_enable_t enable)
911 {
912 rtk_api_ret_t retVal;
913
914 /* Check initialization state */
915 RTK_CHK_INIT_STATE();
916
917 /* Check Port Valid */
918 RTK_CHK_PORT_VALID(port);
919
920 if (enable >= RTK_ENABLE_END)
921 return RT_ERR_INPUT;
922
923 if ((retVal = rtl8367c_setAsicRemarkingDot1pAbility(rtk_switch_port_L2P_get(port), enable)) != RT_ERR_OK)
924 return retVal;
925
926 return RT_ERR_OK;
927 }
928
929 /* Function Name:
930 * rtk_qos_1pRemarkEnable_get
931 * Description:
932 * Get 802.1p remarking ability.
933 * Input:
934 * port - Port id.
935 * Output:
936 * pEnable - Status of 802.1p remark.
937 * Return:
938 * RT_ERR_OK - OK
939 * RT_ERR_FAILED - Failed
940 * RT_ERR_SMI - SMI access error
941 * RT_ERR_PORT_ID - Invalid port number.
942 * Note:
943 * The API can get 802.1p remarking ability.
944 * The status of 802.1p remark:
945 * - DISABLED
946 * - ENABLED
947 */
948 rtk_api_ret_t rtk_qos_1pRemarkEnable_get(rtk_port_t port, rtk_enable_t *pEnable)
949 {
950 rtk_api_ret_t retVal;
951
952 /* Check initialization state */
953 RTK_CHK_INIT_STATE();
954
955 /* Check Port Valid */
956 RTK_CHK_PORT_VALID(port);
957
958 if ((retVal = rtl8367c_getAsicRemarkingDot1pAbility(rtk_switch_port_L2P_get(port), pEnable)) != RT_ERR_OK)
959 return retVal;
960
961 return RT_ERR_OK;
962 }
963
964 /* Function Name:
965 * rtk_qos_1pRemark_set
966 * Description:
967 * Set 802.1p remarking parameter.
968 * Input:
969 * int_pri - Internal priority value.
970 * dot1p_pri - 802.1p priority value.
971 * Output:
972 * None
973 * Return:
974 * RT_ERR_OK - OK
975 * RT_ERR_FAILED - Failed
976 * RT_ERR_SMI - SMI access error
977 * RT_ERR_VLAN_PRIORITY - Invalid 1p priority.
978 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
979 * Note:
980 * The API can set 802.1p parameters source priority and new priority.
981 */
982 rtk_api_ret_t rtk_qos_1pRemark_set(rtk_pri_t int_pri, rtk_pri_t dot1p_pri)
983 {
984 rtk_api_ret_t retVal;
985
986 /* Check initialization state */
987 RTK_CHK_INIT_STATE();
988
989 if (int_pri > RTL8367C_PRIMAX )
990 return RT_ERR_QOS_INT_PRIORITY;
991
992 if (dot1p_pri > RTL8367C_PRIMAX)
993 return RT_ERR_VLAN_PRIORITY;
994
995 if ((retVal = rtl8367c_setAsicRemarkingDot1pParameter(int_pri, dot1p_pri)) != RT_ERR_OK)
996 return retVal;
997
998 return RT_ERR_OK;
999 }
1000
1001 /* Function Name:
1002 * rtk_qos_1pRemark_get
1003 * Description:
1004 * Get 802.1p remarking parameter.
1005 * Input:
1006 * int_pri - Internal priority value.
1007 * Output:
1008 * pDot1p_pri - 802.1p priority value.
1009 * Return:
1010 * RT_ERR_OK - OK
1011 * RT_ERR_FAILED - Failed
1012 * RT_ERR_SMI - SMI access error
1013 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
1014 * Note:
1015 * The API can get 802.1p remarking parameters. It would return new priority of ingress priority.
1016 */
1017 rtk_api_ret_t rtk_qos_1pRemark_get(rtk_pri_t int_pri, rtk_pri_t *pDot1p_pri)
1018 {
1019 rtk_api_ret_t retVal;
1020
1021 /* Check initialization state */
1022 RTK_CHK_INIT_STATE();
1023
1024 if (int_pri > RTL8367C_PRIMAX )
1025 return RT_ERR_QOS_INT_PRIORITY;
1026
1027 if ((retVal = rtl8367c_getAsicRemarkingDot1pParameter(int_pri, pDot1p_pri)) != RT_ERR_OK)
1028 return retVal;
1029
1030 return RT_ERR_OK;
1031 }
1032
1033 /* Function Name:
1034 * rtk_qos_1pRemarkSrcSel_set
1035 * Description:
1036 * Set remarking source of 802.1p remarking.
1037 * Input:
1038 * type - remarking source
1039 * Output:
1040 * None
1041 * Return:
1042 * RT_ERR_OK
1043 * RT_ERR_FAILED
1044 * RT_ERR_NOT_INIT - The module is not initial
1045 * RT_ERR_PORT_ID - invalid port id
1046 * RT_ERR_INPUT - invalid input parameter
1047
1048 * Note:
1049 * The API can configure 802.1p remark functionality to map original 802.1p value or internal
1050 * priority to TX DSCP value.
1051 */
1052 rtk_api_ret_t rtk_qos_1pRemarkSrcSel_set(rtk_qos_1pRmkSrc_t type)
1053 {
1054 rtk_api_ret_t retVal;
1055
1056 /* Check initialization state */
1057 RTK_CHK_INIT_STATE();
1058
1059 if (type >= DOT1P_RMK_SRC_END )
1060 return RT_ERR_QOS_INT_PRIORITY;
1061
1062 if ((retVal = rtl8367c_setAsicRemarkingDot1pSrc(type)) != RT_ERR_OK)
1063 return retVal;
1064
1065 return RT_ERR_OK;
1066 }
1067
1068 /* Function Name:
1069 * rtk_qos_1pRemarkSrcSel_get
1070 * Description:
1071 * Get remarking source of 802.1p remarking.
1072 * Input:
1073 * none
1074 * Output:
1075 * pType - remarking source
1076 * Return:
1077 * RT_ERR_OK
1078 * RT_ERR_FAILED
1079 * RT_ERR_NOT_INIT - The module is not initial
1080 * RT_ERR_PORT_ID - invalid port id
1081 * RT_ERR_INPUT - invalid input parameter
1082 * RT_ERR_NULL_POINTER - input parameter may be null pointer
1083
1084 * Note:
1085 * None
1086 */
1087 rtk_api_ret_t rtk_qos_1pRemarkSrcSel_get(rtk_qos_1pRmkSrc_t *pType)
1088 {
1089 rtk_api_ret_t retVal;
1090
1091 /* Check initialization state */
1092 RTK_CHK_INIT_STATE();
1093
1094 if ((retVal = rtl8367c_getAsicRemarkingDot1pSrc(pType)) != RT_ERR_OK)
1095 return retVal;
1096
1097 return RT_ERR_OK;
1098 }
1099
1100
1101 /* Function Name:
1102 * rtk_qos_dscpRemarkEnable_set
1103 * Description:
1104 * Set DSCP remarking ability.
1105 * Input:
1106 * port - Port id.
1107 * enable - status of DSCP remark.
1108 * Output:
1109 * None
1110 * Return:
1111 * RT_ERR_OK - OK
1112 * RT_ERR_FAILED - Failed
1113 * RT_ERR_SMI - SMI access error
1114 * RT_ERR_PORT_ID - Invalid port number.
1115 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
1116 * RT_ERR_ENABLE - Invalid enable parameter.
1117 * Note:
1118 * The API can enable or disable DSCP remarking ability for whole system.
1119 * The status of DSCP remark:
1120 * - DISABLED
1121 * - ENABLED
1122 */
1123 rtk_api_ret_t rtk_qos_dscpRemarkEnable_set(rtk_port_t port, rtk_enable_t enable)
1124 {
1125 rtk_api_ret_t retVal;
1126
1127 /* Check initialization state */
1128 RTK_CHK_INIT_STATE();
1129
1130 /*for whole system function, the port value should be 0xFF*/
1131 if (port != RTK_WHOLE_SYSTEM)
1132 return RT_ERR_PORT_ID;
1133
1134 if (enable >= RTK_ENABLE_END)
1135 return RT_ERR_INPUT;
1136
1137 if ((retVal = rtl8367c_setAsicRemarkingDscpAbility(enable)) != RT_ERR_OK)
1138 return retVal;
1139
1140 return RT_ERR_OK;
1141 }
1142
1143 /* Function Name:
1144 * rtk_qos_dscpRemarkEnable_get
1145 * Description:
1146 * Get DSCP remarking ability.
1147 * Input:
1148 * port - Port id.
1149 * Output:
1150 * pEnable - status of DSCP remarking.
1151 * Return:
1152 * RT_ERR_OK - OK
1153 * RT_ERR_FAILED - Failed
1154 * RT_ERR_SMI - SMI access error
1155 * RT_ERR_PORT_ID - Invalid port number.
1156 * Note:
1157 * The API can get DSCP remarking ability.
1158 * The status of DSCP remark:
1159 * - DISABLED
1160 * - ENABLED
1161 */
1162 rtk_api_ret_t rtk_qos_dscpRemarkEnable_get(rtk_port_t port, rtk_enable_t *pEnable)
1163 {
1164 rtk_api_ret_t retVal;
1165
1166 /* Check initialization state */
1167 RTK_CHK_INIT_STATE();
1168
1169 /*for whole system function, the port value should be 0xFF*/
1170 if (port != RTK_WHOLE_SYSTEM)
1171 return RT_ERR_PORT_ID;
1172
1173 if ((retVal = rtl8367c_getAsicRemarkingDscpAbility(pEnable)) != RT_ERR_OK)
1174 return retVal;
1175
1176 return RT_ERR_OK;
1177 }
1178
1179 /* Function Name:
1180 * rtk_qos_dscpRemark_set
1181 * Description:
1182 * Set DSCP remarking parameter.
1183 * Input:
1184 * int_pri - Internal priority value.
1185 * dscp - DSCP value.
1186 * Output:
1187 * None
1188 * Return:
1189 * RT_ERR_OK - OK
1190 * RT_ERR_FAILED - Failed
1191 * RT_ERR_SMI - SMI access error
1192 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
1193 * RT_ERR_QOS_DSCP_VALUE - Invalid DSCP value.
1194 * Note:
1195 * The API can set DSCP value and mapping priority.
1196 */
1197 rtk_api_ret_t rtk_qos_dscpRemark_set(rtk_pri_t int_pri, rtk_dscp_t dscp)
1198 {
1199 rtk_api_ret_t retVal;
1200
1201 /* Check initialization state */
1202 RTK_CHK_INIT_STATE();
1203
1204 if (int_pri > RTK_PRIMAX )
1205 return RT_ERR_QOS_INT_PRIORITY;
1206
1207 if (dscp > RTK_DSCPMAX)
1208 return RT_ERR_QOS_DSCP_VALUE;
1209
1210 if ((retVal = rtl8367c_setAsicRemarkingDscpParameter(int_pri, dscp)) != RT_ERR_OK)
1211 return retVal;
1212
1213 return RT_ERR_OK;
1214 }
1215
1216
1217 /* Function Name:
1218 * rtk_qos_dscpRemark_get
1219 * Description:
1220 * Get DSCP remarking parameter.
1221 * Input:
1222 * int_pri - Internal priority value.
1223 * Output:
1224 * Dscp - DSCP value.
1225 * Return:
1226 * RT_ERR_OK - OK
1227 * RT_ERR_FAILED - Failed
1228 * RT_ERR_SMI - SMI access error
1229 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
1230 * Note:
1231 * The API can get DSCP parameters. It would return DSCP value for mapping priority.
1232 */
1233 rtk_api_ret_t rtk_qos_dscpRemark_get(rtk_pri_t int_pri, rtk_dscp_t *pDscp)
1234 {
1235 rtk_api_ret_t retVal;
1236
1237 /* Check initialization state */
1238 RTK_CHK_INIT_STATE();
1239
1240 if (int_pri > RTK_PRIMAX )
1241 return RT_ERR_QOS_INT_PRIORITY;
1242
1243 if ((retVal = rtl8367c_getAsicRemarkingDscpParameter(int_pri, pDscp)) != RT_ERR_OK)
1244 return retVal;
1245
1246 return RT_ERR_OK;
1247 }
1248
1249 /* Function Name:
1250 * rtk_qos_dscpRemarkSrcSel_set
1251 * Description:
1252 * Set remarking source of DSCP remarking.
1253 * Input:
1254 * type - remarking source
1255 * Output:
1256 * None
1257 * Return:
1258 * RT_ERR_OK
1259 * RT_ERR_FAILED
1260 * RT_ERR_NOT_INIT - The module is not initial
1261 * RT_ERR_PORT_ID - invalid port id
1262 * RT_ERR_INPUT - invalid input parameter
1263
1264 * Note:
1265 * The API can configure DSCP remark functionality to map original DSCP value or internal
1266 * priority to TX DSCP value.
1267 */
1268 rtk_api_ret_t rtk_qos_dscpRemarkSrcSel_set(rtk_qos_dscpRmkSrc_t type)
1269 {
1270 rtk_api_ret_t retVal;
1271
1272 /* Check initialization state */
1273 RTK_CHK_INIT_STATE();
1274
1275 if (type >= DSCP_RMK_SRC_END )
1276 return RT_ERR_QOS_INT_PRIORITY;
1277
1278 if ((retVal = rtl8367c_setAsicRemarkingDscpSrc(type)) != RT_ERR_OK)
1279 return retVal;
1280
1281 return RT_ERR_OK;
1282 }
1283
1284 /* Function Name:
1285 * rtk_qos_dcpRemarkSrcSel_get
1286 * Description:
1287 * Get remarking source of DSCP remarking.
1288 * Input:
1289 * none
1290 * Output:
1291 * pType - remarking source
1292 * Return:
1293 * RT_ERR_OK
1294 * RT_ERR_FAILED
1295 * RT_ERR_NOT_INIT - The module is not initial
1296 * RT_ERR_PORT_ID - invalid port id
1297 * RT_ERR_INPUT - invalid input parameter
1298 * RT_ERR_NULL_POINTER - input parameter may be null pointer
1299
1300 * Note:
1301 * None
1302 */
1303 rtk_api_ret_t rtk_qos_dscpRemarkSrcSel_get(rtk_qos_dscpRmkSrc_t *pType)
1304 {
1305 rtk_api_ret_t retVal;
1306
1307 /* Check initialization state */
1308 RTK_CHK_INIT_STATE();
1309
1310 if ((retVal = rtl8367c_getAsicRemarkingDscpSrc(pType)) != RT_ERR_OK)
1311 return retVal;
1312
1313 return RT_ERR_OK;
1314 }
1315
1316 /* Function Name:
1317 * rtk_qos_dscpRemark2Dscp_set
1318 * Description:
1319 * Set DSCP to remarked DSCP mapping.
1320 * Input:
1321 * dscp - DSCP value
1322 * rmkDscp - remarked DSCP value
1323 * Output:
1324 * None.
1325 * Return:
1326 * RT_ERR_OK
1327 * RT_ERR_FAILED
1328 * RT_ERR_QOS_DSCP_VALUE - Invalid dscp value
1329 * Note:
1330 * dscp parameter can be DSCP value or internal priority according to configuration of API
1331 * dal_apollomp_qos_dscpRemarkSrcSel_set(), because DSCP remark functionality can map original DSCP
1332 * value or internal priority to TX DSCP value.
1333 */
1334 rtk_api_ret_t rtk_qos_dscpRemark2Dscp_set(rtk_dscp_t dscp, rtk_dscp_t rmkDscp)
1335 {
1336 rtk_api_ret_t retVal;
1337
1338 /* Check initialization state */
1339 RTK_CHK_INIT_STATE();
1340
1341 if ((dscp > RTK_DSCPMAX) || (rmkDscp > RTK_DSCPMAX))
1342 return RT_ERR_QOS_DSCP_VALUE;
1343
1344 if ((retVal = rtl8367c_setAsicRemarkingDscp2Dscp(dscp, rmkDscp)) != RT_ERR_OK)
1345 return retVal;
1346
1347 return RT_ERR_OK;
1348 }
1349
1350 /* Function Name:
1351 * rtk_qos_dscpRemark2Dscp_get
1352 * Description:
1353 * Get DSCP to remarked DSCP mapping.
1354 * Input:
1355 * dscp - DSCP value
1356 * Output:
1357 * pDscp - remarked DSCP value
1358 * Return:
1359 * RT_ERR_OK
1360 * RT_ERR_FAILED
1361 * RT_ERR_QOS_DSCP_VALUE - Invalid dscp value
1362 * RT_ERR_NULL_POINTER - NULL pointer
1363 * Note:
1364 * None.
1365 */
1366 rtk_api_ret_t rtk_qos_dscpRemark2Dscp_get(rtk_dscp_t dscp, rtk_dscp_t *pDscp)
1367 {
1368 rtk_api_ret_t retVal;
1369
1370 /* Check initialization state */
1371 RTK_CHK_INIT_STATE();
1372
1373 if (dscp > RTK_DSCPMAX)
1374 return RT_ERR_QOS_DSCP_VALUE;
1375
1376 if ((retVal = rtl8367c_getAsicRemarkingDscp2Dscp(dscp, pDscp)) != RT_ERR_OK)
1377 return retVal;
1378
1379 return RT_ERR_OK;
1380 }
1381
1382 /* Function Name:
1383 * rtk_qos_portPriSelIndex_set
1384 * Description:
1385 * Configure priority decision index to each port.
1386 * Input:
1387 * port - Port id.
1388 * index - priority decision index.
1389 * Output:
1390 * None
1391 * Return:
1392 * RT_ERR_OK - OK
1393 * RT_ERR_FAILED - Failed
1394 * RT_ERR_SMI - SMI access error
1395 * RT_ERR_PORT_ID - Invalid port number.
1396 * RT_ERR_ENTRY_INDEX - Invalid entry index.
1397 * Note:
1398 * The API can set priority of port assignments for queue usage and packet scheduling.
1399 */
1400 rtk_api_ret_t rtk_qos_portPriSelIndex_set(rtk_port_t port, rtk_qos_priDecTbl_t index)
1401 {
1402 rtk_api_ret_t retVal;
1403
1404 /* Check initialization state */
1405 RTK_CHK_INIT_STATE();
1406
1407 /* Check Port Valid */
1408 RTK_CHK_PORT_VALID(port);
1409
1410 if (index >= PRIDECTBL_END )
1411 return RT_ERR_ENTRY_INDEX;
1412
1413 if ((retVal = rtl8367c_setAsicPortPriorityDecisionIndex(rtk_switch_port_L2P_get(port), index)) != RT_ERR_OK)
1414 return retVal;
1415
1416 return RT_ERR_OK;
1417 }
1418
1419 /* Function Name:
1420 * rtk_qos_portPriSelIndex_get
1421 * Description:
1422 * Get priority decision index from each port.
1423 * Input:
1424 * port - Port id.
1425 * Output:
1426 * pIndex - priority decision index.
1427 * Return:
1428 * RT_ERR_OK - OK
1429 * RT_ERR_FAILED - Failed
1430 * RT_ERR_SMI - SMI access error
1431 * RT_ERR_PORT_ID - Invalid port number.
1432 * Note:
1433 * The API can get priority of port assignments for queue usage and packet scheduling.
1434 */
1435 rtk_api_ret_t rtk_qos_portPriSelIndex_get(rtk_port_t port, rtk_qos_priDecTbl_t *pIndex)
1436 {
1437 rtk_api_ret_t retVal;
1438
1439 /* Check initialization state */
1440 RTK_CHK_INIT_STATE();
1441
1442 /* Check Port Valid */
1443 RTK_CHK_PORT_VALID(port);
1444
1445 if ((retVal = rtl8367c_getAsicPortPriorityDecisionIndex(rtk_switch_port_L2P_get(port), pIndex)) != RT_ERR_OK)
1446 return retVal;
1447
1448 return RT_ERR_OK;
1449 }
1450
1451
1452