| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537 |
- /*
- * Copyright (C) 2013 Realtek Semiconductor Corp.
- * All Rights Reserved.
- *
- * Unless you and Realtek execute a separate written software license
- * agreement governing use of this software, this software is licensed
- * to you under the terms of the GNU General Public License version 2,
- * available at https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
- *
- * $Revision: 76306 $
- * $Date: 2017-03-08 15:13:58 +0800 (週三, 08 三月 2017) $
- *
- * Purpose : RTK switch high-level API for RTL8367/RTL8367C
- * Feature : Here is a list of all functions and variables in CPU module.
- *
- */
- #include <rtk_switch.h>
- #include <rtk_error.h>
- #include <cpu.h>
- #include <string.h>
- #include <rtl8367c_asicdrv.h>
- #include <rtl8367c_asicdrv_cputag.h>
- /* Function Name:
- * rtk_cpu_enable_set
- * Description:
- * Set CPU port function enable/disable.
- * Input:
- * enable - CPU port function enable
- * Output:
- * None
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input parameter.
- * RT_ERR_PORT_ID - Invalid port number.
- * Note:
- * The API can set CPU port function enable/disable.
- */
- rtk_api_ret_t rtk_cpu_enable_set(rtk_enable_t enable)
- {
- rtk_api_ret_t retVal;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if (enable >= RTK_ENABLE_END)
- return RT_ERR_ENABLE;
- if ((retVal = rtl8367c_setAsicCputagEnable(enable)) != RT_ERR_OK)
- return retVal;
- if (DISABLED == enable)
- {
- if ((retVal = rtl8367c_setAsicCputagPortmask(0)) != RT_ERR_OK)
- return retVal;
- }
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_enable_get
- * Description:
- * Get CPU port and its setting.
- * Input:
- * None
- * Output:
- * pEnable - CPU port function enable
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input parameters.
- * RT_ERR_L2_NO_CPU_PORT - CPU port is not exist
- * Note:
- * The API can get CPU port function enable/disable.
- */
- rtk_api_ret_t rtk_cpu_enable_get(rtk_enable_t *pEnable)
- {
- rtk_api_ret_t retVal;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if(NULL == pEnable)
- return RT_ERR_NULL_POINTER;
- if ((retVal = rtl8367c_getAsicCputagEnable(pEnable)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_tagPort_set
- * Description:
- * Set CPU port and CPU tag insert mode.
- * Input:
- * port - Port id.
- * mode - CPU tag insert for packets egress from CPU port.
- * Output:
- * None
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input parameter.
- * RT_ERR_PORT_ID - Invalid port number.
- * Note:
- * The API can set CPU port and inserting proprietary CPU tag mode (Length/Type 0x8899)
- * to the frame that transmitting to CPU port.
- * The insert CPU tag mode is as following:
- * - CPU_INSERT_TO_ALL
- * - CPU_INSERT_TO_TRAPPING
- * - CPU_INSERT_TO_NONE
- */
- rtk_api_ret_t rtk_cpu_tagPort_set(rtk_port_t port, rtk_cpu_insert_t mode)
- {
- rtk_api_ret_t retVal;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- /* Check port Valid */
- RTK_CHK_PORT_VALID(port);
- if (mode >= CPU_INSERT_END)
- return RT_ERR_INPUT;
- if ((retVal = rtl8367c_setAsicCputagPortmask(1<<rtk_switch_port_L2P_get(port))) != RT_ERR_OK)
- return retVal;
- if ((retVal = rtl8367c_setAsicCputagTrapPort(rtk_switch_port_L2P_get(port))) != RT_ERR_OK)
- return retVal;
- if ((retVal = rtl8367c_setAsicCputagInsertMode(mode)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_tagPort_get
- * Description:
- * Get CPU port and CPU tag insert mode.
- * Input:
- * None
- * Output:
- * pPort - Port id.
- * pMode - CPU tag insert for packets egress from CPU port, 0:all insert 1:Only for trapped packets 2:no insert.
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input parameters.
- * RT_ERR_L2_NO_CPU_PORT - CPU port is not exist
- * Note:
- * The API can get configured CPU port and its setting.
- * The insert CPU tag mode is as following:
- * - CPU_INSERT_TO_ALL
- * - CPU_INSERT_TO_TRAPPING
- * - CPU_INSERT_TO_NONE
- */
- rtk_api_ret_t rtk_cpu_tagPort_get(rtk_port_t *pPort, rtk_cpu_insert_t *pMode)
- {
- rtk_api_ret_t retVal;
- rtk_uint32 pmsk, port;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if(NULL == pPort)
- return RT_ERR_NULL_POINTER;
- if(NULL == pMode)
- return RT_ERR_NULL_POINTER;
- if ((retVal = rtl8367c_getAsicCputagPortmask(&pmsk)) != RT_ERR_OK)
- return retVal;
- if ((retVal = rtl8367c_getAsicCputagTrapPort(&port)) != RT_ERR_OK)
- return retVal;
- *pPort = rtk_switch_port_P2L_get(port);
- if ((retVal = rtl8367c_getAsicCputagInsertMode(pMode)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_awarePort_set
- * Description:
- * Set CPU aware port mask.
- * Input:
- * portmask - Port mask.
- * Output:
- * None
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_PORT_MASK - Invalid port mask.
- * Note:
- * The API can set configured CPU aware port mask.
- */
- rtk_api_ret_t rtk_cpu_awarePort_set(rtk_portmask_t *pPortmask)
- {
- rtk_api_ret_t retVal;
- rtk_uint32 phyMbrPmask;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- /* Check Valid port mask */
- if(NULL == pPortmask)
- return RT_ERR_NULL_POINTER;
- /* Check port mask valid */
- RTK_CHK_PORTMASK_VALID(pPortmask);
- if(rtk_switch_portmask_L2P_get(pPortmask, &phyMbrPmask) != RT_ERR_OK)
- return RT_ERR_FAILED;
- if ((retVal = rtl8367c_setAsicCputagPortmask(phyMbrPmask)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_awarePort_get
- * Description:
- * Get CPU aware port mask.
- * Input:
- * None
- * Output:
- * pPortmask - Port mask.
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * Note:
- * The API can get configured CPU aware port mask.
- */
- rtk_api_ret_t rtk_cpu_awarePort_get(rtk_portmask_t *pPortmask)
- {
- rtk_api_ret_t retVal;
- rtk_uint32 pmsk;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if(NULL == pPortmask)
- return RT_ERR_NULL_POINTER;
- if ((retVal = rtl8367c_getAsicCputagPortmask(&pmsk)) != RT_ERR_OK)
- return retVal;
- if(rtk_switch_portmask_P2L_get(pmsk, pPortmask) != RT_ERR_OK)
- return RT_ERR_FAILED;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_tagPosition_set
- * Description:
- * Set CPU tag position.
- * Input:
- * position - CPU tag position.
- * Output:
- * None
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input.
- * Note:
- * The API can set CPU tag position.
- */
- rtk_api_ret_t rtk_cpu_tagPosition_set(rtk_cpu_position_t position)
- {
- rtk_api_ret_t retVal;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if (position >= CPU_POS_END)
- return RT_ERR_INPUT;
- if ((retVal = rtl8367c_setAsicCputagPosition(position)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_tagPosition_get
- * Description:
- * Get CPU tag position.
- * Input:
- * None
- * Output:
- * pPosition - CPU tag position.
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input.
- * Note:
- * The API can get CPU tag position.
- */
- rtk_api_ret_t rtk_cpu_tagPosition_get(rtk_cpu_position_t *pPosition)
- {
- rtk_api_ret_t retVal;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if(NULL == pPosition)
- return RT_ERR_NULL_POINTER;
- if ((retVal = rtl8367c_getAsicCputagPosition(pPosition)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_tagLength_set
- * Description:
- * Set CPU tag length.
- * Input:
- * length - CPU tag length.
- * Output:
- * None
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input.
- * Note:
- * The API can set CPU tag length.
- */
- rtk_api_ret_t rtk_cpu_tagLength_set(rtk_cpu_tag_length_t length)
- {
- rtk_api_ret_t retVal;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if (length >= CPU_LEN_END)
- return RT_ERR_INPUT;
- if ((retVal = rtl8367c_setAsicCputagMode(length)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_tagLength_get
- * Description:
- * Get CPU tag length.
- * Input:
- * None
- * Output:
- * pLength - CPU tag length.
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input.
- * Note:
- * The API can get CPU tag length.
- */
- rtk_api_ret_t rtk_cpu_tagLength_get(rtk_cpu_tag_length_t *pLength)
- {
- rtk_api_ret_t retVal;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if(NULL == pLength)
- return RT_ERR_NULL_POINTER;
- if ((retVal = rtl8367c_getAsicCputagMode(pLength)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_priRemap_set
- * Description:
- * Configure CPU priorities mapping to internal absolute priority.
- * Input:
- * int_pri - internal priority value.
- * new_pri - new internal priority value.
- * Output:
- * None
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input parameters.
- * RT_ERR_VLAN_PRIORITY - Invalid 1p priority.
- * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
- * Note:
- * Priority of CPU tag assignment for internal asic priority, and it is used for queue usage and packet scheduling.
- */
- rtk_api_ret_t rtk_cpu_priRemap_set(rtk_pri_t int_pri, rtk_pri_t new_pri)
- {
- rtk_api_ret_t retVal;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if (new_pri > RTL8367C_PRIMAX || int_pri > RTL8367C_PRIMAX)
- return RT_ERR_VLAN_PRIORITY;
- if ((retVal = rtl8367c_setAsicCputagPriorityRemapping(int_pri, new_pri)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_priRemap_get
- * Description:
- * Configure CPU priorities mapping to internal absolute priority.
- * Input:
- * int_pri - internal priority value.
- * Output:
- * pNew_pri - new internal priority value.
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input parameters.
- * RT_ERR_VLAN_PRIORITY - Invalid 1p priority.
- * RT_ERR_QOS_INT_PRIORITY - Invalid priority.
- * Note:
- * Priority of CPU tag assignment for internal asic priority, and it is used for queue usage and packet scheduling.
- */
- rtk_api_ret_t rtk_cpu_priRemap_get(rtk_pri_t int_pri, rtk_pri_t *pNew_pri)
- {
- rtk_api_ret_t retVal;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if(NULL == pNew_pri)
- return RT_ERR_NULL_POINTER;
- if (int_pri > RTL8367C_PRIMAX)
- return RT_ERR_QOS_INT_PRIORITY;
- if ((retVal = rtl8367c_getAsicCputagPriorityRemapping(int_pri, pNew_pri)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_acceptLength_set
- * Description:
- * Set CPU accept length.
- * Input:
- * length - CPU tag length.
- * Output:
- * None
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input.
- * Note:
- * The API can set CPU accept length.
- */
- rtk_api_ret_t rtk_cpu_acceptLength_set(rtk_cpu_rx_length_t length)
- {
- rtk_api_ret_t retVal;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if (length >= CPU_RX_END)
- return RT_ERR_INPUT;
- if ((retVal = rtl8367c_setAsicCputagRxMinLength(length)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
- /* Function Name:
- * rtk_cpu_acceptLength_get
- * Description:
- * Get CPU accept length.
- * Input:
- * None
- * Output:
- * pLength - CPU tag length.
- * Return:
- * RT_ERR_OK - OK
- * RT_ERR_FAILED - Failed
- * RT_ERR_SMI - SMI access error
- * RT_ERR_INPUT - Invalid input.
- * Note:
- * The API can get CPU accept length.
- */
- rtk_api_ret_t rtk_cpu_acceptLength_get(rtk_cpu_rx_length_t *pLength)
- {
- rtk_api_ret_t retVal;
- /* Check initialization state */
- RTK_CHK_INIT_STATE();
- if(NULL == pLength)
- return RT_ERR_NULL_POINTER;
- if ((retVal = rtl8367c_getAsicCputagRxMinLength(pLength)) != RT_ERR_OK)
- return retVal;
- return RT_ERR_OK;
- }
|