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
10 * Purpose : RTL8367/RTL8367C switch high-level API
12 * Feature : The file includes QoS module high-layer API defination
16 #ifndef __RTK_API_QOS_H__
17 #define __RTK_API_QOS_H__
20 * Data Type Declaration
22 #define QOS_DEFAULT_TICK_PERIOD (19-1)
23 #define QOS_DEFAULT_BYTE_PER_TOKEN 34
24 #define QOS_DEFAULT_LK_THRESHOLD (34*3) /* Why use 0x400? */
27 #define QOS_DEFAULT_INGRESS_BANDWIDTH 0x3FFF /* 0x3FFF => unlimit */
28 #define QOS_DEFAULT_EGRESS_BANDWIDTH 0x3D08 /*( 0x3D08 + 1) * 64Kbps => 1Gbps*/
29 #define QOS_DEFAULT_PREIFP 1
30 #define QOS_DEFAULT_PACKET_USED_PAGES_FC 0x60
31 #define QOS_DEFAULT_PACKET_USED_FC_EN 0
32 #define QOS_DEFAULT_QUEUE_BASED_FC_EN 1
34 #define QOS_DEFAULT_PRIORITY_SELECT_PORT 8
35 #define QOS_DEFAULT_PRIORITY_SELECT_1Q 0
36 #define QOS_DEFAULT_PRIORITY_SELECT_ACL 0
37 #define QOS_DEFAULT_PRIORITY_SELECT_DSCP 0
39 #define QOS_DEFAULT_DSCP_MAPPING_PRIORITY 0
41 #define QOS_DEFAULT_1Q_REMARKING_ABILITY 0
42 #define QOS_DEFAULT_DSCP_REMARKING_ABILITY 0
43 #define QOS_DEFAULT_QUEUE_GAP 20
44 #define QOS_DEFAULT_QUEUE_NO_MAX 6
45 #define QOS_DEFAULT_AVERAGE_PACKET_RATE 0x3FFF
46 #define QOS_DEFAULT_BURST_SIZE_IN_APR 0x3F
47 #define QOS_DEFAULT_PEAK_PACKET_RATE 2
48 #define QOS_DEFAULT_SCHEDULER_ABILITY_APR 1 /*disable*/
49 #define QOS_DEFAULT_SCHEDULER_ABILITY_PPR 1 /*disable*/
50 #define QOS_DEFAULT_SCHEDULER_ABILITY_WFQ 1 /*disable*/
52 #define QOS_WEIGHT_MAX 127
54 #define RTK_MAX_NUM_OF_PRIORITY 8
55 #define RTK_MAX_NUM_OF_QUEUE 8
59 #define RTK_DSCPMAX 63
62 /* enum Priority Selection Index */
63 typedef enum rtk_qos_priDecTbl_e
71 /* Types of 802.1p remarking source */
72 typedef enum rtk_qos_1pRmkSrc_e
74 DOT1P_RMK_SRC_USER_PRI
,
75 DOT1P_RMK_SRC_TAG_PRI
,
80 /* Types of DSCP remarking source */
81 typedef enum rtk_qos_dscpRmkSrc_e
85 DSCP_RMK_SRC_USER_PRI
,
87 } rtk_qos_dscpRmkSrc_t
;
92 typedef struct rtk_priority_select_s
102 } rtk_priority_select_t
;
104 typedef struct rtk_qos_pri2queue_s
106 rtk_uint32 pri2queue
[RTK_MAX_NUM_OF_PRIORITY
];
107 } rtk_qos_pri2queue_t
;
109 typedef struct rtk_qos_queue_weights_s
111 rtk_uint32 weights
[RTK_MAX_NUM_OF_QUEUE
];
112 } rtk_qos_queue_weights_t
;
114 typedef enum rtk_qos_scheduling_type_e
116 WFQ
= 0, /* Weighted-Fair-Queue */
117 WRR
, /* Weighted-Round-Robin */
119 } rtk_qos_scheduling_type_t
;
121 typedef rtk_uint32 rtk_queue_num_t
; /* queue number*/
126 * Configure Qos default settings with queue number assigment to each port.
128 * queueNum - Queue number of each port.
133 * RT_ERR_FAILED - Failed
134 * RT_ERR_SMI - SMI access error
135 * RT_ERR_QUEUE_NUM - Invalid queue number.
136 * RT_ERR_INPUT - Invalid input parameters.
138 * This API will initialize related Qos setting with queue number assigment.
139 * The queue number is from 1 to 8.
141 extern rtk_api_ret_t
rtk_qos_init(rtk_queue_num_t queueNum
);
146 * Configure the priority order among different priority mechanism.
148 * index - Priority decision table index (0~1)
149 * pPriDec - Priority assign for port, dscp, 802.1p, cvlan, svlan, acl based priority decision.
154 * RT_ERR_FAILED - Failed
155 * RT_ERR_SMI - SMI access error
156 * RT_ERR_QOS_SEL_PRI_SOURCE - Invalid priority decision source parameter.
158 * ASIC will follow user priority setting of mechanisms to select mapped queue priority for receiving frame.
159 * If two priority mechanisms are the same, the ASIC will chose the highest priority from mechanisms to
160 * assign queue priority to receiving frame.
161 * The priority sources are:
171 extern rtk_api_ret_t
rtk_qos_priSel_set(rtk_qos_priDecTbl_t index
, rtk_priority_select_t
*pPriDec
);
177 * Get the priority order configuration among different priority mechanism.
179 * index - Priority decision table index (0~1)
181 * pPriDec - Priority assign for port, dscp, 802.1p, cvlan, svlan, acl based priority decision .
184 * RT_ERR_FAILED - Failed
185 * RT_ERR_SMI - SMI access error
187 * ASIC will follow user priority setting of mechanisms to select mapped queue priority for receiving frame.
188 * If two priority mechanisms are the same, the ASIC will chose the highest priority from mechanisms to
189 * assign queue priority to receiving frame.
190 * The priority sources are:
200 extern rtk_api_ret_t
rtk_qos_priSel_get(rtk_qos_priDecTbl_t index
, rtk_priority_select_t
*pPriDec
);
203 * rtk_qos_1pPriRemap_set
205 * Configure 1Q priorities mapping to internal absolute priority.
207 * dot1p_pri - 802.1p priority value.
208 * int_pri - internal priority value.
213 * RT_ERR_FAILED - Failed
214 * RT_ERR_SMI - SMI access error
215 * RT_ERR_INPUT - Invalid input parameters.
216 * RT_ERR_VLAN_PRIORITY - Invalid 1p priority.
217 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
219 * Priority of 802.1Q assignment for internal asic priority, and it is used for queue usage and packet scheduling.
221 extern rtk_api_ret_t
rtk_qos_1pPriRemap_set(rtk_pri_t dot1p_pri
, rtk_pri_t int_pri
);
224 * rtk_qos_1pPriRemap_get
226 * Get 1Q priorities mapping to internal absolute priority.
228 * dot1p_pri - 802.1p priority value .
230 * pInt_pri - internal priority value.
233 * RT_ERR_FAILED - Failed
234 * RT_ERR_SMI - SMI access error
235 * RT_ERR_VLAN_PRIORITY - Invalid priority.
236 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
238 * Priority of 802.1Q assigment for internal asic priority, and it is uesed for queue usage and packet scheduling.
240 extern rtk_api_ret_t
rtk_qos_1pPriRemap_get(rtk_pri_t dot1p_pri
, rtk_pri_t
*pInt_pri
);
244 * rtk_qos_1pRemarkSrcSel_set
246 * Set remarking source of 802.1p remarking.
248 * type - remarking source
254 * RT_ERR_NOT_INIT - The module is not initial
255 * RT_ERR_PORT_ID - invalid port id
256 * RT_ERR_INPUT - invalid input parameter
259 * The API can configure 802.1p remark functionality to map original 802.1p value or internal
260 * priority to TX DSCP value.
262 extern rtk_api_ret_t
rtk_qos_1pRemarkSrcSel_set(rtk_qos_1pRmkSrc_t type
);
265 * rtk_qos_1pRemarkSrcSel_get
267 * Get remarking source of 802.1p remarking.
271 * pType - remarking source
275 * RT_ERR_NOT_INIT - The module is not initial
276 * RT_ERR_PORT_ID - invalid port id
277 * RT_ERR_INPUT - invalid input parameter
278 * RT_ERR_NULL_POINTER - input parameter may be null pointer
283 extern rtk_api_ret_t
rtk_qos_1pRemarkSrcSel_get(rtk_qos_1pRmkSrc_t
*pType
);
286 * rtk_qos_dscpPriRemap_set
288 * Map dscp value to internal priority.
290 * dscp - Dscp value of receiving frame
291 * int_pri - internal priority value .
296 * RT_ERR_FAILED - Failed
297 * RT_ERR_SMI - SMI access error
298 * RT_ERR_INPUT - Invalid input parameters.
299 * RT_ERR_QOS_DSCP_VALUE - Invalid DSCP value.
300 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
302 * The Differentiated Service Code Point is a selector for router's per-hop behaviors. As a selector, there is no implication that a numerically
303 * 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
304 * DSCP are carefully chosen then backward compatibility can be achieved.
306 extern rtk_api_ret_t
rtk_qos_dscpPriRemap_set(rtk_dscp_t dscp
, rtk_pri_t int_pri
);
309 * rtk_qos_dscpPriRemap_get
311 * Get dscp value to internal priority.
313 * dscp - Dscp value of receiving frame
315 * pInt_pri - internal priority value.
318 * RT_ERR_FAILED - Failed
319 * RT_ERR_SMI - SMI access error
320 * RT_ERR_QOS_DSCP_VALUE - Invalid DSCP value.
322 * The Differentiated Service Code Point is a selector for router's per-hop behaviors. As a selector, there is no implication that a numerically
323 * 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
324 * DSCP are carefully chosen then backward compatibility can be achieved.
326 extern rtk_api_ret_t
rtk_qos_dscpPriRemap_get(rtk_dscp_t dscp
, rtk_pri_t
*pInt_pri
);
329 * rtk_qos_portPri_set
331 * Configure priority usage to each port.
334 * int_pri - internal priority value.
339 * RT_ERR_FAILED - Failed
340 * RT_ERR_SMI - SMI access error
341 * RT_ERR_PORT_ID - Invalid port number.
342 * RT_ERR_QOS_SEL_PORT_PRI - Invalid port priority.
343 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
345 * The API can set priority of port assignments for queue usage and packet scheduling.
347 extern rtk_api_ret_t
rtk_qos_portPri_set(rtk_port_t port
, rtk_pri_t int_pri
) ;
350 * rtk_qos_portPri_get
352 * Get priority usage to each port.
356 * pInt_pri - internal priority value.
359 * RT_ERR_FAILED - Failed
360 * RT_ERR_SMI - SMI access error
361 * RT_ERR_PORT_ID - Invalid port number.
362 * RT_ERR_INPUT - Invalid input parameters.
364 * The API can get priority of port assignments for queue usage and packet scheduling.
366 extern rtk_api_ret_t
rtk_qos_portPri_get(rtk_port_t port
, rtk_pri_t
*pInt_pri
) ;
369 * rtk_qos_queueNum_set
371 * Set output queue number for each port.
374 * index - Mapping queue number (1~8)
379 * RT_ERR_FAILED - Failed
380 * RT_ERR_SMI - SMI access error
381 * RT_ERR_PORT_ID - Invalid port number.
382 * RT_ERR_QUEUE_NUM - Invalid queue number.
384 * The API can set the output queue number of the specified port. The queue number is from 1 to 8.
386 extern rtk_api_ret_t
rtk_qos_queueNum_set(rtk_port_t port
, rtk_queue_num_t queue_num
);
389 * rtk_qos_queueNum_get
391 * Get output queue number.
395 * pQueue_num - Mapping queue number
398 * RT_ERR_FAILED - Failed
399 * RT_ERR_SMI - SMI access error
400 * RT_ERR_PORT_ID - Invalid port number.
402 * The API will return the output queue number of the specified port. The queue number is from 1 to 8.
404 extern rtk_api_ret_t
rtk_qos_queueNum_get(rtk_port_t port
, rtk_queue_num_t
*pQueue_num
);
409 * Set output queue number for each port.
411 * queue_num - Queue number usage.
412 * pPri2qid - Priority mapping to queue ID.
417 * RT_ERR_FAILED - Failed
418 * RT_ERR_SMI - SMI access error
419 * RT_ERR_INPUT - Invalid input parameters.
420 * RT_ERR_QUEUE_NUM - Invalid queue number.
421 * RT_ERR_QUEUE_ID - Invalid queue id.
422 * RT_ERR_PORT_ID - Invalid port number.
423 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
425 * ASIC supports priority mapping to queue with different queue number from 1 to 8.
426 * For different queue numbers usage, ASIC supports different internal available queue IDs.
428 extern rtk_api_ret_t
rtk_qos_priMap_set(rtk_queue_num_t queue_num
, rtk_qos_pri2queue_t
*pPri2qid
);
434 * Get priority to queue ID mapping table parameters.
436 * queue_num - Queue number usage.
438 * pPri2qid - Priority mapping to queue ID.
441 * RT_ERR_FAILED - Failed
442 * RT_ERR_SMI - SMI access error
443 * RT_ERR_INPUT - Invalid input parameters.
444 * RT_ERR_QUEUE_NUM - Invalid queue number.
446 * The API can return the mapping queue id of the specified priority and queue number.
447 * The queue number is from 1 to 8.
449 extern rtk_api_ret_t
rtk_qos_priMap_get(rtk_queue_num_t queue_num
, rtk_qos_pri2queue_t
*pPri2qid
);
452 * rtk_qos_schedulingQueue_set
454 * Set weight and type of queues in dedicated port.
457 * pQweights - The array of weights for WRR/WFQ queue (0 for STRICT_PRIORITY queue).
462 * RT_ERR_FAILED - Failed
463 * RT_ERR_SMI - SMI access error
464 * RT_ERR_PORT_ID - Invalid port number.
465 * RT_ERR_QOS_QUEUE_WEIGHT - Invalid queue weight.
467 * The API can set weight and type, strict priority or weight fair queue (WFQ) for
468 * dedicated port for using queues. If queue id is not included in queue usage,
469 * then its type and weight setting in dummy for setting. There are priorities
470 * as queue id in strict queues. It means strict queue id 5 carrying higher priority
471 * than strict queue id 4. The WFQ queue weight is from 1 to 128, and weight 0 is
472 * for strict priority queue type.
474 extern rtk_api_ret_t
rtk_qos_schedulingQueue_set(rtk_port_t port
, rtk_qos_queue_weights_t
*pQweights
);
477 * rtk_qos_schedulingQueue_get
479 * Get weight and type of queues in dedicated port.
483 * pQweights - The array of weights for WRR/WFQ queue (0 for STRICT_PRIORITY queue).
486 * RT_ERR_FAILED - Failed
487 * RT_ERR_SMI - SMI access error
488 * RT_ERR_INPUT - Invalid input parameters.
489 * RT_ERR_PORT_ID - Invalid port number.
491 * The API can get weight and type, strict priority or weight fair queue (WFQ) for dedicated port for using queues.
492 * The WFQ queue weight is from 1 to 128, and weight 0 is for strict priority queue type.
494 extern rtk_api_ret_t
rtk_qos_schedulingQueue_get(rtk_port_t port
, rtk_qos_queue_weights_t
*pQweights
);
497 * rtk_qos_1pRemarkEnable_set
499 * Set 1p Remarking state
502 * enable - State of per-port 1p Remarking
507 * RT_ERR_FAILED - Failed
508 * RT_ERR_SMI - SMI access error
509 * RT_ERR_PORT_ID - Invalid port number.
510 * RT_ERR_ENABLE - Invalid enable parameter.
512 * The API can enable or disable 802.1p remarking ability for whole system.
513 * The status of 802.1p remark:
517 extern rtk_api_ret_t
rtk_qos_1pRemarkEnable_set(rtk_port_t port
, rtk_enable_t enable
);
520 * rtk_qos_1pRemarkEnable_get
522 * Get 802.1p remarking ability.
526 * pEnable - Status of 802.1p remark.
529 * RT_ERR_FAILED - Failed
530 * RT_ERR_SMI - SMI access error
531 * RT_ERR_PORT_ID - Invalid port number.
533 * The API can get 802.1p remarking ability.
534 * The status of 802.1p remark:
538 extern rtk_api_ret_t
rtk_qos_1pRemarkEnable_get(rtk_port_t port
, rtk_enable_t
*pEnable
);
541 * rtk_qos_1pRemark_set
543 * Set 802.1p remarking parameter.
545 * int_pri - Internal priority value.
546 * dot1p_pri - 802.1p priority value.
551 * RT_ERR_FAILED - Failed
552 * RT_ERR_SMI - SMI access error
553 * RT_ERR_VLAN_PRIORITY - Invalid 1p priority.
554 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
556 * The API can set 802.1p parameters source priority and new priority.
558 extern rtk_api_ret_t
rtk_qos_1pRemark_set(rtk_pri_t int_pri
, rtk_pri_t dot1p_pri
);
561 * rtk_qos_1pRemark_get
563 * Get 802.1p remarking parameter.
565 * int_pri - Internal priority value.
567 * pDot1p_pri - 802.1p priority value.
570 * RT_ERR_FAILED - Failed
571 * RT_ERR_SMI - SMI access error
572 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
574 * The API can get 802.1p remarking parameters. It would return new priority of ingress priority.
576 extern rtk_api_ret_t
rtk_qos_1pRemark_get(rtk_pri_t int_pri
, rtk_pri_t
*pDot1p_pri
);
579 * rtk_qos_dscpRemarkEnable_set
581 * Set DSCP remarking ability.
584 * enable - status of DSCP remark.
589 * RT_ERR_FAILED - Failed
590 * RT_ERR_SMI - SMI access error
591 * RT_ERR_PORT_ID - Invalid port number.
592 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
593 * RT_ERR_ENABLE - Invalid enable parameter.
595 * The API can enable or disable DSCP remarking ability for whole system.
596 * The status of DSCP remark:
600 extern rtk_api_ret_t
rtk_qos_dscpRemarkEnable_set(rtk_port_t port
, rtk_enable_t enable
);
603 * rtk_qos_dscpRemarkEnable_get
605 * Get DSCP remarking ability.
609 * pEnable - status of DSCP remarking.
612 * RT_ERR_FAILED - Failed
613 * RT_ERR_SMI - SMI access error
614 * RT_ERR_PORT_ID - Invalid port number.
616 * The API can get DSCP remarking ability.
617 * The status of DSCP remark:
621 extern rtk_api_ret_t
rtk_qos_dscpRemarkEnable_get(rtk_port_t port
, rtk_enable_t
*pEnable
);
624 * rtk_qos_dscpRemark_set
626 * Set DSCP remarking parameter.
628 * int_pri - Internal priority value.
634 * RT_ERR_FAILED - Failed
635 * RT_ERR_SMI - SMI access error
636 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
637 * RT_ERR_QOS_DSCP_VALUE - Invalid DSCP value.
639 * The API can set DSCP value and mapping priority.
641 extern rtk_api_ret_t
rtk_qos_dscpRemark_set(rtk_pri_t int_pri
, rtk_dscp_t dscp
);
644 * rtk_qos_dscpRemark_get
646 * Get DSCP remarking parameter.
648 * int_pri - Internal priority value.
653 * RT_ERR_FAILED - Failed
654 * RT_ERR_SMI - SMI access error
655 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
657 * The API can get DSCP parameters. It would return DSCP value for mapping priority.
659 extern rtk_api_ret_t
rtk_qos_dscpRemark_get(rtk_pri_t int_pri
, rtk_dscp_t
*pDscp
);
662 * rtk_qos_dscpRemarkSrcSel_set
664 * Set remarking source of DSCP remarking.
666 * type - remarking source
672 * RT_ERR_NOT_INIT - The module is not initial
673 * RT_ERR_PORT_ID - invalid port id
674 * RT_ERR_INPUT - invalid input parameter
677 * The API can configure DSCP remark functionality to map original DSCP value or internal
678 * priority to TX DSCP value.
680 extern rtk_api_ret_t
rtk_qos_dscpRemarkSrcSel_set(rtk_qos_dscpRmkSrc_t type
);
684 * rtk_qos_dcpRemarkSrcSel_get
686 * Get remarking source of DSCP remarking.
690 * pType - remarking source
694 * RT_ERR_NOT_INIT - The module is not initial
695 * RT_ERR_PORT_ID - invalid port id
696 * RT_ERR_INPUT - invalid input parameter
697 * RT_ERR_NULL_POINTER - input parameter may be null pointer
702 extern rtk_api_ret_t
rtk_qos_dscpRemarkSrcSel_get(rtk_qos_dscpRmkSrc_t
*pType
);
706 * rtk_qos_dscpRemark2Dscp_set
708 * Set DSCP to remarked DSCP mapping.
711 * rmkDscp - remarked DSCP value
717 * RT_ERR_QOS_DSCP_VALUE - Invalid dscp value
719 * dscp parameter can be DSCP value or internal priority according to configuration of API
720 * dal_apollomp_qos_dscpRemarkSrcSel_set(), because DSCP remark functionality can map original DSCP
721 * value or internal priority to TX DSCP value.
723 extern rtk_api_ret_t
rtk_qos_dscpRemark2Dscp_set(rtk_dscp_t dscp
, rtk_dscp_t rmkDscp
);
726 * rtk_qos_dscpRemark2Dscp_get
728 * Get DSCP to remarked DSCP mapping.
732 * pDscp - remarked DSCP value
736 * RT_ERR_QOS_DSCP_VALUE - Invalid dscp value
737 * RT_ERR_NULL_POINTER - NULL pointer
741 extern rtk_api_ret_t
rtk_qos_dscpRemark2Dscp_get(rtk_dscp_t dscp
, rtk_dscp_t
*pDscp
);
744 * rtk_qos_portPriSelIndex_set
746 * Configure priority decision index to each port.
749 * index - priority decision index.
754 * RT_ERR_FAILED - Failed
755 * RT_ERR_SMI - SMI access error
756 * RT_ERR_PORT_ID - Invalid port number.
757 * RT_ERR_ENTRY_INDEX - Invalid entry index.
759 * The API can set priority of port assignments for queue usage and packet scheduling.
761 extern rtk_api_ret_t
rtk_qos_portPriSelIndex_set(rtk_port_t port
, rtk_qos_priDecTbl_t index
);
764 * rtk_qos_portPriSelIndex_get
766 * Get priority decision index from each port.
770 * pIndex - priority decision index.
773 * RT_ERR_FAILED - Failed
774 * RT_ERR_SMI - SMI access error
775 * RT_ERR_PORT_ID - Invalid port number.
777 * The API can get priority of port assignments for queue usage and packet scheduling.
779 extern rtk_api_ret_t
rtk_qos_portPriSelIndex_get(rtk_port_t port
, rtk_qos_priDecTbl_t
*pIndex
);
781 #endif /* __RTK_API_QOS_H__ */