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 rate module.
18 #include <rtk_switch.h>
19 #include <rtk_error.h>
24 #include <rtl8367c_asicdrv.h>
25 #include <rtl8367c_asicdrv_meter.h>
26 #include <rtl8367c_asicdrv_inbwctrl.h>
27 #include <rtl8367c_asicdrv_scheduling.h>
30 * rtk_rate_shareMeter_set
32 * Set meter configuration
34 * index - shared meter index
35 * type - shared meter type
36 * rate - rate of share meter
37 * ifg_include - include IFG or not, ENABLE:include DISABLE:exclude
42 * RT_ERR_FAILED - Failed
43 * RT_ERR_SMI - SMI access error
44 * RT_ERR_FILTER_METER_ID - Invalid meter
45 * RT_ERR_RATE - Invalid rate
46 * RT_ERR_INPUT - Invalid input parameters
48 * The API can set shared meter rate and ifg include for each meter.
49 * The rate unit is 1 kbps and the range is from 8k to 1048568k if type is METER_TYPE_KBPS and
50 * the granularity of rate is 8 kbps.
51 * The rate unit is packets per second and the range is 1 ~ 0x1FFF if type is METER_TYPE_PPS.
52 * The ifg_include parameter is used
53 * for rate calculation with/without inter-frame-gap and preamble.
55 rtk_api_ret_t
rtk_rate_shareMeter_set(rtk_meter_id_t index
, rtk_meter_type_t type
, rtk_rate_t rate
, rtk_enable_t ifg_include
)
59 /* Check initialization state */
62 if (index
> RTK_MAX_METER_ID
)
63 return RT_ERR_FILTER_METER_ID
;
65 if (type
>= METER_TYPE_END
)
68 if (ifg_include
>= RTK_ENABLE_END
)
74 if (rate
> RTL8367C_QOS_RATE_INPUT_MAX_HSG
|| rate
< RTL8367C_QOS_RATE_INPUT_MIN
)
77 if ((retVal
= rtl8367c_setAsicShareMeter(index
, rate
>> 3, ifg_include
)) != RT_ERR_OK
)
82 if (rate
> RTL8367C_QOS_PPS_INPUT_MAX
|| rate
< RTL8367C_QOS_PPS_INPUT_MIN
)
85 if ((retVal
= rtl8367c_setAsicShareMeter(index
, rate
, ifg_include
)) != RT_ERR_OK
)
94 if ((retVal
= rtl8367c_setAsicShareMeterType(index
, (rtk_uint32
)type
)) != RT_ERR_OK
)
101 * rtk_rate_shareMeter_get
103 * Get meter configuration
105 * index - shared meter index
108 * pRate - pointer of rate of share meter
109 * pIfg_include - include IFG or not, ENABLE:include DISABLE:exclude
112 * RT_ERR_FAILED - Failed
113 * RT_ERR_SMI - SMI access error
114 * RT_ERR_FILTER_METER_ID - Invalid meter
118 rtk_api_ret_t
rtk_rate_shareMeter_get(rtk_meter_id_t index
, rtk_meter_type_t
*pType
, rtk_rate_t
*pRate
, rtk_enable_t
*pIfg_include
)
120 rtk_api_ret_t retVal
;
123 /* Check initialization state */
124 RTK_CHK_INIT_STATE();
126 if (index
> RTK_MAX_METER_ID
)
127 return RT_ERR_FILTER_METER_ID
;
130 return RT_ERR_NULL_POINTER
;
133 return RT_ERR_NULL_POINTER
;
135 if(NULL
== pIfg_include
)
136 return RT_ERR_NULL_POINTER
;
138 if ((retVal
= rtl8367c_getAsicShareMeter(index
, ®Data
, pIfg_include
)) != RT_ERR_OK
)
141 if ((retVal
= rtl8367c_getAsicShareMeterType(index
, (rtk_uint32
*)pType
)) != RT_ERR_OK
)
144 if(*pType
== METER_TYPE_KBPS
)
153 * rtk_rate_shareMeterBucket_set
155 * Set meter Bucket Size
157 * index - shared meter index
158 * bucket_size - Bucket Size
163 * RT_ERR_FAILED - Failed
164 * RT_ERR_INPUT - Error Input
165 * RT_ERR_SMI - SMI access error
166 * RT_ERR_FILTER_METER_ID - Invalid meter
168 * The API can set shared meter bucket size.
170 rtk_api_ret_t
rtk_rate_shareMeterBucket_set(rtk_meter_id_t index
, rtk_uint32 bucket_size
)
172 rtk_api_ret_t retVal
;
174 /* Check initialization state */
175 RTK_CHK_INIT_STATE();
177 if (index
> RTK_MAX_METER_ID
)
178 return RT_ERR_FILTER_METER_ID
;
180 if(bucket_size
> RTL8367C_METERBUCKETSIZEMAX
)
183 if ((retVal
= rtl8367c_setAsicShareMeterBucketSize(index
, bucket_size
)) != RT_ERR_OK
)
190 * rtk_rate_shareMeterBucket_get
192 * Get meter Bucket Size
194 * index - shared meter index
196 * pBucket_size - Bucket Size
199 * RT_ERR_FAILED - Failed
200 * RT_ERR_SMI - SMI access error
201 * RT_ERR_FILTER_METER_ID - Invalid meter
203 * The API can get shared meter bucket size.
205 rtk_api_ret_t
rtk_rate_shareMeterBucket_get(rtk_meter_id_t index
, rtk_uint32
*pBucket_size
)
207 rtk_api_ret_t retVal
;
209 /* Check initialization state */
210 RTK_CHK_INIT_STATE();
212 if (index
> RTK_MAX_METER_ID
)
213 return RT_ERR_FILTER_METER_ID
;
215 if(NULL
== pBucket_size
)
216 return RT_ERR_NULL_POINTER
;
218 if ((retVal
= rtl8367c_getAsicShareMeterBucketSize(index
, pBucket_size
)) != RT_ERR_OK
)
225 * rtk_rate_igrBandwidthCtrlRate_set
227 * Set port ingress bandwidth control
230 * rate - Rate of share meter
231 * ifg_include - include IFG or not, ENABLE:include DISABLE:exclude
232 * fc_enable - enable flow control or not, ENABLE:use flow control DISABLE:drop
237 * RT_ERR_FAILED - Failed
238 * RT_ERR_SMI - SMI access error
239 * RT_ERR_PORT_ID - Invalid port number.
240 * RT_ERR_ENABLE - Invalid IFG parameter.
241 * RT_ERR_INBW_RATE - Invalid ingress rate parameter.
243 * The rate unit is 1 kbps and the range is from 8k to 1048568k. The granularity of rate is 8 kbps.
244 * The ifg_include parameter is used for rate calculation with/without inter-frame-gap and preamble.
246 rtk_api_ret_t
rtk_rate_igrBandwidthCtrlRate_set(rtk_port_t port
, rtk_rate_t rate
, rtk_enable_t ifg_include
, rtk_enable_t fc_enable
)
248 rtk_api_ret_t retVal
;
250 /* Check initialization state */
251 RTK_CHK_INIT_STATE();
253 /* Check Port Valid */
254 RTK_CHK_PORT_VALID(port
);
256 if(ifg_include
>= RTK_ENABLE_END
)
259 if(fc_enable
>= RTK_ENABLE_END
)
262 if(rtk_switch_isHsgPort(port
) == RT_ERR_OK
)
264 if ((rate
> RTL8367C_QOS_RATE_INPUT_MAX_HSG
) || (rate
< RTL8367C_QOS_RATE_INPUT_MIN
))
265 return RT_ERR_QOS_EBW_RATE
;
269 if ((rate
> RTL8367C_QOS_RATE_INPUT_MAX
) || (rate
< RTL8367C_QOS_RATE_INPUT_MIN
))
270 return RT_ERR_QOS_EBW_RATE
;
273 if ((retVal
= rtl8367c_setAsicPortIngressBandwidth(rtk_switch_port_L2P_get(port
), rate
>>3, ifg_include
,fc_enable
)) != RT_ERR_OK
)
280 * rtk_rate_igrBandwidthCtrlRate_get
282 * Get port ingress bandwidth control
286 * pRate - Rate of share meter
287 * pIfg_include - Rate's calculation including IFG, ENABLE:include DISABLE:exclude
288 * pFc_enable - enable flow control or not, ENABLE:use flow control DISABLE:drop
291 * RT_ERR_FAILED - Failed
292 * RT_ERR_SMI - SMI access error
293 * RT_ERR_PORT_ID - Invalid port number.
294 * RT_ERR_INPUT - Invalid input parameters.
296 * The rate unit is 1 kbps and the range is from 8k to 1048568k. The granularity of rate is 8 kbps.
297 * The ifg_include parameter is used for rate calculation with/without inter-frame-gap and preamble.
299 rtk_api_ret_t
rtk_rate_igrBandwidthCtrlRate_get(rtk_port_t port
, rtk_rate_t
*pRate
, rtk_enable_t
*pIfg_include
, rtk_enable_t
*pFc_enable
)
301 rtk_api_ret_t retVal
;
304 /* Check initialization state */
305 RTK_CHK_INIT_STATE();
307 /* Check Port Valid */
308 RTK_CHK_PORT_VALID(port
);
310 if(NULL
== pIfg_include
)
311 return RT_ERR_NULL_POINTER
;
313 if(NULL
== pFc_enable
)
314 return RT_ERR_NULL_POINTER
;
316 if ((retVal
= rtl8367c_getAsicPortIngressBandwidth(rtk_switch_port_L2P_get(port
), ®Data
, pIfg_include
, pFc_enable
)) != RT_ERR_OK
)
325 * rtk_rate_egrBandwidthCtrlRate_set
327 * Set port egress bandwidth control
330 * rate - Rate of egress bandwidth
331 * ifg_include - include IFG or not, ENABLE:include DISABLE:exclude
336 * RT_ERR_FAILED - Failed
337 * RT_ERR_SMI - SMI access error
338 * RT_ERR_PORT_ID - Invalid port number.
339 * RT_ERR_INPUT - Invalid input parameters.
340 * RT_ERR_QOS_EBW_RATE - Invalid egress bandwidth/rate
342 * The rate unit is 1 kbps and the range is from 8k to 1048568k. The granularity of rate is 8 kbps.
343 * The ifg_include parameter is used for rate calculation with/without inter-frame-gap and preamble.
345 rtk_api_ret_t
rtk_rate_egrBandwidthCtrlRate_set( rtk_port_t port
, rtk_rate_t rate
, rtk_enable_t ifg_include
)
347 rtk_api_ret_t retVal
;
349 /* Check initialization state */
350 RTK_CHK_INIT_STATE();
352 /* Check Port Valid */
353 RTK_CHK_PORT_VALID(port
);
355 if(rtk_switch_isHsgPort(port
) == RT_ERR_OK
)
357 if ((rate
> RTL8367C_QOS_RATE_INPUT_MAX_HSG
) || (rate
< RTL8367C_QOS_RATE_INPUT_MIN
))
358 return RT_ERR_QOS_EBW_RATE
;
362 if ((rate
> RTL8367C_QOS_RATE_INPUT_MAX
) || (rate
< RTL8367C_QOS_RATE_INPUT_MIN
))
363 return RT_ERR_QOS_EBW_RATE
;
366 if (ifg_include
>= RTK_ENABLE_END
)
367 return RT_ERR_ENABLE
;
369 if ((retVal
= rtl8367c_setAsicPortEgressRate(rtk_switch_port_L2P_get(port
), rate
>>3)) != RT_ERR_OK
)
372 if ((retVal
= rtl8367c_setAsicPortEgressRateIfg(ifg_include
)) != RT_ERR_OK
)
379 * rtk_rate_egrBandwidthCtrlRate_get
381 * Get port egress bandwidth control
385 * pRate - Rate of egress bandwidth
386 * pIfg_include - Rate's calculation including IFG, ENABLE:include DISABLE:exclude
389 * RT_ERR_FAILED - Failed
390 * RT_ERR_SMI - SMI access error
391 * RT_ERR_PORT_ID - Invalid port number.
392 * RT_ERR_INPUT - Invalid input parameters.
394 * The rate unit is 1 kbps and the range is from 8k to 1048568k. The granularity of rate is 8 kbps.
395 * The ifg_include parameter is used for rate calculation with/without inter-frame-gap and preamble.
397 rtk_api_ret_t
rtk_rate_egrBandwidthCtrlRate_get(rtk_port_t port
, rtk_rate_t
*pRate
, rtk_enable_t
*pIfg_include
)
399 rtk_api_ret_t retVal
;
402 /* Check initialization state */
403 RTK_CHK_INIT_STATE();
405 /* Check Port Valid */
406 RTK_CHK_PORT_VALID(port
);
409 return RT_ERR_NULL_POINTER
;
411 if(NULL
== pIfg_include
)
412 return RT_ERR_NULL_POINTER
;
414 if ((retVal
= rtl8367c_getAsicPortEgressRate(rtk_switch_port_L2P_get(port
), ®Data
)) != RT_ERR_OK
)
417 *pRate
= regData
<< 3;
419 if ((retVal
= rtl8367c_getAsicPortEgressRateIfg((rtk_uint32
*)pIfg_include
)) != RT_ERR_OK
)
427 * rtk_rate_egrQueueBwCtrlEnable_get
429 * Get enable status of egress bandwidth control on specified queue.
435 * pEnable - Pointer to enable status of egress queue bandwidth control
439 * RT_ERR_PORT_ID - invalid port id
440 * RT_ERR_QUEUE_ID - invalid queue id
441 * RT_ERR_NULL_POINTER - input parameter may be null pointer
445 rtk_api_ret_t
rtk_rate_egrQueueBwCtrlEnable_get(rtk_port_t port
, rtk_qid_t queue
, rtk_enable_t
*pEnable
)
447 rtk_api_ret_t retVal
;
449 /* Check initialization state */
450 RTK_CHK_INIT_STATE();
452 /* Check Port Valid */
453 RTK_CHK_PORT_VALID(port
);
455 /*for whole port function, the queue value should be 0xFF*/
456 if (queue
!= RTK_WHOLE_SYSTEM
)
457 return RT_ERR_QUEUE_ID
;
460 return RT_ERR_NULL_POINTER
;
462 if ((retVal
= rtl8367c_getAsicAprEnable(rtk_switch_port_L2P_get(port
),pEnable
))!=RT_ERR_OK
)
469 * rtk_rate_egrQueueBwCtrlEnable_set
471 * Set enable status of egress bandwidth control on specified queue.
475 * enable - enable status of egress queue bandwidth control
481 * RT_ERR_PORT_ID - invalid port id
482 * RT_ERR_QUEUE_ID - invalid queue id
483 * RT_ERR_INPUT - invalid input parameter
487 rtk_api_ret_t
rtk_rate_egrQueueBwCtrlEnable_set(rtk_port_t port
, rtk_qid_t queue
, rtk_enable_t enable
)
489 rtk_api_ret_t retVal
;
491 /* Check initialization state */
492 RTK_CHK_INIT_STATE();
494 /* Check Port Valid */
495 RTK_CHK_PORT_VALID(port
);
497 /*for whole port function, the queue value should be 0xFF*/
498 if (queue
!= RTK_WHOLE_SYSTEM
)
499 return RT_ERR_QUEUE_ID
;
501 if (enable
>=RTK_ENABLE_END
)
504 if ((retVal
= rtl8367c_setAsicAprEnable(rtk_switch_port_L2P_get(port
), enable
))!=RT_ERR_OK
)
511 * rtk_rate_egrQueueBwCtrlRate_get
513 * Get rate of egress bandwidth control on specified queue.
517 * pIndex - shared meter index
519 * pRate - pointer to rate of egress queue bandwidth control
523 * RT_ERR_PORT_ID - invalid port id
524 * RT_ERR_QUEUE_ID - invalid queue id
525 * RT_ERR_FILTER_METER_ID - Invalid meter id
527 * The actual rate control is set in shared meters.
528 * The unit of granularity is 8Kbps.
530 rtk_api_ret_t
rtk_rate_egrQueueBwCtrlRate_get(rtk_port_t port
, rtk_qid_t queue
, rtk_meter_id_t
*pIndex
)
532 rtk_api_ret_t retVal
;
533 rtk_uint32 offset_idx
;
536 /* Check initialization state */
537 RTK_CHK_INIT_STATE();
539 /* Check Port Valid */
540 RTK_CHK_PORT_VALID(port
);
542 if (queue
>= RTK_MAX_NUM_OF_QUEUE
)
543 return RT_ERR_QUEUE_ID
;
546 return RT_ERR_NULL_POINTER
;
548 phy_port
= rtk_switch_port_L2P_get(port
);
549 if ((retVal
=rtl8367c_getAsicAprMeter(phy_port
, queue
,&offset_idx
))!=RT_ERR_OK
)
552 *pIndex
= offset_idx
+ ((phy_port
%4)*8);
559 * rtk_rate_egrQueueBwCtrlRate_set
561 * Set rate of egress bandwidth control on specified queue.
565 * index - shared meter index
571 * RT_ERR_PORT_ID - invalid port id
572 * RT_ERR_QUEUE_ID - invalid queue id
573 * RT_ERR_FILTER_METER_ID - Invalid meter id
575 * The actual rate control is set in shared meters.
576 * The unit of granularity is 8Kbps.
578 rtk_api_ret_t
rtk_rate_egrQueueBwCtrlRate_set(rtk_port_t port
, rtk_qid_t queue
, rtk_meter_id_t index
)
580 rtk_api_ret_t retVal
;
581 rtk_uint32 offset_idx
;
584 /* Check initialization state */
585 RTK_CHK_INIT_STATE();
587 /* Check Port Valid */
588 RTK_CHK_PORT_VALID(port
);
590 if (queue
>= RTK_MAX_NUM_OF_QUEUE
)
591 return RT_ERR_QUEUE_ID
;
593 if (index
> RTK_MAX_METER_ID
)
594 return RT_ERR_FILTER_METER_ID
;
596 phy_port
= rtk_switch_port_L2P_get(port
);
597 if (index
< ((phy_port
%4)*8) || index
> (7 + (phy_port
%4)*8))
598 return RT_ERR_FILTER_METER_ID
;
600 offset_idx
= index
- ((phy_port
%4)*8);
602 if ((retVal
=rtl8367c_setAsicAprMeter(phy_port
,queue
,offset_idx
))!=RT_ERR_OK
)