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 Mirror module.
18 #include <rtk_switch.h>
19 #include <rtk_error.h>
22 #include <rtl8367c_asicdrv.h>
23 #include <rtl8367c_asicdrv_mirror.h>
26 * rtk_mirror_portBased_set
28 * Set port mirror function.
30 * mirroring_port - Monitor port.
31 * pMirrored_rx_portmask - Rx mirror port mask.
32 * pMirrored_tx_portmask - Tx mirror port mask.
37 * RT_ERR_FAILED - Failed
38 * RT_ERR_SMI - SMI access error
39 * RT_ERR_PORT_ID - Invalid port number
40 * RT_ERR_PORT_MASK - Invalid portmask.
42 * The API is to set mirror function of source port and mirror port.
43 * The mirror port can only be set to one port and the TX and RX mirror ports
44 * should be identical.
46 rtk_api_ret_t
rtk_mirror_portBased_set(rtk_port_t mirroring_port
, rtk_portmask_t
*pMirrored_rx_portmask
, rtk_portmask_t
*pMirrored_tx_portmask
)
49 rtk_enable_t mirRx
, mirTx
;
51 rtk_port_t source_port
;
53 /* Check initialization state */
56 /* Check port valid */
57 RTK_CHK_PORT_VALID(mirroring_port
);
59 if(NULL
== pMirrored_rx_portmask
)
60 return RT_ERR_NULL_POINTER
;
62 if(NULL
== pMirrored_tx_portmask
)
63 return RT_ERR_NULL_POINTER
;
65 RTK_CHK_PORTMASK_VALID(pMirrored_rx_portmask
);
67 RTK_CHK_PORTMASK_VALID(pMirrored_tx_portmask
);
69 /*Mirror Sorce Port Mask Check*/
70 if (pMirrored_tx_portmask
->bits
[0]!=pMirrored_rx_portmask
->bits
[0]&&pMirrored_tx_portmask
->bits
[0]!=0&&pMirrored_rx_portmask
->bits
[0]!=0)
71 return RT_ERR_PORT_MASK
;
73 /*mirror port != source port*/
74 if(RTK_PORTMASK_IS_PORT_SET((*pMirrored_tx_portmask
), mirroring_port
) || RTK_PORTMASK_IS_PORT_SET((*pMirrored_rx_portmask
), mirroring_port
))
75 return RT_ERR_PORT_MASK
;
77 source_port
= rtk_switch_maxLogicalPort_get();
79 RTK_SCAN_ALL_LOG_PORT(i
)
81 if (pMirrored_tx_portmask
->bits
[0]&(1<<i
))
87 if (pMirrored_rx_portmask
->bits
[0]&(1<<i
))
94 if ((retVal
= rtl8367c_setAsicPortMirror(rtk_switch_port_L2P_get(source_port
), rtk_switch_port_L2P_get(mirroring_port
))) != RT_ERR_OK
)
96 if(pMirrored_rx_portmask
->bits
[0] != 0)
98 if ((retVal
= rtk_switch_portmask_L2P_get(pMirrored_rx_portmask
, &pmask
)) != RT_ERR_OK
)
100 if ((retVal
= rtl8367c_setAsicPortMirrorMask(pmask
)) != RT_ERR_OK
)
105 if ((retVal
= rtk_switch_portmask_L2P_get(pMirrored_tx_portmask
, &pmask
)) != RT_ERR_OK
)
107 if ((retVal
= rtl8367c_setAsicPortMirrorMask(pmask
)) != RT_ERR_OK
)
112 if (pMirrored_rx_portmask
->bits
[0])
117 if ((retVal
= rtl8367c_setAsicPortMirrorRxFunction(mirRx
)) != RT_ERR_OK
)
120 if (pMirrored_tx_portmask
->bits
[0])
125 if ((retVal
= rtl8367c_setAsicPortMirrorTxFunction(mirTx
)) != RT_ERR_OK
)
133 * rtk_mirror_portBased_get
135 * Get port mirror function.
139 * pMirroring_port - Monitor port.
140 * pMirrored_rx_portmask - Rx mirror port mask.
141 * pMirrored_tx_portmask - Tx mirror port mask.
144 * RT_ERR_FAILED - Failed
145 * RT_ERR_SMI - SMI access error
146 * RT_ERR_INPUT - Invalid input parameters.
148 * The API is to get mirror function of source port and mirror port.
150 rtk_api_ret_t
rtk_mirror_portBased_get(rtk_port_t
*pMirroring_port
, rtk_portmask_t
*pMirrored_rx_portmask
, rtk_portmask_t
*pMirrored_tx_portmask
)
152 rtk_api_ret_t retVal
;
153 rtk_port_t source_port
;
154 rtk_enable_t mirRx
, mirTx
;
155 rtk_uint32 sport
, mport
, pmask
;
157 /* Check initialization state */
158 RTK_CHK_INIT_STATE();
160 if(NULL
== pMirrored_rx_portmask
)
161 return RT_ERR_NULL_POINTER
;
163 if(NULL
== pMirrored_tx_portmask
)
164 return RT_ERR_NULL_POINTER
;
166 if(NULL
== pMirroring_port
)
167 return RT_ERR_NULL_POINTER
;
169 if ((retVal
= rtl8367c_getAsicPortMirror(&sport
, &mport
)) != RT_ERR_OK
)
171 source_port
= rtk_switch_port_P2L_get(sport
);
172 *pMirroring_port
= rtk_switch_port_P2L_get(mport
);
174 if ((retVal
= rtl8367c_getAsicPortMirrorRxFunction((rtk_uint32
*)&mirRx
)) != RT_ERR_OK
)
177 if ((retVal
= rtl8367c_getAsicPortMirrorTxFunction((rtk_uint32
*)&mirTx
)) != RT_ERR_OK
)
180 if ((retVal
= rtl8367c_getAsicPortMirrorMask(&pmask
)) != RT_ERR_OK
)
183 if (DISABLED
== mirRx
)
184 pMirrored_rx_portmask
->bits
[0]=0;
187 if ((retVal
= rtk_switch_portmask_P2L_get(pmask
, pMirrored_rx_portmask
)) != RT_ERR_OK
)
189 pMirrored_rx_portmask
->bits
[0] |= 1<<source_port
;
192 if (DISABLED
== mirTx
)
193 pMirrored_tx_portmask
->bits
[0]=0;
196 if ((retVal
= rtk_switch_portmask_P2L_get(pmask
, pMirrored_tx_portmask
)) != RT_ERR_OK
)
198 pMirrored_tx_portmask
->bits
[0] |= 1<<source_port
;
206 * rtk_mirror_portIso_set
208 * Set mirror port isolation.
210 * enable |Mirror isolation status.
215 * RT_ERR_FAILED - Failed
216 * RT_ERR_SMI - SMI access error
217 * RT_ERR_ENABLE - Invalid enable input
219 * The API is to set mirror isolation function that prevent normal forwarding packets to miror port.
221 rtk_api_ret_t
rtk_mirror_portIso_set(rtk_enable_t enable
)
223 rtk_api_ret_t retVal
;
225 /* Check initialization state */
226 RTK_CHK_INIT_STATE();
228 if (enable
>= RTK_ENABLE_END
)
229 return RT_ERR_ENABLE
;
231 if ((retVal
= rtl8367c_setAsicPortMirrorIsolation(enable
)) != RT_ERR_OK
)
238 * rtk_mirror_portIso_get
240 * Get mirror port isolation.
244 * pEnable |Mirror isolation status.
247 * RT_ERR_FAILED - Failed
248 * RT_ERR_SMI - SMI access error
249 * RT_ERR_INPUT - Invalid input parameters.
251 * The API is to get mirror isolation status.
253 rtk_api_ret_t
rtk_mirror_portIso_get(rtk_enable_t
*pEnable
)
255 rtk_api_ret_t retVal
;
257 /* Check initialization state */
258 RTK_CHK_INIT_STATE();
261 return RT_ERR_NULL_POINTER
;
263 if ((retVal
= rtl8367c_getAsicPortMirrorIsolation(pEnable
)) != RT_ERR_OK
)
270 * rtk_mirror_vlanLeaky_set
272 * Set mirror VLAN leaky.
274 * txenable -TX leaky enable.
275 * rxenable - RX leaky enable.
280 * RT_ERR_FAILED - Failed
281 * RT_ERR_SMI - SMI access error
282 * RT_ERR_ENABLE - Invalid enable input
284 * The API is to set mirror VLAN leaky function forwarding packets to miror port.
286 rtk_api_ret_t
rtk_mirror_vlanLeaky_set(rtk_enable_t txenable
, rtk_enable_t rxenable
)
288 rtk_api_ret_t retVal
;
290 /* Check initialization state */
291 RTK_CHK_INIT_STATE();
293 if ((txenable
>= RTK_ENABLE_END
) ||(rxenable
>= RTK_ENABLE_END
))
294 return RT_ERR_ENABLE
;
296 if ((retVal
= rtl8367c_setAsicPortMirrorVlanTxLeaky(txenable
)) != RT_ERR_OK
)
299 if ((retVal
= rtl8367c_setAsicPortMirrorVlanRxLeaky(rxenable
)) != RT_ERR_OK
)
306 * rtk_mirror_vlanLeaky_get
308 * Get mirror VLAN leaky.
312 * pTxenable - TX leaky enable.
313 * pRxenable - RX leaky enable.
316 * RT_ERR_FAILED - Failed
317 * RT_ERR_SMI - SMI access error
318 * RT_ERR_INPUT - Invalid input parameters.
320 * The API is to get mirror VLAN leaky status.
322 rtk_api_ret_t
rtk_mirror_vlanLeaky_get(rtk_enable_t
*pTxenable
, rtk_enable_t
*pRxenable
)
324 rtk_api_ret_t retVal
;
326 /* Check initialization state */
327 RTK_CHK_INIT_STATE();
329 if( (NULL
== pTxenable
) || (NULL
== pRxenable
) )
330 return RT_ERR_NULL_POINTER
;
332 if ((retVal
= rtl8367c_getAsicPortMirrorVlanTxLeaky(pTxenable
)) != RT_ERR_OK
)
335 if ((retVal
= rtl8367c_getAsicPortMirrorVlanRxLeaky(pRxenable
)) != RT_ERR_OK
)
342 * rtk_mirror_isolationLeaky_set
344 * Set mirror Isolation leaky.
346 * txenable -TX leaky enable.
347 * rxenable - RX leaky enable.
352 * RT_ERR_FAILED - Failed
353 * RT_ERR_SMI - SMI access error
354 * RT_ERR_ENABLE - Invalid enable input
356 * The API is to set mirror VLAN leaky function forwarding packets to miror port.
358 rtk_api_ret_t
rtk_mirror_isolationLeaky_set(rtk_enable_t txenable
, rtk_enable_t rxenable
)
360 rtk_api_ret_t retVal
;
362 /* Check initialization state */
363 RTK_CHK_INIT_STATE();
365 if ((txenable
>= RTK_ENABLE_END
) ||(rxenable
>= RTK_ENABLE_END
))
366 return RT_ERR_ENABLE
;
368 if ((retVal
= rtl8367c_setAsicPortMirrorIsolationTxLeaky(txenable
)) != RT_ERR_OK
)
371 if ((retVal
= rtl8367c_setAsicPortMirrorIsolationRxLeaky(rxenable
)) != RT_ERR_OK
)
378 * rtk_mirror_isolationLeaky_get
380 * Get mirror isolation leaky.
384 * pTxenable - TX leaky enable.
385 * pRxenable - RX leaky enable.
388 * RT_ERR_FAILED - Failed
389 * RT_ERR_SMI - SMI access error
390 * RT_ERR_INPUT - Invalid input parameters.
392 * The API is to get mirror isolation leaky status.
394 rtk_api_ret_t
rtk_mirror_isolationLeaky_get(rtk_enable_t
*pTxenable
, rtk_enable_t
*pRxenable
)
396 rtk_api_ret_t retVal
;
398 /* Check initialization state */
399 RTK_CHK_INIT_STATE();
401 if( (NULL
== pTxenable
) || (NULL
== pRxenable
) )
402 return RT_ERR_NULL_POINTER
;
404 if ((retVal
= rtl8367c_getAsicPortMirrorIsolationTxLeaky(pTxenable
)) != RT_ERR_OK
)
407 if ((retVal
= rtl8367c_getAsicPortMirrorIsolationRxLeaky(pRxenable
)) != RT_ERR_OK
)
414 * rtk_mirror_keep_set
416 * Set mirror packet format keep.
418 * mode - -mirror keep mode.
423 * RT_ERR_FAILED - Failed
424 * RT_ERR_SMI - SMI access error
425 * RT_ERR_ENABLE - Invalid enable input
427 * The API is to set -mirror keep mode.
428 * The mirror keep mode is as following:
429 * - MIRROR_FOLLOW_VLAN
430 * - MIRROR_KEEP_ORIGINAL
433 rtk_api_ret_t
rtk_mirror_keep_set(rtk_mirror_keep_t mode
)
435 rtk_api_ret_t retVal
;
437 /* Check initialization state */
438 RTK_CHK_INIT_STATE();
440 if (mode
>= MIRROR_KEEP_END
)
441 return RT_ERR_ENABLE
;
443 if ((retVal
= rtl8367c_setAsicPortMirrorRealKeep(mode
)) != RT_ERR_OK
)
450 * rtk_mirror_keep_get
452 * Get mirror packet format keep.
456 * pMode -mirror keep mode.
459 * RT_ERR_FAILED - Failed
460 * RT_ERR_SMI - SMI access error
461 * RT_ERR_INPUT - Invalid input parameters.
463 * The API is to get mirror keep mode.
464 * The mirror keep mode is as following:
465 * - MIRROR_FOLLOW_VLAN
466 * - MIRROR_KEEP_ORIGINAL
469 rtk_api_ret_t
rtk_mirror_keep_get(rtk_mirror_keep_t
*pMode
)
471 rtk_api_ret_t retVal
;
473 /* Check initialization state */
474 RTK_CHK_INIT_STATE();
477 return RT_ERR_NULL_POINTER
;
479 if ((retVal
= rtl8367c_getAsicPortMirrorRealKeep(pMode
)) != RT_ERR_OK
)
486 * rtk_mirror_override_set
488 * Set port mirror override function.
490 * rxMirror - 1: output mirrored packet, 0: output normal forward packet
491 * txMirror - 1: output mirrored packet, 0: output normal forward packet
492 * aclMirror - 1: output mirrored packet, 0: output normal forward packet
497 * RT_ERR_FAILED - Failed
498 * RT_ERR_SMI - SMI access error
500 * The API is to set mirror override function.
501 * This function control the output format when a port output
502 * normal forward & mirrored packet at the same time.
504 rtk_api_ret_t
rtk_mirror_override_set(rtk_enable_t rxMirror
, rtk_enable_t txMirror
, rtk_enable_t aclMirror
)
506 rtk_api_ret_t retVal
;
508 if( (rxMirror
>= RTK_ENABLE_END
) || (txMirror
>= RTK_ENABLE_END
) || (aclMirror
>= RTK_ENABLE_END
))
509 return RT_ERR_ENABLE
;
511 if ((retVal
= rtl8367c_setAsicPortMirrorOverride((rtk_uint32
)rxMirror
, (rtk_uint32
)txMirror
, (rtk_uint32
)aclMirror
)) != RT_ERR_OK
)
518 * rtk_mirror_override_get
520 * Get port mirror override function.
524 * pRxMirror - 1: output mirrored packet, 0: output normal forward packet
525 * pTxMirror - 1: output mirrored packet, 0: output normal forward packet
526 * pAclMirror - 1: output mirrored packet, 0: output normal forward packet
529 * RT_ERR_FAILED - Failed
530 * RT_ERR_SMI - SMI access error
531 * RT_ERR_NULL_POINTER - Null Pointer
533 * The API is to Get mirror override function.
534 * This function control the output format when a port output
535 * normal forward & mirrored packet at the same time.
537 rtk_api_ret_t
rtk_mirror_override_get(rtk_enable_t
*pRxMirror
, rtk_enable_t
*pTxMirror
, rtk_enable_t
*pAclMirror
)
539 rtk_api_ret_t retVal
;
541 if( (pRxMirror
== NULL
) || (pTxMirror
== NULL
) || (pAclMirror
== NULL
))
542 return RT_ERR_ENABLE
;
544 if ((retVal
= rtl8367c_getAsicPortMirrorOverride((rtk_uint32
*)pRxMirror
, (rtk_uint32
*)pTxMirror
, (rtk_uint32
*)pAclMirror
)) != RT_ERR_OK
)