• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6/drivers/char/rtl8365mb/
1/*
2 * Copyright (C) 2013 Realtek Semiconductor Corp.
3 * All Rights Reserved.
4 *
5 * This program is the proprietary software of Realtek Semiconductor
6 * Corporation and/or its licensors, and only be used, duplicated,
7 * modified or distributed under the authorized license from Realtek.
8 *
9 * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
10 * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
11 *
12 * $Revision: 47368 $
13 * $Date: 2014-04-09 13:30:18 +0800 (������, 09 ������ 2014) $
14 *
15 * Purpose : RTK switch high-level API for RTL8367/RTL8367C
16 * Feature : Here is a list of all functions and variables in Mirror module.
17 *
18 */
19
20#include <rtk_switch.h>
21#include <rtk_error.h>
22#include <mirror.h>
23#ifndef __KERNEL__
24#include <string.h>
25#else
26#include <linux/string.h>
27#endif
28
29#include <rtl8367c_asicdrv.h>
30#include <rtl8367c_asicdrv_mirror.h>
31
32/* Function Name:
33 *      rtk_mirror_portBased_set
34 * Description:
35 *      Set port mirror function.
36 * Input:
37 *      mirroring_port          - Monitor port.
38 *      pMirrored_rx_portmask   - Rx mirror port mask.
39 *      pMirrored_tx_portmask   - Tx mirror port mask.
40 * Output:
41 *      None
42 * Return:
43 *      RT_ERR_OK           - OK
44 *      RT_ERR_FAILED       - Failed
45 *      RT_ERR_SMI          - SMI access error
46 *      RT_ERR_PORT_ID      - Invalid port number
47 *      RT_ERR_PORT_MASK    - Invalid portmask.
48 * Note:
49 *      The API is to set mirror function of source port and mirror port.
50 *      The mirror port can only be set to one port and the TX and RX mirror ports
51 *      should be identical.
52 */
53rtk_api_ret_t rtk_mirror_portBased_set(rtk_port_t mirroring_port, rtk_portmask_t *pMirrored_rx_portmask, rtk_portmask_t *pMirrored_tx_portmask)
54{
55    rtk_api_ret_t retVal;
56    rtk_enable_t mirRx, mirTx;
57    rtk_uint32 i, pmask;
58    rtk_port_t source_port;
59
60    /* Check initialization state */
61    RTK_CHK_INIT_STATE();
62
63    /* Check port valid */
64    RTK_CHK_PORT_VALID(mirroring_port);
65
66    if(NULL == pMirrored_rx_portmask)
67        return RT_ERR_NULL_POINTER;
68
69    if(NULL == pMirrored_tx_portmask)
70        return RT_ERR_NULL_POINTER;
71
72    RTK_CHK_PORTMASK_VALID(pMirrored_rx_portmask);
73
74    RTK_CHK_PORTMASK_VALID(pMirrored_tx_portmask);
75
76    /*Mirror Sorce Port Mask Check*/
77    if (pMirrored_tx_portmask->bits[0]!=pMirrored_rx_portmask->bits[0]&&pMirrored_tx_portmask->bits[0]!=0&&pMirrored_rx_portmask->bits[0]!=0)
78        return RT_ERR_PORT_MASK;
79
80     /*mirror port != source port*/
81    if(RTK_PORTMASK_IS_PORT_SET((*pMirrored_tx_portmask), mirroring_port) || RTK_PORTMASK_IS_PORT_SET((*pMirrored_rx_portmask), mirroring_port))
82        return RT_ERR_PORT_MASK;
83
84   source_port = 0;
85
86    RTK_SCAN_ALL_LOG_PORT(i)
87    {
88        if (pMirrored_tx_portmask->bits[0]&(1<<i))
89        {
90            source_port = i;
91            break;
92        }
93
94        if (pMirrored_rx_portmask->bits[0]&(1<<i))
95        {
96            source_port = i;
97            break;
98        }
99    }
100
101    if ((retVal = rtl8367c_setAsicPortMirror(rtk_switch_port_L2P_get(source_port), rtk_switch_port_L2P_get(mirroring_port))) != RT_ERR_OK)
102        return retVal;
103
104    if(pMirrored_rx_portmask->bits[0] != 0)
105    {
106        if ((retVal = rtk_switch_portmask_L2P_get(pMirrored_rx_portmask, &pmask)) != RT_ERR_OK)
107            return retVal;
108        if ((retVal = rtl8367c_setAsicPortMirrorMask(pmask)) != RT_ERR_OK)
109            return retVal;
110    }
111    else
112    {
113        if ((retVal = rtk_switch_portmask_L2P_get(pMirrored_tx_portmask, &pmask)) != RT_ERR_OK)
114            return retVal;
115        if ((retVal = rtl8367c_setAsicPortMirrorMask(pmask)) != RT_ERR_OK)
116            return retVal;
117    }
118
119
120    if (pMirrored_rx_portmask->bits[0])
121        mirRx = ENABLED;
122    else
123        mirRx = DISABLED;
124
125    if ((retVal = rtl8367c_setAsicPortMirrorRxFunction(mirRx)) != RT_ERR_OK)
126        return retVal;
127
128    if (pMirrored_tx_portmask->bits[0])
129        mirTx = ENABLED;
130    else
131        mirTx = DISABLED;
132
133    if ((retVal = rtl8367c_setAsicPortMirrorTxFunction(mirTx)) != RT_ERR_OK)
134        return retVal;
135
136    return RT_ERR_OK;
137
138}
139
140/* Function Name:
141 *      rtk_mirror_portBased_get
142 * Description:
143 *      Get port mirror function.
144 * Input:
145 *      None
146 * Output:
147 *      pMirroring_port         - Monitor port.
148 *      pMirrored_rx_portmask   - Rx mirror port mask.
149 *      pMirrored_tx_portmask   - Tx mirror port mask.
150 * Return:
151 *      RT_ERR_OK           - OK
152 *      RT_ERR_FAILED       - Failed
153 *      RT_ERR_SMI          - SMI access error
154 *      RT_ERR_INPUT 		- Invalid input parameters.
155 * Note:
156 *      The API is to get mirror function of source port and mirror port.
157 */
158rtk_api_ret_t rtk_mirror_portBased_get(rtk_port_t *pMirroring_port, rtk_portmask_t *pMirrored_rx_portmask, rtk_portmask_t *pMirrored_tx_portmask)
159{
160    rtk_api_ret_t retVal;
161    rtk_port_t source_port;
162    rtk_enable_t mirRx, mirTx;
163    rtk_uint32 sport, mport, pmask;
164
165    /* Check initialization state */
166    RTK_CHK_INIT_STATE();
167
168    if(NULL == pMirrored_rx_portmask)
169        return RT_ERR_NULL_POINTER;
170
171    if(NULL == pMirrored_tx_portmask)
172        return RT_ERR_NULL_POINTER;
173
174    if(NULL == pMirroring_port)
175        return RT_ERR_NULL_POINTER;
176
177    if ((retVal = rtl8367c_getAsicPortMirror(&sport, &mport)) != RT_ERR_OK)
178        return retVal;
179    source_port = rtk_switch_port_P2L_get(sport);
180    *pMirroring_port = rtk_switch_port_P2L_get(mport);
181
182    if ((retVal = rtl8367c_getAsicPortMirrorRxFunction((rtk_uint32*)&mirRx)) != RT_ERR_OK)
183        return retVal;
184
185    if ((retVal = rtl8367c_getAsicPortMirrorTxFunction((rtk_uint32*)&mirTx)) != RT_ERR_OK)
186        return retVal;
187
188    if ((retVal = rtl8367c_getAsicPortMirrorMask(&pmask)) != RT_ERR_OK)
189        return retVal;
190
191    if (DISABLED == mirRx)
192        pMirrored_rx_portmask->bits[0]=0;
193    else
194    {
195        if ((retVal = rtk_switch_portmask_P2L_get(pmask, pMirrored_rx_portmask)) != RT_ERR_OK)
196            return retVal;
197        pMirrored_rx_portmask->bits[0] |= 1<<source_port;
198    }
199
200     if (DISABLED == mirTx)
201        pMirrored_tx_portmask->bits[0]=0;
202    else
203    {
204        if ((retVal = rtk_switch_portmask_P2L_get(pmask, pMirrored_tx_portmask)) != RT_ERR_OK)
205            return retVal;
206        pMirrored_tx_portmask->bits[0] |= 1<<source_port;
207    }
208
209    return RT_ERR_OK;
210
211}
212
213/* Function Name:
214 *      rtk_mirror_portIso_set
215 * Description:
216 *      Set mirror port isolation.
217 * Input:
218 *      enable |Mirror isolation status.
219 * Output:
220 *      None
221 * Return:
222 *      RT_ERR_OK           - OK
223 *      RT_ERR_FAILED       - Failed
224 *      RT_ERR_SMI          - SMI access error
225 *      RT_ERR_ENABLE       - Invalid enable input
226 * Note:
227 *      The API is to set mirror isolation function that prevent normal forwarding packets to miror port.
228 */
229rtk_api_ret_t rtk_mirror_portIso_set(rtk_enable_t enable)
230{
231    rtk_api_ret_t retVal;
232
233    /* Check initialization state */
234    RTK_CHK_INIT_STATE();
235
236    if (enable >= RTK_ENABLE_END)
237        return RT_ERR_ENABLE;
238
239    if ((retVal = rtl8367c_setAsicPortMirrorIsolation(enable)) != RT_ERR_OK)
240        return retVal;
241
242    return RT_ERR_OK;
243}
244
245/* Function Name:
246 *      rtk_mirror_portIso_get
247 * Description:
248 *      Get mirror port isolation.
249 * Input:
250 *      None
251 * Output:
252 *      pEnable |Mirror isolation status.
253 * Return:
254 *      RT_ERR_OK           - OK
255 *      RT_ERR_FAILED       - Failed
256 *      RT_ERR_SMI          - SMI access error
257 *      RT_ERR_INPUT 		- Invalid input parameters.
258 * Note:
259 *      The API is to get mirror isolation status.
260 */
261rtk_api_ret_t rtk_mirror_portIso_get(rtk_enable_t *pEnable)
262{
263    rtk_api_ret_t retVal;
264
265    /* Check initialization state */
266    RTK_CHK_INIT_STATE();
267
268    if(NULL == pEnable)
269        return RT_ERR_NULL_POINTER;
270
271    if ((retVal = rtl8367c_getAsicPortMirrorIsolation(pEnable)) != RT_ERR_OK)
272        return retVal;
273
274    return RT_ERR_OK;
275}
276
277/* Function Name:
278 *      rtk_mirror_vlanLeaky_set
279 * Description:
280 *      Set mirror VLAN leaky.
281 * Input:
282 *      txenable -TX leaky enable.
283 *      rxenable - RX leaky enable.
284 * Output:
285 *      None
286 * Return:
287 *      RT_ERR_OK           - OK
288 *      RT_ERR_FAILED       - Failed
289 *      RT_ERR_SMI          - SMI access error
290 *      RT_ERR_ENABLE       - Invalid enable input
291 * Note:
292 *      The API is to set mirror VLAN leaky function forwarding packets to miror port.
293 */
294rtk_api_ret_t rtk_mirror_vlanLeaky_set(rtk_enable_t txenable, rtk_enable_t rxenable)
295{
296    rtk_api_ret_t retVal;
297
298    /* Check initialization state */
299    RTK_CHK_INIT_STATE();
300
301    if ((txenable >= RTK_ENABLE_END) ||(rxenable >= RTK_ENABLE_END))
302        return RT_ERR_ENABLE;
303
304    if ((retVal = rtl8367c_setAsicPortMirrorVlanTxLeaky(txenable)) != RT_ERR_OK)
305        return retVal;
306
307    if ((retVal = rtl8367c_setAsicPortMirrorVlanRxLeaky(rxenable)) != RT_ERR_OK)
308        return retVal;
309
310    return RT_ERR_OK;
311}
312
313/* Function Name:
314 *      rtk_mirror_vlanLeaky_get
315 * Description:
316 *      Get mirror VLAN leaky.
317 * Input:
318 *      None
319 * Output:
320 *      pTxenable - TX leaky enable.
321 *      pRxenable - RX leaky enable.
322 * Return:
323 *      RT_ERR_OK           - OK
324 *      RT_ERR_FAILED       - Failed
325 *      RT_ERR_SMI          - SMI access error
326 *      RT_ERR_INPUT 		- Invalid input parameters.
327 * Note:
328 *      The API is to get mirror VLAN leaky status.
329 */
330rtk_api_ret_t rtk_mirror_vlanLeaky_get(rtk_enable_t *pTxenable, rtk_enable_t *pRxenable)
331{
332    rtk_api_ret_t retVal;
333
334    /* Check initialization state */
335    RTK_CHK_INIT_STATE();
336
337    if( (NULL == pTxenable) || (NULL == pRxenable) )
338        return RT_ERR_NULL_POINTER;
339
340    if ((retVal = rtl8367c_getAsicPortMirrorVlanTxLeaky(pTxenable)) != RT_ERR_OK)
341        return retVal;
342
343    if ((retVal = rtl8367c_getAsicPortMirrorVlanRxLeaky(pRxenable)) != RT_ERR_OK)
344        return retVal;
345
346    return RT_ERR_OK;
347}
348
349/* Function Name:
350 *      rtk_mirror_isolationLeaky_set
351 * Description:
352 *      Set mirror Isolation leaky.
353 * Input:
354 *      txenable -TX leaky enable.
355 *      rxenable - RX leaky enable.
356 * Output:
357 *      None
358 * Return:
359 *      RT_ERR_OK           - OK
360 *      RT_ERR_FAILED       - Failed
361 *      RT_ERR_SMI          - SMI access error
362 *      RT_ERR_ENABLE       - Invalid enable input
363 * Note:
364 *      The API is to set mirror VLAN leaky function forwarding packets to miror port.
365 */
366rtk_api_ret_t rtk_mirror_isolationLeaky_set(rtk_enable_t txenable, rtk_enable_t rxenable)
367{
368    rtk_api_ret_t retVal;
369
370    /* Check initialization state */
371    RTK_CHK_INIT_STATE();
372
373    if ((txenable >= RTK_ENABLE_END) ||(rxenable >= RTK_ENABLE_END))
374        return RT_ERR_ENABLE;
375
376    if ((retVal = rtl8367c_setAsicPortMirrorIsolationTxLeaky(txenable)) != RT_ERR_OK)
377        return retVal;
378
379    if ((retVal = rtl8367c_setAsicPortMirrorIsolationRxLeaky(rxenable)) != RT_ERR_OK)
380        return retVal;
381
382    return RT_ERR_OK;
383}
384
385/* Function Name:
386 *      rtk_mirror_isolationLeaky_get
387 * Description:
388 *      Get mirror isolation leaky.
389 * Input:
390 *      None
391 * Output:
392 *      pTxenable - TX leaky enable.
393 *      pRxenable - RX leaky enable.
394 * Return:
395 *      RT_ERR_OK           - OK
396 *      RT_ERR_FAILED       - Failed
397 *      RT_ERR_SMI          - SMI access error
398 *      RT_ERR_INPUT 		- Invalid input parameters.
399 * Note:
400 *      The API is to get mirror isolation leaky status.
401 */
402rtk_api_ret_t rtk_mirror_isolationLeaky_get(rtk_enable_t *pTxenable, rtk_enable_t *pRxenable)
403{
404    rtk_api_ret_t retVal;
405
406    /* Check initialization state */
407    RTK_CHK_INIT_STATE();
408
409    if( (NULL == pTxenable) || (NULL == pRxenable) )
410        return RT_ERR_NULL_POINTER;
411
412    if ((retVal = rtl8367c_getAsicPortMirrorIsolationTxLeaky(pTxenable)) != RT_ERR_OK)
413        return retVal;
414
415    if ((retVal = rtl8367c_getAsicPortMirrorIsolationRxLeaky(pRxenable)) != RT_ERR_OK)
416        return retVal;
417
418    return RT_ERR_OK;
419}
420
421/* Function Name:
422 *      rtk_mirror_keep_set
423 * Description:
424 *      Set mirror packet format keep.
425 * Input:
426 *      mode - -mirror keep mode.
427 * Output:
428 *      None
429 * Return:
430 *      RT_ERR_OK           - OK
431 *      RT_ERR_FAILED       - Failed
432 *      RT_ERR_SMI          - SMI access error
433 *      RT_ERR_ENABLE       - Invalid enable input
434 * Note:
435 *      The API is to set  -mirror keep mode.
436 *      The mirror keep mode is as following:
437 *      - MIRROR_FOLLOW_VLAN
438 *      - MIRROR_KEEP_ORIGINAL
439 *      - MIRROR_KEEP_END
440 */
441rtk_api_ret_t rtk_mirror_keep_set(rtk_mirror_keep_t mode)
442{
443    rtk_api_ret_t retVal;
444
445    /* Check initialization state */
446    RTK_CHK_INIT_STATE();
447
448    if (mode >= MIRROR_KEEP_END)
449        return RT_ERR_ENABLE;
450
451    if ((retVal = rtl8367c_setAsicPortMirrorRealKeep(mode)) != RT_ERR_OK)
452        return retVal;
453
454    return RT_ERR_OK;
455}
456
457/* Function Name:
458 *      rtk_mirror_keep_get
459 * Description:
460 *      Get mirror packet format keep.
461 * Input:
462 *      None
463 * Output:
464 *      pMode -mirror keep mode.
465 * Return:
466 *      RT_ERR_OK           - OK
467 *      RT_ERR_FAILED       - Failed
468 *      RT_ERR_SMI          - SMI access error
469 *      RT_ERR_INPUT 		- Invalid input parameters.
470 * Note:
471 *      The API is to get mirror keep mode.
472  *      The mirror keep mode is as following:
473 *      - MIRROR_FOLLOW_VLAN
474 *      - MIRROR_KEEP_ORIGINAL
475 *      - MIRROR_KEEP_END
476 */
477rtk_api_ret_t rtk_mirror_keep_get(rtk_mirror_keep_t *pMode)
478{
479    rtk_api_ret_t retVal;
480
481    /* Check initialization state */
482    RTK_CHK_INIT_STATE();
483
484    if(NULL == pMode)
485        return RT_ERR_NULL_POINTER;
486
487    if ((retVal = rtl8367c_getAsicPortMirrorRealKeep(pMode)) != RT_ERR_OK)
488        return retVal;
489
490    return RT_ERR_OK;
491}
492
493/* Function Name:
494 *      rtk_mirror_override_set
495 * Description:
496 *      Set port mirror override function.
497 * Input:
498 *      rxMirror        - 1: output mirrored packet, 0: output normal forward packet
499 *      txMirror        - 1: output mirrored packet, 0: output normal forward packet
500 *      aclMirror       - 1: output mirrored packet, 0: output normal forward packet
501 * Output:
502 *      None
503 * Return:
504 *      RT_ERR_OK           - OK
505 *      RT_ERR_FAILED       - Failed
506 *      RT_ERR_SMI          - SMI access error
507 * Note:
508 *      The API is to set mirror override function.
509 *      This function control the output format when a port output
510 *      normal forward & mirrored packet at the same time.
511 */
512rtk_api_ret_t rtk_mirror_override_set(rtk_enable_t rxMirror, rtk_enable_t txMirror, rtk_enable_t aclMirror)
513{
514    rtk_api_ret_t retVal;
515
516    if( (rxMirror >= RTK_ENABLE_END) || (txMirror >= RTK_ENABLE_END) || (aclMirror >= RTK_ENABLE_END))
517        return RT_ERR_ENABLE;
518
519    if ((retVal = rtl8367c_setAsicPortMirrorOverride((rtk_uint32)rxMirror, (rtk_uint32)txMirror, (rtk_uint32)aclMirror)) != RT_ERR_OK)
520        return retVal;
521
522    return RT_ERR_OK;
523}
524
525/* Function Name:
526 *      rtk_mirror_override_get
527 * Description:
528 *      Get port mirror override function.
529 * Input:
530 *      None
531 * Output:
532 *      pRxMirror       - 1: output mirrored packet, 0: output normal forward packet
533 *      pTxMirror       - 1: output mirrored packet, 0: output normal forward packet
534 *      pAclMirror      - 1: output mirrored packet, 0: output normal forward packet
535 * Return:
536 *      RT_ERR_OK           - OK
537 *      RT_ERR_FAILED       - Failed
538 *      RT_ERR_SMI          - SMI access error
539 *      RT_ERR_NULL_POINTER - Null Pointer
540 * Note:
541 *      The API is to Get mirror override function.
542 *      This function control the output format when a port output
543 *      normal forward & mirrored packet at the same time.
544 */
545rtk_api_ret_t rtk_mirror_override_get(rtk_enable_t *pRxMirror, rtk_enable_t *pTxMirror, rtk_enable_t *pAclMirror)
546{
547    rtk_api_ret_t retVal;
548
549    if( (pRxMirror == NULL) || (pTxMirror == NULL) || (pAclMirror == NULL))
550        return RT_ERR_ENABLE;
551
552    if ((retVal = rtl8367c_getAsicPortMirrorOverride((rtk_uint32 *)pRxMirror, (rtk_uint32 *)pTxMirror, (rtk_uint32 *)pAclMirror)) != RT_ERR_OK)
553        return retVal;
554
555    return RT_ERR_OK;
556}
557