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 CPU module.
18 #include <rtk_switch.h>
19 #include <rtk_error.h>
23 #include <rtl8367c_asicdrv.h>
24 #include <rtl8367c_asicdrv_cputag.h>
29 * Set CPU port function enable/disable.
31 * enable - CPU port function enable
36 * RT_ERR_FAILED - Failed
37 * RT_ERR_SMI - SMI access error
38 * RT_ERR_INPUT - Invalid input parameter.
39 * RT_ERR_PORT_ID - Invalid port number.
41 * The API can set CPU port function enable/disable.
43 rtk_api_ret_t
rtk_cpu_enable_set(rtk_enable_t enable
)
47 /* Check initialization state */
50 if (enable
>= RTK_ENABLE_END
)
53 if ((retVal
= rtl8367c_setAsicCputagEnable(enable
)) != RT_ERR_OK
)
56 if (DISABLED
== enable
)
58 if ((retVal
= rtl8367c_setAsicCputagPortmask(0)) != RT_ERR_OK
)
68 * Get CPU port and its setting.
72 * pEnable - CPU port function enable
75 * RT_ERR_FAILED - Failed
76 * RT_ERR_SMI - SMI access error
77 * RT_ERR_INPUT - Invalid input parameters.
78 * RT_ERR_L2_NO_CPU_PORT - CPU port is not exist
80 * The API can get CPU port function enable/disable.
82 rtk_api_ret_t
rtk_cpu_enable_get(rtk_enable_t
*pEnable
)
86 /* Check initialization state */
90 return RT_ERR_NULL_POINTER
;
92 if ((retVal
= rtl8367c_getAsicCputagEnable(pEnable
)) != RT_ERR_OK
)
101 * Set CPU port and CPU tag insert mode.
104 * mode - CPU tag insert for packets egress from CPU port.
109 * RT_ERR_FAILED - Failed
110 * RT_ERR_SMI - SMI access error
111 * RT_ERR_INPUT - Invalid input parameter.
112 * RT_ERR_PORT_ID - Invalid port number.
114 * The API can set CPU port and inserting proprietary CPU tag mode (Length/Type 0x8899)
115 * to the frame that transmitting to CPU port.
116 * The insert CPU tag mode is as following:
117 * - CPU_INSERT_TO_ALL
118 * - CPU_INSERT_TO_TRAPPING
119 * - CPU_INSERT_TO_NONE
121 rtk_api_ret_t
rtk_cpu_tagPort_set(rtk_port_t port
, rtk_cpu_insert_t mode
)
123 rtk_api_ret_t retVal
;
125 /* Check initialization state */
126 RTK_CHK_INIT_STATE();
128 /* Check port Valid */
129 RTK_CHK_PORT_VALID(port
);
131 if (mode
>= CPU_INSERT_END
)
134 if ((retVal
= rtl8367c_setAsicCputagPortmask(1<<rtk_switch_port_L2P_get(port
))) != RT_ERR_OK
)
137 if ((retVal
= rtl8367c_setAsicCputagTrapPort(rtk_switch_port_L2P_get(port
))) != RT_ERR_OK
)
140 if ((retVal
= rtl8367c_setAsicCputagInsertMode(mode
)) != RT_ERR_OK
)
147 * rtk_cpu_tagPort_get
149 * Get CPU port and CPU tag insert mode.
154 * pMode - CPU tag insert for packets egress from CPU port, 0:all insert 1:Only for trapped packets 2:no insert.
157 * RT_ERR_FAILED - Failed
158 * RT_ERR_SMI - SMI access error
159 * RT_ERR_INPUT - Invalid input parameters.
160 * RT_ERR_L2_NO_CPU_PORT - CPU port is not exist
162 * The API can get configured CPU port and its setting.
163 * The insert CPU tag mode is as following:
164 * - CPU_INSERT_TO_ALL
165 * - CPU_INSERT_TO_TRAPPING
166 * - CPU_INSERT_TO_NONE
168 rtk_api_ret_t
rtk_cpu_tagPort_get(rtk_port_t
*pPort
, rtk_cpu_insert_t
*pMode
)
170 rtk_api_ret_t retVal
;
171 rtk_uint32 pmsk
, port
;
173 /* Check initialization state */
174 RTK_CHK_INIT_STATE();
177 return RT_ERR_NULL_POINTER
;
180 return RT_ERR_NULL_POINTER
;
182 if ((retVal
= rtl8367c_getAsicCputagPortmask(&pmsk
)) != RT_ERR_OK
)
185 if ((retVal
= rtl8367c_getAsicCputagTrapPort(&port
)) != RT_ERR_OK
)
188 *pPort
= rtk_switch_port_P2L_get(port
);
190 if ((retVal
= rtl8367c_getAsicCputagInsertMode(pMode
)) != RT_ERR_OK
)
198 * rtk_cpu_awarePort_set
200 * Set CPU aware port mask.
202 * portmask - Port mask.
207 * RT_ERR_FAILED - Failed
208 * RT_ERR_SMI - SMI access error
209 * RT_ERR_PORT_MASK - Invalid port mask.
211 * The API can set configured CPU aware port mask.
213 rtk_api_ret_t
rtk_cpu_awarePort_set(rtk_portmask_t
*pPortmask
)
215 rtk_api_ret_t retVal
;
216 rtk_uint32 phyMbrPmask
;
218 /* Check initialization state */
219 RTK_CHK_INIT_STATE();
221 /* Check Valid port mask */
222 if(NULL
== pPortmask
)
223 return RT_ERR_NULL_POINTER
;
225 /* Check port mask valid */
226 RTK_CHK_PORTMASK_VALID(pPortmask
);
228 if(rtk_switch_portmask_L2P_get(pPortmask
, &phyMbrPmask
) != RT_ERR_OK
)
229 return RT_ERR_FAILED
;
231 if ((retVal
= rtl8367c_setAsicCputagPortmask(phyMbrPmask
)) != RT_ERR_OK
)
238 * rtk_cpu_awarePort_get
240 * Get CPU aware port mask.
244 * pPortmask - Port mask.
247 * RT_ERR_FAILED - Failed
248 * RT_ERR_SMI - SMI access error
250 * The API can get configured CPU aware port mask.
252 rtk_api_ret_t
rtk_cpu_awarePort_get(rtk_portmask_t
*pPortmask
)
254 rtk_api_ret_t retVal
;
257 /* Check initialization state */
258 RTK_CHK_INIT_STATE();
260 if(NULL
== pPortmask
)
261 return RT_ERR_NULL_POINTER
;
263 if ((retVal
= rtl8367c_getAsicCputagPortmask(&pmsk
)) != RT_ERR_OK
)
266 if(rtk_switch_portmask_P2L_get(pmsk
, pPortmask
) != RT_ERR_OK
)
267 return RT_ERR_FAILED
;
273 * rtk_cpu_tagPosition_set
275 * Set CPU tag position.
277 * position - CPU tag position.
282 * RT_ERR_FAILED - Failed
283 * RT_ERR_SMI - SMI access error
284 * RT_ERR_INPUT - Invalid input.
286 * The API can set CPU tag position.
288 rtk_api_ret_t
rtk_cpu_tagPosition_set(rtk_cpu_position_t position
)
290 rtk_api_ret_t retVal
;
292 /* Check initialization state */
293 RTK_CHK_INIT_STATE();
295 if (position
>= CPU_POS_END
)
298 if ((retVal
= rtl8367c_setAsicCputagPosition(position
)) != RT_ERR_OK
)
305 * rtk_cpu_tagPosition_get
307 * Get CPU tag position.
311 * pPosition - CPU tag position.
314 * RT_ERR_FAILED - Failed
315 * RT_ERR_SMI - SMI access error
316 * RT_ERR_INPUT - Invalid input.
318 * The API can get CPU tag position.
320 rtk_api_ret_t
rtk_cpu_tagPosition_get(rtk_cpu_position_t
*pPosition
)
322 rtk_api_ret_t retVal
;
324 /* Check initialization state */
325 RTK_CHK_INIT_STATE();
327 if(NULL
== pPosition
)
328 return RT_ERR_NULL_POINTER
;
330 if ((retVal
= rtl8367c_getAsicCputagPosition(pPosition
)) != RT_ERR_OK
)
337 * rtk_cpu_tagLength_set
339 * Set CPU tag length.
341 * length - CPU tag length.
346 * RT_ERR_FAILED - Failed
347 * RT_ERR_SMI - SMI access error
348 * RT_ERR_INPUT - Invalid input.
350 * The API can set CPU tag length.
352 rtk_api_ret_t
rtk_cpu_tagLength_set(rtk_cpu_tag_length_t length
)
354 rtk_api_ret_t retVal
;
356 /* Check initialization state */
357 RTK_CHK_INIT_STATE();
359 if (length
>= CPU_LEN_END
)
362 if ((retVal
= rtl8367c_setAsicCputagMode(length
)) != RT_ERR_OK
)
369 * rtk_cpu_tagLength_get
371 * Get CPU tag length.
375 * pLength - CPU tag length.
378 * RT_ERR_FAILED - Failed
379 * RT_ERR_SMI - SMI access error
380 * RT_ERR_INPUT - Invalid input.
382 * The API can get CPU tag length.
384 rtk_api_ret_t
rtk_cpu_tagLength_get(rtk_cpu_tag_length_t
*pLength
)
386 rtk_api_ret_t retVal
;
388 /* Check initialization state */
389 RTK_CHK_INIT_STATE();
392 return RT_ERR_NULL_POINTER
;
394 if ((retVal
= rtl8367c_getAsicCputagMode(pLength
)) != RT_ERR_OK
)
401 * rtk_cpu_priRemap_set
403 * Configure CPU priorities mapping to internal absolute priority.
405 * int_pri - internal priority value.
406 * new_pri - new internal priority value.
411 * RT_ERR_FAILED - Failed
412 * RT_ERR_SMI - SMI access error
413 * RT_ERR_INPUT - Invalid input parameters.
414 * RT_ERR_VLAN_PRIORITY - Invalid 1p priority.
415 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
417 * Priority of CPU tag assignment for internal asic priority, and it is used for queue usage and packet scheduling.
419 rtk_api_ret_t
rtk_cpu_priRemap_set(rtk_pri_t int_pri
, rtk_pri_t new_pri
)
421 rtk_api_ret_t retVal
;
423 /* Check initialization state */
424 RTK_CHK_INIT_STATE();
426 if (new_pri
> RTL8367C_PRIMAX
|| int_pri
> RTL8367C_PRIMAX
)
427 return RT_ERR_VLAN_PRIORITY
;
429 if ((retVal
= rtl8367c_setAsicCputagPriorityRemapping(int_pri
, new_pri
)) != RT_ERR_OK
)
436 * rtk_cpu_priRemap_get
438 * Configure CPU priorities mapping to internal absolute priority.
440 * int_pri - internal priority value.
442 * pNew_pri - new internal priority value.
445 * RT_ERR_FAILED - Failed
446 * RT_ERR_SMI - SMI access error
447 * RT_ERR_INPUT - Invalid input parameters.
448 * RT_ERR_VLAN_PRIORITY - Invalid 1p priority.
449 * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
451 * Priority of CPU tag assignment for internal asic priority, and it is used for queue usage and packet scheduling.
453 rtk_api_ret_t
rtk_cpu_priRemap_get(rtk_pri_t int_pri
, rtk_pri_t
*pNew_pri
)
455 rtk_api_ret_t retVal
;
457 /* Check initialization state */
458 RTK_CHK_INIT_STATE();
461 return RT_ERR_NULL_POINTER
;
463 if (int_pri
> RTL8367C_PRIMAX
)
464 return RT_ERR_QOS_INT_PRIORITY
;
466 if ((retVal
= rtl8367c_getAsicCputagPriorityRemapping(int_pri
, pNew_pri
)) != RT_ERR_OK
)
473 * rtk_cpu_acceptLength_set
475 * Set CPU accept length.
477 * length - CPU tag length.
482 * RT_ERR_FAILED - Failed
483 * RT_ERR_SMI - SMI access error
484 * RT_ERR_INPUT - Invalid input.
486 * The API can set CPU accept length.
488 rtk_api_ret_t
rtk_cpu_acceptLength_set(rtk_cpu_rx_length_t length
)
490 rtk_api_ret_t retVal
;
492 /* Check initialization state */
493 RTK_CHK_INIT_STATE();
495 if (length
>= CPU_RX_END
)
498 if ((retVal
= rtl8367c_setAsicCputagRxMinLength(length
)) != RT_ERR_OK
)
505 * rtk_cpu_acceptLength_get
507 * Get CPU accept length.
511 * pLength - CPU tag length.
514 * RT_ERR_FAILED - Failed
515 * RT_ERR_SMI - SMI access error
516 * RT_ERR_INPUT - Invalid input.
518 * The API can get CPU accept length.
520 rtk_api_ret_t
rtk_cpu_acceptLength_get(rtk_cpu_rx_length_t
*pLength
)
522 rtk_api_ret_t retVal
;
524 /* Check initialization state */
525 RTK_CHK_INIT_STATE();
528 return RT_ERR_NULL_POINTER
;
530 if ((retVal
= rtl8367c_getAsicCputagRxMinLength(pLength
)) != RT_ERR_OK
)