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 : RTL8367C switch high-level API for RTL8367C
14 * Feature : Shared meter related functions
17 #include <rtl8367c_asicdrv_meter.h>
19 * rtl8367c_setAsicShareMeter
21 * Set meter configuration
23 * index - hared meter index (0-31)
24 * rate - 17-bits rate of share meter, unit is 8Kpbs
25 * ifg - Including IFG in rate calculation, 1:include 0:exclude
30 * RT_ERR_SMI - SMI access error
31 * RT_ERR_FILTER_METER_ID - Invalid meter
35 ret_t
rtl8367c_setAsicShareMeter(rtk_uint32 index
, rtk_uint32 rate
, rtk_uint32 ifg
)
39 if(index
> RTL8367C_METERMAX
)
40 return RT_ERR_FILTER_METER_ID
;
45 retVal
= rtl8367c_setAsicReg(RTL8367C_METER_RATE_REG(index
), rate
&0xFFFF);
46 if(retVal
!= RT_ERR_OK
)
49 retVal
= rtl8367c_setAsicReg(RTL8367C_METER_RATE_REG(index
) + 1, (rate
&0x70000) >> 16);
50 if(retVal
!= RT_ERR_OK
)
53 retVal
= rtl8367c_setAsicRegBit(RTL8367C_METER_IFG_CTRL_REG(index
), RTL8367C_METER_IFG_OFFSET(index
), ifg
);
54 if(retVal
!= RT_ERR_OK
)
60 retVal
= rtl8367c_setAsicReg(RTL8367C_REG_METER32_RATE_CTRL0
+ ((index
-32) << 1), rate
&0xFFFF);
61 if(retVal
!= RT_ERR_OK
)
64 retVal
= rtl8367c_setAsicReg(RTL8367C_REG_METER32_RATE_CTRL0
+ ((index
-32) << 1) + 1, (rate
&0x70000) >> 16);
65 if(retVal
!= RT_ERR_OK
)
68 retVal
= rtl8367c_setAsicRegBit(RTL8367C_REG_METER_IFG_CTRL2
+ ((index
-32) >> 4), RTL8367C_METER_IFG_OFFSET(index
), ifg
);
69 if(retVal
!= RT_ERR_OK
)
76 * rtl8367c_getAsicShareMeter
78 * Get meter configuration
80 * index - hared meter index (0-31)
81 * pRate - 17-bits rate of share meter, unit is 8Kpbs
82 * pIfg - Including IFG in rate calculation, 1:include 0:exclude
87 * RT_ERR_SMI - SMI access error
88 * RT_ERR_FILTER_METER_ID - Invalid meter
92 ret_t
rtl8367c_getAsicShareMeter(rtk_uint32 index
, rtk_uint32
*pRate
, rtk_uint32
*pIfg
)
98 if(index
> RTL8367C_METERMAX
)
99 return RT_ERR_FILTER_METER_ID
;
104 retVal
= rtl8367c_getAsicReg(RTL8367C_METER_RATE_REG(index
), ®Data
);
105 if(retVal
!= RT_ERR_OK
)
108 retVal
= rtl8367c_getAsicReg(RTL8367C_METER_RATE_REG(index
) + 1, ®Data2
);
109 if(retVal
!= RT_ERR_OK
)
112 *pRate
= ((regData2
<< 16) & 0x70000) | regData
;
114 retVal
= rtl8367c_getAsicRegBit(RTL8367C_METER_IFG_CTRL_REG(index
), RTL8367C_METER_IFG_OFFSET(index
), pIfg
);
121 retVal
= rtl8367c_getAsicReg(RTL8367C_REG_METER32_RATE_CTRL0
+ ((index
-32) << 1), ®Data
);
122 if(retVal
!= RT_ERR_OK
)
125 retVal
= rtl8367c_getAsicReg(RTL8367C_REG_METER32_RATE_CTRL0
+ ((index
-32) << 1) + 1, ®Data2
);
126 if(retVal
!= RT_ERR_OK
)
129 *pRate
= ((regData2
<< 16) & 0x70000) | regData
;
131 retVal
= rtl8367c_getAsicRegBit(RTL8367C_REG_METER_IFG_CTRL2
+ ((index
-32) >> 4), RTL8367C_METER_IFG_OFFSET(index
), pIfg
);
137 * rtl8367c_setAsicShareMeterBucketSize
139 * Set meter related leaky bucket threshold
141 * index - hared meter index (0-31)
142 * lbthreshold - Leaky bucket threshold of meter
146 * RT_ERR_OK - Success
147 * RT_ERR_SMI - SMI access error
148 * RT_ERR_FILTER_METER_ID - Invalid meter
152 ret_t
rtl8367c_setAsicShareMeterBucketSize(rtk_uint32 index
, rtk_uint32 lbthreshold
)
155 if(index
> RTL8367C_METERMAX
)
156 return RT_ERR_FILTER_METER_ID
;
159 return rtl8367c_setAsicReg(RTL8367C_METER_BUCKET_SIZE_REG(index
), lbthreshold
);
161 return rtl8367c_setAsicReg(RTL8367C_REG_METER32_BUCKET_SIZE
+ index
- 32, lbthreshold
);
164 * rtl8367c_getAsicShareMeterBucketSize
166 * Get meter related leaky bucket threshold
168 * index - hared meter index (0-31)
169 * pLbthreshold - Leaky bucket threshold of meter
173 * RT_ERR_OK - Success
174 * RT_ERR_SMI - SMI access error
175 * RT_ERR_FILTER_METER_ID - Invalid meter
179 ret_t
rtl8367c_getAsicShareMeterBucketSize(rtk_uint32 index
, rtk_uint32
*pLbthreshold
)
181 if(index
> RTL8367C_METERMAX
)
182 return RT_ERR_FILTER_METER_ID
;
185 return rtl8367c_getAsicReg(RTL8367C_METER_BUCKET_SIZE_REG(index
), pLbthreshold
);
187 return rtl8367c_getAsicReg(RTL8367C_REG_METER32_BUCKET_SIZE
+ index
- 32, pLbthreshold
);
191 * rtl8367c_setAsicShareMeterType
195 * index - shared meter index (0-31)
196 * Type - 0: kbps, 1: pps
200 * RT_ERR_OK - Success
201 * RT_ERR_SMI - SMI access error
202 * RT_ERR_FILTER_METER_ID - Invalid meter
206 ret_t
rtl8367c_setAsicShareMeterType(rtk_uint32 index
, rtk_uint32 type
)
210 if(index
> RTL8367C_METERMAX
)
211 return RT_ERR_FILTER_METER_ID
;
214 reg
= RTL8367C_REG_METER_MODE_SETTING0
+ (index
/ 16);
216 reg
= RTL8367C_REG_METER_MODE_SETTING2
+ ((index
- 32) / 16);
217 return rtl8367c_setAsicRegBit(reg
, index
% 16, type
);
221 * rtl8367c_getAsicShareMeterType
225 * index - shared meter index (0-31)
227 * pType - 0: kbps, 1: pps
229 * RT_ERR_OK - Success
230 * RT_ERR_SMI - SMI access error
231 * RT_ERR_FILTER_METER_ID - Invalid meter
235 ret_t
rtl8367c_getAsicShareMeterType(rtk_uint32 index
, rtk_uint32
*pType
)
239 if(index
> RTL8367C_METERMAX
)
240 return RT_ERR_FILTER_METER_ID
;
243 return RT_ERR_NULL_POINTER
;
246 reg
= RTL8367C_REG_METER_MODE_SETTING0
+ (index
/ 16);
248 reg
= RTL8367C_REG_METER_MODE_SETTING2
+ ((index
- 32) / 16);
249 return rtl8367c_getAsicRegBit(reg
, index
% 16, pType
);
254 * rtl8367c_setAsicMeterExceedStatus
256 * Clear shared meter status
258 * index - hared meter index (0-31)
262 * RT_ERR_OK - Success
263 * RT_ERR_SMI - SMI access error
264 * RT_ERR_FILTER_METER_ID - Invalid meter
268 ret_t
rtl8367c_setAsicMeterExceedStatus(rtk_uint32 index
)
270 if(index
> RTL8367C_METERMAX
)
271 return RT_ERR_FILTER_METER_ID
;
274 return rtl8367c_setAsicRegBit(RTL8367C_METER_OVERRATE_INDICATOR_REG(index
), RTL8367C_METER_EXCEED_OFFSET(index
), 1);
276 return rtl8367c_setAsicRegBit(RTL8367C_REG_METER_OVERRATE_INDICATOR2
+ ((index
- 32) >> 4), RTL8367C_METER_EXCEED_OFFSET(index
), 1);
280 * rtl8367c_getAsicMeterExceedStatus
282 * Get shared meter status
284 * index - hared meter index (0-31)
285 * pStatus - 0: rate doesn't exceed 1: rate exceeds
289 * RT_ERR_OK - Success
290 * RT_ERR_SMI - SMI access error
291 * RT_ERR_FILTER_METER_ID - Invalid meter
293 * If rate is over rate*8Kbps of a meter, the state bit of this meter is set to 1.
295 ret_t
rtl8367c_getAsicMeterExceedStatus(rtk_uint32 index
, rtk_uint32
* pStatus
)
297 if(index
> RTL8367C_METERMAX
)
298 return RT_ERR_FILTER_METER_ID
;
301 return rtl8367c_getAsicRegBit(RTL8367C_METER_OVERRATE_INDICATOR_REG(index
), RTL8367C_METER_EXCEED_OFFSET(index
), pStatus
);
303 return rtl8367c_getAsicRegBit(RTL8367C_REG_METER_OVERRATE_INDICATOR2
+ ((index
- 32) >> 4), RTL8367C_METER_EXCEED_OFFSET(index
), pStatus
);