/* * Copyright (C) 2013 Realtek Semiconductor Corp. * All Rights Reserved. * * This program is the proprietary software of Realtek Semiconductor * Corporation and/or its licensors, and only be used, duplicated, * modified or distributed under the authorized license from Realtek. * * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. * * $Revision$ * $Date$ * * Purpose : RTK switch high-level API for RTL8373 * Feature : Here is a list of all functions and variables in rate module. * */ #include #include #include #include #include /* Function Name: * rtk_rate_shareMeter_set * Description: * Set meter configuration * Input: * index - shared meter index(0 - 63) * type - shared meter type * rate - rate of share meter * ifg_include - include IFG or not, ENABLE:include DISABLE:exclude * Output: * None * Return: * RT_ERR_OK - OK * RT_ERR_FAILED - Failed * RT_ERR_SMI - SMI access error * RT_ERR_FILTER_METER_ID - Invalid meter * RT_ERR_RATE - Invalid rate * RT_ERR_INPUT - Invalid input parameters * Note: * The API can set shared meter rate and ifg include for each meter. * The rate unit is 16 kbps and the range is from 0 to 0x98968 if type is METER_TYPE_KBPS and * the granularity of rate is 16 kbps. * The rate unit is packets per second and the range is 0 ~ 0xFFFFF if type is METER_TYPE_PPS. * The ifg_include parameter is used * for rate calculation with/without inter-frame-gap and preamble. */ 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) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_shareMeter_set) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_shareMeter_set(index, type, rate, ifg_include); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_shareMeter_get * Description: * Get meter configuration * Input: * index - shared meter index(0 - 63) * Output: * pType - Meter Type * pRate - pointer of rate of share meter * pIfg_include - include IFG or not, ENABLE:include DISABLE:exclude * Return: * RT_ERR_OK - OK * RT_ERR_FAILED - Failed * RT_ERR_SMI - SMI access error * RT_ERR_FILTER_METER_ID - Invalid meter * Note: * */ 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) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_shareMeter_get) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_shareMeter_get(index, pType, pRate, pIfg_include); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_shareMeterBucket_set * Description: * Set meter Bucket Size * Input: * index - shared meter index * bucket_size - Bucket Size * Output: * None. * Return: * RT_ERR_OK - OK * RT_ERR_FAILED - Failed * RT_ERR_INPUT - Error Input * RT_ERR_SMI - SMI access error * RT_ERR_FILTER_METER_ID - Invalid meter * Note: * The API can set shared meter bucket size. */ rtk_api_ret_t rtk_rate_shareMeterBucket_set(rtk_meter_id_t index, rtk_uint32 bucket_size) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_shareMeterBucket_set) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_shareMeterBucket_set(index, bucket_size); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_shareMeterBucket_get * Description: * Get meter Bucket Size * Input: * index - shared meter index * Output: * pBucket_size - Bucket Size * Return: * RT_ERR_OK - OK * RT_ERR_FAILED - Failed * RT_ERR_SMI - SMI access error * RT_ERR_FILTER_METER_ID - Invalid meter * Note: * The API can get shared meter bucket size. */ rtk_api_ret_t rtk_rate_shareMeterBucket_get(rtk_meter_id_t index, rtk_uint32 *pBucket_size) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_shareMeterBucket_get) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_shareMeterBucket_get(index, pBucket_size); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_shareMeterExceedStatus_set * Description: * Clear shared meter status * Input: * index - share meter index (0 - 63) * Output: * None * Return: * RT_ERR_OK - Success * RT_ERR_SMI - SMI access error * RT_ERR_FILTER_METER_ID - Invalid meter * Note: * None */ ret_t rtk_rate_shareMeterExceedStatus_set(rtk_uint32 index) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_shareMeterExceedStatus_set) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_shareMeterExceedStatus_set(index); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_shareMeterExceedStatus_get * Description: * Get shared meter status * Input: * index - share meter index (0-63) * pStatus - 0: rate doesn't exceed 1: rate exceeds * Output: * None * Return: * RT_ERR_OK - Success * RT_ERR_SMI - SMI access error * RT_ERR_FILTER_METER_ID - Invalid meter * Note: * If rate is over rate*16Kbps of a meter, the state bit of this meter is set to 1. */ ret_t rtk_rate_shareMeterExceedStatus_get(rtk_uint32 index, rtk_uint32 *pStatus) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_shareMeterExceedStatus_get) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_shareMeterExceedStatus_get(index, pStatus); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_shareMeterICPUExceedStatus_set * Description: * Clear shared meter ICPU status * Input: * index - meter index (0 - 63) * Output: * None * Return: * RT_ERR_OK - Success * RT_ERR_SMI - SMI access error * RT_ERR_FILTER_METER_ID - Invalid meter * Note: * None */ ret_t rtk_rate_shareMeterICPUExceedStatus_set(rtk_uint32 index) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_shareMeterICPUExceedStatus_set) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_shareMeterICPUExceedStatus_set(index); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_shareMeterICPUExceedStatus_get * Description: * Get shared meter ICPU exceed status * Input: * index - meter index (0 - 63) * pStatus - 0: rate doesn't exceed 1: rate exceeds * Output: * None * Return: * RT_ERR_OK - Success * RT_ERR_SMI - SMI access error * RT_ERR_FILTER_METER_ID - Invalid meter * Note: * If rate is over rate*16Kbps of a meter, the state bit of this meter is set to 1. */ ret_t rtk_rate_shareMeterICPUExceedStatus_get(rtk_uint32 index, rtk_uint32* pStatus) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_shareMeterICPUExceedStatus_get) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_shareMeterICPUExceedStatus_get(index, pStatus); RTK_API_UNLOCK(); return retVal; } #if 0 /* Function Name: * rtk_rate_igrBandwidthCtrlRate_set * Description: * Set port ingress bandwidth control * Input: * port - Port id * rate - Rate of share meter * ifg_include - include IFG or not, ENABLE:include DISABLE:exclude * fc_enable - enable flow control or not, ENABLE:use flow control DISABLE:drop * Output: * None * Return: * RT_ERR_OK - OK * RT_ERR_FAILED - Failed * RT_ERR_SMI - SMI access error * RT_ERR_PORT_ID - Invalid port number. * RT_ERR_ENABLE - Invalid IFG parameter. * RT_ERR_INBW_RATE - Invalid ingress rate parameter. * Note: * The rate unit is 1 kbps and the range is from 8k to 1048568k. The granularity of rate is 8 kbps. * The ifg_include parameter is used for rate calculation with/without inter-frame-gap and preamble. */ 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) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_igrBandwidthCtrlRate_set) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_igrBandwidthCtrlRate_set(port, rate, ifg_include, fc_enable); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_igrBandwidthCtrlRate_get * Description: * Get port ingress bandwidth control * Input: * port - Port id * Output: * pRate - Rate of share meter * pIfg_include - Rate's calculation including IFG, ENABLE:include DISABLE:exclude * pFc_enable - enable flow control or not, ENABLE:use flow control DISABLE:drop * Return: * RT_ERR_OK - OK * RT_ERR_FAILED - Failed * RT_ERR_SMI - SMI access error * RT_ERR_PORT_ID - Invalid port number. * RT_ERR_INPUT - Invalid input parameters. * Note: * The rate unit is 1 kbps and the range is from 8k to 1048568k. The granularity of rate is 8 kbps. * The ifg_include parameter is used for rate calculation with/without inter-frame-gap and preamble. */ 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) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_igrBandwidthCtrlRate_get) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_igrBandwidthCtrlRate_get(port, pRate, pIfg_include, pFc_enable); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_egrBandwidthCtrlRate_set * Description: * Set port egress bandwidth control * Input: * port - Port id * rate - Rate of egress bandwidth * ifg_include - include IFG or not, ENABLE:include DISABLE:exclude * Output: * None * Return: * RT_ERR_OK - OK * RT_ERR_FAILED - Failed * RT_ERR_SMI - SMI access error * RT_ERR_PORT_ID - Invalid port number. * RT_ERR_INPUT - Invalid input parameters. * RT_ERR_QOS_EBW_RATE - Invalid egress bandwidth/rate * Note: * The rate unit is 1 kbps and the range is from 8k to 1048568k. The granularity of rate is 8 kbps. * The ifg_include parameter is used for rate calculation with/without inter-frame-gap and preamble. */ rtk_api_ret_t rtk_rate_egrBandwidthCtrlRate_set( rtk_port_t port, rtk_rate_t rate, rtk_enable_t ifg_include) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_egrBandwidthCtrlRate_set) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_egrBandwidthCtrlRate_set(port, rate, ifg_include); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_egrBandwidthCtrlRate_get * Description: * Get port egress bandwidth control * Input: * port - Port id * Output: * pRate - Rate of egress bandwidth * pIfg_include - Rate's calculation including IFG, ENABLE:include DISABLE:exclude * Return: * RT_ERR_OK - OK * RT_ERR_FAILED - Failed * RT_ERR_SMI - SMI access error * RT_ERR_PORT_ID - Invalid port number. * RT_ERR_INPUT - Invalid input parameters. * Note: * The rate unit is 1 kbps and the range is from 8k to 1048568k. The granularity of rate is 8 kbps. * The ifg_include parameter is used for rate calculation with/without inter-frame-gap and preamble. */ rtk_api_ret_t rtk_rate_egrBandwidthCtrlRate_get(rtk_port_t port, rtk_rate_t *pRate, rtk_enable_t *pIfg_include) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_egrBandwidthCtrlRate_get) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_egrBandwidthCtrlRate_get(port, pRate, pIfg_include); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_egrQueueBwCtrlEnable_get * Description: * Get enable status of egress bandwidth control on specified queue. * Input: * unit - unit id * port - port id * queue - queue id * Output: * pEnable - Pointer to enable status of egress queue bandwidth control * Return: * RT_ERR_OK * RT_ERR_FAILED * RT_ERR_PORT_ID - invalid port id * RT_ERR_QUEUE_ID - invalid queue id * RT_ERR_NULL_POINTER - input parameter may be null pointer * Note: * None */ rtk_api_ret_t rtk_rate_egrQueueBwCtrlEnable_get(rtk_port_t port, rtk_qid_t queue, rtk_enable_t *pEnable) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_egrQueueBwCtrlEnable_get) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_egrQueueBwCtrlEnable_get(port, queue, pEnable); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_egrQueueBwCtrlEnable_set * Description: * Set enable status of egress bandwidth control on specified queue. * Input: * port - port id * queue - queue id * enable - enable status of egress queue bandwidth control * Output: * None * Return: * RT_ERR_OK * RT_ERR_FAILED * RT_ERR_PORT_ID - invalid port id * RT_ERR_QUEUE_ID - invalid queue id * RT_ERR_INPUT - invalid input parameter * Note: * None */ rtk_api_ret_t rtk_rate_egrQueueBwCtrlEnable_set(rtk_port_t port, rtk_qid_t queue, rtk_enable_t enable) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_egrQueueBwCtrlEnable_set) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_egrQueueBwCtrlEnable_set(port, queue, enable); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_egrQueueBwCtrlRate_get * Description: * Get rate of egress bandwidth control on specified queue. * Input: * port - port id * queue - queue id * pIndex - shared meter index * Output: * pRate - pointer to rate of egress queue bandwidth control * Return: * RT_ERR_OK * RT_ERR_FAILED * RT_ERR_PORT_ID - invalid port id * RT_ERR_QUEUE_ID - invalid queue id * RT_ERR_FILTER_METER_ID - Invalid meter id * Note: * The actual rate control is set in shared meters. * The unit of granularity is 8Kbps. */ rtk_api_ret_t rtk_rate_egrQueueBwCtrlRate_get(rtk_port_t port, rtk_qid_t queue, rtk_meter_id_t *pIndex) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_egrQueueBwCtrlRate_get) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_egrQueueBwCtrlRate_get(port, queue, pIndex); RTK_API_UNLOCK(); return retVal; } /* Function Name: * rtk_rate_egrQueueBwCtrlRate_set * Description: * Set rate of egress bandwidth control on specified queue. * Input: * port - port id * queue - queue id * index - shared meter index * Output: * None * Return: * RT_ERR_OK * RT_ERR_FAILED * RT_ERR_PORT_ID - invalid port id * RT_ERR_QUEUE_ID - invalid queue id * RT_ERR_FILTER_METER_ID - Invalid meter id * Note: * The actual rate control is set in shared meters. * The unit of granularity is 8Kbps. */ rtk_api_ret_t rtk_rate_egrQueueBwCtrlRate_set(rtk_port_t port, rtk_qid_t queue, rtk_meter_id_t index) { rtk_api_ret_t retVal; if (NULL == RT_MAPPER->rate_egrQueueBwCtrlRate_set) return RT_ERR_DRIVER_NOT_FOUND; RTK_API_LOCK(); retVal = RT_MAPPER->rate_egrQueueBwCtrlRate_set(port, queue, index); RTK_API_UNLOCK(); return retVal; } #endif