2 * Copyright (C) 2013 Realtek Semiconductor Corp.
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
11 * $Date: 2017-03-08 15:13:58 +0800 (週三, 08 三月 2017) $
13 * Purpose : RTK switch high-level API for RTL8367/RTL8367C
14 * Feature : Here is a list of all functions and variables in QoS module.
18 #include <rtk_switch.h>
19 #include <rtk_error.h>
23 #include <rtl8367c_asicdrv.h>
24 #include <rtl8367c_asicdrv_qos.h>
25 #include <rtl8367c_asicdrv_fc.h>
26 #include <rtl8367c_asicdrv_scheduling.h>
31 * Configure Qos default settings with queue number assigment to each port.
33 * queueNum - Queue number of each port.
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.
43 * This API will initialize related Qos setting with queue number assigment.
44 * The queue number is from 1 to 8.
46 rtk_api_ret_t
rtk_qos_init(rtk_queue_num_t queueNum
)
48 CONST_T rtk_uint16 g_prioritytToQid
[8][8]= {
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};
69 /* Check initialization state */
72 if (queueNum
<= 0 || queueNum
> RTK_MAX_NUM_OF_QUEUE
)
73 return RT_ERR_QUEUE_NUM
;
75 /*Set Output Queue Number*/
76 if (RTK_MAX_NUM_OF_QUEUE
== queueNum
)
81 RTK_SCAN_ALL_PHY_PORTMASK(port
)
83 if ((retVal
= rtl8367c_setAsicOutputQueueMappingIndex(port
, qmapidx
)) != RT_ERR_OK
)
87 /*Set Priority to Qid*/
88 for (priority
= 0; priority
<= RTK_PRIMAX
; priority
++)
90 if ((retVal
= rtl8367c_setAsicPriorityToQIDMappingTable(queueNum
- 1, priority
, g_prioritytToQid
[queueNum
- 1][priority
])) != RT_ERR_OK
)
94 /*Set Flow Control Type to Ingress Flow Control*/
95 if ((retVal
= rtl8367c_setAsicFlowControlSelect(FC_INGRESS
)) != RT_ERR_OK
)
99 /*Priority Decision Order*/
100 for (priDec
= 0;priDec
< PRIDEC_END
;priDec
++)
102 if ((retVal
= rtl8367c_setAsicPriorityDecision(PRIDECTBL_IDX0
, priDec
, g_priorityDecision
[priDec
])) != RT_ERR_OK
)
104 if ((retVal
= rtl8367c_setAsicPriorityDecision(PRIDECTBL_IDX1
, priDec
, g_priorityDecision
[priDec
])) != RT_ERR_OK
)
108 /*Set Port-based Priority to 0*/
109 RTK_SCAN_ALL_PHY_PORTMASK(port
)
111 if ((retVal
= rtl8367c_setAsicPriorityPortBased(port
, 0)) != RT_ERR_OK
)
115 /*Disable 1p Remarking*/
116 RTK_SCAN_ALL_PHY_PORTMASK(port
)
118 if ((retVal
= rtl8367c_setAsicRemarkingDot1pAbility(port
, DISABLED
)) != RT_ERR_OK
)
122 /*Disable DSCP Remarking*/
123 if ((retVal
= rtl8367c_setAsicRemarkingDscpAbility(DISABLED
)) != RT_ERR_OK
)
126 /*Set 1p & DSCP Priority Remapping & Remarking*/
127 for (priority
= 0; priority
<= RTL8367C_PRIMAX
; priority
++)
129 if ((retVal
= rtl8367c_setAsicPriorityDot1qRemapping(priority
, g_prioritytRemap
[priority
])) != RT_ERR_OK
)
132 if ((retVal
= rtl8367c_setAsicRemarkingDot1pParameter(priority
, 0)) != RT_ERR_OK
)
135 if ((retVal
= rtl8367c_setAsicRemarkingDscpParameter(priority
, 0)) != RT_ERR_OK
)
139 /*Set DSCP Priority*/
140 for (dscp
= 0; dscp
<= 63; dscp
++)
142 if ((retVal
= rtl8367c_setAsicPriorityDscpBased(dscp
, 0)) != RT_ERR_OK
)
146 /* Finetune B/T value */
147 if((retVal
= rtl8367c_setAsicReg(0x1722, 0x1158)) != RT_ERR_OK
)
156 * Configure the priority order among different priority mechanism.
158 * index - Priority decision table index (0~1)
159 * pPriDec - Priority assign for port, dscp, 802.1p, cvlan, svlan, acl based priority decision.
164 * RT_ERR_FAILED - Failed
165 * RT_ERR_SMI - SMI access error
166 * RT_ERR_QOS_SEL_PRI_SOURCE - Invalid priority decision source parameter.
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:
181 rtk_api_ret_t
rtk_qos_priSel_set(rtk_qos_priDecTbl_t index
, rtk_priority_select_t
*pPriDec
)
183 rtk_api_ret_t retVal
;
185 rtk_uint32 dot1q_pow
;
188 rtk_uint32 svlan_pow
;
189 rtk_uint32 cvlan_pow
;
194 /* Check initialization state */
195 RTK_CHK_INIT_STATE();
197 if (index
< 0 || index
>= PRIDECTBL_END
)
198 return RT_ERR_ENTRY_INDEX
;
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
;
205 for (i
= pPriDec
->port_pri
; i
> 0; i
--)
206 port_pow
= (port_pow
)*2;
209 for (i
= pPriDec
->dot1q_pri
; i
> 0; i
--)
210 dot1q_pow
= (dot1q_pow
)*2;
213 for (i
= pPriDec
->acl_pri
; i
> 0; i
--)
214 acl_pow
= (acl_pow
)*2;
217 for (i
= pPriDec
->dscp_pri
; i
> 0; i
--)
218 dscp_pow
= (dscp_pow
)*2;
221 for (i
= pPriDec
->svlan_pri
; i
> 0; i
--)
222 svlan_pow
= (svlan_pow
)*2;
225 for (i
= pPriDec
->cvlan_pri
; i
> 0; i
--)
226 cvlan_pow
= (cvlan_pow
)*2;
229 for (i
= pPriDec
->dmac_pri
; i
> 0; i
--)
230 dmac_pow
= (dmac_pow
)*2;
233 for (i
= pPriDec
->smac_pri
; i
> 0; i
--)
234 smac_pow
= (smac_pow
)*2;
236 if ((retVal
= rtl8367c_setAsicPriorityDecision(index
, PRIDEC_PORT
, port_pow
)) != RT_ERR_OK
)
239 if ((retVal
= rtl8367c_setAsicPriorityDecision(index
, PRIDEC_ACL
, acl_pow
)) != RT_ERR_OK
)
242 if ((retVal
= rtl8367c_setAsicPriorityDecision(index
, PRIDEC_DSCP
, dscp_pow
)) != RT_ERR_OK
)
245 if ((retVal
= rtl8367c_setAsicPriorityDecision(index
, PRIDEC_1Q
, dot1q_pow
)) != RT_ERR_OK
)
248 if ((retVal
= rtl8367c_setAsicPriorityDecision(index
, PRIDEC_1AD
, svlan_pow
)) != RT_ERR_OK
)
251 if ((retVal
= rtl8367c_setAsicPriorityDecision(index
, PRIDEC_CVLAN
, cvlan_pow
)) != RT_ERR_OK
)
254 if ((retVal
= rtl8367c_setAsicPriorityDecision(index
, PRIDEC_DA
, dmac_pow
)) != RT_ERR_OK
)
257 if ((retVal
= rtl8367c_setAsicPriorityDecision(index
, PRIDEC_SA
, smac_pow
)) != RT_ERR_OK
)
266 * Get the priority order configuration among different priority mechanism.
268 * index - Priority decision table index (0~1)
270 * pPriDec - Priority assign for port, dscp, 802.1p, cvlan, svlan, acl based priority decision .
273 * RT_ERR_FAILED - Failed
274 * RT_ERR_SMI - SMI access error
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:
289 rtk_api_ret_t
rtk_qos_priSel_get(rtk_qos_priDecTbl_t index
, rtk_priority_select_t
*pPriDec
)
292 rtk_api_ret_t retVal
;
295 rtk_uint32 dot1q_pow
;
298 rtk_uint32 svlan_pow
;
299 rtk_uint32 cvlan_pow
;
303 /* Check initialization state */
304 RTK_CHK_INIT_STATE();
306 if (index
< 0 || index
>= PRIDECTBL_END
)
307 return RT_ERR_ENTRY_INDEX
;
309 if ((retVal
= rtl8367c_getAsicPriorityDecision(index
, PRIDEC_PORT
, &port_pow
)) != RT_ERR_OK
)
312 if ((retVal
= rtl8367c_getAsicPriorityDecision(index
, PRIDEC_ACL
, &acl_pow
)) != RT_ERR_OK
)
315 if ((retVal
= rtl8367c_getAsicPriorityDecision(index
, PRIDEC_DSCP
, &dscp_pow
)) != RT_ERR_OK
)
318 if ((retVal
= rtl8367c_getAsicPriorityDecision(index
, PRIDEC_1Q
, &dot1q_pow
)) != RT_ERR_OK
)
321 if ((retVal
= rtl8367c_getAsicPriorityDecision(index
, PRIDEC_1AD
, &svlan_pow
)) != RT_ERR_OK
)
324 if ((retVal
= rtl8367c_getAsicPriorityDecision(index
, PRIDEC_CVLAN
, &cvlan_pow
)) != RT_ERR_OK
)
327 if ((retVal
= rtl8367c_getAsicPriorityDecision(index
, PRIDEC_DA
, &dmac_pow
)) != RT_ERR_OK
)
330 if ((retVal
= rtl8367c_getAsicPriorityDecision(index
, PRIDEC_SA
, &smac_pow
)) != RT_ERR_OK
)
333 for (i
= 31; i
>= 0; i
--)
335 if (port_pow
& (1 << i
))
337 pPriDec
->port_pri
= i
;
342 for (i
= 31; i
>= 0; i
--)
344 if (dot1q_pow
& (1 << i
))
346 pPriDec
->dot1q_pri
= i
;
351 for (i
= 31; i
>= 0; i
--)
353 if (acl_pow
& (1 << i
))
355 pPriDec
->acl_pri
= i
;
360 for (i
= 31; i
>= 0; i
--)
362 if (dscp_pow
& (1 << i
))
364 pPriDec
->dscp_pri
= i
;
369 for (i
= 31; i
>= 0; i
--)
371 if (svlan_pow
& (1 << i
))
373 pPriDec
->svlan_pri
= i
;
378 for (i
= 31;i
>= 0; i
--)
380 if (cvlan_pow
& (1 << i
))
382 pPriDec
->cvlan_pri
= i
;
387 for (i
= 31; i
>= 0; i
--)
391 pPriDec
->dmac_pri
= i
;
396 for (i
= 31; i
>= 0; i
--)
398 if (smac_pow
& (1 << i
))
400 pPriDec
->smac_pri
= i
;
409 * rtk_qos_1pPriRemap_set
411 * Configure 1Q priorities mapping to internal absolute priority.
413 * dot1p_pri - 802.1p priority value.
414 * int_pri - internal priority value.
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.
425 * Priority of 802.1Q assignment for internal asic priority, and it is used for queue usage and packet scheduling.
427 rtk_api_ret_t
rtk_qos_1pPriRemap_set(rtk_pri_t dot1p_pri
, rtk_pri_t int_pri
)
429 rtk_api_ret_t retVal
;
431 /* Check initialization state */
432 RTK_CHK_INIT_STATE();
434 if (dot1p_pri
> RTL8367C_PRIMAX
|| int_pri
> RTL8367C_PRIMAX
)
435 return RT_ERR_VLAN_PRIORITY
;
437 if ((retVal
= rtl8367c_setAsicPriorityDot1qRemapping(dot1p_pri
, int_pri
)) != RT_ERR_OK
)
444 * rtk_qos_1pPriRemap_get
446 * Get 1Q priorities mapping to internal absolute priority.
448 * dot1p_pri - 802.1p priority value .
450 * pInt_pri - internal priority value.
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.
458 * Priority of 802.1Q assigment for internal asic priority, and it is uesed for queue usage and packet scheduling.
460 rtk_api_ret_t
rtk_qos_1pPriRemap_get(rtk_pri_t dot1p_pri
, rtk_pri_t
*pInt_pri
)
462 rtk_api_ret_t retVal
;
464 /* Check initialization state */
465 RTK_CHK_INIT_STATE();
467 if (dot1p_pri
> RTL8367C_PRIMAX
)
468 return RT_ERR_QOS_INT_PRIORITY
;
470 if ((retVal
= rtl8367c_getAsicPriorityDot1qRemapping(dot1p_pri
, pInt_pri
)) != RT_ERR_OK
)
477 * rtk_qos_dscpPriRemap_set
479 * Map dscp value to internal priority.
481 * dscp - Dscp value of receiving frame
482 * int_pri - internal priority value .
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.
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.
497 rtk_api_ret_t
rtk_qos_dscpPriRemap_set(rtk_dscp_t dscp
, rtk_pri_t int_pri
)
499 rtk_api_ret_t retVal
;
501 /* Check initialization state */
502 RTK_CHK_INIT_STATE();
504 if (int_pri
> RTL8367C_PRIMAX
)
505 return RT_ERR_QOS_INT_PRIORITY
;
507 if (dscp
> RTL8367C_DSCPMAX
)
508 return RT_ERR_QOS_DSCP_VALUE
;
510 if ((retVal
= rtl8367c_setAsicPriorityDscpBased(dscp
, int_pri
)) != RT_ERR_OK
)
517 * rtk_qos_dscpPriRemap_get
519 * Get dscp value to internal priority.
521 * dscp - Dscp value of receiving frame
523 * pInt_pri - internal priority value.
526 * RT_ERR_FAILED - Failed
527 * RT_ERR_SMI - SMI access error
528 * RT_ERR_QOS_DSCP_VALUE - Invalid DSCP value.
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.
534 rtk_api_ret_t
rtk_qos_dscpPriRemap_get(rtk_dscp_t dscp
, rtk_pri_t
*pInt_pri
)
536 rtk_api_ret_t retVal
;
538 /* Check initialization state */
539 RTK_CHK_INIT_STATE();
541 if (dscp
> RTL8367C_DSCPMAX
)
542 return RT_ERR_QOS_DSCP_VALUE
;
544 if ((retVal
= rtl8367c_getAsicPriorityDscpBased(dscp
, pInt_pri
)) != RT_ERR_OK
)
551 * rtk_qos_portPri_set
553 * Configure priority usage to each port.
556 * int_pri - internal priority value.
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.
567 * The API can set priority of port assignments for queue usage and packet scheduling.
569 rtk_api_ret_t
rtk_qos_portPri_set(rtk_port_t port
, rtk_pri_t int_pri
)
571 rtk_api_ret_t retVal
;
573 /* Check initialization state */
574 RTK_CHK_INIT_STATE();
576 /* Check Port Valid */
577 RTK_CHK_PORT_VALID(port
);
579 if (int_pri
> RTL8367C_PRIMAX
)
580 return RT_ERR_QOS_INT_PRIORITY
;
582 if ((retVal
= rtl8367c_setAsicPriorityPortBased(rtk_switch_port_L2P_get(port
), int_pri
)) != RT_ERR_OK
)
589 * rtk_qos_portPri_get
591 * Get priority usage to each port.
595 * pInt_pri - internal priority value.
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.
603 * The API can get priority of port assignments for queue usage and packet scheduling.
605 rtk_api_ret_t
rtk_qos_portPri_get(rtk_port_t port
, rtk_pri_t
*pInt_pri
)
607 rtk_api_ret_t retVal
;
609 /* Check initialization state */
610 RTK_CHK_INIT_STATE();
612 /* Check Port Valid */
613 RTK_CHK_PORT_VALID(port
);
615 if ((retVal
= rtl8367c_getAsicPriorityPortBased(rtk_switch_port_L2P_get(port
), pInt_pri
)) != RT_ERR_OK
)
623 * rtk_qos_queueNum_set
625 * Set output queue number for each port.
628 * index - Mapping queue number (1~8)
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.
638 * The API can set the output queue number of the specified port. The queue number is from 1 to 8.
640 rtk_api_ret_t
rtk_qos_queueNum_set(rtk_port_t port
, rtk_queue_num_t queue_num
)
642 rtk_api_ret_t retVal
;
644 /* Check initialization state */
645 RTK_CHK_INIT_STATE();
647 /* Check Port Valid */
648 RTK_CHK_PORT_VALID(port
);
650 if ((0 == queue_num
) || (queue_num
> RTK_MAX_NUM_OF_QUEUE
))
651 return RT_ERR_FAILED
;
653 if (RTK_MAX_NUM_OF_QUEUE
== queue_num
)
656 if ((retVal
= rtl8367c_setAsicOutputQueueMappingIndex(rtk_switch_port_L2P_get(port
), queue_num
)) != RT_ERR_OK
)
663 * rtk_qos_queueNum_get
665 * Get output queue number.
669 * pQueue_num - Mapping queue number
672 * RT_ERR_FAILED - Failed
673 * RT_ERR_SMI - SMI access error
674 * RT_ERR_PORT_ID - Invalid port number.
676 * The API will return the output queue number of the specified port. The queue number is from 1 to 8.
678 rtk_api_ret_t
rtk_qos_queueNum_get(rtk_port_t port
, rtk_queue_num_t
*pQueue_num
)
680 rtk_api_ret_t retVal
;
683 /* Check initialization state */
684 RTK_CHK_INIT_STATE();
686 /* Check Port Valid */
687 RTK_CHK_PORT_VALID(port
);
689 if ((retVal
= rtl8367c_getAsicOutputQueueMappingIndex(rtk_switch_port_L2P_get(port
), &qidx
)) != RT_ERR_OK
)
703 * Set output queue number for each port.
705 * queue_num - Queue number usage.
706 * pPri2qid - Priority mapping to queue ID.
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.
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.
722 rtk_api_ret_t
rtk_qos_priMap_set(rtk_queue_num_t queue_num
, rtk_qos_pri2queue_t
*pPri2qid
)
724 rtk_api_ret_t retVal
;
727 /* Check initialization state */
728 RTK_CHK_INIT_STATE();
730 if ((0 == queue_num
) || (queue_num
> RTK_MAX_NUM_OF_QUEUE
))
731 return RT_ERR_QUEUE_NUM
;
733 for (pri
= 0; pri
<= RTK_PRIMAX
; pri
++)
735 if (pPri2qid
->pri2queue
[pri
] > RTK_QIDMAX
)
736 return RT_ERR_QUEUE_ID
;
738 if ((retVal
= rtl8367c_setAsicPriorityToQIDMappingTable(queue_num
- 1, pri
, pPri2qid
->pri2queue
[pri
])) != RT_ERR_OK
)
748 * Get priority to queue ID mapping table parameters.
750 * queue_num - Queue number usage.
752 * pPri2qid - Priority mapping to queue ID.
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.
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.
763 rtk_api_ret_t
rtk_qos_priMap_get(rtk_queue_num_t queue_num
, rtk_qos_pri2queue_t
*pPri2qid
)
765 rtk_api_ret_t retVal
;
768 /* Check initialization state */
769 RTK_CHK_INIT_STATE();
771 if ((0 == queue_num
) || (queue_num
> RTK_MAX_NUM_OF_QUEUE
))
772 return RT_ERR_QUEUE_NUM
;
774 for (pri
= 0; pri
<= RTK_PRIMAX
; pri
++)
776 if ((retVal
= rtl8367c_getAsicPriorityToQIDMappingTable(queue_num
-1, pri
, &pPri2qid
->pri2queue
[pri
])) != RT_ERR_OK
)
784 * rtk_qos_schedulingQueue_set
786 * Set weight and type of queues in dedicated port.
789 * pQweights - The array of weights for WRR/WFQ queue (0 for STRICT_PRIORITY queue).
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.
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.
806 rtk_api_ret_t
rtk_qos_schedulingQueue_set(rtk_port_t port
, rtk_qos_queue_weights_t
*pQweights
)
808 rtk_api_ret_t retVal
;
811 /* Check initialization state */
812 RTK_CHK_INIT_STATE();
814 /* Check Port Valid */
815 RTK_CHK_PORT_VALID(port
);
817 for (qid
= 0; qid
< RTL8367C_QUEUENO
; qid
++)
820 if (pQweights
->weights
[qid
] > QOS_WEIGHT_MAX
)
821 return RT_ERR_QOS_QUEUE_WEIGHT
;
823 if (0 == pQweights
->weights
[qid
])
825 if ((retVal
= rtl8367c_setAsicQueueType(rtk_switch_port_L2P_get(port
), qid
, QTYPE_STRICT
)) != RT_ERR_OK
)
830 if ((retVal
= rtl8367c_setAsicQueueType(rtk_switch_port_L2P_get(port
), qid
, QTYPE_WFQ
)) != RT_ERR_OK
)
833 if ((retVal
= rtl8367c_setAsicWFQWeight(rtk_switch_port_L2P_get(port
),qid
, pQweights
->weights
[qid
])) != RT_ERR_OK
)
842 * rtk_qos_schedulingQueue_get
844 * Get weight and type of queues in dedicated port.
848 * pQweights - The array of weights for WRR/WFQ queue (0 for STRICT_PRIORITY queue).
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.
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.
859 rtk_api_ret_t
rtk_qos_schedulingQueue_get(rtk_port_t port
, rtk_qos_queue_weights_t
*pQweights
)
861 rtk_api_ret_t retVal
;
862 rtk_uint32 qid
,qtype
,qweight
;
864 /* Check initialization state */
865 RTK_CHK_INIT_STATE();
867 /* Check Port Valid */
868 RTK_CHK_PORT_VALID(port
);
870 for (qid
= 0; qid
< RTL8367C_QUEUENO
; qid
++)
872 if ((retVal
= rtl8367c_getAsicQueueType(rtk_switch_port_L2P_get(port
), qid
, &qtype
)) != RT_ERR_OK
)
875 if (QTYPE_STRICT
== qtype
)
877 pQweights
->weights
[qid
] = 0;
879 else if (QTYPE_WFQ
== qtype
)
881 if ((retVal
= rtl8367c_getAsicWFQWeight(rtk_switch_port_L2P_get(port
), qid
, &qweight
)) != RT_ERR_OK
)
883 pQweights
->weights
[qid
] = qweight
;
890 * rtk_qos_1pRemarkEnable_set
892 * Set 1p Remarking state
895 * enable - State of per-port 1p Remarking
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.
905 * The API can enable or disable 802.1p remarking ability for whole system.
906 * The status of 802.1p remark:
910 rtk_api_ret_t
rtk_qos_1pRemarkEnable_set(rtk_port_t port
, rtk_enable_t enable
)
912 rtk_api_ret_t retVal
;
914 /* Check initialization state */
915 RTK_CHK_INIT_STATE();
917 /* Check Port Valid */
918 RTK_CHK_PORT_VALID(port
);
920 if (enable
>= RTK_ENABLE_END
)
923 if ((retVal
= rtl8367c_setAsicRemarkingDot1pAbility(rtk_switch_port_L2P_get(port
), enable
)) != RT_ERR_OK
)
930 * rtk_qos_1pRemarkEnable_get
932 * Get 802.1p remarking ability.
936 * pEnable - Status of 802.1p remark.
939 * RT_ERR_FAILED - Failed
940 * RT_ERR_SMI - SMI access error
941 * RT_ERR_PORT_ID - Invalid port number.
943 * The API can get 802.1p remarking ability.
944 * The status of 802.1p remark:
948 rtk_api_ret_t
rtk_qos_1pRemarkEnable_get(rtk_port_t port
, rtk_enable_t
*pEnable
)
950 rtk_api_ret_t retVal
;
952 /* Check initialization state */
953 RTK_CHK_INIT_STATE();
955 /* Check Port Valid */
956 RTK_CHK_PORT_VALID(port
);
958 if ((retVal
= rtl8367c_getAsicRemarkingDot1pAbility(rtk_switch_port_L2P_get(port
), pEnable
)) != RT_ERR_OK
)
965 * rtk_qos_1pRemark_set
967 * Set 802.1p remarking parameter.
969 * int_pri - Internal priority value.
970 * dot1p_pri - 802.1p priority value.
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.
980 * The API can set 802.1p parameters source priority and new priority.
982 rtk_api_ret_t
rtk_qos_1pRemark_set(rtk_pri_t int_pri
, rtk_pri_t dot1p_pri
)
984 rtk_api_ret_t retVal
;
986 /* Check initialization state */
987 RTK_CHK_INIT_STATE();
989 if (int_pri
> RTL8367C_PRIMAX
)
990 return RT_ERR_QOS_INT_PRIORITY
;
992 if (dot1p_pri
> RTL8367C_PRIMAX
)
993 return RT_ERR_VLAN_PRIORITY
;
995 if ((retVal
= rtl8367c_setAsicRemarkingDot1pParameter(int_pri
, dot1p_pri
)) != RT_ERR_OK
)
1002 * rtk_qos_1pRemark_get
1004 * Get 802.1p remarking parameter.
1006 * int_pri - Internal priority value.
1008 * pDot1p_pri - 802.1p priority value.
1011 * RT_ERR_FAILED - Failed
1012 * RT_ERR_SMI - SMI access error
1013 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
1015 * The API can get 802.1p remarking parameters. It would return new priority of ingress priority.
1017 rtk_api_ret_t
rtk_qos_1pRemark_get(rtk_pri_t int_pri
, rtk_pri_t
*pDot1p_pri
)
1019 rtk_api_ret_t retVal
;
1021 /* Check initialization state */
1022 RTK_CHK_INIT_STATE();
1024 if (int_pri
> RTL8367C_PRIMAX
)
1025 return RT_ERR_QOS_INT_PRIORITY
;
1027 if ((retVal
= rtl8367c_getAsicRemarkingDot1pParameter(int_pri
, pDot1p_pri
)) != RT_ERR_OK
)
1034 * rtk_qos_1pRemarkSrcSel_set
1036 * Set remarking source of 802.1p remarking.
1038 * type - remarking source
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
1049 * The API can configure 802.1p remark functionality to map original 802.1p value or internal
1050 * priority to TX DSCP value.
1052 rtk_api_ret_t
rtk_qos_1pRemarkSrcSel_set(rtk_qos_1pRmkSrc_t type
)
1054 rtk_api_ret_t retVal
;
1056 /* Check initialization state */
1057 RTK_CHK_INIT_STATE();
1059 if (type
>= DOT1P_RMK_SRC_END
)
1060 return RT_ERR_QOS_INT_PRIORITY
;
1062 if ((retVal
= rtl8367c_setAsicRemarkingDot1pSrc(type
)) != RT_ERR_OK
)
1069 * rtk_qos_1pRemarkSrcSel_get
1071 * Get remarking source of 802.1p remarking.
1075 * pType - remarking source
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
1087 rtk_api_ret_t
rtk_qos_1pRemarkSrcSel_get(rtk_qos_1pRmkSrc_t
*pType
)
1089 rtk_api_ret_t retVal
;
1091 /* Check initialization state */
1092 RTK_CHK_INIT_STATE();
1094 if ((retVal
= rtl8367c_getAsicRemarkingDot1pSrc(pType
)) != RT_ERR_OK
)
1102 * rtk_qos_dscpRemarkEnable_set
1104 * Set DSCP remarking ability.
1107 * enable - status of DSCP remark.
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.
1118 * The API can enable or disable DSCP remarking ability for whole system.
1119 * The status of DSCP remark:
1123 rtk_api_ret_t
rtk_qos_dscpRemarkEnable_set(rtk_port_t port
, rtk_enable_t enable
)
1125 rtk_api_ret_t retVal
;
1127 /* Check initialization state */
1128 RTK_CHK_INIT_STATE();
1130 /*for whole system function, the port value should be 0xFF*/
1131 if (port
!= RTK_WHOLE_SYSTEM
)
1132 return RT_ERR_PORT_ID
;
1134 if (enable
>= RTK_ENABLE_END
)
1135 return RT_ERR_INPUT
;
1137 if ((retVal
= rtl8367c_setAsicRemarkingDscpAbility(enable
)) != RT_ERR_OK
)
1144 * rtk_qos_dscpRemarkEnable_get
1146 * Get DSCP remarking ability.
1150 * pEnable - status of DSCP remarking.
1153 * RT_ERR_FAILED - Failed
1154 * RT_ERR_SMI - SMI access error
1155 * RT_ERR_PORT_ID - Invalid port number.
1157 * The API can get DSCP remarking ability.
1158 * The status of DSCP remark:
1162 rtk_api_ret_t
rtk_qos_dscpRemarkEnable_get(rtk_port_t port
, rtk_enable_t
*pEnable
)
1164 rtk_api_ret_t retVal
;
1166 /* Check initialization state */
1167 RTK_CHK_INIT_STATE();
1169 /*for whole system function, the port value should be 0xFF*/
1170 if (port
!= RTK_WHOLE_SYSTEM
)
1171 return RT_ERR_PORT_ID
;
1173 if ((retVal
= rtl8367c_getAsicRemarkingDscpAbility(pEnable
)) != RT_ERR_OK
)
1180 * rtk_qos_dscpRemark_set
1182 * Set DSCP remarking parameter.
1184 * int_pri - Internal priority value.
1185 * dscp - DSCP value.
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.
1195 * The API can set DSCP value and mapping priority.
1197 rtk_api_ret_t
rtk_qos_dscpRemark_set(rtk_pri_t int_pri
, rtk_dscp_t dscp
)
1199 rtk_api_ret_t retVal
;
1201 /* Check initialization state */
1202 RTK_CHK_INIT_STATE();
1204 if (int_pri
> RTK_PRIMAX
)
1205 return RT_ERR_QOS_INT_PRIORITY
;
1207 if (dscp
> RTK_DSCPMAX
)
1208 return RT_ERR_QOS_DSCP_VALUE
;
1210 if ((retVal
= rtl8367c_setAsicRemarkingDscpParameter(int_pri
, dscp
)) != RT_ERR_OK
)
1218 * rtk_qos_dscpRemark_get
1220 * Get DSCP remarking parameter.
1222 * int_pri - Internal priority value.
1224 * Dscp - DSCP value.
1227 * RT_ERR_FAILED - Failed
1228 * RT_ERR_SMI - SMI access error
1229 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
1231 * The API can get DSCP parameters. It would return DSCP value for mapping priority.
1233 rtk_api_ret_t
rtk_qos_dscpRemark_get(rtk_pri_t int_pri
, rtk_dscp_t
*pDscp
)
1235 rtk_api_ret_t retVal
;
1237 /* Check initialization state */
1238 RTK_CHK_INIT_STATE();
1240 if (int_pri
> RTK_PRIMAX
)
1241 return RT_ERR_QOS_INT_PRIORITY
;
1243 if ((retVal
= rtl8367c_getAsicRemarkingDscpParameter(int_pri
, pDscp
)) != RT_ERR_OK
)
1250 * rtk_qos_dscpRemarkSrcSel_set
1252 * Set remarking source of DSCP remarking.
1254 * type - remarking source
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
1265 * The API can configure DSCP remark functionality to map original DSCP value or internal
1266 * priority to TX DSCP value.
1268 rtk_api_ret_t
rtk_qos_dscpRemarkSrcSel_set(rtk_qos_dscpRmkSrc_t type
)
1270 rtk_api_ret_t retVal
;
1272 /* Check initialization state */
1273 RTK_CHK_INIT_STATE();
1275 if (type
>= DSCP_RMK_SRC_END
)
1276 return RT_ERR_QOS_INT_PRIORITY
;
1278 if ((retVal
= rtl8367c_setAsicRemarkingDscpSrc(type
)) != RT_ERR_OK
)
1285 * rtk_qos_dcpRemarkSrcSel_get
1287 * Get remarking source of DSCP remarking.
1291 * pType - remarking source
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
1303 rtk_api_ret_t
rtk_qos_dscpRemarkSrcSel_get(rtk_qos_dscpRmkSrc_t
*pType
)
1305 rtk_api_ret_t retVal
;
1307 /* Check initialization state */
1308 RTK_CHK_INIT_STATE();
1310 if ((retVal
= rtl8367c_getAsicRemarkingDscpSrc(pType
)) != RT_ERR_OK
)
1317 * rtk_qos_dscpRemark2Dscp_set
1319 * Set DSCP to remarked DSCP mapping.
1322 * rmkDscp - remarked DSCP value
1328 * RT_ERR_QOS_DSCP_VALUE - Invalid dscp value
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.
1334 rtk_api_ret_t
rtk_qos_dscpRemark2Dscp_set(rtk_dscp_t dscp
, rtk_dscp_t rmkDscp
)
1336 rtk_api_ret_t retVal
;
1338 /* Check initialization state */
1339 RTK_CHK_INIT_STATE();
1341 if ((dscp
> RTK_DSCPMAX
) || (rmkDscp
> RTK_DSCPMAX
))
1342 return RT_ERR_QOS_DSCP_VALUE
;
1344 if ((retVal
= rtl8367c_setAsicRemarkingDscp2Dscp(dscp
, rmkDscp
)) != RT_ERR_OK
)
1351 * rtk_qos_dscpRemark2Dscp_get
1353 * Get DSCP to remarked DSCP mapping.
1357 * pDscp - remarked DSCP value
1361 * RT_ERR_QOS_DSCP_VALUE - Invalid dscp value
1362 * RT_ERR_NULL_POINTER - NULL pointer
1366 rtk_api_ret_t
rtk_qos_dscpRemark2Dscp_get(rtk_dscp_t dscp
, rtk_dscp_t
*pDscp
)
1368 rtk_api_ret_t retVal
;
1370 /* Check initialization state */
1371 RTK_CHK_INIT_STATE();
1373 if (dscp
> RTK_DSCPMAX
)
1374 return RT_ERR_QOS_DSCP_VALUE
;
1376 if ((retVal
= rtl8367c_getAsicRemarkingDscp2Dscp(dscp
, pDscp
)) != RT_ERR_OK
)
1383 * rtk_qos_portPriSelIndex_set
1385 * Configure priority decision index to each port.
1388 * index - priority decision index.
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.
1398 * The API can set priority of port assignments for queue usage and packet scheduling.
1400 rtk_api_ret_t
rtk_qos_portPriSelIndex_set(rtk_port_t port
, rtk_qos_priDecTbl_t index
)
1402 rtk_api_ret_t retVal
;
1404 /* Check initialization state */
1405 RTK_CHK_INIT_STATE();
1407 /* Check Port Valid */
1408 RTK_CHK_PORT_VALID(port
);
1410 if (index
>= PRIDECTBL_END
)
1411 return RT_ERR_ENTRY_INDEX
;
1413 if ((retVal
= rtl8367c_setAsicPortPriorityDecisionIndex(rtk_switch_port_L2P_get(port
), index
)) != RT_ERR_OK
)
1420 * rtk_qos_portPriSelIndex_get
1422 * Get priority decision index from each port.
1426 * pIndex - priority decision index.
1429 * RT_ERR_FAILED - Failed
1430 * RT_ERR_SMI - SMI access error
1431 * RT_ERR_PORT_ID - Invalid port number.
1433 * The API can get priority of port assignments for queue usage and packet scheduling.
1435 rtk_api_ret_t
rtk_qos_portPriSelIndex_get(rtk_port_t port
, rtk_qos_priDecTbl_t
*pIndex
)
1437 rtk_api_ret_t retVal
;
1439 /* Check initialization state */
1440 RTK_CHK_INIT_STATE();
1442 /* Check Port Valid */
1443 RTK_CHK_PORT_VALID(port
);
1445 if ((retVal
= rtl8367c_getAsicPortPriorityDecisionIndex(rtk_switch_port_L2P_get(port
), pIndex
)) != RT_ERR_OK
)