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 : Proprietary CPU-tag related function drivers
17 #include <rtl8367c_asicdrv_cputag.h>
19 * rtl8367c_setAsicCputagEnable
21 * Set cpu tag function enable/disable
23 * enabled - 1: enabled, 0: disabled
28 * RT_ERR_SMI - SMI access error
29 * RT_ERR_ENABLE - Invalid enable/disable input
31 * If CPU tag function is disabled, CPU tag will not be added to frame
32 * forwarded to CPU port, and all ports cannot parse CPU tag.
34 ret_t
rtl8367c_setAsicCputagEnable(rtk_uint32 enabled
)
39 return rtl8367c_setAsicRegBit(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_EN_OFFSET
, enabled
);
42 * rtl8367c_getAsicCputagEnable
44 * Get cpu tag function enable/disable
46 * pEnabled - 1: enabled, 0: disabled
51 * RT_ERR_SMI - SMI access error
55 ret_t
rtl8367c_getAsicCputagEnable(rtk_uint32
*pEnabled
)
57 return rtl8367c_getAsicRegBit(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_EN_OFFSET
, pEnabled
);
60 * rtl8367c_setAsicCputagTrapPort
62 * Set cpu tag trap port
69 * RT_ERR_SMI - SMI access error
70 * RT_ERR_PORT_ID - Invalid port number
72 * API can set destination port of trapping frame
74 ret_t
rtl8367c_setAsicCputagTrapPort(rtk_uint32 port
)
78 if(port
>= RTL8367C_PORTNO
)
79 return RT_ERR_PORT_ID
;
81 retVal
= rtl8367c_setAsicRegBits(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_TRAP_PORT_MASK
, port
& 7);
82 if(retVal
!= RT_ERR_OK
)
85 retVal
= rtl8367c_setAsicRegBits(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_TRAP_PORT_EXT_MASK
, (port
>>3) & 1);
86 if(retVal
!= RT_ERR_OK
)
92 * rtl8367c_getAsicCputagTrapPort
94 * Get cpu tag trap port
100 * RT_ERR_OK - Success
101 * RT_ERR_SMI - SMI access error
105 ret_t
rtl8367c_getAsicCputagTrapPort(rtk_uint32
*pPort
)
110 retVal
= rtl8367c_getAsicRegBits(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_TRAP_PORT_MASK
, &tmpPort
);
111 if(retVal
!= RT_ERR_OK
)
115 retVal
= rtl8367c_getAsicRegBits(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_TRAP_PORT_EXT_MASK
, &tmpPort
);
116 if(retVal
!= RT_ERR_OK
)
118 *pPort
|= (tmpPort
& 1) << 3;
123 * rtl8367c_setAsicCputagPortmask
125 * Set ports that can parse CPU tag
127 * portmask - port mask
131 * RT_ERR_OK - Success
132 * RT_ERR_SMI - SMI access error
133 * RT_ERR_PORT_MASK - Invalid portmask
137 ret_t
rtl8367c_setAsicCputagPortmask(rtk_uint32 portmask
)
139 if(portmask
> RTL8367C_PORTMASK
)
140 return RT_ERR_PORT_MASK
;
142 return rtl8367c_setAsicReg(RTL8367C_CPU_PORT_MASK_REG
, portmask
);
145 * rtl8367c_getAsicCputagPortmask
147 * Get ports that can parse CPU tag
149 * pPortmask - port mask
153 * RT_ERR_OK - Success
154 * RT_ERR_SMI - SMI access error
158 ret_t
rtl8367c_getAsicCputagPortmask(rtk_uint32
*pPortmask
)
160 return rtl8367c_getAsicReg(RTL8367C_CPU_PORT_MASK_REG
, pPortmask
);
163 * rtl8367c_setAsicCputagInsertMode
165 * Set CPU-tag insert mode
167 * mode - 0: insert to all packets; 1: insert to trapped packets; 2: don't insert
171 * RT_ERR_OK - Success
172 * RT_ERR_SMI - SMI access error
173 * RT_ERR_NOT_ALLOWED - Actions not allowed by the function
177 ret_t
rtl8367c_setAsicCputagInsertMode(rtk_uint32 mode
)
179 if(mode
>= CPUTAG_INSERT_END
)
180 return RT_ERR_NOT_ALLOWED
;
182 return rtl8367c_setAsicRegBits(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_INSERTMODE_MASK
, mode
);
185 * rtl8367c_getAsicCputagInsertMode
187 * Get CPU-tag insert mode
189 * pMode - 0: insert to all packets; 1: insert to trapped packets; 2: don't insert
193 * RT_ERR_OK - Success
194 * RT_ERR_SMI - SMI access error
198 ret_t
rtl8367c_getAsicCputagInsertMode(rtk_uint32
*pMode
)
200 return rtl8367c_getAsicRegBits(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_INSERTMODE_MASK
, pMode
);
203 * rtl8367c_setAsicCputagPriorityRemapping
205 * Set queue assignment of CPU port
207 * srcPri - internal priority (0~7)
208 * newPri - internal priority after remapping (0~7)
212 * RT_ERR_OK - Success
213 * RT_ERR_SMI - SMI access error
214 * RT_ERR_QOS_INT_PRIORITY - Invalid priority
218 ret_t
rtl8367c_setAsicCputagPriorityRemapping(rtk_uint32 srcPri
, rtk_uint32 newPri
)
220 if((srcPri
> RTL8367C_PRIMAX
) || (newPri
> RTL8367C_PRIMAX
))
221 return RT_ERR_QOS_INT_PRIORITY
;
223 return rtl8367c_setAsicRegBits(RTL8367C_QOS_PRIPORITY_REMAPPING_IN_CPU_REG(srcPri
), RTL8367C_QOS_PRIPORITY_REMAPPING_IN_CPU_MASK(srcPri
), newPri
);
226 * rtl8367c_getAsicCputagPriorityRemapping
228 * Get queue assignment of CPU port
230 * srcPri - internal priority (0~7)
231 * pNewPri - internal priority after remapping (0~7)
235 * RT_ERR_OK - Success
236 * RT_ERR_SMI - SMI access error
237 * RT_ERR_QOS_INT_PRIORITY - Invalid priority
241 ret_t
rtl8367c_getAsicCputagPriorityRemapping(rtk_uint32 srcPri
, rtk_uint32
*pNewPri
)
243 if(srcPri
> RTL8367C_PRIMAX
)
244 return RT_ERR_QOS_INT_PRIORITY
;
246 return rtl8367c_getAsicRegBits(RTL8367C_QOS_PRIPORITY_REMAPPING_IN_CPU_REG(srcPri
), RTL8367C_QOS_PRIPORITY_REMAPPING_IN_CPU_MASK(srcPri
), pNewPri
);
249 * rtl8367c_setAsicCputagPosition
251 * Set cpu tag insert position
253 * postion - 1: After entire packet(before CRC field), 0: After MAC_SA (Default)
257 * RT_ERR_OK - Success
258 * RT_ERR_SMI - SMI access error
262 ret_t
rtl8367c_setAsicCputagPosition(rtk_uint32 postion
)
264 return rtl8367c_setAsicRegBit(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_TAG_POSITION_OFFSET
, postion
);
267 * rtl8367c_getAsicCputagPosition
269 * Get cpu tag insert position
271 * pPostion - 1: After entire packet(before CRC field), 0: After MAC_SA (Default)
275 * RT_ERR_OK - Success
276 * RT_ERR_SMI - SMI access error
280 ret_t
rtl8367c_getAsicCputagPosition(rtk_uint32
* pPostion
)
282 return rtl8367c_getAsicRegBit(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_TAG_POSITION_OFFSET
, pPostion
);
286 * rtl8367c_setAsicCputagMode
290 * mode - 1: 4bytes mode, 0: 8bytes mode
294 * RT_ERR_OK - Success
295 * RT_ERR_SMI - SMI access error
296 * RT_ERR_INPUT - Invalid input parameters
298 * If CPU tag function is disabled, CPU tag will not be added to frame
299 * forwarded to CPU port, and all ports cannot parse CPU tag.
301 ret_t
rtl8367c_setAsicCputagMode(rtk_uint32 mode
)
306 return rtl8367c_setAsicRegBit(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_TAG_FORMAT_OFFSET
, mode
);
309 * rtl8367c_getAsicCputagMode
313 * pMode - 1: 4bytes mode, 0: 8bytes mode
317 * RT_ERR_OK - Success
318 * RT_ERR_SMI - SMI access error
322 ret_t
rtl8367c_getAsicCputagMode(rtk_uint32
*pMode
)
324 return rtl8367c_getAsicRegBit(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_TAG_FORMAT_OFFSET
, pMode
);
327 * rtl8367c_setAsicCputagRxMinLength
331 * mode - 1: 64bytes, 0: 72bytes
335 * RT_ERR_OK - Success
336 * RT_ERR_SMI - SMI access error
337 * RT_ERR_INPUT - Invalid input parameters
339 * If CPU tag function is disabled, CPU tag will not be added to frame
340 * forwarded to CPU port, and all ports cannot parse CPU tag.
342 ret_t
rtl8367c_setAsicCputagRxMinLength(rtk_uint32 mode
)
347 return rtl8367c_setAsicRegBit(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_TAG_RXBYTECOUNT_OFFSET
, mode
);
350 * rtl8367c_getAsicCputagRxMinLength
354 * pMode - 1: 64bytes, 0: 72bytes
358 * RT_ERR_OK - Success
359 * RT_ERR_SMI - SMI access error
363 ret_t
rtl8367c_getAsicCputagRxMinLength(rtk_uint32
*pMode
)
365 return rtl8367c_getAsicRegBit(RTL8367C_REG_CPU_CTRL
, RTL8367C_CPU_TAG_RXBYTECOUNT_OFFSET
, pMode
);