[rdkb][common][bsp][Refactor and sync kernel from openwrt]

[Description]
7dbf952c [kernel][mt7988][eth][Refactor error detection rule for the WDMA_RX monitor]
179939e0 [kernel][mt7988][eth][Add individual polarity control to the USXGMII]
cd3e2dc3 [kernel][common][eth][Refactor the link polling mechanism to improve CPU usage in the USXGMII/SGMII]
e59df428 [Openwrt][Common][Change to valid lftp oss package download source]
bcded043 [openwrt][mt7988][crypto][Refactor CAPWAP DTLS code for establish tunnel]
9196c168 [kernel][common][hnat][Refactor entry fp and special tag assignment for handling DSA device]
a531c030 [openwrt][common][Kernel from 5.4.271 to 5.4.281]
849a7206 [openwrt][mt7988][crypto][Add CAPWAP-DTLS IPv6 Support]
65407907 [kernel][common][hnat][Add wdma rx port as match condition to delete entry by bssid, wcid API]
f5aa96c2 [Critical][kernel][common][spinand][Add CASN support for SPI-NAND]
1f7b6c3c [kernel][common][eth][Correct LROv1 invalidate flow]
da101027 [kernel][common][hnat][Add API to delete PPE entry by bssid and wcid]
7d2def2e [HIGH][kernel][mt7988][eth][ fix wdma module set to zero when warm reset fail and switch to cold reset ]
d6d7e24d [openwrt][mt7988][crypto][Add checking xfrm state info to avoid null pointer]
830eba8d [[Kernel][common][hnat]Fix WAN->LAN UNBIND in MAPE/DS_Lite scenario]
70e84050 [openwrt][switch][ARHT][update DSA and GSW driver for AN8855H]
5b59fbfa [openwrt][switch][ARHT][update switch app to v1.0.7]
db21a3af [openwrt][common][app][Fix Coverity defects in the switch utility]
2ad1c4af [mt7988][crypto][Add spin_lock for hnat_bind_crypto_entry()]
be77272d [openwrt][mt7988][pce][add notification chain in PCE]
a1bdbde8 [openwrt][mt7988][pce][Fix PCE freeing wrong cdrt idx bug]
be89679b [[Kernel][common][hnat][Fix 6RD HW PATH fail and ipv4 identification 0]
b199e1fa [[Coverity][REBB]Uninitialized pointer read: 5301002]
5441a4fb [MAC80211][misc][Add Setup SMP Affinity script for kernel6.6 build]
e55494d6 [[Kernel][common][hnat][Add delete entry by IP command]
35e68194 [HIGH][kernel][common][eth][Fix the GDM RX FC packet statistics error issue]
13d31aef [[kernel][common][eth][ fix reset flag coding error and add debug CR dump info ]]
15cf5b55 [openwrt][common][bsp][Add ignore item of checkpatch]
ca1fb699 [kernel][common][eth][Remove redundant break in the pse_info_get() function]
074b842b [kernel][common][eth][Refactor phylink pcs_enable and pcs_disable methods]
696aa6fe [openwrt-24][common][bsp][Fix fit related patches]
cfb45e3a [kernel][common][eth][Fix ETH compilation warnings]
6cbba7f6 [kernel][common][eth][ Reduce timeout value for waiting for WiFi SER 1st-part completion ]
6ff258fa [HIGH][kernel][common][eth][Fix ETH watchdog timeout false alarm during NETSYS SER]
c59c00f9 [HIGH][kernel][common][eth][Fix GDM monitor null pointer issue]
79d7b569 [kernel][common][hnat][Add delete entry by mac command]
b448600a [kernel][mt7988][eth][Correct XGMAC preparation function when using an external 1G/2.5G PHY]
cc241b51 [kernel][common][hnat][Add PSE PPE port link down based on configured PPE number]
111414fc [HIGH][kernel][common][eth][Change the network device TX queue reset flow]
62d9ddd8 [kernel][common][eth][Refactor PSE port link down function]
8de3854d [openwrt][common][bsp][Add ignore item of checkpatch]
a76c2442 [kernel][common][eth][fix wdma tx condition coding error]
bef28556 [MAC80211][misc][Change autobuild folder name to distinguish kernel5.4 and upcoming kernel6.6]
f82f591b [openwrt-24][common][bsp][Remove unnecessary patch due to has been upsteam]
d51fe770 [openwrt][mt7988][crytpo][add debugfs for crypto module]
64a21e7e [openwrt][mt7988][crypto][Add support for L2GREoIPsec]
ced208f6 [[kernel][common][eth][fix eth coverity]]
7b251009 [kernel][common][hnat][Revert the method for writing PPE info1]
e262a913 [HIGH][kernel][mt7988][eth][Add PPE2 case to the SER pending work]

[Release-log]

Change-Id: Ie2733597213f7e17960f79c2d4d69b7d09a7c269
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air.h b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air.h
index c62174f..bedfaf9 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air.h
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air.h
@@ -1,216 +1,216 @@
-/* FILE NAME:   air.h

- * PURPOSE:

- *      Define the initialization in AIR SDK.

- * NOTES:

- */

-

-#ifndef AIR_H

-#define AIR_H

-

-/* INCLUDE FILE DECLARATIONS

- */

-#include <stdio.h>

-#include <string.h>

-#include "air_types.h"

-#include "air_error.h"

-#include "air_reg.h"

-#include "air_aml.h"

-#include "air_port.h"

-#include "air_vlan.h"

-#include "air_lag.h"

-#include "air_l2.h"

-#include "air_stp.h"

-#include "air_mirror.h"

-#include "air_mib.h"

-#include "air_diag.h"

-#include "air_led.h"

-#include "air_cmd.h"

-#include "air_qos.h"

-#include "air_switch.h"

-#include "air_ver.h"

-#include "air_sec.h"

-#include "air_acl.h"

-#include "air_sptag.h"

-

-/* NAMING CONSTANT DECLARATIONS

- */

-

-/* MACRO FUNCTION DECLARATIONS

- */

-#define AIR_CHECK_PTR(__ptr__) do                                          \

-{                                                                           \

-    if (NULL == (__ptr__))                                                  \

-    {                                                                       \

-        return  AIR_E_BAD_PARAMETER;                                       \

-    }                                                                       \

-} while (0)

-

-#define AIR_PARAM_CHK(expr, errCode) do                                    \

-{                                                                           \

-    if ((I32_T)(expr))                                                      \

-    {                                                                       \

-        return errCode;                                                     \

-    }                                                                       \

-} while (0)

-

-#define AIR_PRINT(fmt,...) do                                              \

-{                                                                           \

-    if (_ext_printf)                                                        \

-    {                                                                       \

-        _ext_printf(fmt, ##__VA_ARGS__);                                    \

-    }                                                                       \

-}while (0)

-

-#define AIR_UDELAY(us) do                                                  \

-{                                                                           \

-    if (_ext_udelay)                                                        \

-    {                                                                       \

-        _ext_udelay(us);                                                    \

-    }                                                                       \

-}while (0)

-

-#define AIR_MALLOC(size) (_ext_malloc ? _ext_malloc(size) : NULL)

-

-#define AIR_FREE(ptr) do                                                   \

-    {                                                                       \

-        if (ptr && _ext_free)                                               \

-        {                                                                   \

-            _ext_free(ptr);                                                 \

-        }                                                                   \

-    }while (0)

-

-#ifndef BIT

-#define BIT(nr) (1UL << (nr))

-#endif	/* End of BIT */

-

-/* bits range: for example BITS(16,23) = 0xFF0000*/

-#ifndef BITS

-#define BITS(m, n)   (~(BIT(m) - 1) & ((BIT(n) - 1) | BIT(n)))

-#endif	/* End of BITS */

-

-/* bits range: for example BITS_RANGE(16,4) = 0x0F0000*/

-#ifndef BITS_RANGE

-#define BITS_RANGE(offset, range)   BITS(offset, ((offset)+(range)-1))

-#endif	/* End of BITS_RANGE */

-

-/* bits offset right: for example BITS_OFF_R(0x1234, 8, 4) = 0x2 */

-#ifndef BITS_OFF_R

-#define BITS_OFF_R(val, offset, range)   ((val >> offset) & (BIT(range) - 1))

-#endif	/* End of BITS_OFF_R */

-

-/* bits offset left: for example BITS_OFF_L(0x1234, 8, 4) = 0x400 */

-#ifndef BITS_OFF_L

-#define BITS_OFF_L(val, offset, range)   ((val & (BIT(range) - 1)) << offset)

-#endif	/* End of BITS_OFF_L */

-

-#ifndef MAX

-#define MAX(a, b)   (((a)>(b))?(a):(b))

-#endif	/* End of MAX */

-

-#ifndef MIN

-#define MIN(a, b)   (((a)<(b))?(a):(b))

-#endif	/* End of MIN */

-

-/* DATA TYPE DECLARATIONS

- */

-typedef AIR_ERROR_NO_T

-(*AIR_PRINTF)(

-    C8_T* fmt,

-    ...);

-

-typedef void

-(*AIR_UDELAY)(

-    UI32_T us);

-

-typedef void*

-(*AIR_MALLOC)(

-    UI32_T size);

-

-typedef void

-(*AIR_FREE)(

-    void *ptr);

-

-typedef struct

-{

-    AML_DEV_ACCESS_T    dev_access;

-    AIR_PRINTF         printf;

-    AIR_UDELAY         udelay;

-    AIR_MALLOC         malloc;

-    AIR_FREE           free;

-}AIR_INIT_PARAM_T;

-

-/* EXPORTED SUBPROGRAM SPECIFICATIONS

- */

-extern AIR_PRINTF _ext_printf;

-extern AIR_UDELAY _ext_udelay;

-extern AIR_MALLOC _ext_malloc;

-extern AIR_FREE   _ext_free;

-

-

-/* FUNCTION NAME:   air_init

- * PURPOSE:

- *      This API is used to initialize the SDK.

- *

- * INPUT:

- *      unit            --  The device unit

- *      ptr_init_param  --  The sdk callback functions.

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_OTHERS

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_init(

-    const UI32_T unit,

-    AIR_INIT_PARAM_T *ptr_init_param);

-

-/* FUNCTION NAME:   air_hw_reset

- * PURPOSE:

- *      This API is used to reset hardware.

- *

- * INPUT:

- *      unit            --  The device unit

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_OTHERS

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_hw_reset(

-    const UI32_T unit);

-

-/* FUNCTION NAME:   air_set_gpio_pin_mux

- * PURPOSE:

- *      This API is used to set gpio pin mux.

- *

- * INPUT:

- *      unit            --  The device unit

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_OTHERS

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_set_gpio_pin_mux(

-    const UI32_T unit);

-

-#endif  /* AIR_H */

-

+/* FILE NAME:   air.h
+ * PURPOSE:
+ *      Define the initialization in AIR SDK.
+ * NOTES:
+ */
+
+#ifndef AIR_H
+#define AIR_H
+
+/* INCLUDE FILE DECLARATIONS
+ */
+#include <stdio.h>
+#include <string.h>
+#include "air_types.h"
+#include "air_error.h"
+#include "air_reg.h"
+#include "air_aml.h"
+#include "air_port.h"
+#include "air_vlan.h"
+#include "air_lag.h"
+#include "air_l2.h"
+#include "air_stp.h"
+#include "air_mirror.h"
+#include "air_mib.h"
+#include "air_diag.h"
+#include "air_led.h"
+#include "air_cmd.h"
+#include "air_qos.h"
+#include "air_switch.h"
+#include "air_ver.h"
+#include "air_sec.h"
+#include "air_acl.h"
+#include "air_sptag.h"
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+#define AIR_CHECK_PTR(__ptr__) do                                          \
+{                                                                           \
+    if (NULL == (__ptr__))                                                  \
+    {                                                                       \
+        return  AIR_E_BAD_PARAMETER;                                       \
+    }                                                                       \
+} while (0)
+
+#define AIR_PARAM_CHK(expr, errCode) do                                    \
+{                                                                           \
+    if ((I32_T)(expr))                                                      \
+    {                                                                       \
+        return errCode;                                                     \
+    }                                                                       \
+} while (0)
+
+#define AIR_PRINT(fmt,...) do                                              \
+{                                                                           \
+    if (_ext_printf)                                                        \
+    {                                                                       \
+        _ext_printf(fmt, ##__VA_ARGS__);                                    \
+    }                                                                       \
+}while (0)
+
+#define AIR_UDELAY(us) do                                                  \
+{                                                                           \
+    if (_ext_udelay)                                                        \
+    {                                                                       \
+        _ext_udelay(us);                                                    \
+    }                                                                       \
+}while (0)
+
+#define AIR_MALLOC(size) (_ext_malloc ? _ext_malloc(size) : NULL)
+
+#define AIR_FREE(ptr) do                                                   \
+    {                                                                       \
+        if (ptr && _ext_free)                                               \
+        {                                                                   \
+            _ext_free(ptr);                                                 \
+        }                                                                   \
+    }while (0)
+
+#ifndef BIT
+#define BIT(nr) (1UL << (nr))
+#endif	/* End of BIT */
+
+/* bits range: for example BITS(16,23) = 0xFF0000*/
+#ifndef BITS
+#define BITS(m, n)   (~(BIT(m) - 1) & ((BIT(n) - 1) | BIT(n)))
+#endif	/* End of BITS */
+
+/* bits range: for example BITS_RANGE(16,4) = 0x0F0000*/
+#ifndef BITS_RANGE
+#define BITS_RANGE(offset, range)   BITS(offset, ((offset)+(range)-1))
+#endif	/* End of BITS_RANGE */
+
+/* bits offset right: for example BITS_OFF_R(0x1234, 8, 4) = 0x2 */
+#ifndef BITS_OFF_R
+#define BITS_OFF_R(val, offset, range)   ((val >> offset) & (BIT(range) - 1))
+#endif	/* End of BITS_OFF_R */
+
+/* bits offset left: for example BITS_OFF_L(0x1234, 8, 4) = 0x400 */
+#ifndef BITS_OFF_L
+#define BITS_OFF_L(val, offset, range)   ((val & (BIT(range) - 1)) << offset)
+#endif	/* End of BITS_OFF_L */
+
+#ifndef MAX
+#define MAX(a, b)   (((a)>(b))?(a):(b))
+#endif	/* End of MAX */
+
+#ifndef MIN
+#define MIN(a, b)   (((a)<(b))?(a):(b))
+#endif	/* End of MIN */
+
+/* DATA TYPE DECLARATIONS
+ */
+typedef int
+(*AIR_PRINTF)(
+    const C8_T* fmt,
+    ...);
+
+typedef int
+(*AIR_UDELAY)(
+    UI32_T us);
+
+typedef void*
+(*AIR_MALLOC)(
+    long unsigned int size);
+
+typedef void
+(*AIR_FREE)(
+    void *ptr);
+
+typedef struct
+{
+    AML_DEV_ACCESS_T    dev_access;
+    AIR_PRINTF         printf;
+    AIR_UDELAY         udelay;
+    AIR_MALLOC         malloc;
+    AIR_FREE           free;
+}AIR_INIT_PARAM_T;
+
+/* EXPORTED SUBPROGRAM SPECIFICATIONS
+ */
+extern AIR_PRINTF _ext_printf;
+extern AIR_UDELAY _ext_udelay;
+extern AIR_MALLOC _ext_malloc;
+extern AIR_FREE   _ext_free;
+
+
+/* FUNCTION NAME:   air_init
+ * PURPOSE:
+ *      This API is used to initialize the SDK.
+ *
+ * INPUT:
+ *      unit            --  The device unit
+ *      ptr_init_param  --  The sdk callback functions.
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_OTHERS
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_init(
+    const UI32_T unit,
+    AIR_INIT_PARAM_T *ptr_init_param);
+
+/* FUNCTION NAME:   air_hw_reset
+ * PURPOSE:
+ *      This API is used to reset hardware.
+ *
+ * INPUT:
+ *      unit            --  The device unit
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_OTHERS
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_hw_reset(
+    const UI32_T unit);
+
+/* FUNCTION NAME:   air_set_gpio_pin_mux
+ * PURPOSE:
+ *      This API is used to set gpio pin mux.
+ *
+ * INPUT:
+ *      unit            --  The device unit
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_OTHERS
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_set_gpio_pin_mux(
+    const UI32_T unit);
+
+#endif  /* AIR_H */
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_aml.h b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_aml.h
index 49a38b6..8d40bee 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_aml.h
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_aml.h
@@ -1,214 +1,214 @@
-/* FILE NAME:   air_aml.h

- * PURPOSE:

- *      Define the access management layer function in AIR SDK.

- * NOTES:

- */

-

-#ifndef AIR_AML_H

-#define AIR_AML_H

-

-/* INCLUDE FILE DECLARATIONS

- */

-

-/* NAMING CONSTANT DECLARATIONS

- */

-

-/* MACRO FUNCTION DECLARATIONS

- */

-

-/* DATA TYPE DECLARATIONS

- */

-typedef AIR_ERROR_NO_T

-(*AML_DEV_READ_FUNC_T)(

-    const UI32_T    unit,

-    const UI32_T    addr_offset,

-    UI32_T          *ptr_data);

-

-typedef AIR_ERROR_NO_T

-(*AML_DEV_WRITE_FUNC_T)(

-    const UI32_T    unit,

-    const UI32_T    addr_offset,

-    const UI32_T    data);

-

-typedef AIR_ERROR_NO_T

-(*AML_DEV_PHY_READ_FUNC_T)(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    addr_offset,

-    UI32_T          *ptr_data);

-

-typedef AIR_ERROR_NO_T

-(*AML_DEV_PHY_WRITE_FUNC_T)(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    addr_offset,

-    const UI32_T    data);

-

-typedef AIR_ERROR_NO_T

-(*AML_DEV_PHY_READ_CL45_FUNC_T)(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    dev_type,

-    const UI32_T    addr_offset,

-    UI32_T          *ptr_data);

-

-typedef AIR_ERROR_NO_T

-(*AML_DEV_PHY_WRITE_CL45_FUNC_T)(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    dev_type,

-    const UI32_T    addr_offset,

-    const UI32_T    data);

-

-/* To read or write the HW-intf registers. */

-typedef struct

-{

-    AML_DEV_READ_FUNC_T             read_callback;

-    AML_DEV_WRITE_FUNC_T            write_callback;

-    AML_DEV_PHY_READ_FUNC_T         phy_read_callback;

-    AML_DEV_PHY_WRITE_FUNC_T        phy_write_callback;

-    AML_DEV_PHY_READ_CL45_FUNC_T    phy_cl45_read_callback;

-    AML_DEV_PHY_WRITE_CL45_FUNC_T   phy_cl45_write_callback;

-}AML_DEV_ACCESS_T;

-

-/* EXPORTED SUBPROGRAM SPECIFICATIONS

- */

-extern AML_DEV_ACCESS_T _ext_dev_access;

-

-/* FUNCTION NAME:   aml_readReg

- * PURPOSE:

- *      To read data from the register of the specified chip unit.

- * INPUT:

- *      unit        -- the device unit

- *      addr_offset -- the address of register

- * OUTPUT:

- *      ptr_data    -- pointer for the register data

- * RETURN:

- *      NPS_E_OK     -- Successfully read the data.

- *      NPS_E_OTHERS -- Failed to read the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_readReg(

-    const UI32_T    unit,

-    const UI32_T    addr_offset,

-    UI32_T          *ptr_data);

-

-/* FUNCTION NAME:   aml_writeReg

- * PURPOSE:

- *      To write data to the register of the specified chip unit.

- * INPUT:

- *      unit        -- the device unit

- *      addr_offset -- the address of register

- *      data        -- written data

- * OUTPUT:

- *      none

- * RETURN:

- *      NPS_E_OK     -- Successfully write the data.

- *      NPS_E_OTHERS -- Failed to write the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_writeReg(

-    const UI32_T    unit,

-    const UI32_T    addr_offset,

-    const UI32_T    data);

-

-/* FUNCTION NAME:   aml_readPhyReg

- * PURPOSE:

- *      To read data from the phy register of the specified chip unit in Clause22.

- * INPUT:

- *      unit        -- the device unit

- *      port_id     -- physical port number

- *      addr_offset -- the address of phy register

- * OUTPUT:

- *      ptr_data    -- pointer for the register data

- * RETURN:

- *      NPS_E_OK     -- Successfully read the data.

- *      NPS_E_OTHERS -- Failed to read the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_readPhyReg(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    addr_offset,

-    UI32_T          *ptr_data);

-

-/* FUNCTION NAME:   aml_writePhyReg

- * PURPOSE:

- *      To write data to the phy register of the specified chip unit in Clause22.

- * INPUT:

- *      unit        -- the device unit

- *      port_id     -- physical port number

- *      addr_offset -- the address of phy register

- *      data        -- written data

- * OUTPUT:

- *      none

- * RETURN:

- *      NPS_E_OK     -- Successfully write the data.

- *      NPS_E_OTHERS -- Failed to write the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_writePhyReg(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    addr_offset,

-    const UI32_T    ptr_data);

-

-/* FUNCTION NAME:   aml_readPhyRegCL45

- * PURPOSE:

- *      To read data from the phy register of the specified chip unit in Clause45.

- * INPUT:

- *      unit        -- the device unit

- *      port_id     -- physical port number

- *      dev_type    -- phy register type

- *      addr_offset -- the address of phy register

- * OUTPUT:

- *      ptr_data    -- pointer for the register data

- * RETURN:

- *      NPS_E_OK     -- Successfully read the data.

- *      NPS_E_OTHERS -- Failed to read the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_readPhyRegCL45(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    dev_type,

-    const UI32_T    addr_offset,

-    UI32_T          *ptr_data);

-

-/* FUNCTION NAME:   aml_writePhyRegCL45

- * PURPOSE:

- *      To write data to the phy register of the specified chip unit in Clause45.

- * INPUT:

- *      unit        -- the device unit

- *      port_id     -- physical port number

- *      dev_type    -- phy register offset

- *      addr_offset -- the address of phy register

- *      data        -- written data

- * OUTPUT:

- *      none

- * RETURN:

- *      NPS_E_OK     -- Successfully write the data.

- *      NPS_E_OTHERS -- Failed to write the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_writePhyRegCL45(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    dev_type,

-    const UI32_T    addr_offset,

-    const UI32_T    data);

-

-#endif  /* AIR_AML_H */

-

+/* FILE NAME:   air_aml.h
+ * PURPOSE:
+ *      Define the access management layer function in AIR SDK.
+ * NOTES:
+ */
+
+#ifndef AIR_AML_H
+#define AIR_AML_H
+
+/* INCLUDE FILE DECLARATIONS
+ */
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+
+/* DATA TYPE DECLARATIONS
+ */
+typedef AIR_ERROR_NO_T
+(*AML_DEV_READ_FUNC_T)(
+    const UI32_T    unit,
+    const UI32_T    addr_offset,
+    UI32_T          *ptr_data);
+
+typedef AIR_ERROR_NO_T
+(*AML_DEV_WRITE_FUNC_T)(
+    const UI32_T    unit,
+    const UI32_T    addr_offset,
+    const UI32_T    data);
+
+typedef AIR_ERROR_NO_T
+(*AML_DEV_PHY_READ_FUNC_T)(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    addr_offset,
+    UI32_T          *ptr_data);
+
+typedef AIR_ERROR_NO_T
+(*AML_DEV_PHY_WRITE_FUNC_T)(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    addr_offset,
+    const UI32_T    data);
+
+typedef AIR_ERROR_NO_T
+(*AML_DEV_PHY_READ_CL45_FUNC_T)(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    dev_type,
+    const UI32_T    addr_offset,
+    UI32_T          *ptr_data);
+
+typedef AIR_ERROR_NO_T
+(*AML_DEV_PHY_WRITE_CL45_FUNC_T)(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    dev_type,
+    const UI32_T    addr_offset,
+    const UI32_T    data);
+
+/* To read or write the HW-intf registers. */
+typedef struct
+{
+    AML_DEV_READ_FUNC_T             read_callback;
+    AML_DEV_WRITE_FUNC_T            write_callback;
+    AML_DEV_PHY_READ_FUNC_T         phy_read_callback;
+    AML_DEV_PHY_WRITE_FUNC_T        phy_write_callback;
+    AML_DEV_PHY_READ_CL45_FUNC_T    phy_cl45_read_callback;
+    AML_DEV_PHY_WRITE_CL45_FUNC_T   phy_cl45_write_callback;
+}AML_DEV_ACCESS_T;
+
+/* EXPORTED SUBPROGRAM SPECIFICATIONS
+ */
+extern AML_DEV_ACCESS_T _ext_dev_access;
+
+/* FUNCTION NAME:   aml_readReg
+ * PURPOSE:
+ *      To read data from the register of the specified chip unit.
+ * INPUT:
+ *      unit        -- the device unit
+ *      addr_offset -- the address of register
+ * OUTPUT:
+ *      ptr_data    -- pointer for the register data
+ * RETURN:
+ *      NPS_E_OK     -- Successfully read the data.
+ *      NPS_E_OTHERS -- Failed to read the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_readReg(
+    const UI32_T    unit,
+    const UI32_T    addr_offset,
+    UI32_T          *ptr_data);
+
+/* FUNCTION NAME:   aml_writeReg
+ * PURPOSE:
+ *      To write data to the register of the specified chip unit.
+ * INPUT:
+ *      unit        -- the device unit
+ *      addr_offset -- the address of register
+ *      data        -- written data
+ * OUTPUT:
+ *      none
+ * RETURN:
+ *      NPS_E_OK     -- Successfully write the data.
+ *      NPS_E_OTHERS -- Failed to write the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_writeReg(
+    const UI32_T    unit,
+    const UI32_T    addr_offset,
+    const UI32_T    data);
+
+/* FUNCTION NAME:   aml_readPhyReg
+ * PURPOSE:
+ *      To read data from the phy register of the specified chip unit in Clause22.
+ * INPUT:
+ *      unit        -- the device unit
+ *      port_id     -- physical port number
+ *      addr_offset -- the address of phy register
+ * OUTPUT:
+ *      ptr_data    -- pointer for the register data
+ * RETURN:
+ *      NPS_E_OK     -- Successfully read the data.
+ *      NPS_E_OTHERS -- Failed to read the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_readPhyReg(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    addr_offset,
+    UI32_T          *ptr_data);
+
+/* FUNCTION NAME:   aml_writePhyReg
+ * PURPOSE:
+ *      To write data to the phy register of the specified chip unit in Clause22.
+ * INPUT:
+ *      unit        -- the device unit
+ *      port_id     -- physical port number
+ *      addr_offset -- the address of phy register
+ *      data        -- written data
+ * OUTPUT:
+ *      none
+ * RETURN:
+ *      NPS_E_OK     -- Successfully write the data.
+ *      NPS_E_OTHERS -- Failed to write the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_writePhyReg(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    addr_offset,
+    const UI32_T    ptr_data);
+
+/* FUNCTION NAME:   aml_readPhyRegCL45
+ * PURPOSE:
+ *      To read data from the phy register of the specified chip unit in Clause45.
+ * INPUT:
+ *      unit        -- the device unit
+ *      port_id     -- physical port number
+ *      dev_type    -- phy register type
+ *      addr_offset -- the address of phy register
+ * OUTPUT:
+ *      ptr_data    -- pointer for the register data
+ * RETURN:
+ *      NPS_E_OK     -- Successfully read the data.
+ *      NPS_E_OTHERS -- Failed to read the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_readPhyRegCL45(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    dev_type,
+    const UI32_T    addr_offset,
+    UI32_T          *ptr_data);
+
+/* FUNCTION NAME:   aml_writePhyRegCL45
+ * PURPOSE:
+ *      To write data to the phy register of the specified chip unit in Clause45.
+ * INPUT:
+ *      unit        -- the device unit
+ *      port_id     -- physical port number
+ *      dev_type    -- phy register offset
+ *      addr_offset -- the address of phy register
+ *      data        -- written data
+ * OUTPUT:
+ *      none
+ * RETURN:
+ *      NPS_E_OK     -- Successfully write the data.
+ *      NPS_E_OTHERS -- Failed to write the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_writePhyRegCL45(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    dev_type,
+    const UI32_T    addr_offset,
+    const UI32_T    data);
+
+#endif  /* AIR_AML_H */
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_cmd.h b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_cmd.h
index 071d063..766a9a3 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_cmd.h
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_cmd.h
@@ -1,50 +1,50 @@
-/* FILE NAME:   air_cmd.h

- * PURPOSE:

- *      Define the command line function in AIR SDK.

- * NOTES:

- */

-

-#ifndef AIR_CMD_H

-#define AIR_CMD_H

-

-/* INCLUDE FILE DECLARATIONS

- */

-

-/* NAMING CONSTANT DECLARATIONS

- */

-

-/* MACRO FUNCTION DECLARATIONS

- */

-

-/* DATA TYPE DECLARATIONS

- */

-

-/* EXPORTED SUBPROGRAM SPECIFICATIONS

- */

-/* FUNCTION NAME:   air_parse_cmd

- * PURPOSE:

- *      This function is used process diagnostic cmd

- * INPUT:

- *      argc         -- parameter number

- *      argv         -- parameter strings

- * OUTPUT:

- *      None

- * RETURN:

- *      NPS_E_OK     -- Successfully read the data.

- *      NPS_E_OTHERS -- Failed to read the data.

- * NOTES:

- *

- */

-AIR_ERROR_NO_T

-air_parse_cmd(

-    const UI32_T argc,

-    const C8_T **argv);

-

-UI32_T

-_strtoul(

-    const C8_T *cp,

-    C8_T **endp,

-    UI32_T base);

-

-#endif  /* AIR_CMD_H */

-

+/* FILE NAME:   air_cmd.h
+ * PURPOSE:
+ *      Define the command line function in AIR SDK.
+ * NOTES:
+ */
+
+#ifndef AIR_CMD_H
+#define AIR_CMD_H
+
+/* INCLUDE FILE DECLARATIONS
+ */
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+
+/* DATA TYPE DECLARATIONS
+ */
+
+/* EXPORTED SUBPROGRAM SPECIFICATIONS
+ */
+/* FUNCTION NAME:   air_parse_cmd
+ * PURPOSE:
+ *      This function is used process diagnostic cmd
+ * INPUT:
+ *      argc         -- parameter number
+ *      argv         -- parameter strings
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      NPS_E_OK     -- Successfully read the data.
+ *      NPS_E_OTHERS -- Failed to read the data.
+ * NOTES:
+ *
+ */
+AIR_ERROR_NO_T
+air_parse_cmd(
+    const UI32_T argc,
+    const C8_T **argv);
+
+UI32_T
+_strtoul(
+    const C8_T *cp,
+    C8_T **endp,
+    UI32_T base);
+
+#endif  /* AIR_CMD_H */
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_error.h b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_error.h
index 836d400..a8852ca 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_error.h
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_error.h
@@ -1,56 +1,56 @@
-/* FILE NAME:   air_error.h

- * PURPOSE:

- *      Define the error code in AIR SDK.

- * NOTES:

- */

-

-#ifndef AIR_ERROR_H

-#define AIR_ERROR_H

-

-/* INCLUDE FILE DECLARATIONS

- */

-

-/* NAMING CONSTANT DECLARATIONS

- */

-

-/* MACRO FUNCTION DECLARATIONS

- */

-

-/* DATA TYPE DECLARATIONS

- */

-typedef enum

-{

-    AIR_E_OK = 0,              /* Ok and no error */

-    AIR_E_OTHERS,              /* Operation is unsuccessful */

-    AIR_E_BAD_PARAMETER,       /* Parameter is wrong */

-    AIR_E_TABLE_FULL,          /* Table is full */

-    AIR_E_ENTRY_NOT_FOUND,     /* Entry is not found */

-    AIR_E_ENTRY_EXISTS,        /* Entry already exists */

-    AIR_E_NOT_SUPPORT,         /* Feature is not supported */

-    AIR_E_TIMEOUT,             /* Time out error */

-    AIR_E_LAST

-} AIR_ERROR_NO_T;

-

-/* EXPORTED SUBPROGRAM SPECIFICATIONS

- */

-/* FUNCTION NAME:   air_error_getString

- * PURPOSE:

- *      To obtain the error string of the specified error code

- *

- * INPUT:

- *      cause  -- The specified error code

- * OUTPUT:

- *      None

- * RETURN:

- *      Pointer to the target error string

- *

- * NOTES:

- *

- *

- */

-C8_T *

-air_error_getString(

-    const AIR_ERROR_NO_T cause );

-

-#endif  /* AIR_ERROR_H */

-

+/* FILE NAME:   air_error.h
+ * PURPOSE:
+ *      Define the error code in AIR SDK.
+ * NOTES:
+ */
+
+#ifndef AIR_ERROR_H
+#define AIR_ERROR_H
+
+/* INCLUDE FILE DECLARATIONS
+ */
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+
+/* DATA TYPE DECLARATIONS
+ */
+typedef enum
+{
+    AIR_E_OK = 0,              /* Ok and no error */
+    AIR_E_OTHERS,              /* Operation is unsuccessful */
+    AIR_E_BAD_PARAMETER,       /* Parameter is wrong */
+    AIR_E_TABLE_FULL,          /* Table is full */
+    AIR_E_ENTRY_NOT_FOUND,     /* Entry is not found */
+    AIR_E_ENTRY_EXISTS,        /* Entry already exists */
+    AIR_E_NOT_SUPPORT,         /* Feature is not supported */
+    AIR_E_TIMEOUT,             /* Time out error */
+    AIR_E_LAST
+} AIR_ERROR_NO_T;
+
+/* EXPORTED SUBPROGRAM SPECIFICATIONS
+ */
+/* FUNCTION NAME:   air_error_getString
+ * PURPOSE:
+ *      To obtain the error string of the specified error code
+ *
+ * INPUT:
+ *      cause  -- The specified error code
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      Pointer to the target error string
+ *
+ * NOTES:
+ *
+ *
+ */
+C8_T *
+air_error_getString(
+    const AIR_ERROR_NO_T cause );
+
+#endif  /* AIR_ERROR_H */
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_port.h b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_port.h
index a8745eb..3a39d9b 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_port.h
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_port.h
@@ -1,963 +1,963 @@
-/* FILE NAME:   air_port.h

- * PURPOSE:

- *      Define port function in AIR SDK.

- *

- * NOTES:

- *      None

- */

-

-#ifndef AIR_PORT_H

-#define AIR_PORT_H

-

-/* INCLUDE FILE DECLARATIONS

- */

-

-/* NAMING CONSTANT DECLARATIONS

- */

-#define AIR_MAX_NUM_OF_UNIT            (1)

-#define AIR_DST_DEFAULT_PORT           (31)

-#define AIR_PORT_TX                    (0x00)

-#define AIR_PORT_RX                    (0x01)

-#define AIR_MAX_NUM_OF_PORTS           (7)

-#define AIR_MAX_NUM_OF_GIGA_PORTS      (5)

-#define AIR_SGMII_PORT_OFFSET_BEGIN    (5)

-#define AIR_SGMII_PORT_OFFSET_END      (6)

-#define AIR_ALL_PORT_BITMAP            (0x7F)

-

-/* Definition of Power Saving mode */

-#define AIR_PORT_PS_LINKSTATUS         (0x1 << 0)

-#define AIR_PORT_PS_EEE                (0x1 << 1)

-#define AIR_PORT_PS_MASK               (0x3)

-

-/* MACRO FUNCTION DECLARATIONS

- */

-

-/* DATA TYPE DECLARATIONS

- */

-/* AIR_PORT_BITMAP_T is the data type for physical port bitmap. */

-#define AIR_BITMAP_SIZE(bit_num)                    ((((bit_num) - 1) / AIR_MAX_NUM_OF_PORTS) + 1)

-#define AIR_PORT_BITMAP_SIZE           AIR_BITMAP_SIZE(AIR_MAX_NUM_OF_PORTS)

-typedef UI32_T   AIR_PORT_BITMAP_T[AIR_PORT_BITMAP_SIZE];

-

-#define AIR_INVALID_ID      (0xFFFFFFFF)

-#define AIR_PORT_INVALID    (AIR_INVALID_ID)

-

-/* Definition of SGMII mode */

-typedef enum

-{

-    AIR_PORT_SGMII_MODE_AN,

-    AIR_PORT_SGMII_MODE_FORCE,

-    AIR_PORT_SGMII_MODE_LAST

-}AIR_PORT_SGMII_MODE_T;

-

-/* Definition of port speed */

-typedef enum

-{

-    AIR_PORT_SPEED_10M,

-    AIR_PORT_SPEED_100M,

-    AIR_PORT_SPEED_1000M,

-    AIR_PORT_SPEED_2500M,

-    AIR_PORT_SPEED_LAST

-}AIR_PORT_SPEED_T;

-

-typedef enum

-{

-    AIR_PORT_DUPLEX_HALF,

-    AIR_PORT_DUPLEX_FULL,

-    AIR_PORT_DUPLEX_LAST

-}AIR_PORT_DUPLEX_T;

-

-typedef enum

-{

-    AIR_PORT_LINK_DOWN,

-    AIR_PORT_LINK_UP,

-    AIR_PORT_LINK_LAST

-}AIR_PORT_LINK_T;

-

-/* Definition of Smart speed down will occur after AN failed how many times */

-typedef enum

-{

-    AIR_PORT_SSD_2T,

-    AIR_PORT_SSD_3T,

-    AIR_PORT_SSD_4T,

-    AIR_PORT_SSD_5T,

-    AIR_PORT_SSD_LAST

-}AIR_PORT_SSD_T;

-

-typedef enum

-{

-    AIR_PORT_VLAN_MODE_PORT_MATRIX = 0,    /* Port matrix mode  */

-    AIR_PORT_VLAN_MODE_FALLBACK,           /* Fallback mode  */

-    AIR_PORT_VLAN_MODE_CHECK,              /* Check mode  */

-    AIR_PORT_VLAN_MODE_SECURITY,           /* Security mode  */

-    AIR_PORT_VLAN_MODE_LAST

-} AIR_PORT_VLAN_MODE_T;

-

-/* Definition of AN Advertisement Register */

-typedef struct AIR_AN_ADV_S

-{

-    BOOL_T advCap10HDX;         /* Advertises 10 BASE-T HDX */

-    BOOL_T advCap10FDX;         /* Advertises 10 BASE-T FDX */

-    BOOL_T advCap100HDX;        /* Advertises 100 BASE-T HDX */

-    BOOL_T advCap100FDX;        /* Advertises 100 BASE-T FDX */

-    BOOL_T advCap1000FDX;       /* Advertises 1000 BASE-T FDX */

-    BOOL_T advPause;            /* Advertieses Asynchronous Pause */

-}AIR_AN_ADV_T;

-

-/* Definition of Link Status of a specific port */

-typedef struct AIR_PORT_STATUS_S

-{

-    BOOL_T link;

-    BOOL_T duplex;

-    UI32_T speed;

-}AIR_PORT_STATUS_T;

-

-/* EXPORTED SUBPROGRAM SPECIFICATIONS

- */

-/* FUNCTION NAME: air_port_setPortMatrix

- * PURPOSE:

- *      Set port matrix from the specified device.

- *

- * INPUT:

- *      unit            --  Unit id

- *      port            --  Port id

- *      port_bitmap     --  Matrix port bitmap

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_OTHERS

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_port_setPortMatrix(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const UI32_T    port_bitmap);

-

-/* FUNCTION NAME: air_port_getPortMatrix

- * PURPOSE:

- *      Get port matrix from the specified device.

- *

- * INPUT:

- *      unit            --  Unit id

- *      port            --  Port id

- *

- * OUTPUT:

- *      p_port_bitmap   --  Matrix port bitmap

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_OTHERS

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_port_getPortMatrix(

-    const UI32_T    unit,

-    const UI32_T    port,

-    UI32_T          *p_port_bitmap);

-

-/* FUNCTION NAME: air_port_setVlanMode

- * PURPOSE:

- *      Set port-based vlan mechanism from the specified device.

- *

- * INPUT:

- *      unit            --  Unit id

- *      port            --  Port id

- *      mode            --  Port vlan mode

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_OTHERS

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_port_setVlanMode(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const AIR_PORT_VLAN_MODE_T mode);

-

-/* FUNCTION NAME: air_port_getVlanMode

- * PURPOSE:

- *      Get port-based vlan mechanism from the specified device.

- *

- * INPUT:

- *      unit            --  Unit id

- *      port            --  Port id

- *

- * OUTPUT:

- *      p_mode          --  Port vlan mode

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_OTHERS

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_port_getVlanMode(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_PORT_VLAN_MODE_T *p_mode);

-

-/* FUNCTION NAME: air_port_setAnMode

- * PURPOSE:

- *      Set the auto-negotiation mode for a specific port.(Auto or Forced)

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *      state           --  FALSE:Disable

- *                          TRUE: Enable

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setAnMode(

-    const UI32_T unit,

-    const UI32_T port,

-    const BOOL_T state);

-

-/* FUNCTION NAME: air_port_getAnMode

- * PURPOSE:

- *      Get the auto-negotiation mode for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *

- * OUTPUT:

- *      state           --  FALSE:Disable

- *                          TRUE: Enable

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getAnMode(

-    const UI32_T unit,

-    const UI32_T port,

-    BOOL_T *ptr_state);

-

-/* FUNCTION NAME: air_port_setLocalAdvAbility

- * PURPOSE:

- *      Set the auto-negotiation advertisement for a

- *      specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *      adv             --  AN advertisement setting

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setLocalAdvAbility(

-    const UI32_T unit,

-    const UI32_T port,

-    const AIR_AN_ADV_T adv);

-

-/* FUNCTION NAME: air_port_getLocalAdvAbility

- * PURPOSE:

- *      Get the auto-negotiation advertisement for a

- *      specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *

- * OUTPUT:

- *      ptr_adv         --  AN advertisement setting

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getLocalAdvAbility(

-    const UI32_T unit,

-    const UI32_T port,

-    AIR_AN_ADV_T *ptr_adv);

-

-/* FUNCTION NAME: air_port_getRemoteAdvAbility

- * PURPOSE:

- *      Get the auto-negotiation remote advertisement for a

- *      specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *

- * OUTPUT:

- *      ptr_lp_adv      --  AN advertisement of link partner

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getRemoteAdvAbility(

-    const UI32_T unit,

-    const UI32_T port,

-    AIR_AN_ADV_T *ptr_lp_adv);

-

-/* FUNCTION NAME: air_port_setSpeed

- * PURPOSE:

- *      Set the speed for a specific port.

- *      This setting is used on force mode only.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *      speed           --  AIR_PORT_SPEED_10M:  10Mbps

- *                          AIR_PORT_SPEED_100M: 100Mbps

- *                          AIR_PORT_SPEED_1000M:1Gbps

- *                          AIR_PORT_SPEED_2500M:2.5Gbps (Port5, Port6)

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setSpeed(

-    const UI32_T unit,

-    const UI32_T port,

-    const UI32_T speed);

-

-/* FUNCTION NAME: air_port_getSpeed

- * PURPOSE:

- *      Get the speed for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *

- * OUTPUT:

- *      ptr_speed       --  AIR_PORT_SPEED_10M:  10Mbps

- *                          AIR_PORT_SPEED_100M: 100Mbps

- *                          AIR_PORT_SPEED_1000M:1Gbps

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getSpeed(

-    const UI32_T unit,

-    const UI32_T port,

-    UI32_T *ptr_speed);

-

-/* FUNCTION NAME: air_port_setDuplex

- * PURPOSE:

- *      Get the duplex for a specific port.

- *      This setting is used on force mode only.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *      duplex          --  AIR_PORT_DUPLEX_HALF

- *                          AIR_PORT_DUPLEX_FULL

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setDuplex(

-    const UI32_T unit,

-    const UI32_T port,

-    const BOOL_T duplex);

-

-/* FUNCTION NAME: air_port_getDuplex

- * PURPOSE:

- *      Get the duplex for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *

- * OUTPUT:

- *      ptr_duplex      --  AIR_PORT_DUPLEX_HALF

- *                          AIR_PORT_DUPLEX_FULL

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getDuplex(

-    const UI32_T unit,

-    const UI32_T port,

-    BOOL_T *ptr_duplex);

-

-/* FUNCTION NAME: air_port_getLink

- * PURPOSE:

- *      Get the physical link status for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *

- * OUTPUT:

- *      ptr_ps          --  AIR_PORT_STATUS_T

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getLink(

-    const UI32_T unit,

-    const UI32_T port,

-    AIR_PORT_STATUS_T *ptr_ps);

-

-/* FUNCTION NAME: air_port_setBckPres

- * PURPOSE:

- *      Set the back pressure configuration for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *      bckPres         --  FALSE:Disable

- *                          TRUE: Enable

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setBckPres(

-    const UI32_T unit,

-    const UI32_T port,

-    const BOOL_T bckPres);

-

-/* FUNCTION NAME: air_port_getBckPres

- * PURPOSE:

- *      Get the back pressure configuration for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *

- * OUTPUT:

- *      ptr_bckPres     --  FALSE:Disable

- *                          TRUE: Enable

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getBckPres(

-    const UI32_T unit,

-    const UI32_T port,

-    BOOL_T *ptr_bckPres);

-

-/* FUNCTION NAME: air_port_setFlowCtrl

- * PURPOSE:

- *      Set the flow control configuration for specific port.

- *

- * INPUT:

- *      unit            --  Select device ID

- *      port            --  Select port number (0 - 6)

- *      dir             --  Directions of AIR_PORT_TX or AIR_PORT_RX

- *      fc_en           --  TRUE: Enable select port flow control

- *                          FALSE:Disable select port flow control

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setFlowCtrl(

-    const UI32_T unit,

-    const UI32_T port,

-    const BOOL_T dir,

-    const BOOL_T fc_en);

-

-/* FUNCTION NAME: air_port_getFlowCtrl

- * PURPOSE:

- *      Get the flow control configuration for specific port.

- *

- * INPUT:

- *      unit            --  Select device ID

- *      port            --  Select port number (0..6)

- *      dir             --  AIR_PORT_TX

- *                          AIR_PORT_RX

- * OUTPUT:

- *      ptr_fc_en       --  FALSE: Port flow control disable

- *                          TRUE: Port flow control enable

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getFlowCtrl(

-    const UI32_T unit,

-    const UI32_T port,

-    const BOOL_T dir,

-    BOOL_T *ptr_fc_en);

-

-/* FUNCTION NAME: air_port_setJumbo

- * PURPOSE:

- *      Set accepting jumbo frmes with specificied size.

- *

- * INPUT:

- *      unit            --  Select device ID

- *      pkt_len         --  Select max packet length

- *                          RX_PKT_LEN_1518

- *                          RX_PKT_LEN_1536

- *                          RX_PKT_LEN_1552

- *                          RX_PKT_LEN_MAX_JUMBO

- *      frame_len       --  Select max lenght of jumbo frames

- *                          Range : 2 - 15

- *                          Units : K Bytes

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setJumbo(

-    const UI32_T unit,

-    const UI32_T pkt_len,

-    const UI32_T frame_len);

-

-/* FUNCTION NAME: air_port_getJumbo

- * PURPOSE:

- *      Get accepting jumbo frmes with specificied size.

- *

- * INPUT:

- *      unit            --  Select device ID

- *

- * OUTPUT:

- *      ptr_pkt_len     --  Select max packet length

- *                          RX_PKT_LEN_1518

- *                          RX_PKT_LEN_1536

- *                          RX_PKT_LEN_1552

- *                          RX_PKT_LEN_MAX_JUMBO

- *      ptr_frame_len   --  Select max lenght of jumbo frames

- *                          Range : 2 - 15

- *                          Units : K Bytes

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getJumbo(

-    const UI32_T unit,

-    UI32_T *ptr_pkt_len,

-    UI32_T *ptr_frame_len);

-

-

-/* FUNCTION NAME: air_port_setPsMode

- * PURPOSE:

- *      Set the power saving mode for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *      mode            --  Bit-map:

- *                          AIR_PORT_PS_LINKSTATUS

- *                          AIR_PORT_PS_EEE

- *                          FALSE: Disable / TRUE: Enable

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setPsMode(

-    const UI32_T unit,

-    const UI32_T port,

-    const UI32_T mode);

-

-/* FUNCTION NAME: air_port_getPsMode

- * PURPOSE:

- *      Get the power saving mode for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- * OUTPUT:

- *      ptr_mode        --  Bit-map:

- *                          AIR_PORT_PS_LINKSTATUS

- *                          AIR_PORT_PS_EEE

- *                          FALSE: Disable / TRUE: Enable

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getPsMode(

-    const UI32_T unit,

-    const UI32_T port,

-    UI32_T *ptr_mode);

-

-/* FUNCTION NAME: air_port_setSmtSpdDwn

- * PURPOSE:

- *      Set Smart speed down feature for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *      state           --  FALSE:Disable

- *                          TRUE: Enable

- *      time            --  AIR_PORT_SSD_2T

- *                          AIR_PORT_SSD_3T

- *                          AIR_PORT_SSD_4T

- *                          AIR_PORT_SSD_5T

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setSmtSpdDwn(

-    const UI32_T unit,

-    const UI32_T port,

-    const BOOL_T state,

-    const UI32_T time);

-

-/* FUNCTION NAME: air_port_getSmtSpdDwn

- * PURPOSE:

- *      Get Smart speed down feature for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *

- * OUTPUT:

- *      ptr_state       --  FALSE:Disable

- *                          TRUE: Enable

- *      ptr_time        --  AIR_PORT_SSD_2T

- *                          AIR_PORT_SSD_3T

- *                          AIR_PORT_SSD_4T

- *                          AIR_PORT_SSD_5T

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getSmtSpdDwn(

-    const UI32_T unit,

-    const UI32_T port,

-    UI32_T *ptr_state,

-    UI32_T *ptr_time);

-

-/* FUNCTION NAME: air_port_setEnable

- * PURPOSE:

- *      Set powerdown state for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *      state           --  FALSE:Disable

- *                          TRUE: Enable

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setEnable(

-    const UI32_T unit,

-    const UI32_T port,

-    const BOOL_T state);

-

-/* FUNCTION NAME: air_port_getEnable

- * PURPOSE:

- *      Get powerdown state for a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *

- * OUTPUT:

- *      ptr_state       --  FALSE:Disable

- *                          TRUE: Enable

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getEnable(

-    const UI32_T unit,

-    const UI32_T port,

-    UI32_T *ptr_state);

-

-/* FUNCTION NAME: air_port_setSpTag

- * PURPOSE:

- *      Set special tag state of a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- *      sptag_en        --  TRUE:  Enable special tag

- *                          FALSE: Disable special tag

- * OUTPUT:

- *        None

- *

- * RETURN:

- *        AIR_E_OK

- *        AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setSpTag(

-    const UI32_T unit,

-    const UI32_T port,

-    const BOOL_T sptag_en);

-

-/* FUNCTION NAME: air_port_getSpTag

- * PURPOSE:

- *      Get special tag state of a specific port.

- *

- * INPUT:

- *      unit            --  Device ID

- *      port            --  Index of port number

- * OUTPUT:

- *      ptr_sptag_en    --  TRUE:  Special tag enable

- *                          FALSE: Special tag disable

- *

- * RETURN:

- *        AIR_E_OK

- *        AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_getSpTag(

-    const UI32_T unit,

-    const UI32_T port,

-    BOOL_T *ptr_sptag_en);

-

-/* FUNCTION NAME: air_port_set5GBaseRModeEnable

- * PURPOSE:

- *      Set the port5 5GBase-R mode enable

- *

- * INPUT:

- *      unit            --  Device ID

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_set5GBaseRModeEn(

-    const UI32_T unit);

-

-/* FUNCTION NAME: air_port_setHsgmiiModeEnable

- * PURPOSE:

- *      Set the port5 HSGMII mode enable

- *

- * INPUT:

- *      unit            --  Device ID

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setHsgmiiModeEn(

-    const UI32_T unit);

-

-/* FUNCTION NAME: air_port_setSgmiiMode

- * PURPOSE:

- *      Set the port5 SGMII mode for AN or force

- *

- * INPUT:

- *      unit            --  Device ID

- *      mode            --  AIR_PORT_SGMII_MODE_AN

- *                          AIR_PORT_SGMII_MODE_FORCE

- *      speed           --  AIR_PORT_SPEED_10M:   10Mbps

- *                          AIR_PORT_SPEED_100M:  100Mbps

- *                          AIR_PORT_SPEED_1000M: 1Gbps

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setSgmiiMode(

-    const UI32_T unit,

-    const UI32_T mode,

-    const UI32_T speed);

-

-

-/* FUNCTION NAME: air_port_setRmiiMode

- * PURPOSE:

- *      Set the port5 RMII mode for 100Mbps or 10Mbps

- *

- * INPUT:

- *      unit            --  Device ID

- *      speed           --  AIR_PORT_SPEED_10M:  10Mbps

- *                          AIR_PORT_SPEED_100M: 100Mbps

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setRmiiMode(

-    const UI32_T unit,

-    const UI32_T speed);

-

-/* FUNCTION NAME: air_port_setRgmiiMode

- * PURPOSE:

- *      Set the port5 RGMII mode for 1Gbps or 100Mbps or 10Mbps

- *

- * INPUT:

- *      unit            --  Device ID

- *      speed           --  AIR_PORT_SPEED_10M:   10Mbps

- *                          AIR_PORT_SPEED_100M:  100Mbps

- *                          AIR_PORT_SPEED_1000M: 1Gbps

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_BAD_PARAMETER

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_port_setRgmiiMode(

-    const UI32_T unit,

-    const UI32_T speed);

-

-#endif  /* AIR_PORT_H */

-

+/* FILE NAME:   air_port.h
+ * PURPOSE:
+ *      Define port function in AIR SDK.
+ *
+ * NOTES:
+ *      None
+ */
+
+#ifndef AIR_PORT_H
+#define AIR_PORT_H
+
+/* INCLUDE FILE DECLARATIONS
+ */
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+#define AIR_MAX_NUM_OF_UNIT            (1)
+#define AIR_DST_DEFAULT_PORT           (31)
+#define AIR_PORT_TX                    (0x00)
+#define AIR_PORT_RX                    (0x01)
+#define AIR_MAX_NUM_OF_PORTS           (7)
+#define AIR_MAX_NUM_OF_GIGA_PORTS      (5)
+#define AIR_SGMII_PORT_OFFSET_BEGIN    (5)
+#define AIR_SGMII_PORT_OFFSET_END      (6)
+#define AIR_ALL_PORT_BITMAP            (0x7F)
+
+/* Definition of Power Saving mode */
+#define AIR_PORT_PS_LINKSTATUS         (0x1 << 0)
+#define AIR_PORT_PS_EEE                (0x1 << 1)
+#define AIR_PORT_PS_MASK               (0x3)
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+
+/* DATA TYPE DECLARATIONS
+ */
+/* AIR_PORT_BITMAP_T is the data type for physical port bitmap. */
+#define AIR_BITMAP_SIZE(bit_num)                    ((((bit_num) - 1) / AIR_MAX_NUM_OF_PORTS) + 1)
+#define AIR_PORT_BITMAP_SIZE           AIR_BITMAP_SIZE(AIR_MAX_NUM_OF_PORTS)
+typedef UI32_T   AIR_PORT_BITMAP_T[AIR_PORT_BITMAP_SIZE];
+
+#define AIR_INVALID_ID      (0xFFFFFFFF)
+#define AIR_PORT_INVALID    (AIR_INVALID_ID)
+
+/* Definition of SGMII mode */
+typedef enum
+{
+    AIR_PORT_SGMII_MODE_AN,
+    AIR_PORT_SGMII_MODE_FORCE,
+    AIR_PORT_SGMII_MODE_LAST
+}AIR_PORT_SGMII_MODE_T;
+
+/* Definition of port speed */
+typedef enum
+{
+    AIR_PORT_SPEED_10M,
+    AIR_PORT_SPEED_100M,
+    AIR_PORT_SPEED_1000M,
+    AIR_PORT_SPEED_2500M,
+    AIR_PORT_SPEED_LAST
+}AIR_PORT_SPEED_T;
+
+typedef enum
+{
+    AIR_PORT_DUPLEX_HALF,
+    AIR_PORT_DUPLEX_FULL,
+    AIR_PORT_DUPLEX_LAST
+}AIR_PORT_DUPLEX_T;
+
+typedef enum
+{
+    AIR_PORT_LINK_DOWN,
+    AIR_PORT_LINK_UP,
+    AIR_PORT_LINK_LAST
+}AIR_PORT_LINK_T;
+
+/* Definition of Smart speed down will occur after AN failed how many times */
+typedef enum
+{
+    AIR_PORT_SSD_2T,
+    AIR_PORT_SSD_3T,
+    AIR_PORT_SSD_4T,
+    AIR_PORT_SSD_5T,
+    AIR_PORT_SSD_LAST
+}AIR_PORT_SSD_T;
+
+typedef enum
+{
+    AIR_PORT_VLAN_MODE_PORT_MATRIX = 0,    /* Port matrix mode  */
+    AIR_PORT_VLAN_MODE_FALLBACK,           /* Fallback mode  */
+    AIR_PORT_VLAN_MODE_CHECK,              /* Check mode  */
+    AIR_PORT_VLAN_MODE_SECURITY,           /* Security mode  */
+    AIR_PORT_VLAN_MODE_LAST
+} AIR_PORT_VLAN_MODE_T;
+
+/* Definition of AN Advertisement Register */
+typedef struct AIR_AN_ADV_S
+{
+    BOOL_T advCap10HDX;         /* Advertises 10 BASE-T HDX */
+    BOOL_T advCap10FDX;         /* Advertises 10 BASE-T FDX */
+    BOOL_T advCap100HDX;        /* Advertises 100 BASE-T HDX */
+    BOOL_T advCap100FDX;        /* Advertises 100 BASE-T FDX */
+    BOOL_T advCap1000FDX;       /* Advertises 1000 BASE-T FDX */
+    BOOL_T advPause;            /* Advertieses Asynchronous Pause */
+}AIR_AN_ADV_T;
+
+/* Definition of Link Status of a specific port */
+typedef struct AIR_PORT_STATUS_S
+{
+    BOOL_T link;
+    BOOL_T duplex;
+    UI32_T speed;
+}AIR_PORT_STATUS_T;
+
+/* EXPORTED SUBPROGRAM SPECIFICATIONS
+ */
+/* FUNCTION NAME: air_port_setPortMatrix
+ * PURPOSE:
+ *      Set port matrix from the specified device.
+ *
+ * INPUT:
+ *      unit            --  Unit id
+ *      port            --  Port id
+ *      port_bitmap     --  Matrix port bitmap
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_OTHERS
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_port_setPortMatrix(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const UI32_T    port_bitmap);
+
+/* FUNCTION NAME: air_port_getPortMatrix
+ * PURPOSE:
+ *      Get port matrix from the specified device.
+ *
+ * INPUT:
+ *      unit            --  Unit id
+ *      port            --  Port id
+ *
+ * OUTPUT:
+ *      p_port_bitmap   --  Matrix port bitmap
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_OTHERS
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_port_getPortMatrix(
+    const UI32_T    unit,
+    const UI32_T    port,
+    UI32_T          *p_port_bitmap);
+
+/* FUNCTION NAME: air_port_setVlanMode
+ * PURPOSE:
+ *      Set port-based vlan mechanism from the specified device.
+ *
+ * INPUT:
+ *      unit            --  Unit id
+ *      port            --  Port id
+ *      mode            --  Port vlan mode
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_OTHERS
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_port_setVlanMode(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const AIR_PORT_VLAN_MODE_T mode);
+
+/* FUNCTION NAME: air_port_getVlanMode
+ * PURPOSE:
+ *      Get port-based vlan mechanism from the specified device.
+ *
+ * INPUT:
+ *      unit            --  Unit id
+ *      port            --  Port id
+ *
+ * OUTPUT:
+ *      p_mode          --  Port vlan mode
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_OTHERS
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_port_getVlanMode(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_PORT_VLAN_MODE_T *p_mode);
+
+/* FUNCTION NAME: air_port_setAnMode
+ * PURPOSE:
+ *      Set the auto-negotiation mode for a specific port.(Auto or Forced)
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *      state           --  FALSE:Disable
+ *                          TRUE: Enable
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setAnMode(
+    const UI32_T unit,
+    const UI32_T port,
+    const BOOL_T state);
+
+/* FUNCTION NAME: air_port_getAnMode
+ * PURPOSE:
+ *      Get the auto-negotiation mode for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *
+ * OUTPUT:
+ *      state           --  FALSE:Disable
+ *                          TRUE: Enable
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getAnMode(
+    const UI32_T unit,
+    const UI32_T port,
+    BOOL_T *ptr_state);
+
+/* FUNCTION NAME: air_port_setLocalAdvAbility
+ * PURPOSE:
+ *      Set the auto-negotiation advertisement for a
+ *      specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *      adv             --  AN advertisement setting
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setLocalAdvAbility(
+    const UI32_T unit,
+    const UI32_T port,
+    const AIR_AN_ADV_T adv);
+
+/* FUNCTION NAME: air_port_getLocalAdvAbility
+ * PURPOSE:
+ *      Get the auto-negotiation advertisement for a
+ *      specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *
+ * OUTPUT:
+ *      ptr_adv         --  AN advertisement setting
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getLocalAdvAbility(
+    const UI32_T unit,
+    const UI32_T port,
+    AIR_AN_ADV_T *ptr_adv);
+
+/* FUNCTION NAME: air_port_getRemoteAdvAbility
+ * PURPOSE:
+ *      Get the auto-negotiation remote advertisement for a
+ *      specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *
+ * OUTPUT:
+ *      ptr_lp_adv      --  AN advertisement of link partner
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getRemoteAdvAbility(
+    const UI32_T unit,
+    const UI32_T port,
+    AIR_AN_ADV_T *ptr_lp_adv);
+
+/* FUNCTION NAME: air_port_setSpeed
+ * PURPOSE:
+ *      Set the speed for a specific port.
+ *      This setting is used on force mode only.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *      speed           --  AIR_PORT_SPEED_10M:  10Mbps
+ *                          AIR_PORT_SPEED_100M: 100Mbps
+ *                          AIR_PORT_SPEED_1000M:1Gbps
+ *                          AIR_PORT_SPEED_2500M:2.5Gbps (Port5, Port6)
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setSpeed(
+    const UI32_T unit,
+    const UI32_T port,
+    const UI32_T speed);
+
+/* FUNCTION NAME: air_port_getSpeed
+ * PURPOSE:
+ *      Get the speed for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *
+ * OUTPUT:
+ *      ptr_speed       --  AIR_PORT_SPEED_10M:  10Mbps
+ *                          AIR_PORT_SPEED_100M: 100Mbps
+ *                          AIR_PORT_SPEED_1000M:1Gbps
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getSpeed(
+    const UI32_T unit,
+    const UI32_T port,
+    UI32_T *ptr_speed);
+
+/* FUNCTION NAME: air_port_setDuplex
+ * PURPOSE:
+ *      Get the duplex for a specific port.
+ *      This setting is used on force mode only.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *      duplex          --  AIR_PORT_DUPLEX_HALF
+ *                          AIR_PORT_DUPLEX_FULL
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setDuplex(
+    const UI32_T unit,
+    const UI32_T port,
+    const BOOL_T duplex);
+
+/* FUNCTION NAME: air_port_getDuplex
+ * PURPOSE:
+ *      Get the duplex for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *
+ * OUTPUT:
+ *      ptr_duplex      --  AIR_PORT_DUPLEX_HALF
+ *                          AIR_PORT_DUPLEX_FULL
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getDuplex(
+    const UI32_T unit,
+    const UI32_T port,
+    BOOL_T *ptr_duplex);
+
+/* FUNCTION NAME: air_port_getLink
+ * PURPOSE:
+ *      Get the physical link status for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *
+ * OUTPUT:
+ *      ptr_ps          --  AIR_PORT_STATUS_T
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getLink(
+    const UI32_T unit,
+    const UI32_T port,
+    AIR_PORT_STATUS_T *ptr_ps);
+
+/* FUNCTION NAME: air_port_setBckPres
+ * PURPOSE:
+ *      Set the back pressure configuration for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *      bckPres         --  FALSE:Disable
+ *                          TRUE: Enable
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setBckPres(
+    const UI32_T unit,
+    const UI32_T port,
+    const BOOL_T bckPres);
+
+/* FUNCTION NAME: air_port_getBckPres
+ * PURPOSE:
+ *      Get the back pressure configuration for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *
+ * OUTPUT:
+ *      ptr_bckPres     --  FALSE:Disable
+ *                          TRUE: Enable
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getBckPres(
+    const UI32_T unit,
+    const UI32_T port,
+    BOOL_T *ptr_bckPres);
+
+/* FUNCTION NAME: air_port_setFlowCtrl
+ * PURPOSE:
+ *      Set the flow control configuration for specific port.
+ *
+ * INPUT:
+ *      unit            --  Select device ID
+ *      port            --  Select port number (0 - 6)
+ *      dir             --  Directions of AIR_PORT_TX or AIR_PORT_RX
+ *      fc_en           --  TRUE: Enable select port flow control
+ *                          FALSE:Disable select port flow control
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setFlowCtrl(
+    const UI32_T unit,
+    const UI32_T port,
+    const BOOL_T dir,
+    const BOOL_T fc_en);
+
+/* FUNCTION NAME: air_port_getFlowCtrl
+ * PURPOSE:
+ *      Get the flow control configuration for specific port.
+ *
+ * INPUT:
+ *      unit            --  Select device ID
+ *      port            --  Select port number (0..6)
+ *      dir             --  AIR_PORT_TX
+ *                          AIR_PORT_RX
+ * OUTPUT:
+ *      ptr_fc_en       --  FALSE: Port flow control disable
+ *                          TRUE: Port flow control enable
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getFlowCtrl(
+    const UI32_T unit,
+    const UI32_T port,
+    const BOOL_T dir,
+    BOOL_T *ptr_fc_en);
+
+/* FUNCTION NAME: air_port_setJumbo
+ * PURPOSE:
+ *      Set accepting jumbo frmes with specificied size.
+ *
+ * INPUT:
+ *      unit            --  Select device ID
+ *      pkt_len         --  Select max packet length
+ *                          RX_PKT_LEN_1518
+ *                          RX_PKT_LEN_1536
+ *                          RX_PKT_LEN_1552
+ *                          RX_PKT_LEN_MAX_JUMBO
+ *      frame_len       --  Select max lenght of jumbo frames
+ *                          Range : 2 - 15
+ *                          Units : K Bytes
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setJumbo(
+    const UI32_T unit,
+    const UI32_T pkt_len,
+    const UI32_T frame_len);
+
+/* FUNCTION NAME: air_port_getJumbo
+ * PURPOSE:
+ *      Get accepting jumbo frmes with specificied size.
+ *
+ * INPUT:
+ *      unit            --  Select device ID
+ *
+ * OUTPUT:
+ *      ptr_pkt_len     --  Select max packet length
+ *                          RX_PKT_LEN_1518
+ *                          RX_PKT_LEN_1536
+ *                          RX_PKT_LEN_1552
+ *                          RX_PKT_LEN_MAX_JUMBO
+ *      ptr_frame_len   --  Select max lenght of jumbo frames
+ *                          Range : 2 - 15
+ *                          Units : K Bytes
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getJumbo(
+    const UI32_T unit,
+    UI32_T *ptr_pkt_len,
+    UI32_T *ptr_frame_len);
+
+
+/* FUNCTION NAME: air_port_setPsMode
+ * PURPOSE:
+ *      Set the power saving mode for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *      mode            --  Bit-map:
+ *                          AIR_PORT_PS_LINKSTATUS
+ *                          AIR_PORT_PS_EEE
+ *                          FALSE: Disable / TRUE: Enable
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setPsMode(
+    const UI32_T unit,
+    const UI32_T port,
+    const UI32_T mode);
+
+/* FUNCTION NAME: air_port_getPsMode
+ * PURPOSE:
+ *      Get the power saving mode for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ * OUTPUT:
+ *      ptr_mode        --  Bit-map:
+ *                          AIR_PORT_PS_LINKSTATUS
+ *                          AIR_PORT_PS_EEE
+ *                          FALSE: Disable / TRUE: Enable
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getPsMode(
+    const UI32_T unit,
+    const UI32_T port,
+    UI32_T *ptr_mode);
+
+/* FUNCTION NAME: air_port_setSmtSpdDwn
+ * PURPOSE:
+ *      Set Smart speed down feature for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *      state           --  FALSE:Disable
+ *                          TRUE: Enable
+ *      time            --  AIR_PORT_SSD_2T
+ *                          AIR_PORT_SSD_3T
+ *                          AIR_PORT_SSD_4T
+ *                          AIR_PORT_SSD_5T
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setSmtSpdDwn(
+    const UI32_T unit,
+    const UI32_T port,
+    const BOOL_T state,
+    const UI32_T time);
+
+/* FUNCTION NAME: air_port_getSmtSpdDwn
+ * PURPOSE:
+ *      Get Smart speed down feature for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *
+ * OUTPUT:
+ *      ptr_state       --  FALSE:Disable
+ *                          TRUE: Enable
+ *      ptr_time        --  AIR_PORT_SSD_2T
+ *                          AIR_PORT_SSD_3T
+ *                          AIR_PORT_SSD_4T
+ *                          AIR_PORT_SSD_5T
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getSmtSpdDwn(
+    const UI32_T unit,
+    const UI32_T port,
+    UI32_T *ptr_state,
+    UI32_T *ptr_time);
+
+/* FUNCTION NAME: air_port_setEnable
+ * PURPOSE:
+ *      Set powerdown state for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *      state           --  FALSE:Disable
+ *                          TRUE: Enable
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setEnable(
+    const UI32_T unit,
+    const UI32_T port,
+    const BOOL_T state);
+
+/* FUNCTION NAME: air_port_getEnable
+ * PURPOSE:
+ *      Get powerdown state for a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *
+ * OUTPUT:
+ *      ptr_state       --  FALSE:Disable
+ *                          TRUE: Enable
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getEnable(
+    const UI32_T unit,
+    const UI32_T port,
+    UI32_T *ptr_state);
+
+/* FUNCTION NAME: air_port_setSpTag
+ * PURPOSE:
+ *      Set special tag state of a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ *      sptag_en        --  TRUE:  Enable special tag
+ *                          FALSE: Disable special tag
+ * OUTPUT:
+ *        None
+ *
+ * RETURN:
+ *        AIR_E_OK
+ *        AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setSpTag(
+    const UI32_T unit,
+    const UI32_T port,
+    const BOOL_T sptag_en);
+
+/* FUNCTION NAME: air_port_getSpTag
+ * PURPOSE:
+ *      Get special tag state of a specific port.
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      port            --  Index of port number
+ * OUTPUT:
+ *      ptr_sptag_en    --  TRUE:  Special tag enable
+ *                          FALSE: Special tag disable
+ *
+ * RETURN:
+ *        AIR_E_OK
+ *        AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_getSpTag(
+    const UI32_T unit,
+    const UI32_T port,
+    BOOL_T *ptr_sptag_en);
+
+/* FUNCTION NAME: air_port_set5GBaseRModeEnable
+ * PURPOSE:
+ *      Set the port5 5GBase-R mode enable
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_set5GBaseRModeEn(
+    const UI32_T unit);
+
+/* FUNCTION NAME: air_port_setHsgmiiModeEnable
+ * PURPOSE:
+ *      Set the port5 HSGMII mode enable
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setHsgmiiModeEn(
+    const UI32_T unit);
+
+/* FUNCTION NAME: air_port_setSgmiiMode
+ * PURPOSE:
+ *      Set the port5 SGMII mode for AN or force
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      mode            --  AIR_PORT_SGMII_MODE_AN
+ *                          AIR_PORT_SGMII_MODE_FORCE
+ *      speed           --  AIR_PORT_SPEED_10M:   10Mbps
+ *                          AIR_PORT_SPEED_100M:  100Mbps
+ *                          AIR_PORT_SPEED_1000M: 1Gbps
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setSgmiiMode(
+    const UI32_T unit,
+    const UI32_T mode,
+    const UI32_T speed);
+
+
+/* FUNCTION NAME: air_port_setRmiiMode
+ * PURPOSE:
+ *      Set the port5 RMII mode for 100Mbps or 10Mbps
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      speed           --  AIR_PORT_SPEED_10M:  10Mbps
+ *                          AIR_PORT_SPEED_100M: 100Mbps
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setRmiiMode(
+    const UI32_T unit,
+    const UI32_T speed);
+
+/* FUNCTION NAME: air_port_setRgmiiMode
+ * PURPOSE:
+ *      Set the port5 RGMII mode for 1Gbps or 100Mbps or 10Mbps
+ *
+ * INPUT:
+ *      unit            --  Device ID
+ *      speed           --  AIR_PORT_SPEED_10M:   10Mbps
+ *                          AIR_PORT_SPEED_100M:  100Mbps
+ *                          AIR_PORT_SPEED_1000M: 1Gbps
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_BAD_PARAMETER
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_port_setRgmiiMode(
+    const UI32_T unit,
+    const UI32_T speed);
+
+#endif  /* AIR_PORT_H */
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_ver.h b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_ver.h
index 0681b6c..d702769 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_ver.h
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_ver.h
@@ -1,29 +1,29 @@
-/* FILE NAME: air_ver.h

- * PURPOSE:

- *      Define the version for AIR SDK.

- *

- * NOTES:

- *      None

- */

-

-#ifndef AIR_VER_H

-#define AIR_VER_H

-

-/* INCLUDE FILE DECLARATIONS

- */

-

-/* NAMING CONSTANT DECLARATIONS

- */

-#define AIR_VER_SDK    "v1.0.1"

-

-/* MACRO FUNCTION DECLARATIONS

- */

-

-/* DATA TYPE DECLARATIONS

- */

-

-/* EXPORTED SUBPROGRAM SPECIFICATIONS

- */

-

-#endif  /* AIR_VER_H */

-

+/* FILE NAME: air_ver.h
+ * PURPOSE:
+ *      Define the version for AIR SDK.
+ *
+ * NOTES:
+ *      None
+ */
+
+#ifndef AIR_VER_H
+#define AIR_VER_H
+
+/* INCLUDE FILE DECLARATIONS
+ */
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+#define AIR_VER_SDK    "v1.0.1"
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+
+/* DATA TYPE DECLARATIONS
+ */
+
+/* EXPORTED SUBPROGRAM SPECIFICATIONS
+ */
+
+#endif  /* AIR_VER_H */
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_vlan.h b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_vlan.h
index 1ae6237..3db12e2 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_vlan.h
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/inc/air_vlan.h
@@ -1,977 +1,977 @@
-/* FILE NAME:   air_vlan.h

- * PURPOSE:

- *      Define the vlan functions in AIR SDK.

- * NOTES:

- */

-

-#ifndef AIR_VLAN_H

-#define AIR_VLAN_H

-

-/* INCLUDE FILE DECLARATIONS

- */

-

-/* NAMING CONSTANT DECLARATIONS

- */

-#define AIR_VLAN_ID_MIN                             0

-#define AIR_VLAN_ID_MAX                             4095

-#define AIR_DEFAULT_VLAN_ID                         1

-

-#define AIR_FILTER_ID_MAX                           7

-

-/* MACRO FUNCTION DECLARATIONS

- */

-

-/* DATA TYPE DECLARATIONS

- */

-typedef enum

-{

-    AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_UNTAGGED = 0,

-    AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_TAGGED = 2,

-    AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_LAST,

-} AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_T;

-

-typedef enum

-{

-    AIR_PORT_EGS_TAG_ATTR_UNTAGGED = 0,

-    AIR_PORT_EGS_TAG_ATTR_SWAP,

-    AIR_PORT_EGS_TAG_ATTR_TAGGED,

-    AIR_PORT_EGS_TAG_ATTR_STACK,

-    AIR_PORT_EGS_TAG_ATTR_LAST

-} AIR_PORT_EGS_TAG_ATTR_T;

-

-typedef enum

-{

-    AIR_VLAN_ACCEPT_FRAME_TYPE_ALL = 0,            /* untagged, priority-tagged and tagged  */

-    AIR_VLAN_ACCEPT_FRAME_TYPE_TAG_ONLY,           /* tagged                                */

-    AIR_VLAN_ACCEPT_FRAME_TYPE_UNTAG_ONLY,         /* untagged and priority-tagged          */

-    AIR_VLAN_ACCEPT_FRAME_TYPE_RESERVED,           /* reserved                              */

-    AIR_VLAN_ACCEPT_FRAME_TYPE_LAST

-} AIR_VLAN_ACCEPT_FRAME_TYPE_T;

-

-typedef enum

-{

-    AIR_LEAKY_PKT_TYPE_UNICAST = 0,                /* unicast pkt      */

-    AIR_LEAKY_PKT_TYPE_MULTICAST,                  /* multicast pkt    */

-    AIR_LEAKY_PKT_TYPE_BROADCAST,                  /* broadcast pkt    */

-    AIR_LEAKY_PKT_TYPE_LAST

-} AIR_LEAKY_PKT_TYPE_T;

-

-typedef enum

-{

-    AIR_VLAN_PORT_ATTR_USER_PORT = 0,              /* user port        */

-    AIR_VLAN_PORT_ATTR_STACK_PORT,                 /* stack port       */

-    AIR_VLAN_PORT_ATTR_TRANSLATION_PORT,           /* translation port */

-    AIR_VLAN_PORT_ATTR_TRANSPARENT_PORT,           /* transparent port */

-    AIR_VLAN_PORT_ATTR_LAST

-} AIR_VLAN_PORT_ATTR_T;

-

-typedef enum

-{

-    AIR_IGR_PORT_EG_TAG_ATTR_DISABLE = 0,

-    AIR_IGR_PORT_EG_TAG_ATTR_CONSISTENT,

-    AIR_IGR_PORT_EG_TAG_ATTR_UNTAGGED = 4,

-    AIR_IGR_PORT_EG_TAG_ATTR_SWAP,

-    AIR_IGR_PORT_EG_TAG_ATTR_TAGGED,

-    AIR_IGR_PORT_EG_TAG_ATTR_STACK,

-    AIR_IGR_PORT_EG_TAG_ATTR_LAST

-} AIR_IGR_PORT_EG_TAG_ATTR_T;

-

-typedef union AIR_VLAN_ENTRY_S

-{

-    UI8_T valid : 1;

-    struct

-    {

-        UI32_T  vlan_table0;

-        UI32_T  vlan_table1;

-    } vlan_table;

-    struct

-    {

-        UI64_T   valid             : 1;

-        UI64_T   fid               : 4;

-        UI64_T   ivl               : 1;

-        UI64_T   copy_pri          : 1;

-        UI64_T   user_pri          : 3;

-        UI64_T   eg_ctrl_en        : 1;

-        UI64_T   eg_con            : 1;

-        UI64_T   eg_ctrl           : 14;

-        UI64_T   port_mem          : 7;

-        UI64_T   port_stag         : 1;

-        UI64_T   stag              : 12;

-        UI64_T   unm_vlan_drop     : 1;

-    } vlan_entry_format;

-} AIR_VLAN_ENTRY_T;

-

-typedef union AIR_VLAN_ENTRY_ATTR_S

-{

-    UI8_T valid : 1;

-    struct

-    {

-        UI32_T  vlan_table0;

-        UI32_T  vlan_table1;

-        UI32_T  vlan_table2;

-        UI32_T  vlan_table3;

-        UI32_T  vlan_table4;

-    } vlan_table;

-    struct

-    {

-        UI64_T   valid             : 1;

-        UI64_T   fid               : 4;

-        UI64_T   ivl               : 1;

-        UI64_T   copy_pri          : 1;

-        UI64_T   user_pri          : 3;

-        UI64_T   eg_ctrl_en        : 1;

-        UI64_T   eg_con            : 1;

-        UI64_T   eg_ctrl           : 14;

-        UI64_T   port_mem          : 7;

-        UI64_T   port_stag         : 1;

-        UI64_T   stag              : 12;

-        UI64_T   unm_vlan_drop     : 1;

-    } vlan_entry_format;

-#if 0

-    struct

-    {

-        UI64_T   valid             : 1;

-        UI64_T   type              : 3;

-        UI64_T   mac_addr          : 48;

-        UI64_T   mac_mask_len      : 6;

-        UI64_T   priority          : 3;

-        UI64_T   :0;

-        UI64_T   vid               : 12;

-    } mac_based_vlan_entry_format;

-    struct

-    {

-        UI64_T   valid             : 1;

-        UI64_T   type              : 3;

-        UI64_T   check_field       : 36;

-        UI64_T   :0;

-        UI64_T   check_field_mask  : 36;

-        UI64_T   untagged_packet   : 1;

-        UI64_T   vlan_priority     : 3;

-        UI64_T   svid              : 12;

-    } qinq_based_vlan_entry_format;

-    struct

-    {

-        UI64_T   valid             : 1;

-        UI64_T   type              : 3;

-        UI64_T   ipv4              : 32;

-        UI64_T   :0;

-        UI64_T   subnetmask        : 32;

-        UI64_T   priority          : 3;

-        UI64_T   cvid              : 12;

-    } ipv4_based_vlan_entry_format;

-    struct

-    {

-        UI64_T   valid             : 1;

-        UI64_T   :0;

-        UI64_T   ipv6_high         : 64;

-        UI64_T   ipv6_low          : 64;

-        UI64_T   subnetmask        : 8;

-        UI64_T   priority          : 3;

-        UI64_T   cvid              : 12;

-    } ipv6_based_vlan_entry_format;

-#endif

-} AIR_VLAN_ENTRY_ATTR_T;

-

-void

-_air_vlan_readEntry(

-    const UI32_T unit,

-    const UI16_T vid,

-    AIR_VLAN_ENTRY_T* vlan_entry);

-

-void

-_air_vlan_writeEntry(

-    const UI32_T unit,

-    const UI16_T vid,

-    AIR_VLAN_ENTRY_T* vlan_entry);

-

-void

-_air_untagged_vlan_readEntry(

-    const UI32_T unit,

-    const UI16_T vid,

-    AIR_VLAN_ENTRY_ATTR_T* vlan_entry);

-

-void

-_air_untagged_vlan_writeEntry(

-    const UI32_T unit,

-    const UI16_T vid,

-    AIR_VLAN_ENTRY_ATTR_T* vlan_entry);

-

-/* EXPORTED SUBPROGRAM SPECIFICATIONS

- */

-/* FUNCTION NAME:   air_vlan_create

- * PURPOSE:

- *      Create the vlan in the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      p_attr      -- vlan attr

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Vlan creation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_create(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    AIR_VLAN_ENTRY_ATTR_T *p_attr);

-

-/* FUNCTION NAME:   air_vlan_destroy

- * PURPOSE:

- *      Destroy the vlan in the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK     -- Successfully read the data.

- *      AIR_E_OTHERS -- Vlan destroy failed.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_destroy(

-    const UI32_T    unit,

-    const UI16_T    vid);

-

-/* FUNCTION NAME:   air_vlan_destroyAll

- * PURPOSE:

- *      Destroy the vlan in the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK     -- Successfully read the data.

- *      AIR_E_OTHERS -- Vlan destroy failed.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_destroyAll(

-    const UI32_T    unit,

-    const UI32_T    keep_and_restore_default_vlan);

-

-/* FUNCTION NAME:   air_vlan_reset

- * PURPOSE:

- *      Destroy the vlan in the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK     -- Successfully reset the data.

- *      AIR_E_OTHERS -- Vlan reset failed.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_reset(

-    const UI32_T    unit,

-    const UI16_T    vid);

-

-/* FUNCTION NAME:   air_vlan_setFid

- * PURPOSE:

- *      Set the filter id of the vlan to the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      fid         -- filter id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setFid(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI8_T     fid);

-

-/* FUNCTION NAME:   air_vlan_getFid

- * PURPOSE:

- *      Get the filter id of the vlan from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id to be created

- * OUTPUT:

- *      p_fid       -- filter id

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getFid(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    UI8_T           *p_fid);

-

-/* FUNCTION NAME:   air_vlan_addMemberPort

- * PURPOSE:

- *      Add one vlan member to the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      port        -- port id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_addMemberPort(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI32_T    port);

-

-/* FUNCTION NAME:   air_vlan_delMemberPort

- * PURPOSE:

- *      Delete one vlan member from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      port        -- port id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_delMemberPort(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI32_T    port);

-

-/* FUNCTION NAME:   air_vlan_setMemberPort

- * PURPOSE:

- *      Replace the vlan members in the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      port_bitmap -- member port bitmap

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setMemberPort(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI32_T    port_bitmap);

-

-/* FUNCTION NAME:   air_vlan_getMemberPort

- * PURPOSE:

- *      Get the vlan members from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      port_bitmap -- member port bitmap

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getMemberPort(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    UI32_T          *p_port_bitmap);

-

-/* FUNCTION NAME:   air_vlan_setIVL

- * PURPOSE:

- *      Set L2 lookup mode IVL/SVL for L2 traffic.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      enable      -- enable IVL

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setIVL(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const BOOL_T    enable);

-

-/* FUNCTION NAME:   air_vlan_getIVL

- * PURPOSE:

- *      Get L2 lookup mode IVL/SVL for L2 traffic.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      p_enable    -- enable IVL

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getIVL(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    BOOL_T          *p_enable);

-

-/* FUNCTION NAME:   air_vlan_setPortAcceptFrameType

- * PURPOSE:

- *      Set vlan accept frame type of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      type        -- accept frame type

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortAcceptFrameType(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const AIR_VLAN_ACCEPT_FRAME_TYPE_T type);

-

-/* FUNCTION NAME:   air_vlan_getPortAcceptFrameType

- * PURPOSE:

- *      Get vlan accept frame type of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      p_type      -- accept frame type

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortAcceptFrameType(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_VLAN_ACCEPT_FRAME_TYPE_T *p_type);

-

-/* FUNCTION NAME:   air_vlan_setPortLeakyVlanEnable

- * PURPOSE:

- *      Set leaky vlan enable of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      pkt_type    -- packet type

- *      enable      -- enable leaky

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortLeakyVlanEnable(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_LEAKY_PKT_TYPE_T   pkt_type,

-    const BOOL_T    enable);

-

-/* FUNCTION NAME:   air_vlan_getPortLeakyVlanEnable

- * PURPOSE:

- *      Get leaky vlan enable of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      pkt_type    -- packet type

- * OUTPUT:

- *      p_enable    -- enable leaky

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortLeakyVlanEnable(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_LEAKY_PKT_TYPE_T   pkt_type,

-    BOOL_T          *p_enable);

-

-/* FUNCTION NAME:   air_vlan_setPortAttr

- * PURPOSE:

- *      Set vlan port attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      attr        -- vlan port attr

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const AIR_VLAN_PORT_ATTR_T attr);

-

-/* FUNCTION NAME:   air_vlan_getPortAttr

- * PURPOSE:

- *      Get vlan port attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      p_attr      -- vlan port attr

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_VLAN_PORT_ATTR_T *p_attr);

-

-/* FUNCTION NAME:   air_vlan_setIgrPortTagAttr

- * PURPOSE:

- *      Set vlan incoming port egress tag attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      attr        -- egress tag attr

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setIgrPortTagAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const AIR_IGR_PORT_EG_TAG_ATTR_T attr);

-

-/* FUNCTION NAME:   air_vlan_getIgrPortTagAttr

- * PURPOSE:

- *      Get vlan incoming port egress tag attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      p_attr      -- egress tag attr

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getIgrPortTagAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_IGR_PORT_EG_TAG_ATTR_T *p_attr);

-

-/* FUNCTION NAME:   air_vlan_setPortEgsTagAttr

- * PURPOSE:

- *      Set vlan port egress tag attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      attr        -- egress tag attr

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortEgsTagAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const AIR_PORT_EGS_TAG_ATTR_T attr);

-

-/* FUNCTION NAME:   air_vlan_getPortEgsTagAttr

- * PURPOSE:

- *      Get vlan port egress tag attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      p_attr      -- egress tag attr

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortEgsTagAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_PORT_EGS_TAG_ATTR_T *p_attr);

-

-/* FUNCTION NAME:   air_vlan_setPortOuterTPID

- * PURPOSE:

- *      Set stack tag TPID of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      tpid        -- TPID

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortOuterTPID(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const UI16_T    tpid);

-

-/* FUNCTION NAME:   air_vlan_getPortOuterTPID

- * PURPOSE:

- *      Get stack tag TPID of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      p_tpid        -- TPID

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortOuterTPID(

-    const UI32_T    unit,

-    const UI32_T    port,

-    UI16_T          *p_tpid);

-

-/* FUNCTION NAME:   air_vlan_setPortPVID

- * PURPOSE:

- *      Set PVID of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      pvid        -- native vlan id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortPVID(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const UI16_T    pvid);

-

-/* FUNCTION NAME:   air_vlan_getPortPVID

- * PURPOSE:

- *      Get PVID of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      p_pvid      -- native vlan id

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortPVID(

-    const UI32_T    unit,

-    const UI32_T    port,

-    UI16_T          *p_pvid);

-

-/* FUNCTION NAME:   air_vlan_setServiceTag

- * PURPOSE:

- *      Set Vlan service tag.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      stag        -- service stag

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setServiceTag(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI16_T    stag);

-

-/* FUNCTION NAME:   air_vlan_getServiceTag

- * PURPOSE:

- *      Get Vlan service tag.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      p_stag      -- service stag

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getServiceTag(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    UI16_T          *p_stag);

-

-/* FUNCTION NAME:   air_vlan_setEgsTagCtlEnable

- * PURPOSE:

- *      Set per vlan egress tag control.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      enable      -- enable vlan egress tag control

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setEgsTagCtlEnable(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const BOOL_T    enable);

-

-/* FUNCTION NAME:   air_vlan_getEgsTagCtlEnable

- * PURPOSE:

- *      Get per vlan egress tag control.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      p_enable    -- enable vlan egress tag control

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getEgsTagCtlEnable(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    BOOL_T          *p_enable);

-

-/* FUNCTION NAME:   air_vlan_setEgsTagConsistent

- * PURPOSE:

- *      Set per vlan egress tag consistent.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      enable      -- enable vlan egress tag consistent

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setEgsTagConsistent(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const BOOL_T    enable);

-

-/* FUNCTION NAME:   air_vlan_getEgsTagConsistent

- * PURPOSE:

- *      Get per vlan egress tag consistent.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      p_enable    -- enable vlan egress tag consistent

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getEgsTagConsistent(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    BOOL_T          *p_enable);

-

-/* FUNCTION NAME:   air_vlan_setPortBasedStag

- * PURPOSE:

- *      Set vlan port based stag enable.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      enable      -- vlan port based stag enable

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortBasedStag(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const BOOL_T    enable);

-

-/* FUNCTION NAME:   air_vlan_getPortBasedStag

- * PURPOSE:

- *      Get vlan port based stag enable.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      p_enable    -- vlan port based stag enable

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortBasedStag(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    BOOL_T          *p_enable);

-

-/* FUNCTION NAME:   air_vlan_setPortEgsTagCtl

- * PURPOSE:

- *      Set vlan port egress tag control.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      port        -- port id

- *      tag_ctl     -- egress tag control

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortEgsTagCtl(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI32_T    port,

-    const AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_T    tag_ctl);

-

-/* FUNCTION NAME:   air_vlan_getPortEgsTagCtl

- * PURPOSE:

- *      Get vlan port egress tag control.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      p_tag_ctl   -- egress tag control

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortEgsTagCtl(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI32_T    port,

-    AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_T   *ptr_tag_ctl);

-

-#endif  /* AIR_VLAN_H */

-

+/* FILE NAME:   air_vlan.h
+ * PURPOSE:
+ *      Define the vlan functions in AIR SDK.
+ * NOTES:
+ */
+
+#ifndef AIR_VLAN_H
+#define AIR_VLAN_H
+
+/* INCLUDE FILE DECLARATIONS
+ */
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+#define AIR_VLAN_ID_MIN                             0
+#define AIR_VLAN_ID_MAX                             4095
+#define AIR_DEFAULT_VLAN_ID                         1
+
+#define AIR_FILTER_ID_MAX                           7
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+
+/* DATA TYPE DECLARATIONS
+ */
+typedef enum
+{
+    AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_UNTAGGED = 0,
+    AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_TAGGED = 2,
+    AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_LAST,
+} AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_T;
+
+typedef enum
+{
+    AIR_PORT_EGS_TAG_ATTR_UNTAGGED = 0,
+    AIR_PORT_EGS_TAG_ATTR_SWAP,
+    AIR_PORT_EGS_TAG_ATTR_TAGGED,
+    AIR_PORT_EGS_TAG_ATTR_STACK,
+    AIR_PORT_EGS_TAG_ATTR_LAST
+} AIR_PORT_EGS_TAG_ATTR_T;
+
+typedef enum
+{
+    AIR_VLAN_ACCEPT_FRAME_TYPE_ALL = 0,            /* untagged, priority-tagged and tagged  */
+    AIR_VLAN_ACCEPT_FRAME_TYPE_TAG_ONLY,           /* tagged                                */
+    AIR_VLAN_ACCEPT_FRAME_TYPE_UNTAG_ONLY,         /* untagged and priority-tagged          */
+    AIR_VLAN_ACCEPT_FRAME_TYPE_RESERVED,           /* reserved                              */
+    AIR_VLAN_ACCEPT_FRAME_TYPE_LAST
+} AIR_VLAN_ACCEPT_FRAME_TYPE_T;
+
+typedef enum
+{
+    AIR_LEAKY_PKT_TYPE_UNICAST = 0,                /* unicast pkt      */
+    AIR_LEAKY_PKT_TYPE_MULTICAST,                  /* multicast pkt    */
+    AIR_LEAKY_PKT_TYPE_BROADCAST,                  /* broadcast pkt    */
+    AIR_LEAKY_PKT_TYPE_LAST
+} AIR_LEAKY_PKT_TYPE_T;
+
+typedef enum
+{
+    AIR_VLAN_PORT_ATTR_USER_PORT = 0,              /* user port        */
+    AIR_VLAN_PORT_ATTR_STACK_PORT,                 /* stack port       */
+    AIR_VLAN_PORT_ATTR_TRANSLATION_PORT,           /* translation port */
+    AIR_VLAN_PORT_ATTR_TRANSPARENT_PORT,           /* transparent port */
+    AIR_VLAN_PORT_ATTR_LAST
+} AIR_VLAN_PORT_ATTR_T;
+
+typedef enum
+{
+    AIR_IGR_PORT_EG_TAG_ATTR_DISABLE = 0,
+    AIR_IGR_PORT_EG_TAG_ATTR_CONSISTENT,
+    AIR_IGR_PORT_EG_TAG_ATTR_UNTAGGED = 4,
+    AIR_IGR_PORT_EG_TAG_ATTR_SWAP,
+    AIR_IGR_PORT_EG_TAG_ATTR_TAGGED,
+    AIR_IGR_PORT_EG_TAG_ATTR_STACK,
+    AIR_IGR_PORT_EG_TAG_ATTR_LAST
+} AIR_IGR_PORT_EG_TAG_ATTR_T;
+
+typedef union AIR_VLAN_ENTRY_S
+{
+    UI8_T valid : 1;
+    struct
+    {
+        UI32_T  vlan_table0;
+        UI32_T  vlan_table1;
+    } vlan_table;
+    struct
+    {
+        UI64_T   valid             : 1;
+        UI64_T   fid               : 4;
+        UI64_T   ivl               : 1;
+        UI64_T   copy_pri          : 1;
+        UI64_T   user_pri          : 3;
+        UI64_T   eg_ctrl_en        : 1;
+        UI64_T   eg_con            : 1;
+        UI64_T   eg_ctrl           : 14;
+        UI64_T   port_mem          : 7;
+        UI64_T   port_stag         : 1;
+        UI64_T   stag              : 12;
+        UI64_T   unm_vlan_drop     : 1;
+    } vlan_entry_format;
+} AIR_VLAN_ENTRY_T;
+
+typedef union AIR_VLAN_ENTRY_ATTR_S
+{
+    UI8_T valid : 1;
+    struct
+    {
+        UI32_T  vlan_table0;
+        UI32_T  vlan_table1;
+        UI32_T  vlan_table2;
+        UI32_T  vlan_table3;
+        UI32_T  vlan_table4;
+    } vlan_table;
+    struct
+    {
+        UI64_T   valid             : 1;
+        UI64_T   fid               : 4;
+        UI64_T   ivl               : 1;
+        UI64_T   copy_pri          : 1;
+        UI64_T   user_pri          : 3;
+        UI64_T   eg_ctrl_en        : 1;
+        UI64_T   eg_con            : 1;
+        UI64_T   eg_ctrl           : 14;
+        UI64_T   port_mem          : 7;
+        UI64_T   port_stag         : 1;
+        UI64_T   stag              : 12;
+        UI64_T   unm_vlan_drop     : 1;
+    } vlan_entry_format;
+#if 0
+    struct
+    {
+        UI64_T   valid             : 1;
+        UI64_T   type              : 3;
+        UI64_T   mac_addr          : 48;
+        UI64_T   mac_mask_len      : 6;
+        UI64_T   priority          : 3;
+        UI64_T   :0;
+        UI64_T   vid               : 12;
+    } mac_based_vlan_entry_format;
+    struct
+    {
+        UI64_T   valid             : 1;
+        UI64_T   type              : 3;
+        UI64_T   check_field       : 36;
+        UI64_T   :0;
+        UI64_T   check_field_mask  : 36;
+        UI64_T   untagged_packet   : 1;
+        UI64_T   vlan_priority     : 3;
+        UI64_T   svid              : 12;
+    } qinq_based_vlan_entry_format;
+    struct
+    {
+        UI64_T   valid             : 1;
+        UI64_T   type              : 3;
+        UI64_T   ipv4              : 32;
+        UI64_T   :0;
+        UI64_T   subnetmask        : 32;
+        UI64_T   priority          : 3;
+        UI64_T   cvid              : 12;
+    } ipv4_based_vlan_entry_format;
+    struct
+    {
+        UI64_T   valid             : 1;
+        UI64_T   :0;
+        UI64_T   ipv6_high         : 64;
+        UI64_T   ipv6_low          : 64;
+        UI64_T   subnetmask        : 8;
+        UI64_T   priority          : 3;
+        UI64_T   cvid              : 12;
+    } ipv6_based_vlan_entry_format;
+#endif
+} AIR_VLAN_ENTRY_ATTR_T;
+
+void
+_air_vlan_readEntry(
+    const UI32_T unit,
+    const UI16_T vid,
+    AIR_VLAN_ENTRY_T* vlan_entry);
+
+void
+_air_vlan_writeEntry(
+    const UI32_T unit,
+    const UI16_T vid,
+    AIR_VLAN_ENTRY_T* vlan_entry);
+
+void
+_air_untagged_vlan_readEntry(
+    const UI32_T unit,
+    const UI16_T vid,
+    AIR_VLAN_ENTRY_ATTR_T* vlan_entry);
+
+void
+_air_untagged_vlan_writeEntry(
+    const UI32_T unit,
+    const UI16_T vid,
+    AIR_VLAN_ENTRY_ATTR_T* vlan_entry);
+
+/* EXPORTED SUBPROGRAM SPECIFICATIONS
+ */
+/* FUNCTION NAME:   air_vlan_create
+ * PURPOSE:
+ *      Create the vlan in the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      p_attr      -- vlan attr
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Vlan creation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_create(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    AIR_VLAN_ENTRY_ATTR_T *p_attr);
+
+/* FUNCTION NAME:   air_vlan_destroy
+ * PURPOSE:
+ *      Destroy the vlan in the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK     -- Successfully read the data.
+ *      AIR_E_OTHERS -- Vlan destroy failed.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_destroy(
+    const UI32_T    unit,
+    const UI16_T    vid);
+
+/* FUNCTION NAME:   air_vlan_destroyAll
+ * PURPOSE:
+ *      Destroy the vlan in the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK     -- Successfully read the data.
+ *      AIR_E_OTHERS -- Vlan destroy failed.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_destroyAll(
+    const UI32_T    unit,
+    const UI32_T    keep_and_restore_default_vlan);
+
+/* FUNCTION NAME:   air_vlan_reset
+ * PURPOSE:
+ *      Destroy the vlan in the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK     -- Successfully reset the data.
+ *      AIR_E_OTHERS -- Vlan reset failed.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_reset(
+    const UI32_T    unit,
+    const UI16_T    vid);
+
+/* FUNCTION NAME:   air_vlan_setFid
+ * PURPOSE:
+ *      Set the filter id of the vlan to the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      fid         -- filter id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setFid(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI8_T     fid);
+
+/* FUNCTION NAME:   air_vlan_getFid
+ * PURPOSE:
+ *      Get the filter id of the vlan from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id to be created
+ * OUTPUT:
+ *      p_fid       -- filter id
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getFid(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    UI8_T           *p_fid);
+
+/* FUNCTION NAME:   air_vlan_addMemberPort
+ * PURPOSE:
+ *      Add one vlan member to the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      port        -- port id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_addMemberPort(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI32_T    port);
+
+/* FUNCTION NAME:   air_vlan_delMemberPort
+ * PURPOSE:
+ *      Delete one vlan member from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      port        -- port id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_delMemberPort(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI32_T    port);
+
+/* FUNCTION NAME:   air_vlan_setMemberPort
+ * PURPOSE:
+ *      Replace the vlan members in the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      port_bitmap -- member port bitmap
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setMemberPort(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI32_T    port_bitmap);
+
+/* FUNCTION NAME:   air_vlan_getMemberPort
+ * PURPOSE:
+ *      Get the vlan members from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      port_bitmap -- member port bitmap
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getMemberPort(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    UI32_T          *p_port_bitmap);
+
+/* FUNCTION NAME:   air_vlan_setIVL
+ * PURPOSE:
+ *      Set L2 lookup mode IVL/SVL for L2 traffic.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      enable      -- enable IVL
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setIVL(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const BOOL_T    enable);
+
+/* FUNCTION NAME:   air_vlan_getIVL
+ * PURPOSE:
+ *      Get L2 lookup mode IVL/SVL for L2 traffic.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      p_enable    -- enable IVL
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getIVL(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    BOOL_T          *p_enable);
+
+/* FUNCTION NAME:   air_vlan_setPortAcceptFrameType
+ * PURPOSE:
+ *      Set vlan accept frame type of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      type        -- accept frame type
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortAcceptFrameType(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const AIR_VLAN_ACCEPT_FRAME_TYPE_T type);
+
+/* FUNCTION NAME:   air_vlan_getPortAcceptFrameType
+ * PURPOSE:
+ *      Get vlan accept frame type of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      p_type      -- accept frame type
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortAcceptFrameType(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_VLAN_ACCEPT_FRAME_TYPE_T *p_type);
+
+/* FUNCTION NAME:   air_vlan_setPortLeakyVlanEnable
+ * PURPOSE:
+ *      Set leaky vlan enable of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      pkt_type    -- packet type
+ *      enable      -- enable leaky
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortLeakyVlanEnable(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_LEAKY_PKT_TYPE_T   pkt_type,
+    const BOOL_T    enable);
+
+/* FUNCTION NAME:   air_vlan_getPortLeakyVlanEnable
+ * PURPOSE:
+ *      Get leaky vlan enable of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      pkt_type    -- packet type
+ * OUTPUT:
+ *      p_enable    -- enable leaky
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortLeakyVlanEnable(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_LEAKY_PKT_TYPE_T   pkt_type,
+    BOOL_T          *p_enable);
+
+/* FUNCTION NAME:   air_vlan_setPortAttr
+ * PURPOSE:
+ *      Set vlan port attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      attr        -- vlan port attr
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const AIR_VLAN_PORT_ATTR_T attr);
+
+/* FUNCTION NAME:   air_vlan_getPortAttr
+ * PURPOSE:
+ *      Get vlan port attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      p_attr      -- vlan port attr
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_VLAN_PORT_ATTR_T *p_attr);
+
+/* FUNCTION NAME:   air_vlan_setIgrPortTagAttr
+ * PURPOSE:
+ *      Set vlan incoming port egress tag attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      attr        -- egress tag attr
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setIgrPortTagAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const AIR_IGR_PORT_EG_TAG_ATTR_T attr);
+
+/* FUNCTION NAME:   air_vlan_getIgrPortTagAttr
+ * PURPOSE:
+ *      Get vlan incoming port egress tag attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      p_attr      -- egress tag attr
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getIgrPortTagAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_IGR_PORT_EG_TAG_ATTR_T *p_attr);
+
+/* FUNCTION NAME:   air_vlan_setPortEgsTagAttr
+ * PURPOSE:
+ *      Set vlan port egress tag attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      attr        -- egress tag attr
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortEgsTagAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const AIR_PORT_EGS_TAG_ATTR_T attr);
+
+/* FUNCTION NAME:   air_vlan_getPortEgsTagAttr
+ * PURPOSE:
+ *      Get vlan port egress tag attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      p_attr      -- egress tag attr
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortEgsTagAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_PORT_EGS_TAG_ATTR_T *p_attr);
+
+/* FUNCTION NAME:   air_vlan_setPortOuterTPID
+ * PURPOSE:
+ *      Set stack tag TPID of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      tpid        -- TPID
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortOuterTPID(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const UI16_T    tpid);
+
+/* FUNCTION NAME:   air_vlan_getPortOuterTPID
+ * PURPOSE:
+ *      Get stack tag TPID of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      p_tpid        -- TPID
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortOuterTPID(
+    const UI32_T    unit,
+    const UI32_T    port,
+    UI16_T          *p_tpid);
+
+/* FUNCTION NAME:   air_vlan_setPortPVID
+ * PURPOSE:
+ *      Set PVID of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      pvid        -- native vlan id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortPVID(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const UI16_T    pvid);
+
+/* FUNCTION NAME:   air_vlan_getPortPVID
+ * PURPOSE:
+ *      Get PVID of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      p_pvid      -- native vlan id
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortPVID(
+    const UI32_T    unit,
+    const UI32_T    port,
+    UI16_T          *p_pvid);
+
+/* FUNCTION NAME:   air_vlan_setServiceTag
+ * PURPOSE:
+ *      Set Vlan service tag.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      stag        -- service stag
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setServiceTag(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI16_T    stag);
+
+/* FUNCTION NAME:   air_vlan_getServiceTag
+ * PURPOSE:
+ *      Get Vlan service tag.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      p_stag      -- service stag
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getServiceTag(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    UI16_T          *p_stag);
+
+/* FUNCTION NAME:   air_vlan_setEgsTagCtlEnable
+ * PURPOSE:
+ *      Set per vlan egress tag control.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      enable      -- enable vlan egress tag control
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setEgsTagCtlEnable(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const BOOL_T    enable);
+
+/* FUNCTION NAME:   air_vlan_getEgsTagCtlEnable
+ * PURPOSE:
+ *      Get per vlan egress tag control.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      p_enable    -- enable vlan egress tag control
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getEgsTagCtlEnable(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    BOOL_T          *p_enable);
+
+/* FUNCTION NAME:   air_vlan_setEgsTagConsistent
+ * PURPOSE:
+ *      Set per vlan egress tag consistent.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      enable      -- enable vlan egress tag consistent
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setEgsTagConsistent(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const BOOL_T    enable);
+
+/* FUNCTION NAME:   air_vlan_getEgsTagConsistent
+ * PURPOSE:
+ *      Get per vlan egress tag consistent.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      p_enable    -- enable vlan egress tag consistent
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getEgsTagConsistent(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    BOOL_T          *p_enable);
+
+/* FUNCTION NAME:   air_vlan_setPortBasedStag
+ * PURPOSE:
+ *      Set vlan port based stag enable.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      enable      -- vlan port based stag enable
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortBasedStag(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const BOOL_T    enable);
+
+/* FUNCTION NAME:   air_vlan_getPortBasedStag
+ * PURPOSE:
+ *      Get vlan port based stag enable.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      p_enable    -- vlan port based stag enable
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortBasedStag(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    BOOL_T          *p_enable);
+
+/* FUNCTION NAME:   air_vlan_setPortEgsTagCtl
+ * PURPOSE:
+ *      Set vlan port egress tag control.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      port        -- port id
+ *      tag_ctl     -- egress tag control
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortEgsTagCtl(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI32_T    port,
+    const AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_T    tag_ctl);
+
+/* FUNCTION NAME:   air_vlan_getPortEgsTagCtl
+ * PURPOSE:
+ *      Get vlan port egress tag control.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      p_tag_ctl   -- egress tag control
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortEgsTagCtl(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI32_T    port,
+    AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_T   *ptr_tag_ctl);
+
+#endif  /* AIR_VLAN_H */
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_aml.c b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_aml.c
index 38b85a4..2e4119c 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_aml.c
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_aml.c
@@ -1,218 +1,218 @@
-/* FILE NAME:  air_aml.c

- * PURPOSE:

- *      It provides access management layer function.

- * NOTES:

- *

- */

-

-/* INCLUDE FILE DECLARATIONS

- */

-#include "air.h"

-

-/* NAMING CONSTANT DECLARATIONS

- */

-

-/* MACRO FUNCTION DECLARATIONS

- */

-

-/* DATA TYPE DECLARATIONS

- */

-

-/* GLOBAL VARIABLE DECLARATIONS

- */

-AML_DEV_ACCESS_T _ext_dev_access;

-

-/* EXPORTED SUBPROGRAM BODIES

- */

-

-/* LOCAL SUBPROGRAM BODIES

- */

-/* FUNCTION NAME:   aml_readReg

- * PURPOSE:

- *      To read data from the register of the specified chip unit.

- * INPUT:

- *      unit        -- the device unit

- *      addr_offset -- the address of register

- * OUTPUT:

- *      ptr_data    -- pointer for the register data

- * RETURN:

- *      NPS_E_OK     -- Successfully read the data.

- *      NPS_E_OTHERS -- Failed to read the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_readReg(

-    const UI32_T    unit,

-    const UI32_T    addr_offset,

-    UI32_T          *ptr_data)

-{

-    AIR_CHECK_PTR(ptr_data);

-

-    if (!_ext_dev_access.read_callback)

-    {

-        return AIR_E_OTHERS;

-    }

-

-    return _ext_dev_access.read_callback(unit, addr_offset, ptr_data);

-}

-

-/* FUNCTION NAME:   aml_writeReg

- * PURPOSE:

- *      To write data to the register of the specified chip unit.

- * INPUT:

- *      unit        -- the device unit

- *      addr_offset -- the address of register

- *      data        -- written data

- * OUTPUT:

- *      none

- * RETURN:

- *      NPS_E_OK     -- Successfully write the data.

- *      NPS_E_OTHERS -- Failed to write the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_writeReg(

-    const UI32_T    unit,

-    const UI32_T    addr_offset,

-    const UI32_T    data)

-{

-    if (!_ext_dev_access.write_callback)

-    {

-        return AIR_E_OTHERS;

-    }

-

-    return _ext_dev_access.write_callback(unit, addr_offset, data);

-}

-

-/* FUNCTION NAME:   aml_readPhyReg

- * PURPOSE:

- *      To read data from the phy register of the specified chip unit in Clause22.

- * INPUT:

- *      unit        -- the device unit

- *      port_id     -- physical port number

- *      addr_offset -- the address of phy register

- * OUTPUT:

- *      ptr_data    -- pointer for the register data

- * RETURN:

- *      NPS_E_OK     -- Successfully read the data.

- *      NPS_E_OTHERS -- Failed to read the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_readPhyReg(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    addr_offset,

-    UI32_T          *ptr_data)

-{

-    AIR_CHECK_PTR(ptr_data);

-

-    if (!_ext_dev_access.phy_read_callback)

-    {

-        return AIR_E_OTHERS;

-    }

-

-    return _ext_dev_access.phy_read_callback(unit, port_id, addr_offset, ptr_data);

-}

-

-/* FUNCTION NAME:   aml_writePhyReg

- * PURPOSE:

- *      To write data to the phy register of the specified chip unit in Clause22.

- * INPUT:

- *      unit        -- the device unit

- *      port_id     -- physical port number

- *      addr_offset -- the address of phy register

- *      data        -- written data

- * OUTPUT:

- *      none

- * RETURN:

- *      NPS_E_OK     -- Successfully write the data.

- *      NPS_E_OTHERS -- Failed to write the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_writePhyReg(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    addr_offset,

-    const UI32_T    data)

-{

-    if (!_ext_dev_access.phy_write_callback)

-    {

-        return AIR_E_OTHERS;

-    }

-

-    return _ext_dev_access.phy_write_callback(unit, port_id, addr_offset, data);

-}

-

-/* FUNCTION NAME:   aml_readPhyRegCL45

- * PURPOSE:

- *      To read data from the phy register of the specified chip unit in Clause45.

- * INPUT:

- *      unit        -- the device unit

- *      port_id     -- physical port number

- *      dev_type    -- phy register type

- *      addr_offset -- the address of phy register

- * OUTPUT:

- *      ptr_data    -- pointer for the register data

- * RETURN:

- *      NPS_E_OK     -- Successfully read the data.

- *      NPS_E_OTHERS -- Failed to read the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_readPhyRegCL45(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    dev_type,

-    const UI32_T    addr_offset,

-    UI32_T          *ptr_data)

-{

-    AIR_CHECK_PTR(ptr_data);

-

-    if (!_ext_dev_access.phy_cl45_read_callback)

-    {

-        return AIR_E_OTHERS;

-    }

-

-    return _ext_dev_access.phy_cl45_read_callback(unit, port_id, dev_type, addr_offset, ptr_data);

-}

-

-/* FUNCTION NAME:   aml_writePhyRegCL45

- * PURPOSE:

- *      To write data to the phy register of the specified chip unit in Clause45.

- * INPUT:

- *      unit        -- the device unit

- *      port_id     -- physical port number

- *      dev_type    -- phy register offset

- *      addr_offset -- the address of phy register

- *      data        -- written data

- * OUTPUT:

- *      none

- * RETURN:

- *      NPS_E_OK     -- Successfully write the data.

- *      NPS_E_OTHERS -- Failed to write the data.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-aml_writePhyRegCL45(

-    const UI32_T    unit,

-    const UI32_T    port_id,

-    const UI32_T    dev_type,

-    const UI32_T    addr_offset,

-    const UI32_T    data)

-{

-    if (!_ext_dev_access.phy_cl45_write_callback)

-    {

-        return AIR_E_OTHERS;

-    }

-

-    return _ext_dev_access.phy_cl45_write_callback(unit, port_id, dev_type, addr_offset, data);

-}

-

+/* FILE NAME:  air_aml.c
+ * PURPOSE:
+ *      It provides access management layer function.
+ * NOTES:
+ *
+ */
+
+/* INCLUDE FILE DECLARATIONS
+ */
+#include "air.h"
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+
+/* DATA TYPE DECLARATIONS
+ */
+
+/* GLOBAL VARIABLE DECLARATIONS
+ */
+AML_DEV_ACCESS_T _ext_dev_access;
+
+/* EXPORTED SUBPROGRAM BODIES
+ */
+
+/* LOCAL SUBPROGRAM BODIES
+ */
+/* FUNCTION NAME:   aml_readReg
+ * PURPOSE:
+ *      To read data from the register of the specified chip unit.
+ * INPUT:
+ *      unit        -- the device unit
+ *      addr_offset -- the address of register
+ * OUTPUT:
+ *      ptr_data    -- pointer for the register data
+ * RETURN:
+ *      NPS_E_OK     -- Successfully read the data.
+ *      NPS_E_OTHERS -- Failed to read the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_readReg(
+    const UI32_T    unit,
+    const UI32_T    addr_offset,
+    UI32_T          *ptr_data)
+{
+    AIR_CHECK_PTR(ptr_data);
+
+    if (!_ext_dev_access.read_callback)
+    {
+        return AIR_E_OTHERS;
+    }
+
+    return _ext_dev_access.read_callback(unit, addr_offset, ptr_data);
+}
+
+/* FUNCTION NAME:   aml_writeReg
+ * PURPOSE:
+ *      To write data to the register of the specified chip unit.
+ * INPUT:
+ *      unit        -- the device unit
+ *      addr_offset -- the address of register
+ *      data        -- written data
+ * OUTPUT:
+ *      none
+ * RETURN:
+ *      NPS_E_OK     -- Successfully write the data.
+ *      NPS_E_OTHERS -- Failed to write the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_writeReg(
+    const UI32_T    unit,
+    const UI32_T    addr_offset,
+    const UI32_T    data)
+{
+    if (!_ext_dev_access.write_callback)
+    {
+        return AIR_E_OTHERS;
+    }
+
+    return _ext_dev_access.write_callback(unit, addr_offset, data);
+}
+
+/* FUNCTION NAME:   aml_readPhyReg
+ * PURPOSE:
+ *      To read data from the phy register of the specified chip unit in Clause22.
+ * INPUT:
+ *      unit        -- the device unit
+ *      port_id     -- physical port number
+ *      addr_offset -- the address of phy register
+ * OUTPUT:
+ *      ptr_data    -- pointer for the register data
+ * RETURN:
+ *      NPS_E_OK     -- Successfully read the data.
+ *      NPS_E_OTHERS -- Failed to read the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_readPhyReg(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    addr_offset,
+    UI32_T          *ptr_data)
+{
+    AIR_CHECK_PTR(ptr_data);
+
+    if (!_ext_dev_access.phy_read_callback)
+    {
+        return AIR_E_OTHERS;
+    }
+
+    return _ext_dev_access.phy_read_callback(unit, port_id, addr_offset, ptr_data);
+}
+
+/* FUNCTION NAME:   aml_writePhyReg
+ * PURPOSE:
+ *      To write data to the phy register of the specified chip unit in Clause22.
+ * INPUT:
+ *      unit        -- the device unit
+ *      port_id     -- physical port number
+ *      addr_offset -- the address of phy register
+ *      data        -- written data
+ * OUTPUT:
+ *      none
+ * RETURN:
+ *      NPS_E_OK     -- Successfully write the data.
+ *      NPS_E_OTHERS -- Failed to write the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_writePhyReg(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    addr_offset,
+    const UI32_T    data)
+{
+    if (!_ext_dev_access.phy_write_callback)
+    {
+        return AIR_E_OTHERS;
+    }
+
+    return _ext_dev_access.phy_write_callback(unit, port_id, addr_offset, data);
+}
+
+/* FUNCTION NAME:   aml_readPhyRegCL45
+ * PURPOSE:
+ *      To read data from the phy register of the specified chip unit in Clause45.
+ * INPUT:
+ *      unit        -- the device unit
+ *      port_id     -- physical port number
+ *      dev_type    -- phy register type
+ *      addr_offset -- the address of phy register
+ * OUTPUT:
+ *      ptr_data    -- pointer for the register data
+ * RETURN:
+ *      NPS_E_OK     -- Successfully read the data.
+ *      NPS_E_OTHERS -- Failed to read the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_readPhyRegCL45(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    dev_type,
+    const UI32_T    addr_offset,
+    UI32_T          *ptr_data)
+{
+    AIR_CHECK_PTR(ptr_data);
+
+    if (!_ext_dev_access.phy_cl45_read_callback)
+    {
+        return AIR_E_OTHERS;
+    }
+
+    return _ext_dev_access.phy_cl45_read_callback(unit, port_id, dev_type, addr_offset, ptr_data);
+}
+
+/* FUNCTION NAME:   aml_writePhyRegCL45
+ * PURPOSE:
+ *      To write data to the phy register of the specified chip unit in Clause45.
+ * INPUT:
+ *      unit        -- the device unit
+ *      port_id     -- physical port number
+ *      dev_type    -- phy register offset
+ *      addr_offset -- the address of phy register
+ *      data        -- written data
+ * OUTPUT:
+ *      none
+ * RETURN:
+ *      NPS_E_OK     -- Successfully write the data.
+ *      NPS_E_OTHERS -- Failed to write the data.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+aml_writePhyRegCL45(
+    const UI32_T    unit,
+    const UI32_T    port_id,
+    const UI32_T    dev_type,
+    const UI32_T    addr_offset,
+    const UI32_T    data)
+{
+    if (!_ext_dev_access.phy_cl45_write_callback)
+    {
+        return AIR_E_OTHERS;
+    }
+
+    return _ext_dev_access.phy_cl45_write_callback(unit, port_id, dev_type, addr_offset, data);
+}
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_cmd.c b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_cmd.c
index 95c11e8..6dfe416 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_cmd.c
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_cmd.c
@@ -1,8022 +1,8046 @@
-/* FILE NAME:   air_cmd.c

- * PURPOSE:

- *      Define the command line function in AIR SDK.

- * NOTES:

- */

-

-/* INCLUDE FILE DECLARATIONS

-*/

-#include "air.h"

-

-/* NAMING CONSTANT DECLARATIONS

-*/

-

-/* MACRO FUNCTION DECLARATIONS

-*/

-#define MAC_STR         "%02X%02X%02X%02X%02X%02X"

-#define MAC2STR(m)      (m)[0],(m)[1],(m)[2],(m)[3],(m)[4],(m)[5]

-#define AIR_MAC_LEN    (12)

-#define CMD_NO_PARA     (0xFFFFFFFF)

-#define CMD_VARIABLE_PARA (0xFFFFFFFE)

-#define L2_WDOG_KICK_NUM            (100)

-

-#define TOLOWER(x)      ((x) | 0x20)

-#define isxdigit(c)     (('0' <= (c) && (c) <= '9') || ('a' <= (c) && (c) <= 'f') || ('A' <= (c) && (c) <= 'F'))

-#define isdigit(c)      ('0' <= (c) && (c) <= '9')

-#define CMD_CHECK_PARA(__shift__, __op__, __size__) do          \

-{                                                               \

-    if ((__shift__) __op__ (__size__))                          \

-    {                                                           \

-        ;                                                       \

-    }                                                           \

-    else                                                        \

-    {                                                           \

-        return (AIR_E_BAD_PARAMETER);                           \

-    }                                                           \

-} while(0)

-

-/* DATA TYPE DECLARATIONS

-*/

-typedef struct {

-    C8_T*               name;

-    AIR_ERROR_NO_T     (*func)(UI32_T argc, C8_T *argv[]);

-    UI32_T              argc_min;

-    C8_T*               argc_errmsg;

-} AIR_CMD_T;

-

-/* GLOBAL VARIABLE DECLARATIONS

-*/

-

-/* LOCAL SUBPROGRAM DECLARATIONS

-*/

-/* String Utility */

-static BOOL_T _strcmp(const char *s1, const char *s2);

-static C8_T * _strtok_r(C8_T *s, const C8_T *delim, C8_T **last);

-static C8_T * _strtok(C8_T *s, const C8_T *delim, C8_T **last);

-UI32_T _strtoul(const C8_T *cp, C8_T **endp, UI32_T base);

-static I32_T _strtol(const C8_T *cp, C8_T **endp, UI32_T base);

-

-/* Type Converter */

-static AIR_ERROR_NO_T _str2mac(C8_T *str, C8_T *mac);

-static AIR_ERROR_NO_T _hex2bit(const UI32_T hex, UI32_T *ptr_bit);

-static AIR_ERROR_NO_T _hex2bitstr(const UI32_T hex, C8_T *ptr_bit_str, UI32_T str_len);

-static AIR_ERROR_NO_T _portListStr2Ary(const C8_T *str, UI32_T *ary, const UI32_T ary_num);

-

-/* Register Operation */

-static AIR_ERROR_NO_T doRegRead(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doRegWrite(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doReg(UI32_T argc, C8_T *argv[]);

-

-/* PHY Operation */

-static AIR_ERROR_NO_T doPhyCL22Read(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPhyCL22Write(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPhyCL22(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPhyCL45Read(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPhyCL45Write(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPhyCL45(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPhy(UI32_T argc, C8_T *argv[]);

-

-/* Porting setting */

-static AIR_ERROR_NO_T doPortSetMatrix(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortSetVlanMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortSet(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doPortGetMatrix(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortGetVlanMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortGet(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doPort(UI32_T argc, C8_T *argv[]);

-

-/* Vlan setting */

-static AIR_ERROR_NO_T doVlanInitiate(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanCreate(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanDestroy(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanDestroyAll(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanDump(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanAddPortMem(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanDelPortMem(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doVlanSetFid(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetMemPort(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetIVL(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetPortBaseStag(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetStag(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetEgsTagCtlEn(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetEgsTagCtlCon(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetEgsTagCtl(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetPortActFrame(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetLeakyVlanEn(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetPortVlanAttr(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetIgsPortETagAttr(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetPortETagAttr(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetPortOuterTPID(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSetPvid(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanSet(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doVlanGetPortActFrame(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanGetLeakyVlanEn(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanGetPortVlanAttr(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanGetIgsPortETagAttr(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanGetPortETagAttr(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanGetPortOuterTPID(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanGetPvid(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doVlanGet(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doVlan(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doFlowCtrl(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doJumbo(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doL2Add(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doL2Del(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doL2Clear(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doL2Get(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doL2Set(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doL2Dump(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doL2(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doAnMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLocalAdv(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doRemoteAdv(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortSpeed(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortDuplex(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortStatus(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortBckPres(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortPsMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortSmtSpdDwn(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortSpTag(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortEnable(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPort5GBaseRMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortHsgmiiMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortSgmiiMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortRmiiMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doPortRgmiiMode(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doSptagEn(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSptagMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSptagDecode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSptagEncode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSptag(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doMacAddr(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T _printMacEntry(AIR_MAC_ENTRY_T * mt, UI32_T age_unit, UI8_T count, UI8_T title);

-static AIR_ERROR_NO_T doGetMacAddr(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMacAddrAgeOut(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doDumpMacAddr(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doLagMember(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLagMemberCnt(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLagPtseed(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLagHashtype(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLagDstInfo(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLagState(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLagSpsel(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLagGet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLagSet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLag(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doStpPortstate(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doStpGet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doStpSet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doStp(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doMirrorGetSid(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMirrorDelSid(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMirrorAddRlist(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMirrorAddTlist(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMirrorSetSessionEnable(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMirrorSetSession(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMirrorSet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMirrorAdd(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMirrorGet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMirrorDel(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMirror(UI32_T argc,C8_T *argv[]);

-

-static AIR_ERROR_NO_T doMibClearPort(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMibClearAcl(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMibGetPort(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMibGetAcl(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMibClear(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMibGet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doMib(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doQosScheduleAlgo(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doQosTrustMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doQosPri2Queue(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doQosDscp2Pri(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doQosRateLimitEnable(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doQosRateLimit(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doQosPortPriority(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doQosRateLimitExMngFrm(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doQosGet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doQosSet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doQos(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doDiagTxComply(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doDiagSet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doDiagGet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doDiag(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doLedMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLedState(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLedUsrDef(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLedBlkTime(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLedSet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLedGet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doLed(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doSwitchCpuPortEn(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSwitchCpuPort(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSwitchPhyLCIntrEn(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSwitchPhyLCIntrSts(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSwitchSet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSwitchGet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSwitch(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doShowVersion(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doShow(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T doStormEnable(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doStormRate(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doFldMode(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSaLearning(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSaLimit(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSecGet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSecSet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doSec(UI32_T argc, C8_T *argv[]);

-

-static void _air_acl_printRuleMap(UI32_T *rule_map, UI32_T ary_num);

-static AIR_ERROR_NO_T doAclEn(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclRule(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclUdfRule(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclRmvRule(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclRmvUdfRule(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclAction(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclRmvAction(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclDumpAction(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclTrtcm(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclTrtcmEn(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclRmvTrtcm(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclPortEn(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclDropEn(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclDropThrsh(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclDropPbb(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclMeter(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclDump(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclSet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclGet(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclDel(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAclClear(UI32_T argc, C8_T *argv[]);

-static AIR_ERROR_NO_T doAcl(UI32_T argc, C8_T *argv[]);

-

-static AIR_ERROR_NO_T subcmd(const AIR_CMD_T tab[], UI32_T argc, C8_T *argv[]);

-

-/* STATIC VARIABLE DECLARATIONS

-*/

-const static C8_T *_sptag_vpm[] =

-{

-    "untagged",

-    "8100",

-    "predefined",

-    "unknown"

-};

-

-const static C8_T *_sptag_pt[] =

-{

-    "disable pass through",

-    "enable pass through"

-};

-

-const static C8_T *_air_mac_address_forward_control_string [] =

-{

-    "Default",

-    "CPU include",

-    "CPU exclude",

-    "CPU only",

-    "Drop"

-};

-

-static AIR_CMD_T regCmds[] =

-{

-    {"r",           doRegRead,      1,      "reg r <reg(4'hex)>"},

-    {"w",           doRegWrite,     2,      "reg w <reg(4'hex)> <value(8'hex)>"},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T phyCL22Cmds[] =

-{

-    {"r",           doPhyCL22Read,  2,      "phy cl22 r <port(0..4)> <reg(2'hex)>"},

-    {"w",           doPhyCL22Write, 3,      "phy cl22 w <port(0..4)> <reg(2'hex)> <value(4'hex)>"},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T phyCL45Cmds[] =

-{

-    {"r",           doPhyCL45Read,  3,      "phy cl45 r <port(0..4)> <dev(2'hex)> <reg(3'hex)>"},

-    {"w",           doPhyCL45Write, 4,      "phy cl45 w <port(0..4)> <dev(2'hex)> <reg(3'hex)> <value(4'hex)>"},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T phyCmds[] =

-{

-    {"cl22",         doPhyCL22,     0,      NULL},

-    {"cl45",         doPhyCL45,     0,      NULL},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T portSetCmds[] =

-{

-    {"matrix",      doPortSetMatrix,        2,                "port set matrix <port(0..6)> <matrix(6:0)>"},

-    {"vlanMode",    doPortSetVlanMode,      2,                "port set vlanMode <port(0..6)> <vlanMode(0:matrix,1:fallback,2:check,3:security)>"},

-    {"flowCtrl",    doFlowCtrl,             3,                "port set flowCtrl <port(0..6)> <dir(0:Tx,1:Rx)> <fc_en(1:En,0:Dis)>"},

-    {"jumbo",       doJumbo,                2,                "port set jumbo <pkt_len(0:1518,1:1536,2:1552,3:max)> <frame_len(2..15)>"},

-    {"anMode",      doAnMode,               2,                "port set anMode <port(0..4)> <en(0:force,1:AN)>"},

-    {"localAdv",    doLocalAdv,             7,                "port set localAdv <port(0..4)> <10H(1:En,0:Dis)> <10F(1:En,0:Dis)> <100H(1:En,0:Dis)> <100F(1:En,0:Dis)> <1000F(1:En,0:Dis)> <pause(1:En,0:Dis)>"},

-    {"speed",       doPortSpeed,            2,                "port set speed <port(0..4)> <speed(0:10M,1:100M,2:1G,3:2.5G)>"},

-    {"duplex",      doPortDuplex,           2,                "port set duplex <port(0..4)> <duplex(0:half,1:full)>"},

-    {"bckPres",     doPortBckPres,          2,                "port set bckPres <port(0..6)> <bckPres(1:En,0:Dis)>"},

-    {"psMode",      doPortPsMode,           3,                "port set psMode <port(0..4)> <ls(1:En,0:Dis)> <eee(1:En,0:Dis)>"},

-    {"smtSpdDwn",   doPortSmtSpdDwn,        3,                "port set smtSpdDwn <port(0..4)> <en(1:En,0:Dis)> <retry(2..5)>"},

-    {"spTag",       doPortSpTag,            2,                "port set spTag <port(0..6)> <en(1:En,0:Dis)>"},

-    {"enable",      doPortEnable,           2,                "port set enable <port(0..4)> <en(1:En,0:Dis)>"},

-    {"5GBaseRMode", doPort5GBaseRMode,      CMD_NO_PARA,      "port set 5GBaseRMode"},

-    {"hsgmiiMode",  doPortHsgmiiMode,       CMD_NO_PARA,      "port set hsgmiiMode"},

-    {"sgmiiMode",   doPortSgmiiMode,        2,                "port set sgmiiMode <mode(0:AN,1:Force)> <speed(0:10M,1:100M,2:1G)>"},

-    {"rmiiMode",    doPortRmiiMode,         1,                "port set rmiiMode <speed(0:10M,1:100M)>"},

-    {"rgmiiMode",   doPortRgmiiMode,        1,                "port set rgmiiMode <speed(0:10M,1:100M,2:1G)>"},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T portGetCmds[] =

-{

-    {"matrix",      doPortGetMatrix,        1,                "port get matrix <port(0..6)>"},

-    {"vlanMode",    doPortGetVlanMode,      1,                "port get vlanMode <port(0..6)>"},

-    {"flowCtrl",    doFlowCtrl,             2,                "port get flowCtrl <port(0..6)> <dir(0:Tx,1:Rx)>"},

-    {"jumbo",       doJumbo,                CMD_NO_PARA,      "port get jumbo"},

-    {"anMode",      doAnMode,               1,                "port get anMode <port(0..4)>"},

-    {"localAdv",    doLocalAdv,             1,                "port get localAdv <port(0..4)>"},

-    {"remoteAdv",   doRemoteAdv,            1,                "port get remoteAdv <port(0..4)>"},

-    {"speed",       doPortSpeed,            1,                "port get speed <port(0..4)>"},

-    {"duplex",      doPortDuplex,           1,                "port get duplex <port(0..4)>"},

-    {"status",      doPortStatus,           1,                "port get status <port(0..4)>"},

-    {"bckPres",     doPortBckPres,          1,                "port get bckPres <port(0..6)>"},

-    {"psMode",      doPortPsMode,           1,                "port get psMode <port(0..4)>"},

-    {"smtSpdDwn",   doPortSmtSpdDwn,        1,                "port get smtSpdDwn <port(0..4)>"},

-    {"spTag",       doPortSpTag,            1,                "port get spTag <port(0..6)>"},

-    {"enable",      doPortEnable,           1,                "port get enable <port(0..4)>"},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T portCmds[] =

-{

-    {"set",         doPortSet,      0,      NULL},

-    {"get",         doPortGet,      0,      NULL},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T sptagCmds[] =

-{

-    {"setEnable",       doSptagEn,          2,      "sptag setEnable port<port(0..6)> enable<1:enable 0:disable>"},

-    {"getEnable",       doSptagEn,          1,      "sptag getEnable port<port(0..6)>"},

-    {"setmode",         doSptagMode,        2,      "sptag setmode port<port(0..6)> mode<0:inset 1:replace>"},

-    {"getmode",         doSptagMode,        1,      "sptag getmode port<port(0..6)>"},

-    {"encode",          doSptagEncode,      7,      "sptag encode mode={ insert | replace } opc={ portmap | portid | lookup } dp={bitimap hex} vpm={ untagged | 8100 | 88a8 } pri=<UINT> cfi=<UINT> vid=<UINT> "},

-    {"decode",          doSptagDecode,      4,      "sptag decode <byte(hex)> <byte(hex)> <byte(hex)> <byte(hex)>"},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T vlanSetCmds[] =

-{

-    {"fid",                 doVlanSetFid,               2,      "vlan set fid <vid(0..4095)> <fid(0..7)>"},

-    {"memPort",             doVlanSetMemPort,           2,      "vlan set memPort <vid(0..4095)> <bitmap(6:0)>"},

-    {"ivl",                 doVlanSetIVL,               2,      "vlan set ivl <vid(0..4095)> <(1:En,0:Dis)>"},

-    {"portBaseStag",        doVlanSetPortBaseStag,      2,      "vlan set portBaseStag <vid(0..4095)> <(1:En,0:Dis)>"},

-    {"stag",                doVlanSetStag,              2,      "vlan set stag <vid(0..4095)> <stag(0..4095)>"},

-    {"egsTagCtlEn",         doVlanSetEgsTagCtlEn,       2,      "vlan set egsTagCtlEn <vid(0..4095)> <(1:En,0:Dis)>"},

-    {"egsTagCtlCon",        doVlanSetEgsTagCtlCon,      2,      "vlan set egsTagCtlCon <vid(0..4095)> <(1:En,0:Dis)>"},

-    {"egsTagCtl",           doVlanSetEgsTagCtl,         3,      "vlan set egsTagCtl <vid(0..4095)> <port(0..6)> <ctlType(0:untag,2:tagged)>"},

-

-    {"portActFrame",        doVlanSetPortActFrame,      2,      "vlan set portActFrame <port(0..6)> <frameType(0:all,1:tagged,2:untagged)>"},

-    {"leakyVlanEn",         doVlanSetLeakyVlanEn,       3,      "vlan set LeakyVlanEn <port(0..6)> <pktType(0:uc,1:mc,2:bc,3:ipmc)> <(1:En,0:Dis)>"},

-    {"portVlanAttr",        doVlanSetPortVlanAttr,      2,      "vlan set portVlanAttr <port(0..6)> <vlanAttr(0:user,1:stack,2:translation,3:transparent)>"},

-    {"igsPortETagAttr",     doVlanSetIgsPortETagAttr,   2,      "vlan set igsPortETagAttr <port(0..6)> <egsTagAttr(0:disable,1:consistent,4:untagged,5:swap,6:tagged,7:stack)>"},

-    {"portEgsTagAttr",      doVlanSetPortETagAttr,      2,      "vlan set portEgsTagAttr <port(0..6)> <egsTagAttr(0:untagged,1:swap,2:tagged,3:stack)>"},

-    {"portOuterTPID",       doVlanSetPortOuterTPID,     2,      "vlan set portOuterTPID <port(0..6)> <TPID(hex)>"},

-    {"pvid",                doVlanSetPvid,              2,      "vlan set pvid <port(0..6)> <vid(0..4095)>"},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T vlanGetCmds[] =

-{

-    {"portActFrame",        doVlanGetPortActFrame,      1,      "vlan get portActFrame <port(0..6)>"},

-    {"leakyVlanEn",         doVlanGetLeakyVlanEn,       1,      "vlan get leakyVlanEn <port(0..6)>"},

-    {"portVlanAttr",        doVlanGetPortVlanAttr,      1,      "vlan get portVlanAttr <port(0..6)>"},

-    {"igsPortETagAttr",     doVlanGetIgsPortETagAttr,   1,      "vlan get igsPortETagAttr <port(0..6)>"},

-    {"portEgsTagAttr",      doVlanGetPortETagAttr,      1,      "vlan get portEgsTagAttr <port(0..6)>"},

-    {"portOuterTPID",       doVlanGetPortOuterTPID,     1,      "vlan get portOuterTPID <port(0..6)>"},

-    {"pvid",                doVlanGetPvid,              1,      "vlan get pvid <port(0..6)>"},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T vlanCmds[] =

-{

-    {"initiate",        doVlanInitiate,         9,      "vlan initiate <vid(0..4095)> <fid(0..7)> <bitmap(6:0)> <ivl(1:En,0:Dis)> <portbasestag(1:En,0:Dis)> <stag(0..4095)> <egstagctlen(1:En,0:Dis)> <egstagcon(1:En,0:Dis)> <taggedbitmap(6:0)>"},

-    {"create",          doVlanCreate,           1,      "vlan create <vid(0..4095)>"},

-    {"destroy",         doVlanDestroy,          1,      "vlan destroy [ <vid(0..4095)> | <vidRange(vid0-vid1)> ]"},

-    {"destroyAll",      doVlanDestroyAll,       0,      "vlan destroyAll [ <restoreDefVlan(0:false,1:true)> | ]"},

-    {"dump",            doVlanDump,             0,      "vlan dump [ <vid(0..4095)> | <vidRange(vid0-vid1)> | ]"},

-    {"addPortMem",      doVlanAddPortMem,       2,      "vlan addPortMem <vid(0..4095)> <port(0..6)>"},

-    {"delPortMem",      doVlanDelPortMem,       2,      "vlan addPortMem <vid(0..4095)> <port(0..6)>"},

-    {"set",             doVlanSet,              0,      NULL},

-    {"get",             doVlanGet,              0,      NULL},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T l2ClearCmds[] =

-{

-    {"mac",              doMacAddr,          CMD_NO_PARA,    "l2 clear mac"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T l2DelCmds[] =

-{

-    {"mac",             doMacAddr,           3,    "l2 del mac <mac(12'hex)> [ vid <vid(0..4095)> | fid <fid(0..15)> ]"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T l2AddCmds[] =

-{

-    {"mac",             doMacAddr,           7,    "l2 add mac <static(0:dynamic,1:static)> <unauth(0:auth,1:unauth)> <mac(12'hex)> <portlist(uintlist)> [ vid <vid(0..4095)> | fid <fid(0..15)> ] <src_mac_forward=(0:default,1:cpu-exclude,2:cpu-include,3:cpu-only,4:drop)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T l2SetCmds[] =

-{

-    {"macAddrAgeOut",   doMacAddrAgeOut,    1,    "l2 set macAddrAgeOut <time(1, 1000000)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T l2GetCmds[] =

-{

-    {"mac",             doGetMacAddr,       3,              "l2 get mac <mac(12'hex)> [ vid <vid(0..4095)> | fid <fid(0..15)> ]"},

-    {"macAddrAgeOut",   doMacAddrAgeOut,    CMD_NO_PARA,    "l2 get macAddrAgeOut"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T l2DumpCmds[] =

-{

-    {"mac",                doDumpMacAddr,        0,    "l2 dump mac"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T l2Cmds[] =

-{

-    {"add",         doL2Add,        0,        NULL},

-    {"del",         doL2Del,        0,        NULL},

-    {"clear",       doL2Clear,      0,        NULL},

-    {"get",         doL2Get,        0,        NULL},

-    {"set",         doL2Set,        0,        NULL},

-    {"dump",        doL2Dump,       0,        NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T lagGetCmds[] =

-{

-    {"member",      doLagMember,    1,              "lag get member group_id(0 or 1)"},

-    {"dstInfo",     doLagDstInfo,   CMD_NO_PARA,    "lag get dstInfo"},

-    {"ptseed",      doLagPtseed,    CMD_NO_PARA,    "lag get ptseed"},

-    {"hashtype",    doLagHashtype,  CMD_NO_PARA,    "lag get hashtype"},

-    {"state",       doLagState,     CMD_NO_PARA,    "lag get state"},

-    {"spsel",       doLagSpsel,     CMD_NO_PARA,    "lag get spsel"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T lagSetCmds[] =

-{

-    {"member",       doLagMember,        4,    "lag set member <group_id(0 or 1)> <member_index(0..3)> <enable(0,1)> <port index(0..6)>"},

-    {"dstInfo",      doLagDstInfo,       7,    "lag set dstInfo <sp(1:En,0:Dis)> <sa(1:En,0:Dis)> <da(1:En,0:Dis)> <sip(1:En,0:Dis)> <dip(1:En,0:Dis)> <sport(1:En,0:Dis)> <dport(1:En,0:Dis)>"},

-    {"ptseed",       doLagPtseed,        1,    "lag set ptseed <hex32>"},

-    {"hashtype",     doLagHashtype,      1,    "lag set hashtype <0-crc32lsb;1-crc32msb;2-crc16;3-xor4>"},

-    {"state",        doLagState,         1,    "lag set state <state(1:En,0:Dis)>"},

-    {"spsel",        doLagSpsel,         1,    "lag set spsel <soure port enable(1:En,0:Dis)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T lagCmds[] =

-{

-    {"get",          doLagGet,        0,        NULL},

-    {"set",          doLagSet,        0,        NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T stpGetCmds[] =

-{

-    {"portstate",    doStpPortstate,  2,    "stp get portstate <port(0..6)> <fid(0..15)>"},

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T stpSetCmds[] =

-{

-    {"portstate",    doStpPortstate,  3,    "stp set portstate <port(0..6)> <fid(0..15)> <state(0:disable,1:listen,2:learn,3:forward)>"},

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T stpCmds[] =

-{

-    {"get",         doStpGet,           0,      NULL},

-    {"set",         doStpSet,           0,      NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T mirrorSetCmds[] =

-{

-    {"session",        doMirrorSetSession,       6,      "mirror set session <sid(0,1)> <dst_port(UINT)> <state(1:En,0:Dis)> <tag(1:on, 0:off)> <list(UINTLIST)> <dir(0:none,1:tx,2:rx,3:both)>"},

-    {"session-enable", doMirrorSetSessionEnable, 2,      "mirror set session-enable <sid(0,1)> <state(1:En,0:Dis)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T mirrorAddCmds[] =

-{

-    {"session-rlist",  doMirrorAddRlist,       2,      "mirror add session-rlist <sid(0,1)> <list(UINTLIST)>"},

-    {"session-tlist",  doMirrorAddTlist,       2,      "mirror add session-tlist <sid(0,1)> <list(UINTLIST)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T mirrorGetCmds[] =

-{

-    {"session",        doMirrorGetSid,       1,      "mirror get session <sid(0,1)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T mirrorDelCmds[] =

-{

-    {"session",        doMirrorDelSid,       1,      "mirror del session <sid(0,1)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T mirrorCmds[] =

-{

-    {"set",         doMirrorSet,        0,      NULL},

-    {"add",         doMirrorAdd,        0,      NULL},

-    {"get",         doMirrorGet,        0,      NULL},

-    {"del",         doMirrorDel,        0,      NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T mibClearCmds[] =

-{

-    {"port",        doMibClearPort,     1,      "mib clear port <port(0..6)>"},

-    {"all",         doMibClearPort,     0,      "mib clear all"},

-    {"acl",         doMibClearAcl,      0,      "mib clear acl"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T mibGetCmds[] =

-{

-    {"port",        doMibGetPort,       1,      "mib get port <port(0..6)>"},

-    {"acl",         doMibGetAcl,        1,      "mib get acl <event(0..7)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T mibCmds[] =

-{

-    {"clear",       doMibClear,         0,      NULL},

-    {"get",         doMibGet,           0,      NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T qosGetCmds[] =

-{

-    {"scheduleAlgo",    doQosScheduleAlgo,      2,  "qos get scheduleAlgo <portlist(UINTLIST)> <queue(UINT)>"},

-    {"trustMode",       doQosTrustMode,         1,  "qos get trustMode <portlist(UINTLIST)>"},

-    {"pri2Queue",       doQosPri2Queue,         0,  "qos get pri2Queue"},

-    {"dscp2Pri",        doQosDscp2Pri,          1,  "qos get dscp2Pri <dscp(0..63)>"},

-    {"rateLimitEnable", doQosRateLimitEnable,   1,  "qos get rateLimitEnable <portlist(UINTLIST)>"},

-    {"rateLimit",       doQosRateLimit,         1,  "qos get rateLimit <portlist(UINTLIST)>"},

-    {"portPriority",    doQosPortPriority,      1,  "qos get portPriority <portlist(UINTLIST)>"},

-    {"rateLmtExMngFrm", doQosRateLimitExMngFrm, 0,  "qos get rateLmtExMngFrm"},

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T qosSetCmds[] =

-{

-    {"scheduleAlgo",    doQosScheduleAlgo,      4,  "qos set scheduleAlgo <portlist(UINTLIST)> <queue(UINT)> <scheduler(0:SP,1:WRR,2:WFQ)> <weight(0..128)>, weight 0 is valid only on sp mode"},

-    {"trustMode",       doQosTrustMode,         2,  "qos set trustMode <portlist(UINTLIST)> <mode(0:port,1:1p-port,2:dscp-port,3:dscp-1p-port>"},

-    {"pri2Queue",       doQosPri2Queue,         2,  "qos set pri2Queue <priority(0..7)> <queue(0..7)>"},

-    {"dscp2Pri",        doQosDscp2Pri,          2,  "qos set dscp2Pri <dscp(0..63)> <priority(0..7)>"},

-    {"rateLimitEnable", doQosRateLimitEnable,   3,  "qos set rateLimitEnable <portlist(UINTLIST)> <dir(0:egress,1:ingress)> <rate_en(1:En,0:Dis)>"},

-    {"rateLimit",       doQosRateLimit,         5,  "qos set rateLimit <portlist(UINTLIST)> <I_CIR(0..80000)> <I_CBS(0..127)> <E_CIR(0..80000)> <E_CBS(0..127)>"},

-    {"portPriority",    doQosPortPriority,      2,  "qos set portPriority <portlist(UINTLIST)> <priority(0..7)>"},

-    {"rateLmtExMngFrm", doQosRateLimitExMngFrm, 2,  "qos set rateLmtExMngFrm <dir(0:egress)> <en(0:include,1:exclude)>"},

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T qosCmds[] =

-{

-    {"get",          doQosGet,        0,        NULL},

-    {"set",          doQosSet,        0,        NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T diagSetCmds[] =

-{

-    {"txComply",    doDiagTxComply,     2,      "diag set txComply <phy(0..5)> <mode(0..8)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T diagGetCmds[] =

-{

-    {"txComply",    doDiagTxComply,     1,      "diag get txComply <phy(0..5)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T diagCmds[] =

-{

-    {"set",         doDiagSet,          0,      NULL},

-    {"get",         doDiagGet,          0,      NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T ledSetCmds[] =

-{

-    {"mode",        doLedMode,          1,      "led set mode <mode(0:disable, 1..3:2 LED, 4:user-define)>"},

-    {"state",       doLedState,         2,      "led set state <led(0..1)> <state(1:En,0:Dis)>"},

-    {"usr",         doLedUsrDef,        4,      "led set usr <led(0..1)> <polarity(0:low, 1:high)> <on_evt(7'bin)> <blink_evt(10'bin)>"},

-    {"time",        doLedBlkTime,       1,      "led set time <time(0..5:32ms~1024ms)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T ledGetCmds[] =

-{

-    {"mode",        doLedMode,          CMD_NO_PARA,      "led get mode"},

-    {"state",       doLedState,         1,                "led get state <led(0..1)>"},

-    {"usr",         doLedUsrDef,        1,                "led get usr <led(0..1)>"},

-    {"time",        doLedBlkTime,       CMD_NO_PARA,      "led get time"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T ledCmds[] =

-{

-    {"set",         doLedSet,           0,      NULL},

-    {"get",         doLedGet,           0,      NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T showCmds[] =

-{

-    {"version",     doShowVersion,        0,        NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T secGetCmds[] =

-{

-    {"stormEnable",     doStormEnable,   2,  "sec get stormEnable <port(0..6)> <type(0:bcst,1:mcst,2:ucst)>"},

-    {"stormRate",       doStormRate,     2,  "sec get stormRate <port(0..6)> <type(0:bcst,1:mcst,2:ucst)>"},

-    {"fldMode",         doFldMode,       2,  "sec get fldMode <port(0..6)> <type(0:bcst,1:mcst,2:ucst,3:qury>"},

-    {"saLearning",      doSaLearning,    1,  "sec get saLearning <port(0..6)>"},

-    {"saLimit",         doSaLimit,       1,  "sec get saLimit <port(0..6)>"},

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T secSetCmds[] =

-{

-    {"stormEnable",     doStormEnable,   3,  "sec set stormEnable <port(0..6)> <type(0:bcst,1:mcst,2:ucst)> <en(1:En,0:Dis)>"},

-    {"stormRate",       doStormRate,     4,  "sec set stormRate <port(0..6)> <type(0:bcst,1:mcst,2:ucst)> <count(0..255)> <unit(0:64k,1:256k,2:1M,3:4M,4:16M)>"},

-    {"fldMode",         doFldMode,       3,  "sec set fldMode <port(0..6)> <type(0:bcst,1:mcst,2:ucst,3:qury> <en(1:En,0:Dis)>"},

-    {"saLearning",      doSaLearning,    2,  "sec set saLearning <port(0..6)> <learn(0:disable,1:enable)>"},

-    {"saLimit",         doSaLimit,       3,  "sec set saLimit <port(0..6)> <mode(0:disable,1:enable)> <count(0..4095)>"},

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T secCmds[] =

-{

-    {"get",          doSecGet,        0,        NULL},

-    {"set",          doSecSet,        0,        NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T switchSetCmds[] =

-{

-    {"cpuPortEn",   doSwitchCpuPortEn,   1,              "switch set cpuPortEn <cpu_en(1:En,0:Dis)>"},

-    {"cpuPort",     doSwitchCpuPort,     1,              "switch set cpuPort <port_number>"},

-    {"phyLCIntrEn",     doSwitchPhyLCIntrEn,     2,      "switch set phyLCIntrEn <phy(0..6)> <(1:En,0:Dis)>"},

-    {"phyLCIntrSts",    doSwitchPhyLCIntrSts,    2,      "switch set phyLCIntrSts <phy(0..6)> <(1:Clear)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T switchGetCmds[] =

-{

-    {"cpuPortEn",   doSwitchCpuPortEn,   CMD_NO_PARA,      "switch get cpuPortEn"},

-    {"cpuPort",     doSwitchCpuPort,     CMD_NO_PARA,      "switch get cpuPort"},

-    {"phyLCIntrEn",     doSwitchPhyLCIntrEn,     1,        "switch get phyLCIntrEn <phy(0..6)>"},

-    {"phyLCIntrSts",    doSwitchPhyLCIntrSts,    1,        "switch get phyLCIntrSts <phy(0..6)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T switchCmds[] =

-{

-    {"set",         doSwitchSet,        0,      NULL},

-    {"get",         doSwitchGet,        0,      NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T aclSetCmds[] =

-{

-    {"en",              doAclEn,            1,                     "acl set en <en(1:En,0:Dis)>"},

-    {"rule",            doAclRule,          CMD_VARIABLE_PARA,     "acl set rule <idx(0..127)>\n <state(0:Dis,1:En)> <reverse(0:Dis,1:En)> <end(0:Dis,1:En)>\n <portmap(7'bin)><ipv6(0:Dis,1:En,2:Not care)>\n[ dmac <dmac(12'hex)> <dmac_mask(12'hex)> ]\n[ smac <smac(12'hex)> <smac_mask(12'hex)> ]\n[ stag <stag(4'hex)> <stag_mask(4'hex)> ]\n[ ctag <ctag(4'hex)> <ctag_mask(4'hex)> ]\n[ etype <etype(4'hex)> <etype_mask(4'hex)> ]\n[ dip <dip(IPADDR)> <dip_mask(IPADDR)> ]\n[ sip <sip(IPADDR)> <sip_mask(IPADDR)> ]\n[ dscp <dscp(2'hex)> <dscp_mask(2'hex)> ]\n[ protocol <protocol(12'hex)> <protocol_mask(12'hex)> ]\n[ dport <dport(4'hex)> <dport_mask(4'hex)> ]\n[ sport <sport(4'hex)> <sport_mask(4'hex)> ]\n[ flow_label <flow_label(4'hex)> <flow_label_mask(4'hex)> ]\n[ udf <udf(4'hex)> <udf_mask(4'hex)> ] "},

-    {"udfRule",         doAclUdfRule,       7,                     "acl set udfRule <idx(0..15)> <mode(0:pattern, 1:threshold)> [ <pat(4'hex)> <mask(4'hex)> | <low(4'hex)> <high(4'hex)> ] <start(0:MAC header, 1:L2 payload, 2:IPv4 header, 3:IPv6 header, 4:L3 payload, 5:TCP header, 6:UDP header, 7: L4 payload)> <offset(0..127,unit:2 bytes)> <portmap(7'bin)>"},

-    {"action",          doAclAction,        CMD_VARIABLE_PARA,     "acl set action <idx(0..127)> \n[ forward <forward(0:Default,4:Exclude CPU,5:Include CPU,6:CPU only,7:Drop)> ]\n[ egtag <egtag(0:Default,1:Consistent,4:Untag,5:Swap,6:Tag,7:Stack)> ]\n[ mirrormap <mirrormap(2'bin)> ]\n[ priority <priority(0..7)> ]\n[ redirect <redirect(0:Dst,1:Vlan)> <portmap(7'bin)> ]\n[ leaky_vlan <leaky_vlan(1:En,0:Dis)> ]\n[ cnt_idx <cnt_idx(0..63)> ]\n[ rate_idx <rate_idx(0..31)> ] \n[ attack_idx <attack_idx(0..95)> ] \n[ vid <vid(0..4095)> ] \n[ manage <manage(1:En,0:Dis)> ] \n[ bpdu <bpdu(1:En,0:Dis)> ]\n[ class <class(0:Original,1:Defined)>[0..7] ]\n[ drop_pcd <drop_pcd(0:Original,1:Defined)> [red <red(0..7)>][yellow <yellow(0..7)>][green <green(0..7)>] ]\n[ color <color(0:Defined,1:Trtcm)> [ <defined_color(0:Dis,1:Green,2:Yellow,3:Red)> | <trtcm_idx(0..31)> ] ]"},

-    {"trtcm",           doAclTrtcm,         5,                     "acl set trtcm <idx(1..31)> <cir(4'hex)> <pir(4'hex)> <cbs(4'hex)> <pbs(4'hex)>"},

-    {"trtcmEn",         doAclTrtcmEn,       1,                     "acl set trtcmEn <en(1:En,0:Dis)>"},

-    {"portEn",          doAclPortEn,        2,                     "acl set portEn <port(0..6)> <en(1:En,0:Dis)>"},

-    {"dropEn",          doAclDropEn,        2,                     "acl set dropEn <port(0..6)> <en(1:En,0:Dis)>"},

-    {"dropThrsh",       doAclDropThrsh,     5,                     "acl set dropThrsh <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> <high(0..2047)> <low(0..2047)>"},

-    {"dropPbb",         doAclDropPbb,       4,                     "acl set dropPbb <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> <probability(0..1023)>"},

-    {"meter",           doAclMeter,         3,                     "acl set meter <idx(0..31)> <en(1:En,0:Dis)> <rate(0..65535)>\n Note: Limit rate = rate * 64Kbps"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T aclGetCmds[] =

-{

-    {"en",              doAclEn,            CMD_NO_PARA,    "acl get en"},

-    {"rule",            doAclRule,          1,              "acl get rule <idx(0..127)> "},

-    {"udfRule",         doAclUdfRule,       1,              "acl get udfRule <idx(0..15)>"},

-    {"action",          doAclAction,        1,              "acl get action <idx(0..127)>"},

-    {"trtcm",           doAclTrtcm,         1,              "acl get trtcm <idx(1..31)>"},

-    {"trtcmEn",         doAclTrtcmEn,       CMD_NO_PARA,    "acl get trtcmEn"},

-    {"portEn",          doAclPortEn,        1,              "acl get portEn <port(0..6)>"},

-    {"dropEn",          doAclDropEn,        1,              "acl get dropEn <port(0..6)>"},

-    {"dropThrsh",       doAclDropThrsh,     3,              "acl get dropThrsh <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)>"},

-    {"dropPbb",         doAclDropPbb,       3,              "acl get dropPbb <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)>"},

-    {"meter",           doAclMeter,         1,              "acl get meter <idx(0..31)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T aclDelCmds[] =

-{

-    {"rule",        doAclRmvRule,          1,         "acl del rule <idx(0..127)>"},

-    {"udfRule",     doAclRmvUdfRule,       1,         "acl del udfRule <idx(0..15)>"},

-    {"action",      doAclRmvAction,        1,         "acl del action <idx(0..127)>"},

-    {"trtcm",       doAclRmvTrtcm,         1,         "acl del trtcm <idx(0..31)>"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T aclClearCmds[] =

-{

-    {"rule",        doAclRmvRule,          CMD_NO_PARA,       "acl clear rule"},

-    {"udfRule",     doAclRmvUdfRule,       CMD_NO_PARA,       "acl clear udfRule"},

-    {"action",      doAclRmvAction,        CMD_NO_PARA,       "acl clear action"},

-    {"trtcm",       doAclRmvTrtcm,         CMD_NO_PARA,       "acl clear trtcm"},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T aclCmds[] =

-{

-    {"set",         doAclSet,           0,      NULL},

-    {"get",         doAclGet,           0,      NULL},

-    {"del",         doAclDel,           0,      NULL},

-    {"clear",       doAclClear,         0,      NULL},

-    {"dump",        doAclDump,          0,      NULL},

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-static AIR_CMD_T Cmds[] =

-{

-    {"reg",         doReg,          0,      NULL},

-    {"phy",         doPhy,          0,      NULL},

-    {"port",        doPort,         0,      NULL},

-    {"vlan",        doVlan,         0,      NULL},

-    {"l2",          doL2,           0,      NULL},

-    {"lag",         doLag,          0,      NULL},

-    {"stp",         doStp,          0,      NULL},

-    {"mirror",      doMirror,       0,      NULL},

-    {"mib",         doMib,          0,      NULL},

-    {"qos",         doQos,          0,      NULL},

-    {"diag",        doDiag,         0,      NULL},

-    {"led",         doLed,          0,      NULL},

-    {"switch",      doSwitch,       0,      NULL},

-    {"show",        doShow,         0,      NULL},

-    {"sec",         doSec,          0,      NULL},

-    {"acl",         doAcl,          0,      NULL},

-    {"sptag",       doSptag,        0,      NULL},

-

-    /* last entry, do not modify this entry */

-    {NULL, NULL, 0, NULL},

-};

-

-/* EXPORTED SUBPROGRAM BODIES

-*/

-

-/* LOCAL SUBPROGRAM BODIES

-*/

-static BOOL_T

-_strcmp(const char *s1, const char *s2)

-{

-    while(*s1 == *s2++)

-        if (*s1++ == '\0')

-            return (0);

-    return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 -1));

-}

-

-static C8_T *

-_strtok_r(

-    C8_T *s,

-    const C8_T *delim,

-    C8_T **last)

-{

-    char *spanp;

-    int c = 0, sc = 0;

-    char *tok;

-

-    if (s == NULL && (s = *last) == NULL)

-    {

-        return (NULL);

-    }

-

-    /*

-     * Skip (span) leading delimiters (s += strspn(s, delim), sort of).

-     */

-    for (;;)

-    {

-        c = *s++;

-        spanp = (char *)delim;

-        do

-        {

-            if (c == (sc = *spanp++))

-            {

-                break;

-            }

-        } while (sc != 0);

-        if (sc == 0)

-        {

-            break;

-        }

-    }

-

-    if (c == 0)

-    {   /* no non-delimiter characters */

-        *last = NULL;

-        return (NULL);

-    }

-    tok = s - 1;

-

-    /*

-     * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).

-     * Note that delim must have one NUL; we stop if we see that, too.

-     */

-    for (;;)

-    {

-        c = *s++;

-        spanp = (char *)delim;

-        do

-        {

-            if ((sc = *spanp++) == c)

-            {

-                if (c == 0)

-                {

-                    s = NULL;

-                }

-                else

-                {

-                    s[-1] = 0;

-                }

-                *last = s;

-                return (tok);

-            }

-        } while (sc != 0);

-    }

-    /* NOTREACHED */

-}

-

-static C8_T *

-_strtok(

-    C8_T *s,

-    const C8_T *delim,

-    C8_T **last)

-{

-    return _strtok_r(s, delim, last);

-}

-

-UI32_T

-_strtoul(

-    const C8_T *cp,

-    C8_T **endp,

-    UI32_T base)

-{

-    UI32_T result = 0, value = 0;

-

-    if (!base)

-    {

-        base = 10;

-        if (*cp == '0')

-        {

-            base = 8;

-            cp++;

-            if ((TOLOWER(*cp) == 'x') && isxdigit(cp[1]))

-            {

-                cp++;

-                base = 16;

-            }

-        }

-    }

-    else if (base == 16)

-    {

-        if (cp[0] == '0' && TOLOWER(cp[1]) == 'x')

-        {

-            cp += 2;

-        }

-    }

-    while (isxdigit(*cp) &&

-           (value = isdigit(*cp) ? *cp-'0' : TOLOWER(*cp)-'a'+10) < base)

-    {

-        result = result*base + value;

-        cp++;

-    }

-    if (endp)

-    {

-        *endp = (char *)cp;

-    }

-    return result;

-}

-

-static I32_T

-_strtol(

-    const C8_T *cp,

-    C8_T **endp,

-    UI32_T base)

-{

-    if(*cp=='-')

-    {

-        return -_strtoul(cp + 1, endp, base);

-    }

-    return _strtoul(cp, endp, base);

-}

-

-static AIR_ERROR_NO_T

-_str2mac(

-        C8_T *str,

-        C8_T *mac)

-{

-    UI32_T i = 0;

-    C8_T tmpstr[3];

-

-    /* check str */

-    AIR_CHECK_PTR(str);

-    AIR_PARAM_CHK(strlen(str) != AIR_MAC_LEN, AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(mac);

-

-    for(i=0; i<6; i++)

-    {

-        strncpy(tmpstr, str+(i*2), 2);

-        tmpstr[2] = '\0';

-        mac[i] = _strtoul(tmpstr, NULL, 16);

-    }

-

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-_str2ipv4(

-    const C8_T *ptr_str,

-    UI32_T     *ptr_addr)

-{

-    UI32_T value = 0, idx = 0, shift = 0;

-

-    AIR_CHECK_PTR(ptr_str);

-    AIR_CHECK_PTR(ptr_addr);

-

-    /* e.g. 192.168.1.2, strlen = 11 */

-    for (idx = 0; idx < strlen(ptr_str); idx++)

-    {

-        if (('0' <= ptr_str[idx]) && ('9' >= ptr_str[idx]))

-        {

-            value = (value * 10) + (ptr_str[idx] - '0');

-        }

-        else if ('.' == ptr_str[idx])

-        {

-            CMD_CHECK_PARA(value, <, 256); /* Error: invalid value */

-            CMD_CHECK_PARA(shift, <, 4);   /* Error: mem-overwrite */

-            *ptr_addr |= value << (24 - shift * 8);

-            shift += 1;

-            value = 0;

-        }

-        else

-        {

-            return AIR_E_BAD_PARAMETER; /* Error: not a digit number or dot */

-        }

-    }

-    CMD_CHECK_PARA(value, <, 256); /* Error: invalid value */

-    CMD_CHECK_PARA(shift, ==, 3);  /* Error: not an ipv4 addr */

-    *ptr_addr |= value << (24 - shift * 8);

-

-    return AIR_E_OK;

-}

-

-AIR_ERROR_NO_T

-_str2ipv6(

-    const C8_T  *ptr_str,

-    UI8_T       *ptr_addr)

-{

-    UI32_T              hex_value = 0, dec_value = 0, idx = 0;

-    BOOL_T              double_colon = FALSE, ipv4_compatible = FALSE;

-    UI32_T              double_colon_pos = 0, last_pos = 0;

-    UI8_T               tmp_ipv6[16] = {0};

-

-    AIR_CHECK_PTR(ptr_str);

-    AIR_CHECK_PTR(ptr_addr);

-

-    /* e.g. invalid:

-     * 3ffe::c0a8:0:      last cannot be colon except double-colon

-     * 3ffe:::c0a8:0      triple-colon

-     * 3ffe::c0a8::0      two double-colons

-     */

-

-    /* e.g. valid:

-     * 3ffe::c0a8:0       strlen = 12 (double-colon in middle)

-     * 3ffe:c0a8:0::      strlen = 13 (double-colon in last)

-     * ::3ffe:c0a8:0      strlen = 13 (double-colon in first)

-     * 3ffe::192.168.0.0  strlen = 17 (IPv4-compatible address)

-     */

-    for (idx = 0; idx < strlen(ptr_str); idx++)

-    {

-        if (('0' <= ptr_str[idx]) && ('9' >= ptr_str[idx]))

-        {

-            hex_value = (hex_value << 4) + (ptr_str[idx] - '0');

-            dec_value = (dec_value * 10) + (ptr_str[idx] - '0');

-        }

-        else if (('a' <= ptr_str[idx]) && ('f' >= ptr_str[idx]))

-        {

-            hex_value = (hex_value << 4) + (ptr_str[idx] - 'a') + 10;

-        }

-        else if (('A' <= ptr_str[idx]) && ('F' >= ptr_str[idx]))

-        {

-            hex_value = (hex_value << 4) + (ptr_str[idx] - 'A') + 10;

-        }

-        else if (':' == ptr_str[idx])

-        {

-            /* must belong to double-colon, calculate from last */

-            if (0 == idx)

-            {

-                continue;

-            }

-            /* not the first ch but a double-colon */

-            else if (':' == ptr_str[idx - 1])

-            {

-                CMD_CHECK_PARA(double_colon, ==, FALSE); /* Error: triple-colon or two double-colons */

-                double_colon = TRUE;

-            }

-            /* not the first ch and a double-colon */

-            else

-            {

-                CMD_CHECK_PARA(double_colon_pos, <, 15); /* Error: only 16 units for UI8_T  */

-                CMD_CHECK_PARA(last_pos,         <, 15); /* Error: only 16 units for UI8_T  */

-                tmp_ipv6[last_pos]     = (UI8_T)((hex_value >> 8) & 0xff);

-                tmp_ipv6[last_pos + 1] = (UI8_T)((hex_value >> 0) & 0xff);

-                double_colon_pos += (FALSE == double_colon)? 2 : 0;

-                last_pos += 2;

-                hex_value = 0;

-                dec_value = 0;

-            }

-        }

-        else if ('.' == ptr_str[idx])

-        {

-            CMD_CHECK_PARA(last_pos, <, 16); /* Error: only 16 units for UI8_T  */

-            tmp_ipv6[last_pos] = dec_value;

-            last_pos += 1;

-            dec_value = 0;

-            ipv4_compatible = TRUE;

-        }

-        else

-        {

-            return AIR_E_BAD_PARAMETER; /* Error: not a hex number or colon */

-        }

-    }

-

-    /* last data */

-    if (':' != ptr_str[idx - 1])

-    {

-        if (FALSE == ipv4_compatible)

-        {

-            CMD_CHECK_PARA(last_pos, <, 15); /* Error: only 16 units for UI8_T  */

-            tmp_ipv6[last_pos]     = (UI8_T)((hex_value >> 8) & 0xff);

-            tmp_ipv6[last_pos + 1] = (UI8_T)((hex_value >> 0) & 0xff);

-            last_pos += 2;

-        }

-        else

-        {

-            CMD_CHECK_PARA(last_pos, <, 16); /* Error: only 16 units for UI8_T  */

-            tmp_ipv6[last_pos] = dec_value;

-            last_pos += 1;

-        }

-    }

-    else

-    {

-        if (':' != ptr_str[idx - 2])

-        {

-            return AIR_E_BAD_PARAMETER; /* Error: last cannot be colon except double-colon */

-        }

-    }

-

-    /* move tmp_ipv6 to ptr_value */

-    if (TRUE == double_colon)

-    {

-        /* e.g.

-         * 3ffe::c0a8:0       double_colon_pos = 2, last_pos = 4+2, tmp_ipv6 = {3f,fe,c0,a8,00,00,...}

-         * 3ffe:c0a8:0::      double_colon_pos = 6, last_pos = 6,   tmp_ipv6 = {3f,fe,c0,a8,00,00,...}

-         * ::3ffe:c0a8:0      double_colon_pos = 0, last_pos = 4+2, tmp_ipv6 = {3f,fe,c0,a8,00,00,...}

-         * 3ffe::192.168.0.0  double_colon_pos = 2, last_pos = 5+1, tmp_ipv6 = {3f,fe,c0,a8,00,00,...}

-         *

-         *                                 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

-         * 3ffe::c0a8:0       ptr_value = {3f,fe,--,--,--,--,--,--,--,--,--,--,--,--,--,--}

-         * 3ffe:c0a8:0::      ptr_value = {3f,fe,c0,a8,00,00,--,--,--,--,--,--,--,--,--,--}

-         * ::3ffe:c0a8:0      ptr_value = {--,--,--,--,--,--,--,--,--,--,--,--,--,--,--,--}

-         * 3ffe::192.168.0.0  ptr_value = {3f,fe,--,--,--,--,--,--,--,--,--,--,--,--,--,--}

-         */

-        for (idx = 0; idx < double_colon_pos; idx++)

-        {

-            ptr_addr[idx] = tmp_ipv6[idx];

-        }

-        /* e.g.

-         *                                 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f

-         * 3ffe::c0a8:0       ptr_value = {3f,fe,--,--,--,--,--,--,--,--,--,--,c0,a8,00,00}

-         * 3ffe:c0a8:0::      ptr_value = {3f,fe,c0,a8,00,00,--,--,--,--,--,--,--,--,--,--}

-         * ::3ffe:c0a8:0      ptr_value = {--,--,--,--,--,--,--,--,--,--,3f,fe,c0,a8,00,00}

-         * 3ffe::192.168.0.0  ptr_value = {3f,fe,--,--,--,--,--,--,--,--,--,--,c0,a8,00,00}

-         */

-        for (idx = double_colon_pos; idx < last_pos; idx++)

-        {

-            ptr_addr[16 - (last_pos - idx)] = tmp_ipv6[idx];

-        }

-    }

-    else

-    {

-        for (idx = 0; idx < 16; idx++)

-        {

-            ptr_addr[idx] = tmp_ipv6[idx];

-        }

-    }

-

-    return AIR_E_OK;

-}

-

-void

-_showIpv6Str(

-    const UI8_T *ptr_ipv6,

-    C8_T *ptr_str)

-{

-    UI32_T idx = 0, next = 0, last = 16;

-    UI32_T cont_zero = 0;

-

-    while (idx < last)

-    {

-        if ((0 == cont_zero) && (0 == ptr_ipv6[idx]) && (0 == ptr_ipv6[idx + 1]))

-        {

-            next = idx + 2;

-

-            while (next < last)

-            {

-                if ((ptr_ipv6[next]) || (ptr_ipv6[next + 1]))

-                {

-                    AIR_PRINT(

-                            ptr_str + strlen(ptr_str),

-                            40 - strlen(ptr_str),

-                            "%s", (cont_zero) ? (":") : (":0"));

-                    break;

-                }

-

-                if (0 == cont_zero)

-                {

-                    cont_zero = 1;

-                }

-                next += 2;

-            }

-

-            if (next == last)

-            {

-

-                AIR_PRINT(

-                        ptr_str + strlen(ptr_str),

-                        40 - strlen(ptr_str),

-                        "%s", (cont_zero) ? ("::") : (":0"));

-            }

-

-            idx = next;

-        }

-        else

-        {

-            if (idx)

-            {

-                AIR_PRINT(

-                    ptr_str + strlen(ptr_str),

-                    40 - strlen(ptr_str),

-                    ":");

-            }

-

-            if (ptr_ipv6[idx])

-            {

-                AIR_PRINT(

-                    ptr_str + strlen(ptr_str),

-                    40 - strlen(ptr_str),

-                    "%0x%02x", ptr_ipv6[idx], ptr_ipv6[idx + 1]);

-            }

-            else

-            {

-                AIR_PRINT(

-                    ptr_str + strlen(ptr_str),

-                    40 - strlen(ptr_str),

-                    "%0x", ptr_ipv6[idx + 1]);

-            }

-

-            idx += 2;

-        }

-    }

-}

-

-static AIR_ERROR_NO_T

-_hex2bit(

-        const UI32_T hex,

-        UI32_T *ptr_bit)

-{

-    UI32_T i = 0;

-

-    /* Mistake proofing */

-    AIR_CHECK_PTR(ptr_bit);

-

-    (*ptr_bit) = 0;

-    for(i=0; i<AIR_MAX_NUM_OF_PORTS; i++)

-    {

-        if(hex & BIT(i))

-        {

-            (*ptr_bit) |= BITS_OFF_L(1UL, 4*(AIR_MAX_NUM_OF_PORTS - i - 1), 4);

-        }

-    }

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-_hex2bitstr(

-        const UI32_T hex,

-        C8_T *ptr_bit_str,

-        UI32_T str_len)

-{

-    UI32_T i = 0;

-    C8_T str_bitmap[AIR_MAX_NUM_OF_PORTS+1];

-

-    /* Mistake proofing */

-    AIR_CHECK_PTR(ptr_bit_str);

-    AIR_PARAM_CHK(str_len <= AIR_MAX_NUM_OF_PORTS, AIR_E_BAD_PARAMETER);

-

-    memset(str_bitmap, 0, AIR_MAX_NUM_OF_PORTS+1);

-

-    for(i=0; i<AIR_MAX_NUM_OF_PORTS; i++)

-    {

-        if(hex & BIT(i))

-        {

-            str_bitmap[i] = '1';

-        }

-        else

-        {

-            str_bitmap[i] = '-';

-        }

-    }

-    str_bitmap[i] = '\0';

-    strncpy(ptr_bit_str, str_bitmap, i+1);

-

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-_portListStr2Ary(

-    const C8_T *str,

-    UI32_T *ary,

-    const UI32_T ary_num)

-{

-    UI32_T i = 0;

-    UI32_T str_len = 0;

-    UI32_T val = 0;

-    C8_T *str2;

-    C8_T *pch;

-    C8_T *last;

-

-    /* Mistake proofing */

-    AIR_CHECK_PTR(str);

-    AIR_CHECK_PTR(ary);

-    AIR_PARAM_CHK(0 == ary_num, AIR_E_BAD_PARAMETER);

-

-    /* Allocate new string */

-    str_len = strlen(str);

-    str2 = AIR_MALLOC(str_len+1);

-    AIR_CHECK_PTR(str2);

-    memset(str2, 0, str_len+1);

-    strncpy(str2, str, str_len+1);

-

-    /* clear array */

-    memset(ary, 0, ary_num*4);

-

-    /* split string by ',' */

-    pch = _strtok(str2, ",", &last);

-    while(NULL != pch)

-    {

-        val = _strtoul(pch, NULL, 0);

-        ary[val/32] |= BIT(val%32);

-        pch = _strtok(NULL, ",", &last);

-    }

-

-    AIR_FREE(str2);

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-doRegRead(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    UI32_T reg = 0, val = 0;

-

-    reg = _strtoul(argv[0], NULL, 16);

-    aml_readReg(0, reg, &val);

-    AIR_PRINT("Read reg=0x%x, value=0x%x\n", reg, val);

-

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-doRegWrite(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    UI32_T reg = 0, val = 0;

-

-    reg = _strtoul(argv[0], NULL, 16);

-    val = _strtoul(argv[1], NULL, 16);

-    aml_writeReg(0, reg, val);

-    AIR_PRINT("Write reg=0x%x, value=0x%x\n", reg, val);

-

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-doReg(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(regCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doPhyCL22Read(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    UI32_T port = 0, reg = 0, val = 0;

-

-    port = _strtoul(argv[0], NULL, 0);

-    reg  = _strtoul(argv[1], NULL, 16);

-    aml_readPhyReg(0, port, reg, &val);

-    AIR_PRINT("Phy read port=%d, reg=0x%x, value=0x%x\n", port, reg, val);

-

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-doPhyCL22Write(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    UI32_T port = 0, reg = 0, val = 0;

-

-    port = _strtoul(argv[0], NULL, 0);

-    reg  = _strtoul(argv[1], NULL, 16);

-    val  = _strtoul(argv[2], NULL, 16);

-    aml_writePhyReg(0, port, reg, val);

-    AIR_PRINT("Phy write port=%d, reg=0x%x, value=0x%x\n", port, reg, val);

-

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-doPhyCL22(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(phyCL22Cmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doPhyCL45Read(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    UI32_T port = 0, dev = 0, reg = 0, val = 0;

-

-    port = _strtoul(argv[0], NULL, 0);

-    dev  = _strtoul(argv[1], NULL, 16);

-    reg  = _strtoul(argv[2], NULL, 16);

-    aml_readPhyRegCL45(0, port, dev, reg, &val);

-    AIR_PRINT("Phy read port=%d, dev=0x%x, reg=0x%x, value=0x%x\n", port, dev, reg, val);

-

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-doPhyCL45Write(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    UI32_T port = 0, dev = 0, reg = 0, val = 0;

-

-    port = _strtoul(argv[0], NULL, 0);

-    dev  = _strtoul(argv[1], NULL, 16);

-    reg  = _strtoul(argv[2], NULL, 16);

-    val  = _strtoul(argv[3], NULL, 16);

-    aml_writePhyRegCL45(0, port, dev, reg, val);

-    AIR_PRINT("Phy write port=%d, dev=0x%x, reg=0x%x, value=0x%x\n", port, dev, reg, val);

-

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-doPhyCL45(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(phyCL45Cmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doPhy(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(phyCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doPortSetMatrix(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    UI32_T matrix = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port   = _strtoul(argv[0], NULL, 0);

-    matrix = _strtoul(argv[1], NULL, 16);

-    rc = air_port_setPortMatrix(0, port, matrix);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doPortSetVlanMode(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    AIR_PORT_VLAN_MODE_T vlan_mode;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port      = _strtoul(argv[0], NULL, 0);

-    vlan_mode = _strtoul(argv[1], NULL, 0);

-    rc = air_port_setVlanMode(0, port, vlan_mode);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doPortSet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(portSetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doPortGetMatrix(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    UI32_T matrix = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    rc = air_port_getPortMatrix(0, port, &matrix);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-        return rc;

-    }

-    AIR_PRINT("Port %d Matrix: %2x\n", port, matrix);

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doPortGetVlanMode(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    AIR_PORT_VLAN_MODE_T vlan_mode;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    rc = air_port_getVlanMode(0, port, &vlan_mode);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-        return rc;

-    }

-    AIR_PRINT("Port %d Vlan Mode: ", port);

-    switch(vlan_mode)

-    {

-        case AIR_PORT_VLAN_MODE_PORT_MATRIX:

-            AIR_PRINT("matrix(%d)\n", vlan_mode);

-            break;

-        case AIR_PORT_VLAN_MODE_FALLBACK:

-            AIR_PRINT("fallback(%d)\n", vlan_mode);

-            break;

-        case AIR_PORT_VLAN_MODE_CHECK:

-            AIR_PRINT("check(%d)\n", vlan_mode);

-            break;

-        case AIR_PORT_VLAN_MODE_SECURITY:

-            AIR_PRINT("security(%d)\n", vlan_mode);

-            break;

-        default:

-            AIR_PRINT("unknown(%d)\n", vlan_mode);

-            break;

-    };

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doPortGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(portGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doPort(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(portCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doVlanInitiate(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0;

-    AIR_VLAN_ENTRY_ATTR_T vlan_entry = {0};

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid = _strtoul(argv[0], NULL, 0);

-    if (9 == argc)

-    {

-        vlan_entry.vlan_entry_format.fid           = _strtoul(argv[1], NULL, 0);

-        vlan_entry.vlan_entry_format.port_mem      = _strtoul(argv[2], NULL, 0);

-        vlan_entry.vlan_entry_format.ivl           = _strtoul(argv[3], NULL, 0);

-        vlan_entry.vlan_entry_format.port_stag     = _strtoul(argv[4], NULL, 0);

-        vlan_entry.vlan_entry_format.stag          = _strtoul(argv[5], NULL, 0);

-        vlan_entry.vlan_entry_format.eg_ctrl_en    = _strtoul(argv[6], NULL, 0);

-        vlan_entry.vlan_entry_format.eg_con        = _strtoul(argv[7], NULL, 0);

-        vlan_entry.vlan_entry_format.eg_ctrl       = _strtoul(argv[8], NULL, 0);

-

-        rc = air_vlan_create(0, vid, &vlan_entry);

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        rc = AIR_E_BAD_PARAMETER;

-    }

-

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                            break;

-        case     AIR_E_ENTRY_EXISTS:  AIR_PRINT("VLAN already exist!\n");             break;

-        default:                      AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanCreate(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid = _strtoul(argv[0], NULL, 0);

-    rc  = air_vlan_create(0, vid, NULL);

-

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                            break;

-        case     AIR_E_ENTRY_EXISTS:  AIR_PRINT("VLAN already exist!\n");             break;

-        default:                      AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanDestroy(UI32_T argc, C8_T *argv[])

-{

-    C8_T *token = NULL;

-    UI16_T vid = 0, vid_limit = AIR_VLAN_ID_MAX;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    if (argc > 0)

-    {

-        if (isdigit(argv[0][0]))

-        {

-            token = _strtok(argv[0], "-", &argv[0]);

-            vid = _strtoul(token, NULL, 0);

-            if ((token = _strtok(argv[0], "-", &argv[0])))

-                vid_limit = _strtoul(token, NULL, 0);

-            else

-                vid_limit = vid;

-            if (AIR_VLAN_ID_MAX < vid_limit)

-            {

-                AIR_PRINT("vid number should less than %d!\n", AIR_VLAN_ID_MAX);

-                return AIR_E_BAD_PARAMETER;

-            }

-            if (vid > vid_limit)

-            {

-                AIR_PRINT("vid0 should less than vid1!\n");

-                return AIR_E_BAD_PARAMETER;

-            }

-        }

-        else

-        {

-            AIR_PRINT("Bad parameter!\n");

-            return AIR_E_BAD_PARAMETER;

-        }

-    }

-

-    for (; vid <= vid_limit; vid++)

-    {

-        rc = air_vlan_destroy(0, vid);

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanDestroyAll(UI32_T argc, C8_T *argv[])

-{

-    UI32_T restore_def_vlan = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    if (argc > 0)

-    {

-        restore_def_vlan = _strtoul(argv[0], NULL, 0);

-    }

-

-    rc = air_vlan_destroyAll(0, restore_def_vlan);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanDump(UI32_T argc, C8_T *argv[])

-{

-    C8_T *token = NULL;

-    UI16_T port = 0, valid_count = 0, vid = 0, vid_limit = AIR_VLAN_ID_MAX;

-    AIR_PORT_EGS_TAG_ATTR_T tag_ctl[AIR_MAX_NUM_OF_PORTS] = {0};

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    if (argc > 0)

-    {

-        if (isdigit(argv[0][0]))

-        {

-            token = _strtok(argv[0], "-", &argv[0]);

-            vid = _strtoul(token, NULL, 0);

-            if ((token = _strtok(argv[0], "-", &argv[0])))

-                vid_limit = _strtoul(token, NULL, 0);

-            else

-                vid_limit = vid;

-            if (AIR_VLAN_ID_MAX < vid_limit)

-            {

-                AIR_PRINT("vid number should less than %d!\n", AIR_VLAN_ID_MAX);

-                return AIR_E_BAD_PARAMETER;

-            }

-            if (vid > vid_limit)

-            {

-                AIR_PRINT("vid0 should less than vid1!\n");

-                return AIR_E_BAD_PARAMETER;

-            }

-        }

-        else

-        {

-            AIR_PRINT("Bad parameter!\n");

-            return AIR_E_BAD_PARAMETER;

-        }

-    }

-

-    for (valid_count = 0; vid <= vid_limit; vid++)

-    {

-        _air_vlan_readEntry(0, vid, &vlan_entry);

-        if (vlan_entry.valid)

-        {

-            valid_count++;

-            if (1 == valid_count)

-                AIR_PRINT(" Vid Fid MemPort Ivl PortBaseStag Stag EgsTagCtlEn EgsTagCon EgsTagCtl\n======================================================================\n");

-            for (port = 0; port < AIR_MAX_NUM_OF_PORTS; port++)

-                tag_ctl[port] = (vlan_entry.vlan_entry_format.eg_ctrl >> (port * 2)) & 0x3;

-            AIR_PRINT("%4d %3d      %2x %3d %12d %4d %11d %9d   %1x%1x%1x%1x%1x%1x%1x\n",

-                vid, vlan_entry.vlan_entry_format.fid, vlan_entry.vlan_entry_format.port_mem, vlan_entry.vlan_entry_format.ivl,

-                vlan_entry.vlan_entry_format.port_stag, vlan_entry.vlan_entry_format.stag, vlan_entry.vlan_entry_format.eg_ctrl_en, vlan_entry.vlan_entry_format.eg_con,

-                tag_ctl[6], tag_ctl[5], tag_ctl[4], tag_ctl[3], tag_ctl[2], tag_ctl[1], tag_ctl[0]);

-        }

-    }

-

-    if (!valid_count)

-        AIR_PRINT("not found!\n");

-    else

-        AIR_PRINT("Found %d valid entries!\n", valid_count);

-

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-doVlanAddPortMem(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0, port = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid  = _strtoul(argv[0], NULL, 0);

-    port = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_addMemberPort(0, vid, port);

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                               break;

-        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;

-        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanDelPortMem(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0, port = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid  = _strtoul(argv[0], NULL, 0);

-    port = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_delMemberPort(0, vid, port);

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                               break;

-        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;

-        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetFid(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0;

-    UI8_T  fid = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid = _strtoul(argv[0], NULL, 0);

-    fid = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_setFid(0, vid, fid);

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                               break;

-        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;

-        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetMemPort(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0, port_bitmap = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid         = _strtoul(argv[0], NULL, 0);

-    port_bitmap = _strtoul(argv[1], NULL, 16);

-    rc = air_vlan_setMemberPort(0, vid, port_bitmap);

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                               break;

-        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;

-        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetIVL(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0;

-    BOOL_T enable = TRUE;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid    = _strtoul(argv[0], NULL, 0);

-    enable = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_setIVL(0, vid, enable);

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                               break;

-        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;

-        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetPortBaseStag(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0;

-    BOOL_T enable = TRUE;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid    = _strtoul(argv[0], NULL, 0);

-    enable = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_setPortBasedStag(0, vid, enable);

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                               break;

-        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;

-        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetStag(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0, stag = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid  = _strtoul(argv[0], NULL, 0);

-    stag = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_setServiceTag(0, vid, stag);

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                               break;

-        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;

-        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetEgsTagCtlEn(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0;

-    BOOL_T enable = TRUE;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid    = _strtoul(argv[0], NULL, 0);

-    enable = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_setEgsTagCtlEnable(0, vid, enable);

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                               break;

-        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;

-        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetEgsTagCtlCon(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0;

-    BOOL_T enable = TRUE;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid    = _strtoul(argv[0], NULL, 0);

-    enable = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_setEgsTagConsistent(0, vid, enable);

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                               break;

-        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;

-        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetEgsTagCtl(UI32_T argc, C8_T *argv[])

-{

-    UI16_T vid = 0, port = 0;

-    AIR_PORT_EGS_TAG_ATTR_T tag_ctl = AIR_PORT_EGS_TAG_ATTR_UNTAGGED;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    vid     = _strtoul(argv[0], NULL, 0);

-    port    = _strtoul(argv[1], NULL, 0);

-    tag_ctl = _strtoul(argv[2], NULL, 0);

-    rc = air_vlan_setPortEgsTagCtl(0, vid, port, tag_ctl);

-    switch (rc)

-    {

-        case     AIR_E_OK:                                                               break;

-        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;

-        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetPortActFrame(UI32_T argc, C8_T *argv[])

-{

-    UI16_T port = 0;

-    AIR_VLAN_ACCEPT_FRAME_TYPE_T type = AIR_VLAN_ACCEPT_FRAME_TYPE_ALL;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    type = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_setPortAcceptFrameType(0, port, type);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetLeakyVlanEn(UI32_T argc, C8_T *argv[])

-{

-    UI16_T port = 0;

-    AIR_LEAKY_PKT_TYPE_T pkt_type = AIR_LEAKY_PKT_TYPE_UNICAST;

-    BOOL_T enable = TRUE;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port     = _strtoul(argv[0], NULL, 0);

-    pkt_type = _strtoul(argv[1], NULL, 0);

-    enable   = _strtoul(argv[2], NULL, 0);

-    rc = air_vlan_setPortLeakyVlanEnable(0, port, pkt_type, enable);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetPortVlanAttr(UI32_T argc, C8_T *argv[])

-{

-    UI16_T port = 0;

-    AIR_VLAN_PORT_ATTR_T attr = AIR_VLAN_PORT_ATTR_USER_PORT;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    attr = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_setPortAttr(0, port, attr);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetIgsPortETagAttr(UI32_T argc, C8_T *argv[])

-{

-    UI16_T port = 0;

-    AIR_IGR_PORT_EG_TAG_ATTR_T attr = AIR_IGR_PORT_EG_TAG_ATTR_DISABLE;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    attr = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_setIgrPortTagAttr(0, port, attr);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetPortETagAttr(UI32_T argc, C8_T *argv[])

-{

-    UI16_T port = 0;

-    AIR_PORT_EGS_TAG_ATTR_T attr = AIR_PORT_EGS_TAG_ATTR_UNTAGGED;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    attr = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_setPortEgsTagAttr(0, port, attr);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetPortOuterTPID(UI32_T argc, C8_T *argv[])

-{

-    UI16_T port = 0, tpid = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    tpid = _strtoul(argv[1], NULL, 16);

-    rc = air_vlan_setPortOuterTPID(0, port, tpid);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSetPvid(UI32_T argc, C8_T *argv[])

-{

-    UI16_T port = 0, pvid = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    pvid = _strtoul(argv[1], NULL, 0);

-    rc = air_vlan_setPortPVID(0, port, pvid);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanSet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(vlanSetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doVlanGetPortActFrame(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    AIR_VLAN_ACCEPT_FRAME_TYPE_T type;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    rc = air_vlan_getPortAcceptFrameType(0, port, &type);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-        return rc;

-    }

-    AIR_PRINT("Port %d Acceptable Frame Type: ", port);

-    switch(type)

-    {

-        case AIR_VLAN_ACCEPT_FRAME_TYPE_ALL:

-            AIR_PRINT("all(%d)\n", type);

-            break;

-        case AIR_VLAN_ACCEPT_FRAME_TYPE_TAG_ONLY:

-            AIR_PRINT("tagged-only(%d)\n", type);

-            break;

-        case AIR_VLAN_ACCEPT_FRAME_TYPE_UNTAG_ONLY:

-            AIR_PRINT("untagged-only(%d)\n", type);

-            break;

-        default:

-            AIR_PRINT("unknown(%d)\n", type);

-            break;

-    };

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanGetLeakyVlanEn(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    BOOL_T uc = FALSE, mc = FALSE, bc = FALSE;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    rc += air_vlan_getPortLeakyVlanEnable(0, port, AIR_LEAKY_PKT_TYPE_UNICAST, &uc);

-    rc += air_vlan_getPortLeakyVlanEnable(0, port, AIR_LEAKY_PKT_TYPE_MULTICAST, &mc);

-    rc += air_vlan_getPortLeakyVlanEnable(0, port, AIR_LEAKY_PKT_TYPE_BROADCAST, &bc);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-        return rc;

-    }

-

-    AIR_PRINT("Port %d Leaky Vlan Enable\n", port);

-    AIR_PRINT("Unicast     : %s\n", uc ? "TRUE" : "FALSE");

-    AIR_PRINT("Multicast   : %s\n", mc ? "TRUE" : "FALSE");

-    AIR_PRINT("Broadcast   : %s\n", bc ? "TRUE" : "FALSE");

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanGetPortVlanAttr(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    AIR_VLAN_PORT_ATTR_T attr;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    rc = air_vlan_getPortAttr(0, port, &attr);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-        return rc;

-    }

-    AIR_PRINT("Port %d Vlan Attr: ", port);

-    switch(attr)

-    {

-        case AIR_VLAN_PORT_ATTR_USER_PORT:

-            AIR_PRINT("user port(%d)\n", attr);

-            break;

-        case AIR_VLAN_PORT_ATTR_STACK_PORT:

-            AIR_PRINT("stack port(%d)\n", attr);

-            break;

-        case AIR_VLAN_PORT_ATTR_TRANSLATION_PORT:

-            AIR_PRINT("translation port(%d)\n", attr);

-            break;

-        case AIR_VLAN_PORT_ATTR_TRANSPARENT_PORT:

-            AIR_PRINT("transparent port(%d)\n", attr);

-            break;

-        default:

-            AIR_PRINT("unknown(%d)\n", attr);

-            break;

-    };

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanGetIgsPortETagAttr(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    AIR_IGR_PORT_EG_TAG_ATTR_T attr;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    rc = air_vlan_getIgrPortTagAttr(0, port, &attr);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-        return rc;

-    }

-    AIR_PRINT("Port %d Incomming Port Egress Tag Attr: ", port);

-    switch(attr)

-    {

-        case AIR_IGR_PORT_EG_TAG_ATTR_DISABLE:

-            AIR_PRINT("disable(%d)\n", attr);

-            break;

-        case AIR_IGR_PORT_EG_TAG_ATTR_CONSISTENT:

-            AIR_PRINT("consistent(%d)\n", attr);

-            break;

-        case AIR_IGR_PORT_EG_TAG_ATTR_UNTAGGED:

-            AIR_PRINT("untagged(%d)\n", attr);

-            break;

-        case AIR_IGR_PORT_EG_TAG_ATTR_SWAP:

-            AIR_PRINT("swap(%d)\n", attr);

-            break;

-        case AIR_IGR_PORT_EG_TAG_ATTR_TAGGED:

-            AIR_PRINT("tagged(%d)\n", attr);

-            break;

-        case AIR_IGR_PORT_EG_TAG_ATTR_STACK:

-            AIR_PRINT("stack(%d)\n", attr);

-            break;

-        default:

-            AIR_PRINT("unknown(%d)\n", attr);

-            break;

-    };

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanGetPortETagAttr(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    AIR_PORT_EGS_TAG_ATTR_T attr;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    rc = air_vlan_getPortEgsTagAttr(0, port, &attr);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-        return rc;

-    }

-    AIR_PRINT("Port %d Egress Tag Attr: ", port);

-    switch(attr)

-    {

-        case AIR_PORT_EGS_TAG_ATTR_UNTAGGED:

-            AIR_PRINT("untagged(%d)\n", attr);

-            break;

-        case AIR_PORT_EGS_TAG_ATTR_SWAP:

-            AIR_PRINT("swap(%d)\n", attr);

-            break;

-        case AIR_PORT_EGS_TAG_ATTR_TAGGED:

-            AIR_PRINT("tagged(%d)\n", attr);

-            break;

-        case AIR_PORT_EGS_TAG_ATTR_STACK:

-            AIR_PRINT("stack(%d)\n", attr);

-            break;

-        default:

-            AIR_PRINT("unknown(%d)\n", attr);

-            break;

-    };

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanGetPortOuterTPID(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    UI16_T tpid = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    rc = air_vlan_getPortOuterTPID(0, port, &tpid);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-        return rc;

-    }

-    AIR_PRINT("Port %d Outer TPID: %4x\n", port, tpid);

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanGetPvid(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    UI16_T pvid = 0;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    rc = air_vlan_getPortPVID(0, port, &pvid);

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("Error: Operation failed!\n");

-        return rc;

-    }

-    AIR_PRINT("Port %d PVID: %d\n", port, pvid);

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doVlanGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(vlanGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doVlan(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(vlanCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doJumbo(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    I32_T pkt_len = 0, frame_len = 0;

-

-    if(0 == argc)

-    {

-        /* get command */

-        ret = air_port_getJumbo(0, &pkt_len, &frame_len);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get ");

-            switch(pkt_len)

-            {

-                case 0:

-                    AIR_PRINT("RX_1518 ");

-                    break;

-                case 1:

-                    AIR_PRINT("RX_1536 ");

-                    break;

-                case 2:

-                    AIR_PRINT("RX_1552 ");

-                    break;

-                case 3:

-                    AIR_PRINT("RX_JUMBO ");

-                    break;

-            }

-            AIR_PRINT("frames lengths %d KBytes\n", frame_len);

-        }

-        else

-        {

-            AIR_PRINT("Get Jumbo Fail.\n");

-        }

-    }

-    else

-    {

-        /* set command */

-        pkt_len = _strtol(argv[0], NULL, 10);

-        frame_len = _strtol(argv[1], NULL, 10);

-

-        ret = air_port_setJumbo(0, pkt_len, frame_len);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set ");

-            switch(pkt_len)

-            {

-                case 0:

-                    AIR_PRINT("RX_1518 ");

-                    break;

-                case 1:

-                    AIR_PRINT("RX_1536 ");

-                    break;

-                case 2:

-                    AIR_PRINT("RX_1552 ");

-                    break;

-                case 3:

-                    AIR_PRINT("RX_JUMBO ");

-                    break;

-            }

-            AIR_PRINT("frames lengths %d KBytes\n", frame_len);

-        }

-        else

-            AIR_PRINT("Set Jumbo Fail.\n");

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doFlowCtrl(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    BOOL_T fc_en = 0, dir = 0;

-    I32_T port = 0;

-

-    port = _strtol(argv[0], NULL, 10);

-    dir = _strtol(argv[1], NULL, 10);

-

-    if(2 == argc)

-    {

-        /* get command */

-        ret = air_port_getFlowCtrl(0, port, dir, &fc_en);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Get Port%02d %s Flow Control %s\n", port, ((dir)?"RX":"TX"), ((fc_en)?"Enable":"Disable"));

-        else

-            AIR_PRINT("Get Flow Control Fail.\n");

-    }

-    else

-    {

-        /* set command */

-        fc_en = _strtol(argv[2], NULL, 10);

-

-        ret = air_port_setFlowCtrl(0, port, dir, fc_en);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Set Port%02d %s Flow Control %s\n", port, ((dir)?"RX":"TX"), ((fc_en)?"Enable":"Disable"));

-        else

-            AIR_PRINT("Set Flow Control Fail.\n");

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doL2Set(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(l2SetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doL2Get(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(l2GetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doL2Clear(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(l2ClearCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doL2Del(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(l2DelCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doL2Add(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(l2AddCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doL2(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(l2Cmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doAnMode(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    BOOL_T en = 0;

-

-    port = _strtol(argv[0], NULL, 10);

-

-    if(1 == argc)

-    {

-        /* port get anCap <port> */

-        ret = air_port_getAnMode(0, port, &en);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Get Port%02d Auto-Negotiation %s\n", port, ((en)?"Enabled":"Disabled"));

-        else

-            AIR_PRINT("Get Port%02d Auto-Negotiation Fail.\n", port);

-    }

-    else if(2 == argc)

-    {

-        /* "port set anMode <port> <en> */

-        en = _strtol(argv[1], NULL, 10);

-        ret = air_port_setAnMode(0, port, en);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Set Port%02d Auto-Negotiation Mode:%s\n", port, ((en)?"Enabled":"Disabled"));

-        else

-            AIR_PRINT("Set Port%02d Auto-Negotiation Fail.\n", port);

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doLocalAdv(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    AIR_AN_ADV_T adv;

-

-    memset(&adv, 0, sizeof(AIR_AN_ADV_T));

-    port = _strtol(argv[0], NULL, 10);

-

-    if(1 == argc)

-    {

-        /* port get localAdv <port> */

-        ret = air_port_getLocalAdvAbility(0, port, &adv);

-        AIR_PRINT("Get Port%02d Local Auto-Negotiation Advertisement: ", port);

-        if(AIR_E_OK != ret)

-        {

-            AIR_PRINT("Fail!\n");

-        }

-    }

-    else if(7 == argc)

-    {

-        /* port set localAdv <port> <10H> <10F> <100H> <100F> <1000F> <pause> */

-        adv.advCap10HDX = _strtol(argv[1], NULL, 0) & BIT(0);

-        adv.advCap10FDX = _strtol(argv[2], NULL, 0) & BIT(0);

-        adv.advCap100HDX = _strtol(argv[3], NULL, 0) & BIT(0);

-        adv.advCap100FDX = _strtol(argv[4], NULL, 0) & BIT(0);

-        adv.advCap1000FDX = _strtol(argv[5], NULL, 0) & BIT(0);

-        adv.advPause = _strtol(argv[6], NULL, 0) & BIT(0);

-        ret = air_port_setLocalAdvAbility(0, port, adv);

-        AIR_PRINT("Set Port%02d Local Auto-Negotiation Advertisement: ", port);

-        if(AIR_E_OK != ret)

-        {

-            AIR_PRINT("Fail!\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        AIR_PRINT("\n");

-        AIR_PRINT("\tAdvertise 10BASE-T Half Duplex: %s\n", (adv.advCap10HDX)?"Effective":"Not Effective" );

-        AIR_PRINT("\tAdvertise 10BASE-T Full Duplex: %s\n", (adv.advCap10FDX)?"Effective":"Not Effective" );

-        AIR_PRINT("\tAdvertise 100BASE-T Half Duplex: %s\n", (adv.advCap100HDX)?"Effective":"Not Effective" );

-        AIR_PRINT("\tAdvertise 100BASE-T Full Duplex: %s\n", (adv.advCap100FDX)?"Effective":"Not Effective" );

-        AIR_PRINT("\tAdvertise 1000BASE-T Full Duplex: %s\n", (adv.advCap1000FDX)?"Effective":"Not Effective" );

-        AIR_PRINT("\tAdvertise Asynchronous Pause: %s\n", (adv.advPause)?"Effective":"Not Effective" );

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doRemoteAdv(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    AIR_AN_ADV_T lp_adv;

-

-    memset(&lp_adv, 0, sizeof(AIR_AN_ADV_T));

-    port = _strtol(argv[0], NULL, 10);

-

-    if(1 == argc)

-    {

-        /* port get remoteAdv <port> */

-        ret = air_port_getRemoteAdvAbility(0, port, &lp_adv);

-        AIR_PRINT("Get Port%02d Remote Auto-Negotiation Advertisement: ", port);

-        if(AIR_E_OK != ret)

-        {

-            AIR_PRINT("Fail!\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        AIR_PRINT("\n");

-        AIR_PRINT("\tAdvertise 10BASE-T Half Duplex: %s\n", lp_adv.advCap10HDX?"Effective":"Not Effective" );

-        AIR_PRINT("\tAdvertise 10BASE-T Full Duplex: %s\n", lp_adv.advCap10FDX?"Effective":"Not Effective" );

-        AIR_PRINT("\tAdvertise 100BASE-T Half Duplex: %s\n", lp_adv.advCap100HDX?"Effective":"Not Effective" );

-        AIR_PRINT("\tAdvertise 100BASE-T Full Duplex: %s\n", lp_adv.advCap100FDX?"Effective":"Not Effective" );

-        AIR_PRINT("\tAdvertise 1000BASE-T Full Duplex: %s\n", (lp_adv.advCap1000FDX)?"Effective":"Not Effective" );

-        AIR_PRINT("\tAdvertise Asynchronous Pause: %s\n", (lp_adv.advPause)?"Effective":"Not Effective" );

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortSpeed(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    UI32_T speed = 0;

-

-    port = _strtol(argv[0], NULL, 10);

-

-    if(1 == argc)

-    {

-        /* port get speed <port> */

-        ret = air_port_getSpeed(0, port, &speed);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get Port%02d Speed:", port);

-        }

-        else

-        {

-            AIR_PRINT("Get Port%02d Speed Fail!\n", port);

-        }

-    }

-    else if(2 == argc)

-    {

-        /* port set speed <port> <speed> */

-        speed = _strtol(argv[1], NULL, 10);

-        ret = air_port_setSpeed(0, port, speed);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set Port%02d Speed:", port);

-        }

-        else

-        {

-            AIR_PRINT("Set Port%02d Speed Fail!\n", port);

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        switch(speed)

-        {

-            case AIR_PORT_SPEED_10M:

-                AIR_PRINT(" 10 Mbps\n");

-                break;

-            case AIR_PORT_SPEED_100M:

-                AIR_PRINT(" 100 Mbps\n");

-                break;

-            case AIR_PORT_SPEED_1000M:

-                AIR_PRINT(" 1 Gbps\n");

-                break;

-            case AIR_PORT_SPEED_2500M:

-                AIR_PRINT(" 2.5 Gbps\n");

-                break;

-            default:

-                AIR_PRINT(" Reserved\n");

-                break;

-        }

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortDuplex(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    UI32_T duplex = 0;

-

-    port = _strtol(argv[0], NULL, 10);

-

-    if(1 == argc)

-    {

-        /* port get duplex <port> */

-        ret = air_port_getDuplex(0, port, &duplex);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get Port%02d Duplex:%s\n", port, duplex?"Full":"Half");

-        }

-        else

-        {

-            AIR_PRINT("Get Port%02d Duplex Fail!\n", port);

-        }

-    }

-    else if(2 == argc)

-    {

-        /* port set duplex <port> <duplex> */

-        duplex = _strtol(argv[1], NULL, 10);

-        ret = air_port_setDuplex(0, port, duplex);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set Port%02d Duplex:%s\n", port, duplex?"Full":"Half");

-        }

-        else

-        {

-            AIR_PRINT("Set Port%02d Duplex Fail!\n", port);

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortStatus(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    AIR_PORT_STATUS_T ps;

-

-    memset(&ps, 0, sizeof(AIR_PORT_STATUS_T));

-    port = _strtol(argv[0], NULL, 10);

-

-    if(1 == argc)

-    {

-        /* port get status <port> */

-        ret = air_port_getLink(0, port, &ps);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get Port%02d Link-Status\n", port);

-            AIR_PRINT("\tLink: %s\n", ps.link?"Up":"Down");

-            AIR_PRINT("\tDuplex: %s\n", ps.duplex?"Full":"Half");

-            AIR_PRINT("\tSpeed: ");

-            switch(ps.speed)

-            {

-                case AIR_PORT_SPEED_10M:

-                    AIR_PRINT("10 Mbps\n");

-                    break;

-                case AIR_PORT_SPEED_100M:

-                    AIR_PRINT("100 Mbps\n");

-                    break;

-                case AIR_PORT_SPEED_1000M:

-                    AIR_PRINT("1 Gbps\n");

-                    break;

-                case AIR_PORT_SPEED_2500M:

-                    AIR_PRINT("2.5 Gbps\n");

-                    break;

-                default:

-                    AIR_PRINT("Reserved\n");

-                    break;

-            }

-        }

-        else

-            AIR_PRINT("Get Port%02d Link-Status Fail!", port);

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortBckPres(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    UI32_T bckPres = 0;

-

-    port = _strtol(argv[0], NULL, 10);

-

-    if(1 == argc)

-    {

-        /* port get bckPres <port> */

-        ret = air_port_getBckPres(0, port, &bckPres);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Get Port%02d BckPres:%s\n", port, bckPres?"Enabled":"Disabled");

-        else

-            AIR_PRINT("Get Port%02d BckPres Fail!\n", port);

-    }

-    else if(2 == argc)

-    {

-        /* port set bckPres <port> <bckPres> */

-        bckPres = _strtol(argv[1], NULL, 10);

-        ret = air_port_setBckPres(0, port, bckPres);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Set Port%02d BckPres:%s\n", port, bckPres?"Enabled":"Disabled");

-        else

-            AIR_PRINT("Set Port%02d BckPres Fail!\n", port);

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortPsMode(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    UI32_T mode = 0;

-    BOOL_T ls_en = 0;

-    BOOL_T eee_en = 0;

-

-    port = _strtol(argv[0], NULL, 10);

-

-    if(1 == argc)

-    {

-        /* port get psMode <port> */

-        ret = air_port_getPsMode(0, port, &mode);

-        AIR_PRINT("Get Port%02d Power-Saving: ", port);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Done\n");

-        }

-        else

-        {

-            AIR_PRINT("Fail!\n");

-        }

-    }

-    else if(3 == argc)

-    {

-        /* port set psMode <port> <ls> <eee> */

-        ls_en = _strtol(argv[1], NULL, 0);

-        eee_en = _strtol(argv[2], NULL, 0);

-        if(TRUE == ls_en)

-        {

-            mode |= AIR_PORT_PS_LINKSTATUS;

-        }

-        if(TRUE == eee_en)

-        {

-            mode |= AIR_PORT_PS_EEE;

-        }

-        ret = air_port_setPsMode(0, port, mode);

-        AIR_PRINT("Set Port%02d Power-Saving: ", port);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Done\n");

-        }

-        else

-        {

-            AIR_PRINT("Fail!\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-    if(ret == AIR_E_OK)

-    {

-        AIR_PRINT("\tLink status:%s\n", (mode & AIR_PORT_PS_LINKSTATUS)?"Enable":"Disable");

-        AIR_PRINT("\tEEE:%s\n", (mode & AIR_PORT_PS_EEE)?"Enable":"Disable");

-    }

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortSmtSpdDwn(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    UI32_T state = 0;

-    UI32_T retry = 0;

-

-    port = _strtol(argv[0], NULL, 10);

-

-    if(1 == argc)

-    {

-        /* port get smtSpdDwn <port> */

-        ret = air_port_getSmtSpdDwn(0, port, &state, &retry);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get Port%02d Smart Speed Down: %s\n", port, state?"Enabled":"Disabled");

-            AIR_PRINT("Get Port%02d Retry Time: %d\n", port, retry + 2);

-        }

-        else

-            AIR_PRINT("Get Port%02d Smart-SpeedDown Fail!\n", port);

-    }

-    else if(3 == argc)

-    {

-        /* port set smtSpdDwn <port> <en> <retry> */

-        state = _strtol(argv[1], NULL, 10);

-        retry = _strtol(argv[2], NULL, 10);

-        if(retry >= 2)

-        {

-            ret = air_port_setSmtSpdDwn(0, port, state, retry - 2);

-            if(ret == AIR_E_OK)

-            {

-                AIR_PRINT("Set Port%02d Smart Speed Down: %s\n", port, state?"Enabled":"Disabled");

-                AIR_PRINT("Set Port%02d Retry Time: %d\n", port, retry);

-            }

-            else

-                AIR_PRINT("Set Port%02d Smart-SpeedDown Fail!\n", port);

-        }

-        else

-        {

-            ret = AIR_E_BAD_PARAMETER;

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortSpTag(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    BOOL_T sptag_en = FALSE;

-

-    port = _strtol(argv[0], NULL, 10);

-

-    if(1 == argc)

-    {

-        /* port get spTag <port> */

-        ret = air_port_getSpTag(0, port, &sptag_en);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Get Port%02d Special Tag %s\n", port, ((sptag_en)?"Enabled":"Disabled"));

-        }

-        else

-        {

-            AIR_PRINT("Get Port%02d Special Tag Fail.\n", port);

-        }

-    }

-    else if(2 == argc)

-    {

-        /* port set spTag <port> <en> */

-        sptag_en = _strtol(argv[1], NULL, 10);

-        ret = air_port_setSpTag(0, port, sptag_en);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Set Port%02d Special Tag:%s\n", port, ((sptag_en)?"Enabled":"Disabled"));

-        }

-        else

-        {

-            AIR_PRINT("Set Port%02d Special Tag Fail.\n", port);

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortEnable(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    UI32_T state = 0;

-

-    port = _strtol(argv[0], NULL, 10);

-

-    if(1 == argc)

-    {

-        /* port get enable <port> */

-        ret = air_port_getEnable(0, port, &state);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Get Port%02d State:%s\n", port, state?"Enable":"Disable");

-        else

-            AIR_PRINT("Get Port%02d State Fail!\n", port);

-    }

-    else if(2 == argc)

-    {

-        /* port set enable <port> <en> */

-        state = _strtol(argv[1], NULL, 10);

-        ret = air_port_setEnable(0, port, state);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Set Port%02d State:%s\n", port, state?"Enable":"Disable");

-        else

-            AIR_PRINT("Set Port%02d State Fail!\n", port);

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPort5GBaseRMode(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-

-    if(0 == argc)

-    {

-        /* port set 5GBaseRMode */

-        ret = air_port_set5GBaseRModeEn(0);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Set Port05 Mode: 5GBase-R\n");

-        else

-            AIR_PRINT("Set Port05 HSGMII Mode Fail.\n");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortHsgmiiMode(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-

-    if(0 == argc)

-    {

-        /* port set hsgmiiMode */

-        ret = air_port_setHsgmiiModeEn(0);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Set Port05 Mode: HSGMII\n");

-        else

-            AIR_PRINT("Set Port05 HSGMII Mode Fail.\n");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortSgmiiMode(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T mode = 0;

-    UI32_T speed = 0;

-

-    if(2 == argc)

-    {

-        /* port set sgmiiMode <mode(0:AN,1:Force)> <speed> */

-        mode = _strtol(argv[0], NULL, 10);

-        speed = _strtol(argv[1], NULL, 10);

-        ret = air_port_setSgmiiMode(0, mode, speed);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Set Port05 SGMII Mode:%s\nIf in Force Mode, speed:", mode?"Force":"AN");

-        else

-            AIR_PRINT("Set Port05 SGMII Mode Fail.\n");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        switch(speed)

-        {

-            case AIR_PORT_SPEED_10M:

-                AIR_PRINT(" 10 Mbps\n");

-                break;

-            case AIR_PORT_SPEED_100M:

-                AIR_PRINT(" 100 Mbps\n");

-                break;

-            case AIR_PORT_SPEED_1000M:

-                AIR_PRINT(" 1 Gbps\n");

-                break;

-            default:

-                AIR_PRINT(" Reserved\n");

-                break;

-        }

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortRmiiMode(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T speed = 0;

-

-    if(1 == argc)

-    {

-        /* port set rmiiMode <speed> */

-        speed = _strtol(argv[0], NULL, 10);

-        ret = air_port_setRmiiMode(0, speed);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set Port05 RMII Mode Speed:");

-        }

-        else

-        {

-            AIR_PRINT("Set Port05 RMII Mode Fail!\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        switch(speed)

-        {

-            case AIR_PORT_SPEED_10M:

-                AIR_PRINT(" 10 Mbps\n");

-                break;

-            case AIR_PORT_SPEED_100M:

-                AIR_PRINT(" 100 Mbps\n");

-                break;

-            default:

-                AIR_PRINT(" Reserved\n");

-                break;

-        }

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doPortRgmiiMode(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T speed = 0;

-

-    if(1 == argc)

-    {

-        /* port set rgmiiMode <speed> */

-        speed = _strtol(argv[0], NULL, 10);

-        ret = air_port_setRgmiiMode(0, speed);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set Port05 RGMII Mode Speed:");

-        }

-        else

-        {

-            AIR_PRINT("Set Port05 RGMII Mode Fail!\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        switch(speed)

-        {

-            case AIR_PORT_SPEED_10M:

-                AIR_PRINT(" 10 Mbps\n");

-                break;

-            case AIR_PORT_SPEED_100M:

-                AIR_PRINT(" 100 Mbps\n");

-                break;

-            case AIR_PORT_SPEED_1000M:

-                AIR_PRINT(" 1 Gbps\n");

-                break;

-            default:

-                AIR_PRINT(" Reserved\n");

-                break;

-        }

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doSptagEn(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    BOOL_T sp_en = FALSE;

-

-    port =  _strtol(argv[0], NULL, 10);

-    if (2 == argc)

-    {

-        sp_en =  _strtol(argv[1], NULL, 10);

-        ret = air_sptag_setState(0,port,sp_en);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("set port %d SpTag state %s sucess\n", port,sp_en?"Enable":"Disable");

-        }

-        else

-        {

-            AIR_PRINT("set port %d SpTag state %s fail\n", port,sp_en?"Enable":"Disable");

-        }

-    }

-    else if(1 == argc)

-    {

-        air_sptag_getState(0,port,&sp_en);

-        AIR_PRINT("get port %d SpTag state: %s \n", port,sp_en?"Enable":"Disable");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doSptagMode(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    BOOL_T sp_mode = FALSE;

-

-

-    port =  _strtol(argv[0], NULL, 10);

-    if (2 == argc)

-    {

-        sp_mode  =  _strtol(argv[1], NULL, 10);

-        ret = air_sptag_setMode(0,port,sp_mode);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("set port %d SpTag Mode  %s sucess\n", port,sp_mode?"replace":"insert");

-        }

-        else

-        {

-            AIR_PRINT("set port %d SpTag state %s fail\n", port,sp_mode?"replace":"insert");

-        }

-    }

-    else if(1 == argc)

-    {

-        air_sptag_getMode(0,port,&sp_mode);

-        AIR_PRINT("get port %d SpTag state: %s \n", port,sp_mode?"replace":"insert");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doSptagDecode(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    AIR_SPTAG_RX_PARA_T sptag_rx = {0};

-    UI8_T buf[AIR_STAG_BUF_LEN] = {0};

-    UI32_T len = AIR_STAG_BUF_LEN, i = 0;

-

-    if (4 == argc)

-    {

-        for(i = 0; i < len; i++)

-        {

-            buf[i] = _strtoul(argv[i], NULL, 16);

-        }

-

-        ret = air_sptag_decodeRx(0, buf, len, &sptag_rx);

-        if (AIR_E_OK != ret)

-        {

-            AIR_PRINT("SpTag decode fail\n");

-            return ret;

-        }

-

-        AIR_PRINT("SpTag decode success:\n");

-        AIR_PRINT("RSN : %s\n", _sptag_pt[sptag_rx.rsn]);

-        AIR_PRINT("VPM : %s\n", _sptag_vpm[sptag_rx.vpm]);

-        AIR_PRINT("SPN : %d\n", sptag_rx.spn);

-        AIR_PRINT("PRI : %d\n", sptag_rx.pri);

-        AIR_PRINT("CFI : %d\n", sptag_rx.cfi);

-        AIR_PRINT("VID : %d\n", sptag_rx.vid);

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doSptagEncode(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    AIR_STAG_TX_PARA_T sptag_tx = {0};

-    UI8_T buf[AIR_STAG_BUF_LEN] = {0};

-    UI32_T len = AIR_STAG_BUF_LEN;

-    char str[128] = {'\0'};

-    UI32_T data = 0;

-    AIR_STAG_MODE_T mode = AIR_STAG_MODE_LAST;

-

-    if (7 == argc)

-    {

-        if(_strcmp(argv[0],"mode=replace") == 0)

-            mode = AIR_STAG_MODE_REPLACE;

-        else if(_strcmp(argv[0],"mode=insert") == 0)

-            mode = AIR_STAG_MODE_INSERT;

-        else

-            printf("mode is wrong!!");

-

-        if(_strcmp(argv[1],"opc=portmap") == 0)

-            sptag_tx.opc = AIR_STAG_OPC_PORTMAP;

-        else if(_strcmp(argv[1],"opc=portid") == 0)

-            sptag_tx.opc = AIR_STAG_OPC_PORTID;

-        else if(_strcmp(argv[1],"opc=lookup") == 0)

-            sptag_tx.opc = AIR_STAG_OPC_LOOKUP;

-        else

-            printf("opc is wrong!!");

-

-        if(sscanf(argv[2],"dp=%x",&data) != -1)

-        {

-            sptag_tx.pbm = data;

-            AIR_PRINT("sptag_tx.pbm %x\n",sptag_tx.pbm);

-        }

-

-        if(_strcmp(argv[3],"vpm=untagged") == 0)

-            sptag_tx.vpm = AIR_STAG_VPM_UNTAG;

-        else if(_strcmp(argv[3],"vpm=8100") == 0)

-            sptag_tx.vpm = AIR_STAG_VPM_TPID_8100;

-        else if(_strcmp(argv[3],"vpm=88a8") == 0)

-            sptag_tx.vpm = AIR_STAG_VPM_TPID_88A8;

-        else

-            printf("vpm is wrong!!");

-

-        if(sscanf(argv[4],"pri=%d",&data) != -1)

-        {

-            sptag_tx.pri = data;

-            AIR_PRINT("sptag_tx.pri %d\n",sptag_tx.pri);

-        }

-

-        if(sscanf(argv[5],"cfi=%d",&data) != -1)

-        {

-            sptag_tx.cfi  = data;

-            AIR_PRINT("sptag_tx.cfi %d\n",sptag_tx.cfi);

-        }

-

-        if(sscanf(argv[6],"vid=%d",&data) != -1)

-        {

-            sptag_tx.vid = data;

-            AIR_PRINT("sptag_tx.vid %d\n",sptag_tx.vid);

-        }

-

-        ret = air_sptag_encodeTx(0,mode, &sptag_tx, (UI8_T *)&buf, &len);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("SpTag encode sucess, returned len=%d\n", len);

-            AIR_PRINT("Encoded SpTag: %02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]);

-        }

-        else

-        {

-            AIR_PRINT("SpTag encode fail\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doSptag(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(sptagCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doL2Dump(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(l2DumpCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doMacAddr(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    AIR_MAC_ENTRY_T mt;

-    UI32_T fwd = 0;

-

-    memset(&mt, 0, sizeof(AIR_MAC_ENTRY_T));

-

-    if(0 == argc)

-    {

-        /* l2 clear mac */

-        ret = air_l2_clearMacAddr(0);

-        if(ret == AIR_E_OK)

-            AIR_PRINT("Clear MAC Address Table Done.\n");

-        else

-            AIR_PRINT("Clear MAC Address Table Fail.\n");

-    }

-    else if(3 == argc)

-    {

-        /* l2 del mac <mac(12'hex)> { vid <vid(0..4095)> | fid <fid(0..15)> } */

-        ret = _str2mac(argv[0], (C8_T *)mt.mac);

-        if(ret != AIR_E_OK)

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            return ret;

-        }

-

-        /* check argument 1 */

-        if(FALSE == _strcmp(argv[1], "vid"))

-        {

-            /* get mac entry by MAC address & vid */

-            mt.cvid = _strtoul(argv[2], NULL, 0);

-            mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_IVL;

-            AIR_PRINT("Get MAC Address:" MAC_STR " with vid:%u", MAC2STR(mt.mac), mt.cvid);

-        }

-        else if(FALSE == _strcmp(argv[1], "fid"))

-        {

-            /* get mac entry by MAC address & fid */

-            mt.fid = _strtoul(argv[2], NULL, 0);

-            AIR_PRINT("Get MAC Address:" MAC_STR " with fid:%u", MAC2STR(mt.mac), mt.fid);

-        }

-        else

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            return AIR_E_BAD_PARAMETER;

-        }

-        ret = air_l2_delMacAddr(0, &mt);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT(" Done.\n");

-        }

-        else

-            AIR_PRINT("\n Fail!\n");

-    }

-    else if(7 == argc)

-    {

-        /* l2 add mac <static(0:dynamic,1:static)> <unauth(0:auth,1:unauth)> <mac(12'hex)> <portlist(uintlist)> [ vid <vid(0..4095)> | fid <fid(0..15)> ] <src_mac_forward=(0:default,1:cpu-include,2:cpu-exclude,3:cpu-only,4:drop)> */

-        if(argv[0])

-            mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_STATIC;

-

-        if(argv[1])

-            mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_UNAUTH;

-

-        ret = _str2mac(argv[2], (C8_T *)mt.mac);

-        if(ret != AIR_E_OK)

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            return ret;

-        }

-

-        ret = _portListStr2Ary(argv[3], mt.port_bitmap, 1);

-        if(ret != AIR_E_OK)

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            return ret;

-        }

-

-        /* check argument fid or vid */

-        if(FALSE == _strcmp(argv[4], "vid"))

-        {

-            /* get mac entry by MAC address & vid */

-            mt.cvid = _strtoul(argv[5], NULL, 0);

-            mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_IVL;

-        }

-        else if(FALSE == _strcmp(argv[4], "fid"))

-        {

-            /* get mac entry by MAC address & fid */

-            mt.fid = _strtoul(argv[5], NULL, 0);

-        }

-        else

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            return AIR_E_BAD_PARAMETER;

-        }

-        fwd = _strtoul(argv[6], NULL, 0);

-        if(0 == fwd)

-            mt.sa_fwd = AIR_L2_FWD_CTRL_DEFAULT;

-        else if(1 == fwd)

-            mt.sa_fwd = AIR_L2_FWD_CTRL_CPU_INCLUDE;

-        else if(2 == fwd)

-            mt.sa_fwd = AIR_L2_FWD_CTRL_CPU_EXCLUDE;

-        else if(3 == fwd)

-            mt.sa_fwd = AIR_L2_FWD_CTRL_CPU_ONLY;

-        else if(4 == fwd)

-            mt.sa_fwd = AIR_L2_FWD_CTRL_DROP;

-        else

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            return AIR_E_BAD_PARAMETER;

-        }

-        ret = air_l2_addMacAddr(0, &mt);

-        AIR_PRINT("Add MAC Address:" MAC_STR, MAC2STR(mt.mac));

-        if(ret == AIR_E_OK)

-            AIR_PRINT(" Done.\n");

-        else

-            AIR_PRINT(" Fail.\n");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-_printMacEntry(

-        AIR_MAC_ENTRY_T *mt,

-        UI32_T age_unit,

-        UI8_T count,

-        UI8_T title)

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    I32_T i = 0, j = 0;

-    UI8_T first = 0;

-    UI8_T find = 0;

-    if(title)

-    {

-        AIR_PRINT("%-6s%-15s%-5s%-5s%-5s%-10s%-10s%-6s\n",

-                "unit",

-                "mac",

-                "ivl",

-                "vid",

-                "fid",

-                "age-time",

-                "forward",

-                "port");

-        return ret;

-    }

-    for(i = 0; i < count; i++)

-    {

-        AIR_PRINT("%-6d", age_unit);

-        AIR_PRINT(MAC_STR, MAC2STR(mt[i].mac));

-        AIR_PRINT("...");

-        if(mt[i].flags & AIR_L2_MAC_ENTRY_FLAGS_IVL)

-        {

-            AIR_PRINT("%-3s..", "ivl");

-            AIR_PRINT("%-5d", mt[i].cvid);

-            AIR_PRINT("%-5s", ".....");

-        }

-        else

-        {

-            AIR_PRINT("%-3s..", "svl");

-            AIR_PRINT("%-5s", ".....");

-            AIR_PRINT("%-5d", mt[i].fid);

-        }

-        if(mt[i].flags & AIR_L2_MAC_ENTRY_FLAGS_STATIC)

-        {

-            AIR_PRINT("%-10s.", "static");

-        }

-        else

-        {

-            AIR_PRINT("%d sec..", mt[i].timer);

-        }

-        AIR_PRINT("%-10s", _air_mac_address_forward_control_string[mt[i].sa_fwd]);

-        first = 0;

-        find = 0;

-        for (j = (AIR_MAX_NUM_OF_PORTS - 1); j >= 0; j--)

-        {

-            if((mt[i].port_bitmap[0]) & (1 << j))

-            {

-                first = j;

-                find = 1;

-                break;

-            }

-        }

-        if(find)

-        {

-            for (j = 0; j < AIR_MAX_NUM_OF_PORTS; j++)

-            {

-                if((mt[i].port_bitmap[0]) & (1 << j))

-                {

-                    if(j == first)

-                        AIR_PRINT("%-2d", j);

-                    else

-                        AIR_PRINT("%-2d,", j);

-                }

-            }

-        }

-        else

-            AIR_PRINT("no dst port");

-        AIR_PRINT("\n");

-    }

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doGetMacAddr(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI8_T count = 0;

-    AIR_MAC_ENTRY_T * ptr_mt;

-

-    if(3 == argc)

-    {

-        ptr_mt = AIR_MALLOC(sizeof(AIR_MAC_ENTRY_T));

-        if (NULL == ptr_mt)

-        {

-            AIR_PRINT("***Error***, allocate memory fail\n");

-            return AIR_E_OTHERS;

-        }

-        memset(ptr_mt, 0, sizeof(AIR_MAC_ENTRY_T));

-        /* l2 get mac <mac(12'hex)> { vid <vid(0..4095)> | fid <fid(0..15)> } */

-        ret = _str2mac(argv[0], (C8_T *)ptr_mt->mac);

-        if(ret != AIR_E_OK)

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            AIR_FREE(ptr_mt);

-            return ret;

-        }

-

-        /* check argument 1 */

-        if(FALSE == _strcmp(argv[1], "vid"))

-        {

-            /* get mac entry by MAC address & vid */

-            ptr_mt->cvid = _strtoul(argv[2], NULL, 0);

-            ptr_mt->flags |= AIR_L2_MAC_ENTRY_FLAGS_IVL;

-            AIR_PRINT("Get MAC Address:" MAC_STR " with vid:%u", MAC2STR(ptr_mt->mac), ptr_mt->cvid);

-        }

-        else if(FALSE == _strcmp(argv[1], "fid"))

-        {

-            /* get mac entry by MAC address & fid */

-            ptr_mt->fid = _strtoul(argv[2], NULL, 0);

-            AIR_PRINT("Get MAC Address:" MAC_STR " with fid:%u", MAC2STR(ptr_mt->mac), ptr_mt->fid);

-        }

-        else

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            AIR_FREE(ptr_mt);

-            return AIR_E_BAD_PARAMETER;

-        }

-        ret = air_l2_getMacAddr(0, &count, ptr_mt);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT(" Done.\n");

-            _printMacEntry(ptr_mt, 0, 1, TRUE);

-            _printMacEntry(ptr_mt, 0, 1, FALSE);

-        }

-        else

-            AIR_PRINT("\n Not found!\n");

-        AIR_FREE(ptr_mt);

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doMacAddrAgeOut(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T time = 0;

-    if(0 == argc)

-    {

-        /* l2 get macAddrAgeOut */

-        ret = air_l2_getMacAddrAgeOut(0, &time);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get MAC Address Age Out Time Done.\n");

-        }

-        else

-        {

-            AIR_PRINT("Get MAC Address Age Out Time Fail.\n");

-        }

-    }

-    else if(1 == argc)

-    {

-        /* l2 set macAddrAgeOut <time(1, 1000000)> */

-        time = _strtoul(argv[0], NULL, 0);

-        if(time < 1 || time > 1000000)

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            return AIR_E_BAD_PARAMETER;

-        }

-        ret = air_l2_setMacAddrAgeOut(0, time);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set MAC Address Age Out Time Done.\n");

-        }

-        else

-        {

-            AIR_PRINT("Set MAC Address Age Out Time Fail.\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        AIR_PRINT("MAC Address Age Out Time: %u seconds.\n", time);

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doDumpMacAddr(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    AIR_MAC_ENTRY_T *ptr_mt;

-    UI8_T count = 0;

-    UI32_T bucket_size = 0;

-    UI32_T total_count = 0;

-

-    if(0 != argc)

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-    /* get unit of aging time */

-    ret = air_l2_getMacBucketSize(0, &bucket_size);

-    if(ret != AIR_E_OK)

-    {

-        AIR_PRINT("Get MAC Age Time Fail!\n");

-        return ret;

-    }

-    ptr_mt = AIR_MALLOC(sizeof(AIR_MAC_ENTRY_T) * bucket_size);

-    if (NULL == ptr_mt)

-    {

-        AIR_PRINT("***Error***, allocate memory fail\n");

-        return AIR_E_OTHERS;

-    }

-    memset(ptr_mt, 0, sizeof(AIR_MAC_ENTRY_T) * bucket_size);

-    _printMacEntry(ptr_mt, 0, count, TRUE);

-    /* get 1st entry of MAC table */

-    ret = air_l2_getMacAddr(0, &count, ptr_mt);

-    switch(ret)

-    {

-        case AIR_E_ENTRY_NOT_FOUND:

-            AIR_FREE(ptr_mt);

-            AIR_PRINT("Not Found!\n");

-            return ret;

-        case AIR_E_TIMEOUT:

-            AIR_FREE(ptr_mt);

-            AIR_PRINT("Time Out!\n");

-            return ret;

-        case AIR_E_BAD_PARAMETER:

-            AIR_FREE(ptr_mt);

-            AIR_PRINT("Bad Parameter!\n");

-            return ret;

-        default:

-            break;

-    }

-    total_count += count;

-    _printMacEntry(ptr_mt, 0, count, FALSE);

-

-    /* get other entries of MAC table */

-    while(1)

-    {

-        memset(ptr_mt, 0, sizeof(AIR_MAC_ENTRY_T) * bucket_size);

-        ret = air_l2_getNextMacAddr(0, &count, ptr_mt);

-        if(AIR_E_OK != ret)

-        {

-            break;

-        }

-        total_count += count;

-        _printMacEntry(ptr_mt, 0, count, FALSE);

-    }

-    switch(ret)

-    {

-        case AIR_E_TIMEOUT:

-            AIR_PRINT("Time Out!\n");

-            break;

-        case AIR_E_BAD_PARAMETER:

-            AIR_PRINT("Bad Parameter!\n");

-            break;

-        default:

-            AIR_PRINT("Found %u %s\n", total_count, (total_count>1)?"entries":"entry");

-            break;

-    }

-    AIR_FREE(ptr_mt);

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doLagMember(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T portrunk_index = 0, member_index = 0, member_enable = 0, port_index = 0, i = 0;

-    AIR_LAG_PTGINFO_T  member;

-    memset(&member,0,sizeof(AIR_LAG_PTGINFO_T));

-

-    if(4 == argc)

-    {

-        /* lag set member <port trunk index> <member index> <member enable> <port_index>*/

-        portrunk_index  = _strtol(argv[0], NULL, 10);

-        member_index    = _strtol(argv[1], NULL, 10);

-        member_enable   = _strtol(argv[2], NULL, 10);

-        port_index      = _strtol(argv[3], NULL, 10);

-        ret = air_lag_setMember(0, portrunk_index, member_index, member_enable,port_index);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set port trunk index %d member_index:%d member_enable:%d, port_index:%d ok.\n", portrunk_index, member_index, member_enable,port_index);

-        }

-        else

-        {

-            AIR_PRINT("Set port trunk index %d member_index:%d member_enable:%d, port_index:%d fail.\n", portrunk_index, member_index, member_enable,port_index);

-        }

-        memset(&member,0,sizeof(member));

-        air_lag_getMember(0, portrunk_index, &member);

-        if(! member.csr_gp_enable[0])

-        {

-            AIR_PRINT("\r\n!!!!!!!!!Port trunk index %d member_index:0 must be set,or else have taffic issues.\n", portrunk_index);

-        }

-    }

-    else if(1 == argc)

-    {

-        portrunk_index = _strtol(argv[0], NULL, 10);

-

-        /* lag get member <port> */

-        memset(&member,0,sizeof(member));

-        ret = air_lag_getMember(0, portrunk_index, &member);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get port trunk %u member:\n", portrunk_index);

-            for(i = 0; i < AIR_LAG_MAX_MEM_NUM; i++)

-            {

-                if(member.csr_gp_enable[i])

-                    AIR_PRINT("port %d \r\n", member.csr_gp_port[i]);

-            }

-            AIR_PRINT("\r\n");

-        }

-        else

-        {

-            AIR_PRINT("Get port trunk:%u Member Fail.\n", portrunk_index);

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-

-static AIR_ERROR_NO_T

-doLagDstInfo(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    AIR_LAG_DISTINFO_T dstInfo;

-

-    memset(&dstInfo, 0, sizeof(AIR_LAG_DISTINFO_T));

-    if(7 == argc)

-    {

-        /* lag set dstInfo <sp> <sa> <da> <sip> <dip> <sport> <dport> */

-        dstInfo.sp = _strtol(argv[0], NULL, 10) & BIT(0);

-        dstInfo.sa = _strtol(argv[1], NULL, 10) & BIT(0);

-        dstInfo.da = _strtol(argv[2], NULL, 10) & BIT(0);

-        dstInfo.sip = _strtol(argv[3], NULL, 10) & BIT(0);

-        dstInfo.dip = _strtol(argv[4], NULL, 10) & BIT(0);

-        dstInfo.sport = _strtol(argv[5], NULL, 10) & BIT(0);

-        dstInfo.dport = _strtol(argv[6], NULL, 10) & BIT(0);

-        ret = air_lag_setDstInfo(0, dstInfo);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set LAG packet distrubution.\n");

-        }

-        else

-        {

-            AIR_PRINT("Set LAG packet distrubution Fail.\n");

-        }

-    }

-    else if(0 == argc)

-    {

-        /* lag get dstInfo */

-        ret = air_lag_getDstInfo(0, &dstInfo);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get LAG packet distrubution:\n");

-        }

-        else

-        {

-            AIR_PRINT("Get LAG packet distrubution Fail.\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-    if(ret == AIR_E_OK)

-    {

-        AIR_PRINT("%-5s|%-5s|%-5s|%-5s|%-5s|%-5s|%-5s\n",

-                "SP", "SA", "DA", "SIP", "DIP", "SPORT", "DPORT");

-        AIR_PRINT("%-5s|%-5s|%-5s|%-5s|%-5s|%-5s|%-5s\n",

-                (dstInfo.sp)?"En":"Dis",

-                (dstInfo.sa)?"En":"Dis",

-                (dstInfo.da)?"En":"Dis",

-                (dstInfo.sip)?"En":"Dis",

-                (dstInfo.dip)?"En":"Dis",

-                (dstInfo.sport)?"En":"Dis",

-                (dstInfo.dport)?"En":"Dis");

-    }

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doLagHashtype(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T hashtype = 0;

-

-    if(1 == argc)

-    {

-        hashtype = _strtol(argv[0], NULL, 10);

-        ret = air_lag_sethashtype(0, hashtype);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set LAG hashtype Ok.\n");

-        }

-        else

-        {

-            AIR_PRINT("Set LAG hashtype Fail.\n");

-        }

-    }

-    else if(0 == argc)

-    {

-        /* lag get dstInfo */

-        ret = air_lag_gethashtype(0, &hashtype);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get LAG hashtype:\n");

-        }

-        else

-        {

-            AIR_PRINT("Get LLAG hashtype Fail.\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-    if(ret == AIR_E_OK)

-    {

-        switch (hashtype)

-        {

-            case 0:

-                AIR_PRINT("hashtype:crc32lsb.\n");

-                break;

-            case 1:

-                AIR_PRINT("hashtype:crc32msb.\n");

-                break;

-            case 2:

-                AIR_PRINT("hashtype:crc16.\n");

-                break;

-            case 3:

-                AIR_PRINT("hashtype:xor4.\n");

-                break;

-            default:

-                AIR_PRINT("wrong hashtype:%d.\n",hashtype);

-        }

-

-    }

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doLagPtseed(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T ptseed = 0;

-

-    if(1 == argc)

-    {

-        ptseed = _strtol(argv[0], NULL, 16);

-        ret = air_lag_setPTSeed(0, ptseed);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set LAG Port Seed:%x(hex) ok\n",ptseed);

-        }

-        else

-        {

-            AIR_PRINT("Set LAG Port Seed:%x(hex) fail\n",ptseed);

-        }

-    }

-    else if(0 == argc)

-    {

-        /* lag get seed */

-        ret = air_lag_getPTSeed(0, &ptseed);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get port trunk seed: %x(hex)\n",ptseed);

-        }

-        else

-        {

-            AIR_PRINT("Get port trunk seed Fail.\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doLagSpsel(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    UI32_T state = 0;

-

-    if(1 == argc)

-    {

-        /* lag set spsel <state> */

-        state = _strtol(argv[0], NULL, 10);

-        ret = air_lag_setSpSel(0,state);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set source port compare function:%s.\n", (state)?"Enabled":"Disabled");

-        }

-        else

-        {

-            AIR_PRINT("Set source port compare function Fail.\n");

-        }

-    }

-    else if(0 == argc)

-    {

-        /* lag get spsel*/

-        ret = air_lag_getSpSel(0, &state);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get source port compare function:%s.\n", (state)?"Enabled":"Disabled");

-        }

-        else

-        {

-            AIR_PRINT("Get source port compare function Fail.\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-

-static AIR_ERROR_NO_T

-doLagState(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    UI32_T state = 0;

-

-    if(1 == argc)

-    {

-        /* lag set state <state> */

-        state = _strtol(argv[0], NULL, 10);

-        ret = air_lag_set_ptgc_state(0,state);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set LAG Port Trunk State:%s.\n", (state)?"Enabled":"Disabled");

-        }

-        else

-        {

-            AIR_PRINT("Set LAG Port Trunk State Fail.\n");

-        }

-    }

-    else if(0 == argc)

-    {

-        /* lag get state*/

-        ret = air_lag_get_ptgc_state(0, &state);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get LAG Port Trunk State:%s.\n", (state)?"Enabled":"Disabled");

-        }

-        else

-        {

-            AIR_PRINT("Get LAG Port Trunk State Fail.\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doLagGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(lagGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doLagSet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(lagSetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doLag(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(lagCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doStpPortstate(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    UI32_T fid = 0;

-    UI32_T state = 0;

-

-    port = _strtol(argv[0], NULL, 10);

-    fid = _strtol(argv[1], NULL, 10);

-    if(3 == argc)

-    {

-        /* stp set portstate <port> <fid(0..15)> <state> */

-        state = _strtol(argv[2], NULL, 10);

-        ret = air_stp_setPortstate(0, port, fid, state);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Set STP Port:%u FID:%u State:", port, fid);

-            switch(state)

-            {

-                case AIR_STP_STATE_DISABLE:

-                    AIR_PRINT("Disable(STP) / Discard(RSTP).\n");

-                    break;

-                case AIR_STP_STATE_LISTEN:

-                    AIR_PRINT("Listening(STP) / Discard(RSTP).\n");

-                    break;

-                case AIR_STP_STATE_LEARN:

-                    AIR_PRINT("Learning(STP) / Learning(RSTP).\n");

-                    break;

-                case AIR_STP_STATE_FORWARD:

-                    AIR_PRINT("Forwarding(STP) / Forwarding(RSTP).\n");

-                    break;

-                default:

-                    break;

-            }

-        }

-        else

-        {

-            AIR_PRINT("Set STP Port:%u FID:%u State Fail.", port, fid);

-        }

-    }

-    else if(2 == argc)

-    {

-        /* stp get portstate <port> <fid(0..15)> */

-        ret = air_stp_getPortstate(0, port, fid, &state);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Get STP Port:%u FID:%u State:", port, fid);

-            switch(state)

-            {

-                case AIR_STP_STATE_DISABLE:

-                    AIR_PRINT("Disable(STP) / Discard(RSTP).\n");

-                    break;

-                case AIR_STP_STATE_LISTEN:

-                    AIR_PRINT("Listening(STP) / Discard(RSTP).\n");

-                    break;

-                case AIR_STP_STATE_LEARN:

-                    AIR_PRINT("Learning(STP) / Learning(RSTP).\n");

-                    break;

-                case AIR_STP_STATE_FORWARD:

-                    AIR_PRINT("Forwarding(STP) / Forwarding(RSTP).\n");

-                    break;

-                default:

-                    break;

-            }

-        }

-        else

-        {

-            AIR_PRINT("Get STP Port:%u FID:%u State Fail.", port, fid);

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doStpGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(stpGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doStpSet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(stpSetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doStp(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(stpCmds, argc, argv);

-}

-

-static void

-_mir_printPortList(UI32_T * mt)

-{

-    I8_T j = 0;

-    UI8_T first = 0;

-    UI8_T find = 0;

-    for(j = (AIR_MAX_NUM_OF_PORTS - 1); j >= 0; j--)

-    {

-        if((*mt) & (1 << j))

-        {

-            first = j;

-            find = 1;

-            break;

-        }

-    }

-    if(find)

-    {

-        for(j = 0; j < AIR_MAX_NUM_OF_PORTS; j++)

-        {

-            if((*mt) & (1 << j))

-            {

-                if(j == first)

-                    AIR_PRINT("%-2d", j);

-                else

-                    AIR_PRINT("%-2d,", j);

-            }

-        }

-    }

-    else

-        AIR_PRINT("NULL");

-    AIR_PRINT("\n");

-}

-

-static void

-_mir_printSrcPortList(

-    const UI32_T         unit,

-    const UI32_T         sessionid)

-{

-

-    I8_T i = 0;

-    AIR_MIR_SESSION_T   session;

-    AIR_PORT_BITMAP_T txPbm = {0}, rxPbm = {0};

-

-    for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-    {

-         memset(&session, 0, sizeof(session));

-         session.src_port = i;

-         air_mir_getMirrorPort(unit, sessionid, &session);

-

-         if(session.flags & AIR_MIR_SESSION_FLAGS_DIR_TX)

-         {

-            txPbm[0] |= (1 << i);

-         }

-         if(session.flags & AIR_MIR_SESSION_FLAGS_DIR_RX)

-         {

-            rxPbm[0] |= (1 << i);

-         }

-    }

-    AIR_PRINT("Src PortList\n");

-    AIR_PRINT(" - Rx portlist = ");

-    _mir_printPortList(rxPbm);

-    AIR_PRINT(" - Tx portlist = ");

-    _mir_printPortList(txPbm);

-}

-

-static void

-_mir_printSession(

-    const UI32_T            unit,

-    const UI32_T            session_id,

-    const AIR_MIR_SESSION_T *ptr_session)

-{

-

-    AIR_PRINT("Session id: %d\n", session_id);

-    AIR_PRINT("State: %s \n", (ptr_session->flags & AIR_MIR_SESSION_FLAGS_ENABLE)? "enable": "disable");

-    AIR_PRINT("Tx tag: %s \n", (ptr_session->flags & AIR_MIR_SESSION_FLAGS_TX_TAG_OBEY_CFG)? "On": "Off");

-    AIR_PRINT("Dst port: %d \n", ptr_session->dst_port);

-    _mir_printSrcPortList(unit,session_id);

-}

-

-static AIR_ERROR_NO_T

-doMirrorGetSid(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T      rc = AIR_E_OK;

-    UI32_T              session_id = 0;

-    AIR_MIR_SESSION_T   session = {0};

-    I8_T i = 0;

-

-    session_id = _strtoul(argv[0], NULL, 0);

-    rc = air_mir_getSession(0, session_id, &session);

-    if (AIR_E_OK != rc)

-    {

-        AIR_PRINT("***Error***, get mirror session fail\n");

-        return rc;

-    }

-    /* print session information */

-    if(session.dst_port == AIR_PORT_INVALID)

-    {

-        AIR_PRINT("Session id %d not found\n", session_id);

-    }

-    else

-    {

-        _mir_printSession(0, session_id, &session);

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doMirrorDelSid(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T      rc = AIR_E_OK;

-    UI32_T              session_id = 0;

-    AIR_MIR_SESSION_T   session = {0};

-    UI8_T i = 0;

-

-    session_id = _strtoul(argv[0], NULL, 0);

-    rc = air_mir_delSession(0, session_id);

-    if (AIR_E_OK != rc)

-    {

-        AIR_PRINT("***Error***, del mirror session fail\n");

-        return rc;

-    }

-    for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-    {

-        session.src_port = i;

-        rc = air_mir_setMirrorPort(0, session_id, &session);

-        if (AIR_E_OK != rc)

-        {

-            AIR_PRINT("***Error***,port=%u error\n", i);

-            return rc;

-        }

-    }

-    if (rc != AIR_E_OK)

-    {

-        AIR_PRINT("***Error***, delete mirror session fail\n");

-    }

-    else

-        AIR_PRINT("***OK***, delete mirror session success\n");

-

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doMirrorAddRlist(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T      rc = AIR_E_OK;

-    UI32_T              session_id = 0;

-    AIR_MIR_SESSION_T   session = {0};

-    AIR_PORT_BITMAP_T rxPbm = {0};

-    UI8_T i = 0;

-

-    /*mirror add session-rlist <sid(0..3)> <list(UINTLIST)>*/

-    session_id = _strtoul(argv[0], NULL, 0);

-    rc = _portListStr2Ary(argv[1], rxPbm, 1);

-    if(rc != AIR_E_OK)

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return rc;

-    }

-    if(!rxPbm[0])

-    {

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            memset(&session, 0, sizeof(AIR_MIR_SESSION_T));

-            session.src_port = i;

-            rc = air_mir_getMirrorPort(0, session_id, &session);

-            if (AIR_E_OK != rc)

-            {

-                AIR_PRINT("***Error***,get port=%u error\n", i);

-                return rc;

-            }

-

-            session.flags &= ~AIR_MIR_SESSION_FLAGS_DIR_RX;

-            session.src_port = i;

-            rc = air_mir_setMirrorPort(0, session_id, &session);

-            if (AIR_E_OK != rc)

-            {

-                AIR_PRINT("***Error***,set rx port=%u error\n", i);

-                return rc;

-            }

-        }

-    }

-    else

-    {

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(rxPbm[0] & (1 << i))

-            {

-                memset(&session, 0, sizeof(AIR_MIR_SESSION_T));

-                session.src_port = i;

-                rc = air_mir_getMirrorPort(0, session_id, &session);

-                if (AIR_E_OK != rc)

-                {

-                    AIR_PRINT("***Error***,get port=%u error\n", i);

-                    return rc;

-                }

-

-                session.flags |= AIR_MIR_SESSION_FLAGS_DIR_RX;

-                session.src_port = i;

-                rc = air_mir_setMirrorPort(0, session_id, &session);

-                if (AIR_E_OK != rc)

-                {

-                    AIR_PRINT("***Error***,port=%u error\n", i);

-                    return rc;

-                }

-            }

-        }

-    }

-

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doMirrorAddTlist(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T      rc = AIR_E_OK;

-    UI32_T              session_id = 0;

-    AIR_MIR_SESSION_T   session = {0};

-    AIR_PORT_BITMAP_T txPbm = {0};

-    UI8_T i = 0;

-

-    /*mirror add session-tlist <sid(0..3)> <list(UINTLIST)>*/

-    session_id = _strtoul(argv[0], NULL, 0);

-    rc = _portListStr2Ary(argv[1], txPbm, 1);

-    if(rc != AIR_E_OK)

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return rc;

-    }

-    if(!txPbm[0])

-    {

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            memset(&session, 0, sizeof(AIR_MIR_SESSION_T));

-            session.src_port = i;

-            rc = air_mir_getMirrorPort(0, session_id, &session);

-            if (AIR_E_OK != rc)

-            {

-                AIR_PRINT("***Error***,get port=%u error\n", i);

-                return rc;

-            }

-

-            session.flags &= ~AIR_MIR_SESSION_FLAGS_DIR_TX;

-            session.src_port = i;

-            rc = air_mir_setMirrorPort(0, session_id, &session);

-            if (AIR_E_OK != rc)

-            {

-                AIR_PRINT("***Error***,set rx port=%u error\n", i);

-                return rc;

-            }

-        }

-    }

-    else

-    {

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(txPbm[0] & (1 << i))

-            {

-                memset(&session, 0, sizeof(AIR_MIR_SESSION_T));

-                session.src_port = i;

-                rc = air_mir_getMirrorPort(0, session_id, &session);

-                if (AIR_E_OK != rc)

-                {

-                    AIR_PRINT("***Error***,get port=%u error\n", i);

-                    return rc;

-                }

-

-                session.flags |= AIR_MIR_SESSION_FLAGS_DIR_TX;

-                session.src_port = i;

-                rc = air_mir_setMirrorPort(0, session_id, &session);

-                if (AIR_E_OK != rc)

-                {

-                    AIR_PRINT("***Error***,port=%u error\n", i);

-                    return rc;

-                }

-            }

-        }

-    }

-

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doMirrorSetSessionEnable(

-    UI32_T argc,

-    C8_T *argv[])

-

-{

-    AIR_ERROR_NO_T      rc = AIR_E_OK;

-    UI32_T              session_id = 0;

-    UI32_T              enable = 0;

-    BOOL_T              tmp_en = FALSE;

-

-    /*mirror set session-enable <sid(0..3)> <state(1:En,0:Dis)>*/

-    session_id = _strtoul(argv[0], NULL, 0);

-    enable = _strtoul(argv[1], NULL, 0);

-    if(enable)

-        tmp_en = TRUE;

-    /* set port mirror state */

-    rc = air_mir_setSessionAdminMode(0, session_id, tmp_en);

-    if(AIR_E_OK!=rc)

-    {

-        AIR_PRINT("***Error***\n");

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doMirrorSetSession(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T      rc = AIR_E_OK;

-    UI32_T              session_id = 0;

-    UI32_T              dst_port = 0;

-    UI8_T               enable = 0;

-    UI8_T               tag_en = 0;

-    UI8_T               dir = 0;

-    AIR_MIR_SESSION_T  session = {0};

-    AIR_PORT_BITMAP_T   rxPbm = {0};

-    I8_T               i = 0;

-

-    /*mirror set session <sid(0..3)> <dst_port(UINT)> <state(1:En,0:Dis)> <tag(1:on, 0:off)> <list(UINTLIST)> <dir(0:none,1:tx,2:rx,3:both)>*/

-    session_id = _strtoul(argv[0], NULL, 0);

-    dst_port = _strtoul(argv[1], NULL, 0);

-    AIR_PRINT("session id %d dst port %d.\n", session_id, dst_port);

-    session.dst_port = dst_port;

-    enable = _strtoul(argv[2], NULL, 0);

-    if(enable)

-    {

-        session.flags |= AIR_MIR_SESSION_FLAGS_ENABLE;

-    }

-    else

-    {

-        session.flags &= ~AIR_MIR_SESSION_FLAGS_ENABLE;

-    }

-    tag_en = _strtoul(argv[3], NULL, 0);

-    if(tag_en)

-    {

-        session.flags |= AIR_MIR_SESSION_FLAGS_TX_TAG_OBEY_CFG;

-    }

-    else

-    {

-        session.flags &= ~AIR_MIR_SESSION_FLAGS_TX_TAG_OBEY_CFG;

-    }

-    rc = _portListStr2Ary(argv[4], rxPbm, 1);

-    if(rc != AIR_E_OK)

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return rc;

-    }

-    AIR_PRINT("pbm %x.\n", rxPbm);

-    dir = _strtoul(argv[5], NULL, 0);

-    if(dir == 1)

-    {

-        session.flags |= AIR_MIR_SESSION_FLAGS_DIR_TX;

-    }

-    else if(dir == 2)

-    {

-        session.flags |= AIR_MIR_SESSION_FLAGS_DIR_RX;

-    }

-    else if(dir == 3)

-    {

-        session.flags |= AIR_MIR_SESSION_FLAGS_DIR_TX;

-        session.flags |= AIR_MIR_SESSION_FLAGS_DIR_RX;

-    }

-    else if (!dir)

-    {

-        session.flags &= ~AIR_MIR_SESSION_FLAGS_DIR_TX;

-        session.flags &= ~AIR_MIR_SESSION_FLAGS_DIR_RX;

-    }

-    else

-    {

-        return AIR_E_BAD_PARAMETER;

-    }

-    for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-    {

-        if(rxPbm[0] & (1 << i))

-        {

-            session.src_port = i;

-            /* set port mirror session */

-            rc = air_mir_addSession(0, session_id, &session);

-

-            if(AIR_E_OK!=rc)

-            {

-                AIR_PRINT("***Error***,dst-port=%u, src-port=%u error\n", session.dst_port, session.src_port);

-                return rc;

-            }

-            else

-                AIR_PRINT("add session %d,dst-port=%u, src-port=%u\n", session_id, session.dst_port, session.src_port);

-        }

-    }

-

-    return rc;

-}

-

-

-

-static AIR_ERROR_NO_T

-doMirrorSet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(mirrorSetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doMirrorAdd(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(mirrorAddCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doMirrorGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(mirrorGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doMirrorDel(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(mirrorDelCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doMirror(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(mirrorCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doMibClearPort(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-

-    if(1 == argc)

-    {

-        /* mib clear port */

-        port = _strtoul(argv[0], NULL, 0);

-        ret = air_mib_clear_by_port(0,port);

-        AIR_PRINT("Clear port %d mib stats",port);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Done.\n");

-        }

-        else

-        {

-            AIR_PRINT("Fail.\n");

-        }

-    }

-    else if(0 == argc)

-    {

-        /*restart mib counter*/

-        air_mib_clear(0);

-        AIR_PRINT("Clear all mib stats",port);

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doMibClearAcl(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-

-    if(0 == argc)

-    {

-        /* mib clear acl */

-        ret = air_mib_clearAclEvent(0);

-        AIR_PRINT("Clear ACL Event Counter ");

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Done.\n");

-        }

-        else

-        {

-            AIR_PRINT("Fail.\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doMibGetPort(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0;

-    UI32_T tmp32 = 0xffffffff;

-    AIR_MIB_CNT_RX_T rx_mib = {0};

-    AIR_MIB_CNT_TX_T tx_mib = {0};

-

-    port = _strtoul(argv[0], NULL, 0);

-    if(1 == argc)

-    {

-        /* mib get <port(0..6)> */

-        ret = air_mib_get(0, port, &rx_mib, &tx_mib);

-        AIR_PRINT("Get MIB Counter of Port %u ", port);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Done.\n");

-            AIR_PRINT("RX Drop Packet                    : %u\n", rx_mib.RDPC);

-            AIR_PRINT("RX filtering Packet               : %u\n", rx_mib.RFPC);

-            AIR_PRINT("RX Unicast Packet                 : %u\n", rx_mib.RUPC);

-            AIR_PRINT("RX Multicast Packet               : %u\n", rx_mib.RMPC);

-            AIR_PRINT("RX Broadcast Packet               : %u\n", rx_mib.RBPC);

-            AIR_PRINT("RX Alignment Error Packet         : %u\n", rx_mib.RAEPC);

-            AIR_PRINT("RX CRC Packet                     : %u\n", rx_mib.RCEPC);

-            AIR_PRINT("RX Undersize Packet               : %u\n", rx_mib.RUSPC);

-            AIR_PRINT("RX Fragment Error Packet          : %u\n", rx_mib.RFEPC);

-            AIR_PRINT("RX Oversize Packet                : %u\n", rx_mib.ROSPC);

-            AIR_PRINT("RX Jabber Error Packet            : %u\n", rx_mib.RJEPC);

-            AIR_PRINT("RX Pause Packet                   : %u\n", rx_mib.RPPC);

-            AIR_PRINT("RX Packet Length 64 bytes         : %u\n", rx_mib.RL64PC);

-            AIR_PRINT("RX Packet Length 65 ~ 127 bytes   : %u\n", rx_mib.RL65PC);

-            AIR_PRINT("RX Packet Length 128 ~ 255 bytes  : %u\n", rx_mib.RL128PC);

-            AIR_PRINT("RX Packet Length 256 ~ 511 bytes  : %u\n", rx_mib.RL256PC);

-            AIR_PRINT("RX Packet Length 512 ~ 1023 bytes : %u\n", rx_mib.RL512PC);

-            AIR_PRINT("RX Packet Length 1024 ~ 1518 bytes: %u\n", rx_mib.RL1024PC);

-            AIR_PRINT("RX Packet Length 1519 ~ max bytes : %u\n", rx_mib.RL1519PC);

-            AIR_PRINT("RX_CTRL Drop Packet               : %u\n", rx_mib.RCDPC);

-            AIR_PRINT("RX Ingress Drop Packet            : %u\n", rx_mib.RIDPC);

-            AIR_PRINT("RX ARL Drop Packet                : %u\n", rx_mib.RADPC);

-            AIR_PRINT("FLow Control Drop Packet          : %u\n", rx_mib.FCDPC);

-            AIR_PRINT("WRED Drop Packtet                 : %u\n", rx_mib.WRDPC);

-            AIR_PRINT("Mirror Drop Packet                : %u\n", rx_mib.MRDPC);

-            AIR_PRINT("RX  sFlow Sampling Packet         : %u\n", rx_mib.SFSPC);

-            AIR_PRINT("Rx sFlow Total Packet             : %u\n", rx_mib.SFTPC);

-            AIR_PRINT("Port Control Drop Packet          : %u\n", rx_mib.RXC_DPC);

-            AIR_PRINT("RX Octets good or bad packtes l32 : %u\n", (UI32_T)(rx_mib.ROC & tmp32));

-            AIR_PRINT("RX Octets good or bad packtes h32 : %u\n", (UI32_T)((rx_mib.ROC >> 32) & tmp32));

-            AIR_PRINT("RX Octets bad packets l32         : %u\n", (UI32_T)(rx_mib.ROC2 & tmp32));

-            AIR_PRINT("RX Octets bad packets h32         : %u\n", (UI32_T)((rx_mib.ROC2 >> 32) & tmp32));

-            AIR_PRINT("\n");

-            AIR_PRINT("TX Drop Packet                    : %u\n", tx_mib.TDPC);

-            AIR_PRINT("TX CRC Packet                     : %u\n", tx_mib.TCRC);

-            AIR_PRINT("TX Unicast Packet                 : %u\n", tx_mib.TUPC);

-            AIR_PRINT("TX Multicast Packet               : %u\n", tx_mib.TMPC);

-            AIR_PRINT("TX Broadcast Packet               : %u\n", tx_mib.TBPC);

-            AIR_PRINT("TX Collision Event Count          : %u\n", tx_mib.TCEC);

-            AIR_PRINT("TX Single Collision Event Count   : %u\n", tx_mib.TSCEC);

-            AIR_PRINT("TX Multiple Conllision Event Count: %u\n", tx_mib.TMCEC);

-            AIR_PRINT("TX Deferred Event Count           : %u\n", tx_mib.TDEC);

-            AIR_PRINT("TX Late Collision Event Count     : %u\n", tx_mib.TLCEC);

-            AIR_PRINT("TX Excessive Collision Event Count: %u\n", tx_mib.TXCEC);

-            AIR_PRINT("TX Pause Packet                   : %u\n", tx_mib.TPPC);

-            AIR_PRINT("TX Packet Length 64 bytes         : %u\n", tx_mib.TL64PC);

-            AIR_PRINT("TX Packet Length 65 ~ 127 bytes   : %u\n", tx_mib.TL65PC);

-            AIR_PRINT("TX Packet Length 128 ~ 255 bytes  : %u\n", tx_mib.TL128PC);

-            AIR_PRINT("TX Packet Length 256 ~ 511 bytes  : %u\n", tx_mib.TL256PC);

-            AIR_PRINT("TX Packet Length 512 ~ 1023 bytes : %u\n", tx_mib.TL512PC);

-            AIR_PRINT("TX Packet Length 1024 ~ 1518 bytes: %u\n", tx_mib.TL1024PC);

-            AIR_PRINT("TX Packet Length 1519 ~ max bytes : %u\n", tx_mib.TL1519PC);

-            AIR_PRINT("TX Oversize Drop Packet           : %u\n", tx_mib.TODPC);

-            AIR_PRINT("TX Octets good or bad packtes l32 : %u\n", (UI32_T)(tx_mib.TOC & tmp32));

-            AIR_PRINT("TX Octets good or bad packtes h32 : %u\n", (UI32_T)((tx_mib.TOC >> 32) & tmp32));

-            AIR_PRINT("TX Octets bad packets l32         : %u\n", (UI32_T)(tx_mib.TOC2 & tmp32));

-            AIR_PRINT("TX Octets bad packets h32         : %u\n", (UI32_T)((tx_mib.TOC2 >> 32) & tmp32));

-        }

-        else

-        {

-            AIR_PRINT("Fail.\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doMibGetAcl(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T event = 0;

-    UI32_T cnt = 0;

-

-    if(1 == argc)

-    {

-        /* mib get acl <event(0..7)> */

-        event = _strtoul(argv[0], NULL, 0);

-        ret = air_mib_getAclEvent(0, event, &cnt);

-        AIR_PRINT("Get counter of ACL event %u ", event);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Done.\n");

-            AIR_PRINT("ACL Event Counter:%u\n", cnt);

-        }

-        else

-        {

-            AIR_PRINT("Fail.\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doMibClear(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(mibClearCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doMibGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(mibGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doMib(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(mibCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doQosRateLimitExMngFrm(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T dir = 0;

-    BOOL_T enable = FALSE;

-

-    dir = _strtoul(argv[0], NULL, 0);

-    if(2 == argc)

-    {

-        if(dir == 0)

-            dir = AIR_QOS_RATE_DIR_EGRESS;

-        else if(dir == 1)

-            dir = AIR_QOS_RATE_DIR_INGRESS;

-        else

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            ret = AIR_E_BAD_PARAMETER;

-            return ret;

-        }

-        enable = _strtoul(argv[1], NULL, 0);

-        ret = air_qos_setRateLimitExMngFrm(0, dir, enable);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Success.\n");

-            AIR_PRINT("Set %s Rate Limit Control %s management frame.\n",

-                    (AIR_QOS_RATE_DIR_INGRESS == dir)?"Ingress":"Egress",

-                    (TRUE == enable)?"exclude":"include");

-        }

-        else

-        {

-            AIR_PRINT("Fail.\n");

-            return ret;

-        }

-    }

-    else if(0 == argc)

-    {

-        dir = AIR_QOS_RATE_DIR_EGRESS;

-        ret = air_qos_getRateLimitExMngFrm(0, dir, &enable);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Success.\n");

-            AIR_PRINT("Get %s Rate Limit Control %s management frame.\n",

-                    (AIR_QOS_RATE_DIR_INGRESS == dir)?"Ingress":"Egress",

-                    (TRUE == enable)?"exclude":"include");

-        }

-        else

-        {

-            AIR_PRINT("Fail.\n");

-            return ret;

-        }

-        dir = AIR_QOS_RATE_DIR_INGRESS;

-        ret = air_qos_getRateLimitExMngFrm(0, dir, &enable);

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT("Success.\n");

-            AIR_PRINT("Get %s Rate Limit Control %s management frame.\n",

-                    (AIR_QOS_RATE_DIR_INGRESS == dir)?"Ingress":"Egress",

-                    (TRUE == enable)?"exclude":"include");

-        }

-        else

-        {

-            AIR_PRINT("Fail.\n");

-            return ret;

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-

-}

-

-static AIR_ERROR_NO_T

-doQosPortPriority(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    AIR_PORT_BITMAP_T portlist = {0};

-    UI32_T priority = 0;

-    UI8_T i = 0;

-

-    ret = _portListStr2Ary(argv[0], portlist, 1);

-    if(ret != AIR_E_OK)

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return ret;

-    }

-    if(2 == argc)

-    {

-        priority = _strtoul(argv[1], NULL, 0);

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(portlist[0] & (1 << i))

-            {

-                ret = air_qos_setPortPriority(0, i, priority);

-                if(ret == AIR_E_OK)

-                {

-                    AIR_PRINT("Set Port%02d port based priority %d Success.\n", i, priority);

-                }

-                else

-                {

-                    AIR_PRINT("Set Port%02d port based priority %d Fail.\n", i, priority);

-                }

-            }

-        }

-    }

-    else if(1 == argc)

-    {

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(portlist[0] & (1 << i))

-            {

-                ret = air_qos_getPortPriority(0, i, &priority);

-                if(ret == AIR_E_OK)

-                {

-                    AIR_PRINT("Get Port%d port based priority %d.\n", i, priority);

-                }

-                else

-                {

-                    AIR_PRINT("Get Port%d port based priority Fail.\n", i);

-                }

-            }

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doQosRateLimit(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    AIR_PORT_BITMAP_T portlist = {0};

-    AIR_QOS_RATE_LIMIT_CFG_T rl = {0};

-    UI8_T i = 0;

-

-    ret = _portListStr2Ary(argv[0], portlist, 1);

-    if(ret != AIR_E_OK)

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return ret;

-    }

-    if(5 == argc)

-    {

-        rl.ingress_cir = _strtoul(argv[1], NULL, 0);

-        rl.ingress_cbs = _strtoul(argv[2], NULL, 0);

-        rl.egress_cir = _strtoul(argv[3], NULL, 0);

-        rl.egress_cbs = _strtoul(argv[4], NULL, 0);

-        rl.flags |= AIR_QOS_RATE_LIMIT_CFG_FLAGS_ENABLE_INGRESS;

-        rl.flags |= AIR_QOS_RATE_LIMIT_CFG_FLAGS_ENABLE_EGRESS;

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(portlist[0] & (1 << i))

-            {

-                ret = air_qos_setRateLimit(0, i, &rl);

-                if(ret == AIR_E_OK)

-                {

-                    AIR_PRINT("Set Port%02d Ingress CIR %d CBS %d Egress CIR %d CBS %d Success.\n", i, rl.ingress_cir, rl.ingress_cbs, rl.egress_cir, rl.egress_cbs);

-                }

-                else

-                {

-                    AIR_PRINT("Set Port%02d Ingress CIR %d CBS %d Egress CIR %d CBS %d Fail.\n", i, rl.ingress_cir, rl.ingress_cbs, rl.egress_cir, rl.egress_cbs);

-                }

-            }

-        }

-    }

-    else if(1 == argc)

-    {

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(portlist[0] & (1 << i))

-            {

-                ret = air_qos_getRateLimit(0, i, &rl);

-                if(ret == AIR_E_OK)

-                {

-                    AIR_PRINT("Get Port%02d Ingress CIR %d CBS %d Egress CIR %d CBS %d\n", i, rl.ingress_cir, rl.ingress_cbs, rl.egress_cir, rl.egress_cbs);

-                }

-                else

-                {

-                    AIR_PRINT("Get Port%02d Rate Info Fail.\n", i);

-                }

-            }

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doQosRateLimitEnable(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    AIR_PORT_BITMAP_T portlist = {0};

-    C8_T sten[2][10] = {"Disable", "Enable"};

-    C8_T stdir[2][10] = {"Egress", "Ingress"};

-    UI32_T dir = 0, en = 0;

-    AIR_QOS_RATE_DIR_T tmp_dir = AIR_QOS_RATE_DIR_LAST;

-    BOOL_T state = FALSE;

-    UI8_T i = 0;

-

-    ret = _portListStr2Ary(argv[0], portlist, 1);

-    if(ret != AIR_E_OK)

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return ret;

-    }

-    if(3 == argc)

-    {

-        dir = _strtoul(argv[1], NULL, 0);

-        en = _strtoul(argv[2], NULL, 0);

-        if(dir == 0)

-            tmp_dir = AIR_QOS_RATE_DIR_EGRESS;

-        else if(dir == 1)

-            tmp_dir = AIR_QOS_RATE_DIR_INGRESS;

-        else

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            return AIR_E_BAD_PARAMETER;

-        }

-        if(en)

-            state= TRUE;

-        else

-            state = FALSE;

-

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(portlist[0] & (1 << i))

-            {

-                ret = air_qos_setRateLimitEnable(0, i, tmp_dir, state);

-                if(AIR_E_OK == ret)

-                {

-                    AIR_PRINT("Set Port%02d %s rate %s Success.\n", i, stdir[dir], sten[en]);

-                }

-                else

-                {

-                    AIR_PRINT("Set Port%02d %s rate %s Fail.\n", i, stdir[dir], sten[en]);

-                }

-            }

-        }

-    }

-    else if(1 == argc)

-    {

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(portlist[0] & (1 << i))

-            {

-                tmp_dir = AIR_QOS_RATE_DIR_EGRESS;

-                dir = 0;

-                ret = air_qos_getRateLimitEnable(0, i, tmp_dir, &state);

-                if(AIR_E_OK == ret)

-                {

-                    AIR_PRINT("Get Port%02d %s rate %s Success.\n", i, stdir[dir], sten[state]);

-                }

-                else

-                {

-                    AIR_PRINT("Get Port%02d %s rate state Fail.\n", i, stdir[dir]);

-                }

-                tmp_dir = AIR_QOS_RATE_DIR_INGRESS;

-                dir = 1;

-                ret = air_qos_getRateLimitEnable(0, i, tmp_dir, &state);

-                if(AIR_E_OK == ret)

-                {

-                    AIR_PRINT("Get Port%02d %s rate %s Success.\n", i, stdir[dir], sten[state]);

-                }

-                else

-                {

-                    AIR_PRINT("Get Port%02d %s rate state Fail.\n", i, stdir[dir]);

-                }

-            }

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-

-}

-

-static AIR_ERROR_NO_T

-doQosDscp2Pri(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T dscp = 0, priority = 0;

-

-    dscp = _strtoul(argv[0], NULL, 0);

-    if(2 == argc)

-    {

-        priority = _strtoul(argv[1], NULL, 0);

-        ret = air_qos_setDscp2Pri(0, dscp, priority);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Set DSCP %d to priority %d Success.\n", dscp, priority);

-        }

-        else

-        {

-            AIR_PRINT("Set DSCP %d to priority %d Fail.\n", dscp, priority);

-        }

-    }

-    else if(1 == argc)

-    {

-        ret = air_qos_getDscp2Pri(0, dscp, &priority);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Get DSCP %d to priority %d\n", dscp, priority);

-        }

-        else

-        {

-            AIR_PRINT("Get DSCP %d to priority Fail.\n", dscp);

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doQosPri2Queue(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T priority = 0, queue = 0;

-

-    priority = _strtoul(argv[1], NULL, 0);

-

-    if(2 == argc)

-    {

-        priority = _strtoul(argv[0], NULL, 0);

-        queue = _strtoul(argv[1], NULL, 0);

-        ret = air_qos_setPri2Queue(0, priority, queue);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Set priority %d to queue %d Success.\n", priority, queue);

-        }

-        else

-        {

-            AIR_PRINT("Set priority %d to queue %d Fail.\n", priority, queue);

-        }

-    }

-    else

-    {

-        for(; priority < AIR_QOS_QUEUE_MAX_NUM; priority++)

-        {

-            ret = air_qos_getPri2Queue(0, priority, &queue);

-            if(AIR_E_OK == ret)

-            {

-                AIR_PRINT("Get priority %d to queue %d\n", priority, queue);

-            }

-            else

-            {

-                AIR_PRINT("Get priority %d to queue Fail.\n", priority);

-            }

-        }

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doQosTrustMode(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T mode = 0;

-    C8_T bs[4][13] = {"port", "1p_port", "dscp_port", "dscp_1p_port"};

-    AIR_QOS_TRUST_MODE_T mode_t = AIR_QOS_TRUST_MODE_LAST;

-    AIR_PORT_BITMAP_T portlist = {0};

-    UI8_T i = 0;

-

-    ret = _portListStr2Ary(argv[0], portlist, 1);

-    if(ret != AIR_E_OK)

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return ret;

-    }

-    if(2 == argc)

-    {

-        mode = _strtoul(argv[1], NULL, 0);

-        if(mode == 0)

-            mode_t = AIR_QOS_TRUST_MODE_PORT;

-        else if(mode == 1)

-            mode_t = AIR_QOS_TRUST_MODE_1P_PORT;

-        else if(mode == 2)

-            mode_t = AIR_QOS_TRUST_MODE_DSCP_PORT;

-        else if(mode == 3)

-            mode_t = AIR_QOS_TRUST_MODE_DSCP_1P_PORT;

-        else

-        {

-            AIR_PRINT("Unrecognized command.\n");

-            return AIR_E_BAD_PARAMETER;

-        }

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(portlist[0] & (1 << i))

-            {

-                ret = air_qos_setTrustMode(0, i, mode_t);

-                if(AIR_E_OK == ret)

-                {

-                    AIR_PRINT("port %d Set Trust mode %s Success.\n", i, bs[mode]);

-                }

-                else

-                {

-                    AIR_PRINT("port %d Set Trust mode %s Fail.\n", i, bs[mode]);

-                }

-            }

-        }

-    }

-    else if(1 == argc)

-    {

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(portlist[0] & (1 << i))

-            {

-                mode_t = AIR_QOS_TRUST_MODE_LAST;

-                ret = air_qos_getTrustMode(0, i, &mode_t);

-                if(AIR_E_OK == ret)

-                {

-                    if(mode_t == AIR_QOS_TRUST_MODE_PORT)

-                        mode = 0;

-                    else if(mode_t == AIR_QOS_TRUST_MODE_1P_PORT)

-                        mode = 1;

-                    else if(mode_t == AIR_QOS_TRUST_MODE_DSCP_PORT)

-                        mode = 2;

-                    else if(mode_t == AIR_QOS_TRUST_MODE_DSCP_1P_PORT)

-                        mode = 3;

-                    else

-                    {

-                        AIR_PRINT("port %d Get Trust mode Fail.\n", i);

-                        return AIR_E_OTHERS;

-                    }

-                    AIR_PRINT("port %d Get Trust mode %s\n", i, bs[mode]);

-                }

-                else

-                {

-                    AIR_PRINT("port %d Get Trust mode Fail.\n", i);

-                }

-            }

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doQosScheduleAlgo(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    AIR_PORT_BITMAP_T portlist = {0};

-    AIR_QOS_SCH_MODE_T sch_mode = AIR_QOS_SCH_MODE_LAST;

-    UI32_T scheduler = 0;

-    UI8_T queue = 0;

-    C8_T sche[3][5] = {"SP", "WRR", "WFQ"};

-    UI32_T weight = AIR_QOS_SHAPER_NOSETTING;

-    UI8_T i = 0;

-

-    ret = _portListStr2Ary(argv[0], portlist, 1);

-    if(ret != AIR_E_OK)

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return ret;

-    }

-    AIR_PRINT("port list is %d\n", portlist[0]);

-    if(4 == argc)

-    {

-        queue = _strtoul(argv[1], NULL, 0);

-        AIR_PRINT("queue is %d\n", queue);

-        scheduler = _strtoul(argv[2], NULL, 0);

-        AIR_PRINT("scheduler is %d\n", scheduler);

-        weight = _strtoul(argv[3], NULL, 0);

-        AIR_PRINT("weight is %d\n", weight);

-        if(scheduler == 0)

-        {

-            sch_mode = AIR_QOS_SCH_MODE_SP;

-            weight = AIR_QOS_SHAPER_NOSETTING;

-            if(weight != AIR_QOS_SHAPER_NOSETTING)

-                AIR_PRINT("[Warning] SP schedule mode no need weight\n");

-        }

-        else if(scheduler == 1)

-        {

-            sch_mode = AIR_QOS_SCH_MODE_WRR;

-            if(weight == AIR_QOS_SHAPER_NOSETTING)

-            {

-                AIR_PRINT("[Warning] No weight value input , plz check\n");

-                return AIR_E_BAD_PARAMETER;

-            }

-            AIR_PRINT("sch_mode is 1\n");

-        }

-        else if(scheduler == 2)

-        {

-            sch_mode = AIR_QOS_SCH_MODE_WFQ;

-            if(weight == AIR_QOS_SHAPER_NOSETTING)

-            {

-                AIR_PRINT("[Warning] No weight value input , plz check\n");

-                return AIR_E_BAD_PARAMETER;

-            }

-        }

-        else

-        {

-            AIR_PRINT("Unknown schedule mode, plz check again\n");

-            return AIR_E_BAD_PARAMETER;

-        }

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(portlist[0] & (1 << i))

-            {

-                AIR_PRINT("port %d\n", i);

-                ret = air_qos_setScheduleAlgo(0, i, queue, sch_mode, weight);

-                if(AIR_E_OK == ret)

-                {

-                    AIR_PRINT("Set Port%02d Scheduler %s Success.\n", i, sche[scheduler]);

-                }

-                else

-                {

-                    AIR_PRINT("Set Port%02d Scheduler %s Fail.\n", i, sche[scheduler]);

-                }

-            }

-        }

-    }

-    else if(2 == argc)

-    {

-        queue = _strtoul(argv[1], NULL, 0);

-        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)

-        {

-            if(portlist[0] & (1 << i))

-            {

-                ret = air_qos_getScheduleAlgo(0, i, queue, &sch_mode, &weight);

-                if(AIR_E_OK == ret)

-                {

-                    if(sch_mode == AIR_QOS_SCH_MODE_SP)

-                        AIR_PRINT("Get Port%02d queue %d Scheduler %s\n", i, queue, sche[sch_mode]);

-                    else if((sch_mode == AIR_QOS_SCH_MODE_WRR) || (sch_mode == AIR_QOS_SCH_MODE_WFQ))

-                        AIR_PRINT("Get Port%02d queue %d Scheduler %s weight %d\n", i, queue, sche[sch_mode], weight);

-                    else

-                        AIR_PRINT("Get Port%02d queue %d Scheduler unknown\n", i, queue);

-                }

-                else

-                {

-                    AIR_PRINT("Get Port%02d queue %d Scheduler Fail.\n", i, queue);

-                }

-            }

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doQosGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(qosGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doQosSet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(qosSetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doQos(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(qosCmds, argc, argv);

-}

-static AIR_ERROR_NO_T

-doDiagTxComply(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T phy = 0;

-    UI32_T mode = 0;

-

-    phy = _strtoul(argv[0], NULL, 0);

-    if(2 == argc)

-    {

-        /* diag set txComply <phy(0~5)> <mode(0~8)> */

-        mode = _strtoul(argv[1], NULL, 0);

-        ret = air_diag_setTxComplyMode(0, phy, mode);

-        AIR_PRINT("Set diagnostic function: PHY %u Tx Compliance mode = %u ", phy, mode);

-    }

-    else if(1 == argc)

-    {

-        /* diag get txComply <phy(0~5)> */

-        ret = air_diag_getTxComplyMode(0, phy, &mode);

-        AIR_PRINT("Get diagnostic function: PHY %u Tx Compliance mode ", phy);

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(AIR_E_OK == ret)

-    {

-        AIR_PRINT("Done.\n\tMode=");

-        switch(mode)

-        {

-            case AIR_DIAG_TXCOMPLY_MODE_10M_NLP:

-                AIR_PRINT("%s\n", "10M_NLP");

-                break;

-            case AIR_DIAG_TXCOMPLY_MODE_10M_RANDOM:

-                AIR_PRINT("%s\n", "10M_Random");

-                break;

-            case AIR_DIAG_TXCOMPLY_MODE_10M_SINE:

-                AIR_PRINT("%s\n", "10M_Sine");

-                break;

-            case AIR_DIAG_TXCOMPLY_MODE_100M_PAIR_A:

-                AIR_PRINT("%s\n", "100M_Pair_a");

-                break;

-            case AIR_DIAG_TXCOMPLY_MODE_100M_PAIR_B:

-                AIR_PRINT("%s\n", "100M_Pair_b");

-                break;

-            case AIR_DIAG_TXCOMPLY_MODE_1000M_TM1:

-                AIR_PRINT("%s\n", "1000M_TM1");

-                break;

-            case AIR_DIAG_TXCOMPLY_MODE_1000M_TM2:

-                AIR_PRINT("%s\n", "1000M_TM2");

-                break;

-            case AIR_DIAG_TXCOMPLY_MODE_1000M_TM3:

-                AIR_PRINT("%s\n", "1000M_TM3");

-                break;

-            case AIR_DIAG_TXCOMPLY_MODE_1000M_TM4:

-                AIR_PRINT("%s\n", "1000M_TM4");

-                break;

-            default:

-                break;

-        }

-    }

-    else

-    if(AIR_E_OTHERS == ret)

-    {

-        AIR_PRINT("isn't setting.\n");

-    }

-    else

-    {

-        AIR_PRINT("Fail.\n");

-    }

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doDiagSet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(diagSetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doDiagGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(diagGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doDiag(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(diagCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doLedMode(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T mode = 0;

-

-    if(1 == argc)

-    {

-        /* led set mode <mode(0:disable, 1~3:2 LED, 4:User-Define)> */

-        mode = _strtoul(argv[0], NULL, 0);

-        ret = air_led_setMode(0, 0, mode);

-        AIR_PRINT("Set LED mode ");

-    }

-    else if(0 == argc)

-    {

-        /* led get mode */

-        ret = air_led_getMode(0, 0, &mode);

-        AIR_PRINT("Get LED mode ");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(AIR_E_OK == ret)

-    {

-        switch(mode)

-        {

-            case AIR_LED_MODE_DISABLE:

-                AIR_PRINT(": Disabled.\n");

-                break;

-            case AIR_LED_MODE_2LED_MODE0:

-                AIR_PRINT(": LED 0:Link / LED 1:Activity.\n");

-                break;

-            case AIR_LED_MODE_2LED_MODE1:

-                AIR_PRINT(": LED 0:1000M Activity / LED 1:100M Activity.\n");

-                break;

-            case AIR_LED_MODE_2LED_MODE2:

-                AIR_PRINT(": LED 0:1000M Activity / LED 1:10&100M Activity.\n");

-                break;

-            case AIR_LED_MODE_USER_DEFINE:

-                AIR_PRINT(": User-Defined.\n");

-                break;

-            default:

-                AIR_PRINT(": Fail.\n");

-                break;

-        }

-    }

-    else

-    if(AIR_E_OTHERS == ret)

-    {

-        AIR_PRINT(": Unrecognized.\n");

-    }

-    else

-    {

-        AIR_PRINT("Fail.\n");

-    }

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doLedState(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI8_T entity = 0;

-    BOOL_T state = FALSE;

-

-    entity = _strtoul(argv[0], NULL, 0);

-    if(2 == argc)

-    {

-        /* led set state <led(0..1)> <state(1:En 0:Dis)> */

-        state = _strtoul(argv[1], NULL, 0);

-        ret = air_led_setState(0, 0, entity, state);

-        AIR_PRINT("Set LED %u state ", entity);

-    }

-    else if(1 == argc)

-    {

-        /* led get state <led(0..1)> */

-        ret = air_led_getState(0, 0, entity, &state);

-        AIR_PRINT("Get LED %u state ", entity );

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(AIR_E_OK == ret)

-    {

-        AIR_PRINT(": %s.\n", (state)?"Enable":"Disabled");

-    }

-    else

-    if(AIR_E_OTHERS == ret)

-    {

-        AIR_PRINT(": Unrecognized.\n");

-    }

-    else

-    {

-        AIR_PRINT("Fail.\n");

-    }

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doLedUsrDef(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T i = 0;

-    UI8_T entity = 0;

-    BOOL_T polarity = LOW;

-    UI32_T on_evt_map = 0;

-    UI32_T blk_evt_map = 0;

-    AIR_LED_ON_EVT_T on_evt;

-    AIR_LED_BLK_EVT_T blk_evt;

-

-    entity = _strtoul(argv[0], NULL, 0);

-    if(4 == argc)

-    {

-        /* led set usr <led(0..1)> <polarity(0:low, 1:high)> <on_evt(7'bin)> <blink_evt(10'bin)> */

-        polarity = _strtoul(argv[1], NULL, 0);

-        on_evt_map = _strtoul(argv[2], NULL, 2);

-        blk_evt_map = _strtoul(argv[3], NULL, 2);

-

-        memset(&on_evt, 0, sizeof(AIR_LED_ON_EVT_T));

-        if(on_evt_map & BIT(0))

-        {

-            on_evt.link_1000m = TRUE;

-        }

-        if(on_evt_map & BIT(1))

-        {

-            on_evt.link_100m = TRUE;

-        }

-        if(on_evt_map & BIT(2))

-        {

-            on_evt.link_10m = TRUE;

-        }

-        if(on_evt_map & BIT(3))

-        {

-            on_evt.link_dn = TRUE;

-        }

-        if(on_evt_map & BIT(4))

-        {

-            on_evt.fdx = TRUE;

-        }

-        if(on_evt_map & BIT(5))

-        {

-            on_evt.hdx = TRUE;

-        }

-        if(on_evt_map & BIT(6))

-        {

-            on_evt.force = TRUE;

-        }

-

-        memset(&blk_evt, 0, sizeof(AIR_LED_BLK_EVT_T));

-        if(blk_evt_map & BIT(0))

-        {

-            blk_evt.tx_act_1000m = TRUE;

-        }

-        if(blk_evt_map & BIT(1))

-        {

-            blk_evt.rx_act_1000m = TRUE;

-        }

-        if(blk_evt_map & BIT(2))

-        {

-            blk_evt.tx_act_100m = TRUE;

-        }

-        if(blk_evt_map & BIT(3))

-        {

-            blk_evt.rx_act_100m = TRUE;

-        }

-        if(blk_evt_map & BIT(4))

-        {

-            blk_evt.tx_act_10m = TRUE;

-        }

-        if(blk_evt_map & BIT(5))

-        {

-            blk_evt.rx_act_10m = TRUE;

-        }

-        if(blk_evt_map & BIT(6))

-        {

-            blk_evt.cls = TRUE;

-        }

-        if(blk_evt_map & BIT(7))

-        {

-            blk_evt.rx_crc = TRUE;

-        }

-        if(blk_evt_map & BIT(8))

-        {

-            blk_evt.rx_idle = TRUE;

-        }

-        if(blk_evt_map & BIT(9))

-        {

-            blk_evt.force = TRUE;

-        }

-        ret = air_led_setUsrDef(0, 0, entity, polarity, on_evt, blk_evt);

-        AIR_PRINT("Set LED %u User-define ", entity);

-    }

-    else if(1 == argc)

-    {

-        /* led get usr <led(0..1)> */

-        ret = air_led_getUsrDef(0, 0, entity, &polarity, &on_evt, &blk_evt);

-        AIR_PRINT("Get LED %u User-define ", entity );

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(AIR_E_OK == ret)

-    {

-        AIR_PRINT("Done.\n");

-        AIR_PRINT("Polarity:%u.\n", polarity);

-        AIR_PRINT("On Event:\n");

-        i = 6;

-        AIR_PRINT("\t(%u)Force on :%s\n", i--, (on_evt.force)?"On":"Off");

-        AIR_PRINT("\t(%u)Half Duplex :%s\n", i--, (on_evt.hdx)?"On":"Off");

-        AIR_PRINT("\t(%u)Full Duplex :%s\n", i--, (on_evt.fdx)?"On":"Off");

-        AIR_PRINT("\t(%u)Link Down :%s\n", i--, (on_evt.link_dn)?"On":"Off");

-        AIR_PRINT("\t(%u)Link 10M :%s\n", i--, (on_evt.link_10m)?"On":"Off");

-        AIR_PRINT("\t(%u)Link 100M :%s\n", i--, (on_evt.link_100m)?"On":"Off");

-        AIR_PRINT("\t(%u)Link 1000M :%s\n", i--, (on_evt.link_1000m)?"On":"Off");

-

-        AIR_PRINT("Blinking Event:\n");

-        i = 9;

-        AIR_PRINT("\t(%u)Force blinks :%s\n", i--, (blk_evt.force)?"On":"Off");

-        AIR_PRINT("\t(%u)Rx Idle Error :%s\n", i--, (blk_evt.rx_idle)?"On":"Off");

-        AIR_PRINT("\t(%u)Rx CRC Error :%s\n", i--, (blk_evt.rx_crc)?"On":"Off");

-        AIR_PRINT("\t(%u)Collision :%s\n", i--, (blk_evt.cls)?"On":"Off");

-        AIR_PRINT("\t(%u)10Mbps RX Activity :%s\n", i--, (blk_evt.rx_act_10m)?"On":"Off");

-        AIR_PRINT("\t(%u)10Mbps TX Activity :%s\n", i--, (blk_evt.tx_act_10m)?"On":"Off");

-        AIR_PRINT("\t(%u)100Mbps RX Activity :%s\n", i--, (blk_evt.rx_act_100m)?"On":"Off");

-        AIR_PRINT("\t(%u)100Mbps TX Activity :%s\n", i--, (blk_evt.tx_act_100m)?"On":"Off");

-        AIR_PRINT("\t(%u)1000Mbps RX Activity :%s\n", i--, (blk_evt.rx_act_1000m)?"On":"Off");

-        AIR_PRINT("\t(%u)1000Mbps TX Activity :%s\n", i--, (blk_evt.tx_act_1000m)?"On":"Off");

-    }

-    else

-    {

-        AIR_PRINT("Fail.\n");

-    }

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doLedBlkTime(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    AIR_LED_BLK_DUR_T time = 0;

-

-    if(1 == argc)

-    {

-        /* led set time <time(0~5)> */

-        time = _strtoul(argv[0], NULL, 0);

-        ret = air_led_setBlkTime(0, 0, time);

-        AIR_PRINT("Set Blinking Duration ");

-    }

-    else if(0 == argc)

-    {

-        /* led get time */

-        ret = air_led_getBlkTime(0, 0, &time);

-        AIR_PRINT("Get Blinking Duration ");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(AIR_E_OK == ret)

-    {

-        AIR_PRINT("Done.\n");

-        AIR_PRINT("\tBlinking duration : %u (ms)\n", (32 << time) );

-    }

-    else

-    {

-        AIR_PRINT("Fail.\n");

-    }

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doLedSet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(ledSetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doLedGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(ledGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doLed(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(ledCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doShowVersion(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_PRINT("VERSION: %s\n", AIR_VER_SDK);

-

-    return AIR_E_OK;

-}

-

-static AIR_ERROR_NO_T

-doShow(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(showCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doStormRate(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0, type = 0;

-    UI32_T unit = 0, count = 0;

-    C8_T stype[3][5] = {"Bcst", "Mcst", "Ucst"};

-    UI32_T kb = 0;

-

-    port = _strtol(argv[0], NULL, 10);

-    type = _strtol(argv[1], NULL, 10);

-    if(4 == argc)

-    {

-        count = _strtol(argv[2], NULL, 10);

-        unit = _strtol(argv[3], NULL, 10);

-

-        if(0 == unit)

-            kb = 64;

-        else if(1 == unit)

-            kb = 256;

-        else if(2 == unit)

-            kb = 1024;

-        else if(3 == unit)

-            kb = 4096;

-        else

-            kb = 16384;

-        ret = air_sec_setStormRate(0, port, type, count, unit);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Set Port%02d %s storm rate (%d * %d) = %d Kbps\n", port, stype[type], count, kb, (count*kb));

-        }

-        else

-        {

-            AIR_PRINT("Set Port%02d %s storm rate Fail.\n", port, stype[type]);

-            AIR_PRINT("Note: Port(0..4) can only select unit(0..3), port(5..6) can only select unit(4)\n");

-        }

-    }

-    else if(2 == argc)

-    {

-        ret = air_sec_getStormRate(0, port, type, &count, &unit);

-        if(AIR_E_OK == ret)

-        {

-            if(0 == unit)

-                kb = 64;

-            else if(1 == unit)

-                kb = 256;

-            else if(2 == unit)

-                kb = 1024;

-            else if(3 == unit)

-                kb = 4096;

-            else

-                kb = 16384;

-            AIR_PRINT("Port%02d %s storm rate (%d * %d) = %d Kbps\n", port, stype[type], count, kb, (count*kb));

-        }

-        else

-        {

-            AIR_PRINT("Get Port%02d %s storm rate Fail\n", port, stype[type]);

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doFldMode(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0, type = 0;

-    BOOL_T fld_en = 0;

-    C8_T stype[4][5] = {"Bcst", "Mcst", "Ucst", "Qury"};

-    C8_T sen[2][10] = {"Disable", "Enable"};

-

-    port = _strtol(argv[0], NULL, 10);

-    type = _strtol(argv[1], NULL, 10);

-

-    if(2 == argc)

-    {

-        ret = air_sec_getFldMode(0, port, type, &fld_en);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Get Port%02d flooding %s frame %s\n", port, stype[type], sen[fld_en]);

-        }

-        else

-        {

-            AIR_PRINT("Get Port%02d flooding %s frame Fail\n", port, stype[type]);

-        }

-    }

-    else if(3 == argc)

-    {

-        fld_en = _strtol(argv[2], NULL, 10);

-        ret = air_sec_setFldMode(0, port, type, fld_en);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Set Port%02d flooding %s frame %s Success\n", port, stype[type], sen[fld_en]);

-        }

-        else

-        {

-            AIR_PRINT("Set Port%02d flooding %s frame %s Fail\n", port, stype[type], sen[fld_en]);

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doStormEnable(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T port = 0, type = 0;

-    BOOL_T en = 0;

-    C8_T sen[2][10] = {"Disable", "Enable"};

-    C8_T stype[3][5] = {"Bcst", "Mcst", "Ucst"};

-

-    port = _strtol(argv[0], NULL, 10);

-    type = _strtol(argv[1], NULL, 10);

-    if(3 == argc)

-    {

-        en = _strtol(argv[2], NULL, 10);

-        ret = air_sec_setStormEnable(0, port, type, en);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Set Port%02d %s storm %s Success.\n", port, stype[type], sen[en]);

-        }

-        else

-        {

-            AIR_PRINT("Set Port%02d %s storm %s Fail.\n", port, stype[type], sen[en]);

-        }

-    }

-    else if(2 == argc)

-    {

-        ret = air_sec_getStormEnable(0, port, type, &en);

-        if(AIR_E_OK == ret)

-        {

-            AIR_PRINT("Port%02d %s storm %s\n", port, stype[type], sen[en]);

-        }

-        else

-        {

-            AIR_PRINT("Get Port%02d %s storm Fail\n", port, stype[type]);

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doSaLearning(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    AIR_SEC_PORTSEC_PORT_CONFIG_T port_config;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    if(2 == argc)

-    {

-        memset(&port_config, 0, sizeof(AIR_SEC_PORTSEC_PORT_CONFIG_T));

-        rc = air_sec_getPortSecPortCfg(0, port, &port_config);

-        port_config.sa_lrn_en = _strtoul(argv[1], NULL, 0);

-        rc = air_sec_setPortSecPortCfg(0, port, port_config);

-        if(AIR_E_OK == rc)

-        {

-            AIR_PRINT("Set Port%02d sa learn %s Success.\n", port, port_config.sa_lrn_en?"Enable":"Disable");

-        }

-        else

-        {

-            AIR_PRINT("Set Port%02d sa learn %s Fail.\n", port, port_config.sa_lrn_en?"Enable":"Disable");

-        }

-    }

-    else if(1 == argc)

-    {

-        rc = air_sec_getPortSecPortCfg(0, port, &port_config);

-        if(AIR_E_OK == rc)

-        {

-            AIR_PRINT("Port%02d sa learn: %s\n", port, port_config.sa_lrn_en?"Enable":"Disable");

-        }

-        else

-        {

-            AIR_PRINT("Get Port%02d sa learn Fail\n", port);

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        rc = AIR_E_BAD_PARAMETER;

-    }

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doSaLimit(UI32_T argc, C8_T *argv[])

-{

-    UI32_T port = 0;

-    AIR_SEC_PORTSEC_PORT_CONFIG_T port_config;

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-

-    port = _strtoul(argv[0], NULL, 0);

-    if(3 == argc)

-    {

-        memset(&port_config, 0, sizeof(AIR_SEC_PORTSEC_PORT_CONFIG_T));

-        rc = air_sec_getPortSecPortCfg(0, port, &port_config);

-        port_config.sa_lmt_en = _strtoul(argv[1], NULL, 0);

-        port_config.sa_lmt_cnt = _strtoul(argv[2], NULL, 0);

-        rc = air_sec_setPortSecPortCfg(0, port, port_config);

-        if(AIR_E_OK == rc)

-        {

-            AIR_PRINT("Set Port%02d sa limit %s Success.\n", port, port_config.sa_lmt_en?"Enable":"Disable");

-        }

-        else

-        {

-            AIR_PRINT("Set Port%02d sa limit %s Fail.\n", port, port_config.sa_lmt_en?"Enable":"Disable");

-        }

-    }

-    else if(1 == argc)

-    {

-        rc = air_sec_getPortSecPortCfg(0, port, &port_config);

-        if(AIR_E_OK == rc)

-        {

-            AIR_PRINT("Port%02d ", port);

-            AIR_PRINT("sa limit: %s\n", port_config.sa_lmt_en?"Enable":"Disable");

-            if(TRUE == (port_config.sa_lmt_en && (AIR_MAX_NUM_OF_MAC ==  port_config.sa_lmt_cnt)))

-            {

-                AIR_PRINT("Sa learning without limitation\n");

-            }

-            else if(TRUE == (port_config.sa_lmt_en && (AIR_MAX_NUM_OF_MAC >  port_config.sa_lmt_cnt)))

-            {

-                AIR_PRINT("Rx sa allowable learning number: %d\n", port_config.sa_lmt_cnt);

-            }

-        }

-        else

-        {

-            AIR_PRINT("Get Port%02d sa limit Fail\n", port);

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        rc = AIR_E_BAD_PARAMETER;

-    }

-

-    return rc;

-}

-

-static AIR_ERROR_NO_T

-doSecGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(secGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doSecSet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(secSetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doSec(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(secCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doSwitchCpuPortEn(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    BOOL_T cpu_en = FALSE;

-

-    if(0 == argc)

-    {

-        /* switch get sysPhyEn */

-        ret = air_switch_getCpuPortEn(0, &cpu_en);

-        AIR_PRINT("Get Cpu Port State ");

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT(": %s\n", cpu_en?"Enable":"Disable");

-        }

-        else

-        {

-            AIR_PRINT("Fail!\n");

-        }

-    }

-    else if(1 == argc)

-    {

-        /* switch set sysPhyEn <phy_en> */

-        cpu_en = _strtol(argv[0], NULL, 0);

-        ret = air_switch_setCpuPortEn(0, cpu_en);

-        AIR_PRINT("Set CPU port State ");

-        if(ret == AIR_E_OK)

-        {

-            AIR_PRINT(": %s\n", cpu_en?"Enable":"Disable");

-        }

-        else

-        {

-            AIR_PRINT("Fail!\n");

-        }

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doSwitchCpuPort(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    BOOL_T cpu_en = FALSE;

-    UI32_T port = 0;

-    C8_T str_temp[AIR_MAX_NUM_OF_PORTS+1];

-

-    if(1 == argc)

-    {

-        /* switch set cpuPort <portnumber> */

-        port = _strtol(argv[0], NULL, 10);

-        ret = air_switch_setCpuPort(0, port);

-        AIR_PRINT("Set CPU Port ");

-    }

-    else if(0 == argc)

-    {

-        /* switch get cpuPort */

-        ret = air_switch_getCpuPort(0, &port);

-        AIR_PRINT("Get CPU Port ");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    if(AIR_E_OK == ret)

-    {

-        AIR_PRINT(": %d\n", port);

-    }

-    else

-    {

-        AIR_PRINT("Fail!\n");

-    }

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doSwitchPhyLCIntrEn(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T phy = 0;

-    BOOL_T enable = FALSE;

-

-    if(2 == argc)

-    {

-        /* switch set phyLCIntrEn <phy(0..6)> <(1:En,0:Dis)> */

-        phy    = _strtol(argv[0], NULL, 10);

-        enable = _strtol(argv[1], NULL, 10);

-        ret    = air_switch_setSysIntrEn(0, (phy + AIR_SYS_INTR_TYPE_PHY0_LC), enable);

-    }

-    else if(1 == argc)

-    {

-        /* switch get phyLCIntrEn <phy(0..6)> */

-        phy = _strtol(argv[0], NULL, 10);

-        ret = air_switch_getSysIntrEn(0, (phy + AIR_SYS_INTR_TYPE_PHY0_LC), &enable);

-        AIR_PRINT("PHY(%d) LinkChange interrupt : %s\n", phy, (TRUE == enable) ? "enable" : "disable");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doSwitchPhyLCIntrSts(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T phy = 0;

-    BOOL_T enable = FALSE;

-

-    if(2 == argc)

-    {

-        /* switch set phyLCIntrSts <phy(0..6)> <(1:En)> */

-        phy    = _strtol(argv[0], NULL, 10);

-        enable = _strtol(argv[1], NULL, 10);

-        ret    = air_switch_setSysIntrStatus(0, (phy + AIR_SYS_INTR_TYPE_PHY0_LC), enable);

-    }

-    else if(1 == argc)

-    {

-        /* switch get phyLCIntrSts <phy(0..6)> */

-        phy = _strtol(argv[0], NULL, 10);

-        ret = air_switch_getSysIntrStatus(0, (phy + AIR_SYS_INTR_TYPE_PHY0_LC), &enable);

-        AIR_PRINT("PHY(%d) LinkChange interrupt state : %s\n", phy, (TRUE == enable) ? "set" : "unset");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        ret = AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-

-static AIR_ERROR_NO_T

-doSwitchSet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(switchSetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doSwitchGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(switchGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doSwitch(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(switchCmds, argc, argv);

-}

-

-static void _air_acl_printRuleMap(UI32_T *rule_map, UI32_T ary_num)

-{

-    UI32_T i;

-    BOOL_T first;

-

-    first = TRUE;

-    for(i=0; i<ary_num*32; i++)

-    {

-        if(rule_map[i/32] & BIT(i%32))

-        {

-            if(TRUE == first)

-            {

-                AIR_PRINT("%u", i);

-                first = FALSE;

-            }

-            else

-            {

-                AIR_PRINT(",%u", i);

-            }

-        }

-    }

-    AIR_PRINT("\n");

-}

-

-static AIR_ERROR_NO_T

-doAclEn(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T argi=0;

-    UI32_T port = 0;

-    BOOL_T en = FALSE;

-

-    if(1 == argc)

-    {

-        /* acl set en <en(1:En,0:Dis)> */

-        en = _strtoul(argv[argi++], NULL, 2);

-        ret = air_acl_setGlobalState(0, en);

-        AIR_PRINT("Set Global ACL function ");

-    }

-    else if(0 == argc)

-    {

-        /* acl get en */

-        ret = air_acl_getGlobalState(0, &en);

-        AIR_PRINT("Get Global ACL function ");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        AIR_PRINT(": %s\n", (TRUE == en)?"Enable":"Disable");

-    }

-    else

-    {

-        AIR_PRINT("Fail!\n");

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclRule(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T rule_idx = 0;

-    BOOL_T state = FALSE, reverse = FALSE, end = FALSE;

-    UI32_T argi = 0, ipv6 = 0, i = 0;

-    AIR_ACL_RULE_T rule;

-    UI8_T tmp_ip[16] = {0};

-    C8_T str_temp[AIR_MAX_NUM_OF_PORTS+1];

-    C8_T str[40];

-

-    memset(&rule, 0, sizeof(AIR_ACL_RULE_T));

-    if(argc >= 6)

-    {

-        /* acl set rule <idx(0..255)> <state(0:Dis,1:En)> <reverse(0:Dis,1:En)> <end(0:Dis,1:En)> <portmap(7'bin)>

-        <ipv6(0:Dis,1:En,2:Not care)>

-        [ dmac <dmac(12'hex)> <dmac_mask(12'hex)> ]

-        [ smac <smac(12'hex)> <smac_mask(12'hex)> ]

-        [ stag <stag(4'hex)> <stag_mask(4'hex)> ]

-        [ ctag <ctag(4'hex)> <ctag_mask(4'hex)> ]

-        [ etype <etype(4'hex)> <etype_mask(4'hex)> ]

-        [ dip <dip(IPADDR)> <dip_mask(IPADDR)> ]

-        [ sip <sip(IPADDR)> <sip_mask(IPADDR)> ]

-        [ dscp <dscp(2'hex)> <dscp_mask(2'hex)> ]

-        [ protocol <protocol(2'hex)> <protocol_mask(2'hex)> ]

-        [ dport <dport(4'hex)> <dport_mask(4'hex)> ]

-        [ sport <sport(4'hex)> <sport_mask(4'hex)> ]

-        [ flow_label <flow_label(4'hex)> <flow_label_mask(4'hex)> ]

-        [ udf <udf(4'hex)> <udf_mask(4'hex)> ] */

-

-        rule_idx = _strtoul(argv[argi++], NULL, 0);

-

-        rule.ctrl.rule_en = _strtoul(argv[argi++], NULL, 0);

-        rule.ctrl.reverse = _strtoul(argv[argi++], NULL, 0);

-        rule.ctrl.end = _strtoul(argv[argi++], NULL, 0);

-

-        rule.key.portmap = _strtoul(argv[argi++], NULL, 2);

-        rule.mask.portmap = (~rule.key.portmap) & AIR_ALL_PORT_BITMAP;

-

-        ipv6 = _strtoul(argv[argi++], NULL, 0);

-        if(0 == ipv6)

-        {

-            rule.key.isipv6 = FALSE;

-            rule.mask.isipv6 = TRUE;

-        }

-        else if(1 == ipv6)

-        {

-            rule.key.isipv6 = TRUE;

-            rule.mask.isipv6 = TRUE;

-        }

-        else

-        {

-            rule.mask.isipv6 = FALSE;

-        }

-

-        if(0 == _strcmp(argv[argi], "dmac"))

-        {

-            argi++;

-            _str2mac(argv[argi++], rule.key.dmac);

-            _str2mac(argv[argi++], rule.mask.dmac);

-            rule.key.fieldmap |= 1 << AIR_ACL_DMAC;

-        }

-

-        if(0 == _strcmp(argv[argi], "smac"))

-        {

-            argi++;

-            _str2mac(argv[argi++], rule.key.smac);

-            _str2mac(argv[argi++], rule.mask.smac);

-            rule.key.fieldmap |= 1 << AIR_ACL_SMAC;

-        }

-

-        if(0 == _strcmp(argv[argi], "stag"))

-        {

-            argi++;

-            rule.key.stag = _strtoul(argv[argi++], NULL, 16);

-            rule.mask.stag = _strtoul(argv[argi++], NULL, 16);

-            rule.key.fieldmap |= 1 << AIR_ACL_STAG;

-        }

-

-        if(0 == _strcmp(argv[argi], "ctag"))

-        {

-            argi++;

-            rule.key.ctag = _strtoul(argv[argi++], NULL, 16);

-            rule.mask.ctag = _strtoul(argv[argi++], NULL, 16);

-            rule.key.fieldmap |= 1 << AIR_ACL_CTAG;

-        }

-

-        if(0 == _strcmp(argv[argi], "etype"))

-        {

-            argi++;

-            rule.key.etype= _strtoul(argv[argi++], NULL, 16);

-            rule.mask.etype = _strtoul(argv[argi++], NULL, 16);

-            rule.key.fieldmap |= 1 << AIR_ACL_ETYPE;

-        }

-

-        if(0 == _strcmp(argv[argi], "dip"))

-        {

-            argi++;

-            if(0 == ipv6)

-            {

-                _str2ipv4(argv[argi++], rule.key.dip);

-                _str2ipv4(argv[argi++], rule.mask.dip);

-            }

-            else if(1 == ipv6)

-            {

-                _str2ipv6(argv[argi++], tmp_ip);

-                rule.key.dip[3] = (tmp_ip[0]<<24) | (tmp_ip[1]<<16) | (tmp_ip[2]<<8) | tmp_ip[3];

-                rule.key.dip[2] = (tmp_ip[4]<<24) | (tmp_ip[5]<<16) | (tmp_ip[6]<<8) | tmp_ip[7];

-                rule.key.dip[1] = (tmp_ip[8]<<24) | (tmp_ip[9]<<16) | (tmp_ip[10]<<8) | tmp_ip[11];

-                rule.key.dip[0] = (tmp_ip[12]<<24) | (tmp_ip[13]<<16) | (tmp_ip[14]<<8) | tmp_ip[15];

-                _str2ipv6(argv[argi++], tmp_ip);

-                rule.mask.dip[3] = (tmp_ip[0]<<24) | (tmp_ip[1]<<16) | (tmp_ip[2]<<8) | tmp_ip[3];

-                rule.mask.dip[2] = (tmp_ip[4]<<24) | (tmp_ip[5]<<16) | (tmp_ip[6]<<8) | tmp_ip[7];

-                rule.mask.dip[1] = (tmp_ip[8]<<24) | (tmp_ip[9]<<16) | (tmp_ip[10]<<8) | tmp_ip[11];

-                rule.mask.dip[0] = (tmp_ip[12]<<24) | (tmp_ip[13]<<16) | (tmp_ip[14]<<8) | tmp_ip[15];

-            }

-            rule.key.fieldmap |= 1 << AIR_ACL_DIP;

-        }

-

-        if(0 == _strcmp(argv[argi], "sip"))

-        {

-            argi++;

-            if(0 == ipv6)

-            {

-                _str2ipv4(argv[argi++], rule.key.sip);

-                _str2ipv4(argv[argi++], rule.mask.sip);

-            }

-            else if(1 == ipv6)

-            {

-                _str2ipv6(argv[argi++], tmp_ip);

-                rule.key.sip[3] = (tmp_ip[0]<<24) | (tmp_ip[1]<<16) | (tmp_ip[2]<<8) | tmp_ip[3];

-                rule.key.sip[2] = (tmp_ip[4]<<24) | (tmp_ip[5]<<16) | (tmp_ip[6]<<8) | tmp_ip[7];

-                rule.key.sip[1] = (tmp_ip[8]<<24) | (tmp_ip[9]<<16) | (tmp_ip[10]<<8) | tmp_ip[11];

-                rule.key.sip[0] = (tmp_ip[12]<<24) | (tmp_ip[13]<<16) | (tmp_ip[14]<<8) | tmp_ip[15];

-                _str2ipv6(argv[argi++], tmp_ip);

-                rule.mask.sip[3] = (tmp_ip[0]<<24) | (tmp_ip[1]<<16) | (tmp_ip[2]<<8) | tmp_ip[3];

-                rule.mask.sip[2] = (tmp_ip[4]<<24) | (tmp_ip[5]<<16) | (tmp_ip[6]<<8) | tmp_ip[7];

-                rule.mask.sip[1] = (tmp_ip[8]<<24) | (tmp_ip[9]<<16) | (tmp_ip[10]<<8) | tmp_ip[11];

-                rule.mask.sip[0] = (tmp_ip[12]<<24) | (tmp_ip[13]<<16) | (tmp_ip[14]<<8) | tmp_ip[15];

-            }

-            rule.key.fieldmap |= 1 << AIR_ACL_SIP;

-        }

-

-        if(0 == _strcmp(argv[argi], "dscp"))

-        {

-            argi++;

-            rule.key.dscp = _strtoul(argv[argi++], NULL, 16);

-            rule.mask.dscp = _strtoul(argv[argi++], NULL, 16);

-            rule.key.fieldmap |= 1 << AIR_ACL_DSCP;

-        }

-

-        if(0 == _strcmp(argv[argi], "protocol"))

-        {

-            argi++;

-            rule.key.protocol = _strtoul(argv[argi++], NULL, 16);

-            rule.mask.protocol = _strtoul(argv[argi++], NULL, 16);

-            rule.key.fieldmap |= 1 << AIR_ACL_PROTOCOL;

-        }

-

-        if(0 == _strcmp(argv[argi], "dport"))

-        {

-            argi++;

-            rule.key.dport = _strtoul(argv[argi++], NULL, 16);

-            rule.mask.dport = _strtoul(argv[argi++], NULL, 16);

-            rule.key.fieldmap |= 1 << AIR_ACL_DPORT;

-        }

-

-        if(0 == _strcmp(argv[argi], "sport"))

-        {

-            argi++;

-            rule.key.sport = _strtoul(argv[argi++], NULL, 16);

-            rule.mask.sport = _strtoul(argv[argi++], NULL, 16);

-            rule.key.fieldmap |= 1 << AIR_ACL_SPORT;

-        }

-

-        if(0 == _strcmp(argv[argi], "flow_label"))

-        {

-            argi++;

-            rule.key.flow_label= _strtoul(argv[argi++], NULL, 16);

-            rule.mask.flow_label= _strtoul(argv[argi++], NULL, 16);

-            rule.key.fieldmap |= 1 << AIR_ACL_FLOW_LABEL;

-        }

-

-        if(0 == _strcmp(argv[argi], "udf"))

-        {

-            argi++;

-            rule.key.udf = _strtoul(argv[argi++], NULL, 16);

-            rule.mask.udf = _strtoul(argv[argi++], NULL, 16);

-            rule.key.fieldmap |= 1 << AIR_ACL_UDF;

-        }

-

-        rule.mask.fieldmap = rule.key.fieldmap;

-        ret = air_acl_setRule(0, rule_idx, &rule);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Set ACL Rule(%u): %s\n", rule_idx, air_error_getString(ret));

-    }

-    else if(1 == argc)

-    {

-        rule_idx = _strtoul(argv[0], NULL, 0);

-        ret = air_acl_getRule(0, rule_idx, &rule);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Get ACL Rule(%u): %s\n", rule_idx, air_error_getString(ret));

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(AIR_E_OK == ret)

-    {

-        if(TRUE == rule.ctrl.rule_en)

-        {

-            AIR_PRINT("\t Rule end          : %s\n", (TRUE == rule.ctrl.end)?"Enable":"Disable");

-            AIR_PRINT("\t Rule reverse      : %s\n", (TRUE == rule.ctrl.reverse)?"Enable":"Disable");

-            _hex2bitstr((~rule.mask.portmap) & AIR_ALL_PORT_BITMAP, str_temp, AIR_MAX_NUM_OF_PORTS+1);

-            AIR_PRINT("\t Portmap[0:6]      : %s\n", str_temp);

-            for(i = AIR_ACL_DMAC; i < AIR_ACL_FIELD_TYPE_LAST; i++)

-            {

-                if((1 << i) & rule.mask.fieldmap)

-                {

-                    switch (i)

-                    {

-                        case AIR_ACL_DMAC:

-                            AIR_PRINT("\t dmac: ");

-                            AIR_PRINT("%02x-%02x-%02x-%02x-%02x-%02x",

-                            rule.key.dmac[0], rule.key.dmac[1], rule.key.dmac[2],

-                            rule.key.dmac[3], rule.key.dmac[4], rule.key.dmac[5]);

-                            AIR_PRINT(", dmac-mask: ");

-                            AIR_PRINT("%02x-%02x-%02x-%02x-%02x-%02x\n",

-                            rule.mask.dmac[0], rule.mask.dmac[1], rule.mask.dmac[2],

-                            rule.mask.dmac[3], rule.mask.dmac[4], rule.mask.dmac[5]);

-                            break;

-                        case AIR_ACL_SMAC:

-                            AIR_PRINT("\t smac: ");

-                            AIR_PRINT("%02x-%02x-%02x-%02x-%02x-%02x",

-                            rule.key.smac[0], rule.key.smac[1], rule.key.smac[2],

-                            rule.key.smac[3], rule.key.smac[4], rule.key.smac[5]);

-                            AIR_PRINT(", smac-mask: ");

-                            AIR_PRINT("%02x-%02x-%02x-%02x-%02x-%02x\n",

-                            rule.mask.smac[0], rule.mask.smac[1], rule.mask.smac[2],

-                            rule.mask.smac[3], rule.mask.smac[4], rule.mask.smac[5]);

-                            break;

-                        case AIR_ACL_ETYPE:

-                            AIR_PRINT("\t etype: 0x%x, etype-mask: 0x%x\n", rule.key.etype, rule.mask.etype);

-                            break;

-                        case AIR_ACL_STAG:

-                            AIR_PRINT("\t stag: 0x%x, stag-mask: 0x%x\n", rule.key.stag, rule.mask.stag);

-                            break;

-                        case AIR_ACL_CTAG:

-                            AIR_PRINT("\t ctag: 0x%x, ctag-mask: 0x%x\n", rule.key.ctag, rule.mask.ctag);

-                            break;

-                        case AIR_ACL_DPORT:

-                            AIR_PRINT("\t dport: 0x%x, dport-mask: 0x%x\n", rule.key.dport, rule.mask.dport);

-                            break;

-                        case AIR_ACL_SPORT:

-                            AIR_PRINT("\t sport: 0x%x, sport-mask: 0x%x\n", rule.key.sport, rule.mask.sport);

-                            break;

-                        case AIR_ACL_UDF:

-                            AIR_PRINT("\t udf: 0x%x, udf-mask: 0x%x\n", rule.key.udf, rule.mask.udf);

-                            break;

-                        case AIR_ACL_DIP:

-                            if (0 == rule.key.isipv6)

-                            {

-                                AIR_PRINT("\t dip: ");

-                                AIR_PRINT("%d.%d.%d.%d",

-                                ((rule.key.dip[0])&0xFF000000)>>24,((rule.key.dip[0])&0x00FF0000)>>16,

-                                ((rule.key.dip[0])&0x0000FF00)>>8, ((rule.key.dip[0])&0x000000FF));

-                                AIR_PRINT(", dip-mask: ");

-                                AIR_PRINT("%d.%d.%d.%d\n ",

-                                ((rule.mask.dip[0])&0xFF000000)>>24,((rule.mask.dip[0])&0x00FF0000)>>16,

-                                ((rule.mask.dip[0])&0x0000FF00)>>8, ((rule.mask.dip[0])&0x000000FF));

-                            }

-                            else

-                            {

-                                for(i=0; i<4; i++){

-                                    tmp_ip[i] = (rule.key.dip[3] >> (8*(3-i))) & 0xff;

-                                    AIR_PRINT("get tmp_ip[%d]=0x%x\n", i, tmp_ip[i]);

-                                }

-                                for(i=4; i<8; i++){

-                                    tmp_ip[i] = (rule.key.dip[2] >> (8*(7-i))) & 0xff;

-                                }

-                                for(i=8; i<12; i++){

-                                    tmp_ip[i] = (rule.key.dip[1] >> (8*(11-i))) & 0xff;

-                                }

-                                for(i=12; i<16; i++){

-                                    tmp_ip[i] = (rule.key.dip[0] >> (8*(15-i))) & 0xff;

-                                }

-

-                                AIR_PRINT("\t dip: ");

-                                AIR_PRINT("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",

-                                    tmp_ip[0], tmp_ip[1],tmp_ip[2], tmp_ip[3],tmp_ip[4], tmp_ip[5],tmp_ip[6], tmp_ip[7],

-                                    tmp_ip[8], tmp_ip[9],tmp_ip[10], tmp_ip[11],tmp_ip[12], tmp_ip[13],tmp_ip[14], tmp_ip[15]);

-                                for(i=0; i<4; i++){

-                                    tmp_ip[i] = (rule.mask.dip[3] >> (8*(3-i))) & 0xff;

-                                }

-                                for(i=4; i<8; i++){

-                                    tmp_ip[i] = (rule.mask.dip[2] >> (8*(7-i))) & 0xff;

-                                }

-                                for(i=8; i<12; i++){

-                                    tmp_ip[i] = (rule.mask.dip[1] >> (8*(11-i))) & 0xff;

-                                }

-                                for(i=12; i<16; i++){

-                                    tmp_ip[i] = (rule.mask.dip[0] >> (8*(15-i))) & 0xff;

-                                }

-                                AIR_PRINT(", dip-mask: ");

-                                AIR_PRINT("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",

-                                    tmp_ip[0], tmp_ip[1],tmp_ip[2], tmp_ip[3],tmp_ip[4], tmp_ip[5],tmp_ip[6], tmp_ip[7],

-                                    tmp_ip[8], tmp_ip[9],tmp_ip[10], tmp_ip[11],tmp_ip[12], tmp_ip[13],tmp_ip[14], tmp_ip[15]);

-                            }

-                            break;

-                        case AIR_ACL_SIP:

-                            if (0 == rule.key.isipv6)

-                            {

-                                AIR_PRINT("\t sip: ");

-                                AIR_PRINT("%d.%d.%d.%d ",

-                                ((rule.key.sip[0])&0xFF000000)>>24,((rule.key.sip[0])&0x00FF0000)>>16,

-                                ((rule.key.sip[0])&0x0000FF00)>>8, ((rule.key.sip[0])&0x000000FF));

-                                AIR_PRINT(", sip-mask: ");

-                                AIR_PRINT("%d.%d.%d.%d\n ",

-                                ((rule.mask.sip[0])&0xFF000000)>>24,((rule.mask.sip[0])&0x00FF0000)>>16,

-                                ((rule.mask.sip[0])&0x0000FF00)>>8, ((rule.mask.sip[0])&0x000000FF));

-                            }

-                            else

-                            {

-                                for(i=0; i<4; i++){

-                                    tmp_ip[i] = (rule.key.sip[3] >> (8*(3-i))) & 0xff;

-                                }

-                                for(i=4; i<8; i++){

-                                    tmp_ip[i] = (rule.key.sip[2] >> (8*(7-i))) & 0xff;

-                                }

-                                for(i=8; i<12; i++){

-                                    tmp_ip[i] = (rule.key.sip[1] >> (8*(11-i))) & 0xff;

-                                }

-                                for(i=12; i<16; i++){

-                                    tmp_ip[i] = (rule.key.sip[0] >> (8*(15-i))) & 0xff;

-                                }

-                                AIR_PRINT("\t sip: ");

-                                AIR_PRINT("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",

-                                    tmp_ip[0], tmp_ip[1],tmp_ip[2], tmp_ip[3],tmp_ip[4], tmp_ip[5],tmp_ip[6], tmp_ip[7],

-                                    tmp_ip[8], tmp_ip[9],tmp_ip[10], tmp_ip[11],tmp_ip[12], tmp_ip[13],tmp_ip[14], tmp_ip[15]);

-                                for(i=0; i<4; i++){

-                                    tmp_ip[i] = (rule.mask.sip[3] >> (8*(3-i))) & 0xff;

-                                }

-                                for(i=4; i<8; i++){

-                                    tmp_ip[i] = (rule.mask.sip[2] >> (8*(7-i))) & 0xff;

-                                }

-                                for(i=8; i<12; i++){

-                                    tmp_ip[i] = (rule.mask.sip[1] >> (8*(11-i))) & 0xff;

-                                }

-                                for(i=12; i<16; i++){

-                                    tmp_ip[i] = (rule.mask.sip[0] >> (8*(15-i))) & 0xff;

-                                }

-                                AIR_PRINT(", sip-mask: ");

-                                AIR_PRINT("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",

-                                    tmp_ip[0], tmp_ip[1],tmp_ip[2], tmp_ip[3],tmp_ip[4], tmp_ip[5],tmp_ip[6], tmp_ip[7],

-                                    tmp_ip[8], tmp_ip[9],tmp_ip[10], tmp_ip[11],tmp_ip[12], tmp_ip[13],tmp_ip[14], tmp_ip[15]);

-                            }

-                            break;

-                        case AIR_ACL_DSCP:

-                            AIR_PRINT("\t dscp: 0x%x, dscp-mask: 0x%x\n", rule.key.dscp, rule.mask.dscp);

-                            break;

-                        case AIR_ACL_PROTOCOL:

-                            AIR_PRINT("\t protocol: 0x%x, protocol-mask: 0x%x\n", rule.key.protocol, rule.mask.protocol);

-                            break;

-                        case AIR_ACL_FLOW_LABEL:

-                            AIR_PRINT("\t flow-label: 0x%x, flow-label-mask: 0x%x\n", rule.key.flow_label, rule.mask.flow_label);

-                            break;

-                        default:

-                            AIR_PRINT("error\n");

-                            break;

-                    }

-                }

-            }

-        }

-        else

-        {

-            AIR_PRINT("Entry is Invalid.\n");

-        }

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclRmvRule(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T rule_idx = 0;

-

-    if(1 == argc)

-    {

-        /* acl del rule <idx(0..127)> */

-        rule_idx = _strtoul(argv[0], NULL, 0);

-        ret = air_acl_delRule(0, rule_idx);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Delete ACL Rule(%u): %s\n", rule_idx, air_error_getString(ret));

-    }

-    else if(0 == argc)

-    {

-        /* acl clear rule */

-        ret = air_acl_clearRule(0);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Clear ACL Rule: %s\n", air_error_getString(ret));

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclUdfRule(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T rule_idx;

-    AIR_ACL_UDF_RULE_T rule;

-    C8_T start_addr[8][12]=

-    {

-        "MAC header",

-        "L2 payload",

-        "IPv4 header",

-        "IPv6 header",

-        "L3 payload",

-        "TCP header",

-        "UDP header",

-        "L4 payload"

-    };

-    C8_T str_temp[AIR_MAX_NUM_OF_PORTS+1];

-

-    memset(&rule, 0, sizeof(AIR_ACL_UDF_RULE_T));

-    if(7 == argc)

-    {

-        /* acl set rule <idx(0..255)> <mode(0:pattern, 1:threshold)> [ <pat(4'hex)> <mask(4'hex)> | <low(4'hex)> <high(4'hex)> ] <start(0:MAC,1:ether,2:IP,3:IP_data,4:TCP/UDP,5:TCP/UDP data,6:IPv6)> <offset(0..62,unit:2 bytes)> <portmap(7'bin)> */

-        rule_idx = _strtoul(argv[0], NULL, 0);

-        rule.cmp_sel = _strtoul(argv[1], NULL, 2);

-        if(AIR_ACL_RULE_CMP_SEL_PATTERN == rule.cmp_sel)

-        {

-            rule.pattern = _strtoul(argv[2], NULL, 16);

-            rule.mask = _strtoul(argv[3], NULL, 16);

-        }

-        else

-        {

-            rule.low_threshold = _strtoul(argv[2], NULL, 16);

-            rule.high_threshold = _strtoul(argv[3], NULL, 16);

-        }

-        rule.offset_format = _strtoul(argv[4], NULL, 0);

-        rule.offset = _strtoul(argv[5], NULL, 0);

-        rule.portmap = _strtoul(argv[6], NULL, 2);

-        rule.valid = TRUE;

-        ret = air_acl_setUdfRule(0, rule_idx, rule);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Set ACL UDF Rule(%u): %s\n", rule_idx, air_error_getString(ret));

-    }

-    else if(1 == argc)

-    {

-        rule_idx = _strtoul(argv[0], NULL, 0);

-        ret = air_acl_getUdfRule(0, rule_idx, &rule);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Get ACL UDF Rule(%u): %s\n", rule_idx, air_error_getString(ret));

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(AIR_E_OK == ret)

-    {

-        if(TRUE == rule.valid)

-        {

-            AIR_PRINT("\tMode          : %s\n", (AIR_ACL_RULE_CMP_SEL_PATTERN == rule.cmp_sel)?"Pattern":"Threshold");

-            if(AIR_ACL_RULE_CMP_SEL_PATTERN == rule.cmp_sel)

-            {

-                AIR_PRINT("\tPattern       : 0x%04X\n", rule.pattern);

-                AIR_PRINT("\tMask          : 0x%04X\n", rule.mask);

-            }

-            else

-            {

-                AIR_PRINT("\tLow Threshold : 0x%04X\n", rule.low_threshold);

-                AIR_PRINT("\tHigh Threshold: 0x%04X\n", rule.high_threshold);

-            }

-            AIR_PRINT("\tOffset Start  : %s\n", start_addr[rule.offset_format]);

-            AIR_PRINT("\tOffset        : %u %s\n", rule.offset*2, (0==rule.offset)?"Byte":"Bytes");

-            _hex2bitstr(rule.portmap, str_temp, AIR_MAX_NUM_OF_PORTS+1);

-            AIR_PRINT("\tPortmap[0:6]  : %s\n", str_temp);

-        }

-        else

-        {

-            AIR_PRINT("Entry is Invalid.\n");

-        }

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclRmvUdfRule(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T rule_idx;

-

-    if(1 == argc)

-    {

-        /* acl del udfRule <idx(0..15)> */

-        rule_idx = _strtoul(argv[0], NULL, 0);

-        ret = air_acl_delUdfRule(0, rule_idx);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Delete ACL UDF Rule(%u): %s\n", rule_idx, air_error_getString(ret));

-    }

-    else if(0 == argc)

-    {

-        /* acl clear udfRule */

-        ret = air_acl_clearUdfRule(0);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Clear ACL UDF Rule: %s\n", air_error_getString(ret));

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclAction(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T argi = 0;

-    UI32_T act_idx;

-    AIR_ACL_ACTION_T act;

-    UI32_T redirect, trtcm, fwd;

-    C8_T fwding[AIR_ACL_ACT_FWD_LAST][25] =

-    {

-        "Default",

-        "Default",

-        "Default",

-        "Default",

-        "Default & CPU excluded",

-        "Default & CPU included",

-        "CPU only",

-        "Drop"

-    };

-    C8_T trtcm_usr[AIR_ACL_ACT_USR_TCM_LAST][8] =

-    {

-        "Default",

-        "Green",

-        "Yellow",

-        "Red"

-    };

-    C8_T egtag[AIR_ACL_ACT_EGTAG_LAST][11] =

-    {

-        "Default",

-        "Consistent",

-        "",

-        "",

-        "Untag",

-        "Swap",

-        "Tag",

-        "Stack"

-    };

-    C8_T str_temp[20];

-

-    memset(&act, 0, sizeof(AIR_ACL_ACTION_T));

-    if(2 < argc)

-    {

-        /* acl set action <idx(0..127)>

-        [ forward <forward(0:Default,4:Exclude CPU,5:Include CPU,6:CPU only,7:Drop)> ]

-        [ egtag <egtag(0:Default,1:Consistent,4:Untag,5:Swap,6:Tag,7:Stack)> ]

-        [ mirrormap <mirrormap(2'bin)> ]

-        [ priority <priority(0..7)> ]

-        [ redirect <redirect(0:Dst,1:Vlan)> <portmap(7'bin)> ]

-        [ leaky_vlan <leaky_vlan(1:En,0:Dis)> ]

-        [ cnt_idx <cnt_idx(0..63)> ]

-        [ rate_idx <rate_idx(0..31)> ]

-        [ attack_idx <attack_idx(0..95)> ]

-        [ vid <vid(0..4095)> ]

-        [ manage <manage(1:En,0:Dis)> ]

-        [ bpdu <bpdu(1:En,0:Dis)> ]

-        [ class <class(0:Original,1:Defined)>[0..7] ]

-        [ drop_pcd <drop_pcd(0:Original,1:Defined)> [red <red(0..7)>][yellow <yellow(0..7)>][green <green(0..7)>] ]

-        [ color <color(0:Defined,1:Trtcm)> [ <defined_color(0:Dis,1:Green,2:Yellow,3:Red)> | <trtcm_idx(0..31)> ] ]*/

-

-        act_idx = _strtoul(argv[argi++], NULL, 0);

-        if(0 == _strcmp(argv[argi], "forward"))

-        {

-            argi++;

-            fwd = _strtoul(argv[argi++], NULL, 0);

-            act.fwd_en = TRUE;

-            act.fwd = fwd;

-        }

-

-        if(0 == _strcmp(argv[argi], "egtag"))

-        {

-            argi++;

-            act.egtag_en = TRUE;

-            act.egtag = _strtoul(argv[argi++], NULL, 0);

-        }

-

-        if(0 == _strcmp(argv[argi], "mirrormap"))

-        {

-            argi++;

-            act.mirrormap = _strtoul(argv[argi++], NULL, 2);

-        }

-

-        if(0 == _strcmp(argv[argi], "priority"))

-        {

-            argi++;

-            act.pri_user_en = TRUE;

-            act.pri_user= _strtoul(argv[argi++], NULL, 0);

-        }

-

-        if(0 == _strcmp(argv[argi], "redirect"))

-        {

-            argi++;

-            redirect = _strtoul(argv[argi++], NULL, 0);

-            if(0 ==  redirect)

-            {

-                act.port_en = TRUE;

-                act.dest_port_sel = TRUE;

-                act.portmap = _strtoul(argv[argi++], NULL, 2);

-            }

-            else

-            {

-                act.port_en = TRUE;

-                act.vlan_port_sel = TRUE;

-                act.portmap = _strtoul(argv[argi++], NULL, 2);

-            }

-        }

-

-        if(0 == _strcmp(argv[argi], "leaky_vlan"))

-        {

-            argi++;

-            act.lyvlan_en = TRUE;

-            act.lyvlan = _strtoul(argv[argi++], NULL, 0);

-        }

-

-        /* ACL event counter */

-        if(0 == _strcmp(argv[argi], "cnt_idx"))

-        {

-            argi++;

-            act.cnt_en = TRUE;

-            act.cnt_idx = _strtol(argv[argi++], NULL, 0);

-        }

-

-        if(0 == _strcmp(argv[argi], "rate_idx"))

-        {

-            argi++;

-            act.rate_en = TRUE;

-            act.rate_idx = _strtol(argv[argi++], NULL, 0);

-        }

-

-        if(0 == _strcmp(argv[argi], "attack_idx"))

-        {

-            argi++;

-            act.attack_en = TRUE;

-            act.attack_idx = _strtol(argv[argi++], NULL, 0);

-        }

-

-        if(0 == _strcmp(argv[argi], "vid"))

-        {

-            argi++;

-            act.vlan_en = TRUE;

-            act.vlan_idx = _strtol(argv[argi++], NULL, 0);

-        }

-

-        /* Management frame */

-        if(0 == _strcmp(argv[argi], "manage"))

-        {

-            argi++;

-            act.mang = _strtoul(argv[argi++], NULL, 2);

-        }

-

-        if(0 == _strcmp(argv[argi], "bpdu"))

-        {

-            argi++;

-            act.bpdu = _strtoul(argv[argi++], NULL, 2);

-        }

-

-        /* DSCP class remap */

-        if(0 == _strcmp(argv[argi], "class"))

-        {

-            argi++;

-            act.trtcm_en = TRUE;

-            act.trtcm.cls_slr_sel = _strtoul(argv[argi++], NULL, 2);

-            if(TRUE == act.trtcm.cls_slr_sel)

-            {

-                act.trtcm.cls_slr = _strtoul(argv[argi++], NULL, 0);

-            }

-        }

-        if(0 == _strcmp(argv[argi], "drop_pcd"))

-        {

-            argi++;

-            act.trtcm_en = TRUE;

-            act.trtcm.drop_pcd_sel = _strtoul(argv[argi++], NULL, 2);

-            if(TRUE == act.trtcm.drop_pcd_sel)

-            {

-                if(0 == _strcmp(argv[argi], "red"))

-                {

-                    argi++;

-                    act.trtcm.drop_pcd_r= _strtoul(argv[argi++], NULL, 0);

-                }

-                if(0 == _strcmp(argv[argi], "yellow"))

-                {

-                    argi++;

-                    act.trtcm.drop_pcd_y= _strtoul(argv[argi++], NULL, 0);

-                }

-                if(0 == _strcmp(argv[argi], "green"))

-                {

-                    argi++;

-                    act.trtcm.drop_pcd_g= _strtoul(argv[argi++], NULL, 0);

-                }

-            }

-        }

-

-        /* trTCM */

-        if(0 == _strcmp(argv[argi], "color"))

-        {

-            argi++;

-            act.trtcm_en = TRUE;

-            act.trtcm.tcm_sel = _strtoul(argv[argi++], NULL, 2);

-            trtcm = _strtoul(argv[argi++], NULL, 0);

-            if(FALSE == act.trtcm.tcm_sel)

-            {

-                act.trtcm.usr_tcm = trtcm;

-            }

-            else

-            {

-                act.trtcm.tcm_idx = trtcm;

-            }

-        }

-        ret = air_acl_setAction(0, act_idx, act);

-        AIR_PRINT("Set ACL Action(%u): %s\n", act_idx, air_error_getString(ret));

-    }

-    else if(1 == argc)

-    {

-        /* acl get action <idx(0..127)> */

-        act_idx = _strtoul(argv[argi++], NULL, 0);

-        ret = air_acl_getAction(0, act_idx, &act);

-        AIR_PRINT("Get ACL Action(%u): %s\n", act_idx, air_error_getString(ret));

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(AIR_E_OK == ret)

-    {

-        if(TRUE == act.fwd_en)

-        {

-            AIR_PRINT("\t Forwarding           : %s\n", fwding[act.fwd]);

-        }

-

-        if(TRUE == act.egtag_en)

-        {

-            AIR_PRINT("\t Egress tag           : %s\n", egtag[act.egtag]);

-        }

-

-        if(act.mirrormap)

-        {

-            AIR_PRINT("\t Mirror Session Map   : %u\n", act.mirrormap);

-        }

-

-        if(TRUE == act.pri_user_en)

-        {

-            AIR_PRINT("\t User Priority        : %u\n", act.pri_user);

-        }

-

-        if(TRUE == act.port_en)

-        {

-            _hex2bitstr(act.portmap, str_temp, AIR_MAX_NUM_OF_PORTS+1);

-            if(TRUE == act.dest_port_sel)

-            {

-                AIR_PRINT("\t Destination Port[0:6]: %s\n", str_temp);

-            }

-            else

-            {

-                AIR_PRINT("\t VLAN Port[0:6]       : %s\n", str_temp);

-            }

-        }

-

-        if(TRUE == act.lyvlan_en)

-        {

-            AIR_PRINT("\t Leaky VLAN           : %s\n", (TRUE == act.lyvlan)?"Enable":"Disable");

-        }

-        AIR_PRINT("\t Management Frame     : %s\n", (TRUE == act.mang)?"Enable":"Disable");

-        AIR_PRINT("\t BPDU Frame           : %s\n", (TRUE == act.bpdu)?"Enable":"Disable");

-

-        if(TRUE == act.cnt_en)

-        {

-            AIR_PRINT("\t Event Index          : %u\n", act.cnt_idx);

-        }

-

-        /* trTCM*/

-        if(TRUE == act.trtcm_en)

-        {

-            if(TRUE == act.trtcm.cls_slr_sel)

-            {

-                AIR_PRINT("\t Class Selector Remap : %u\n", act.trtcm.cls_slr);

-            }

-            else

-            {

-                AIR_PRINT("\t Class Selector Remap : %s\n", "Disable");

-            }

-            if(TRUE == act.trtcm.drop_pcd_sel)

-            {

-                AIR_PRINT("\t Drop Precedence Remap(Red): %u\n", act.trtcm.drop_pcd_r);

-                AIR_PRINT("\t Drop Precedence Remap(Yel): %u\n", act.trtcm.drop_pcd_y);

-                AIR_PRINT("\t Drop Precedence Remap(Gre): %u\n", act.trtcm.drop_pcd_g);

-            }

-            else

-            {

-                AIR_PRINT("\t Drop Precedence Remap: %s\n", "Disable");

-            }

-

-            if(TRUE == act.trtcm.tcm_sel)

-            {

-                AIR_PRINT("\t trTCM Meter Index    : %u\n", act.trtcm.tcm_idx);

-            }

-            else

-            {

-                AIR_PRINT("\t trTCM User Defined   : %s\n", trtcm_usr[act.trtcm.usr_tcm]);

-            }

-        }

-        /* rate control */

-        if(TRUE == act.rate_en)

-        {

-            AIR_PRINT("\t Rate Control Index   : %u\n", act.rate_idx);

-        }

-

-        if(TRUE == act.attack_en)

-        {

-            AIR_PRINT("\t Attack Rate Control Index: %u\n", act.attack_idx);

-        }

-

-        if(TRUE == act.vlan_en)

-        {

-            AIR_PRINT("\t ACL VLAN Index       : %u\n", act.vlan_idx);

-        }

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclRmvAction(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T act_idx;

-

-    if(1 == argc)

-    {

-        /* acl del action <idx(0..127)> */

-        act_idx = _strtoul(argv[0], NULL, 0);

-        ret = air_acl_delAction(0, act_idx);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Delete ACL Action(%u): %s\n", act_idx, air_error_getString(ret));

-    }

-    else if(0 == argc)

-    {

-        /* acl clear action */

-        ret = air_acl_clearAction(0);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Clear ACL Action: %s\n", air_error_getString(ret));

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclTrtcm(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T argi = 0;

-    UI32_T tcm_idx;

-    AIR_ACL_TRTCM_T tcm;

-

-    memset(&tcm, 0, sizeof(AIR_ACL_TRTCM_T));

-    if(5 == argc)

-    {

-        /* acl set trtcm <idx(0..31)> <cir(4'hex)> <pir(4'hex)> <cbs(4'hex)> <pbs(4'hex)> */

-        tcm_idx = _strtoul(argv[argi++], NULL, 0);

-        tcm.cir = _strtoul(argv[argi++], NULL, 16);

-        tcm.pir = _strtoul(argv[argi++], NULL, 16);

-        tcm.cbs = _strtoul(argv[argi++], NULL, 16);

-        tcm.pbs = _strtoul(argv[argi++], NULL, 16);

-

-        ret = air_acl_setTrtcm(0, tcm_idx, tcm);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Set ACL trTCM(%u): %s\n", tcm_idx, air_error_getString(ret));

-    }

-    else if(1 == argc)

-    {

-        /* acl get trtcm <idx(1..31)> */

-        tcm_idx = _strtoul(argv[argi++], NULL, 0);

-        ret = air_acl_getTrtcm(0, tcm_idx, &tcm);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Get ACL trTCM(%u): %s\n", tcm_idx, air_error_getString(ret));

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(AIR_E_OK == ret)

-    {

-        AIR_PRINT("\t CIR: 0x%04X(unit:64Kbps)\n", tcm.cir);

-        AIR_PRINT("\t PIR: 0x%04X(unit:64Kbps)\n", tcm.pir);

-        AIR_PRINT("\t CBS: 0x%04X(unit:Byte)\n", tcm.cbs);

-        AIR_PRINT("\t PBS: 0x%04X(unit:Byte)\n", tcm.pbs);

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclTrtcmEn(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    BOOL_T state = FALSE;

-

-    if (1 == argc)

-    {

-        /* acl set trtcmEn <en(1:En,0:Dis)> */

-        state = _strtol(argv[0], NULL, 10);

-        ret = air_acl_setTrtcmEnable(0, state);

-        AIR_PRINT("Set trTCM State ");

-    }

-    else if (0 == argc)

-    {

-        /* acl get trtcmEn */

-        ret = air_acl_getTrtcmEnable(0, &state);

-        AIR_PRINT("Get trTCM State ");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if (ret == AIR_E_OK)

-    {

-        AIR_PRINT(": %s\n", (TRUE == state) ? "Enable" : "Disable");

-    }

-    else

-    {

-        AIR_PRINT("Fail!\n");

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclRmvTrtcm(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T tcm_idx;

-

-    if(1 == argc)

-    {

-        /* acl del trtcm <idx(1..31)> */

-        tcm_idx = _strtoul(argv[0], NULL, 0);

-        ret = air_acl_delTrtcm(0, tcm_idx);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Delete ACL TRTCM(%u): %s\n", tcm_idx, air_error_getString(ret));

-    }

-    else if(0 == argc)

-    {

-        /* acl clear trtcm */

-        ret = air_acl_clearTrtcm(0);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Clear ACL TRTCM: %s\n", air_error_getString(ret));

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclPortEn(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T argi=0;

-    UI32_T port = 0;

-    BOOL_T en;

-

-    if(2 == argc)

-    {

-        /* acl set portEn <port(0..6)> <en(1:En,0:Dis)> */

-        port = _strtoul(argv[argi++], NULL, 0);

-        en = _strtoul(argv[argi++], NULL, 2);

-        ret = air_acl_setPortEnable(0, port, en);

-        AIR_PRINT("Set Port:%u ACL function ", port);

-    }

-    else if(1 == argc)

-    {

-        /* acl get portEn <port(0..6)> */

-        port = _strtoul(argv[argi++], NULL, 0);

-        ret = air_acl_getPortEnable(0, port, &en);

-        AIR_PRINT("Get Port:%u ACL function ", port);

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        AIR_PRINT(": %s\n", (TRUE == en)?"Enable":"Disable");

-    }

-    else

-    {

-        AIR_PRINT("Fail!\n");

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclDropEn(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T argi=0;

-    UI32_T port = 0;

-    BOOL_T en;

-

-    if(2 == argc)

-    {

-        /* acl set dropEn <port(0..6)> <en(1:En,0:Dis)> */

-        port = _strtoul(argv[argi++], NULL, 0);

-        en = _strtoul(argv[argi++], NULL, 2);

-        ret = air_acl_setDropEnable(0, port, en);

-        AIR_PRINT("Set ACL Drop precedence ");

-    }

-    else if(1 == argc)

-    {

-        /* acl set dropEn <port(0..6)> */

-        port = _strtoul(argv[argi++], NULL, 0);

-        ret = air_acl_getDropEnable(0, port, &en);

-        AIR_PRINT("Get ACL Drop precedence ");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        AIR_PRINT("(Port %u):%s\n",

-                port,

-                (TRUE == en)?"Enable":"Disable");

-    }

-    else

-    {

-        AIR_PRINT("Fail!\n");

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclDropThrsh(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T argi=0;

-    UI32_T port = 0;

-    AIR_ACL_DP_COLOR_T color;

-    UI8_T queue;

-    UI32_T high, low;

-    C8_T dp_color[AIR_ACL_DP_COLOR_LAST][7] =

-    {

-        "Green",

-        "Yellow",

-        "Red"

-    };

-

-    if(5 == argc)

-    {

-        /* acl set dropThrsh <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> <high(0..2047)> <low(0..2047) */

-        port = _strtoul(argv[argi++], NULL, 0);

-        color = _strtoul(argv[argi++], NULL, 0);

-        queue = _strtoul(argv[argi++], NULL, 0);

-        high = _strtoul(argv[argi++], NULL, 0);

-        low = _strtoul(argv[argi++], NULL, 0);

-        ret = air_acl_setDropThreshold(0, port, color, queue, high, low);

-        AIR_PRINT("Set ACL Drop precedence ");

-    }

-    else if(3 == argc)

-    {

-        /* acl get dropThrsh <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> */

-        port = _strtoul(argv[argi++], NULL, 0);

-        color = _strtoul(argv[argi++], NULL, 0);

-        queue = _strtoul(argv[argi++], NULL, 0);

-        ret = air_acl_getDropThreshold(0, port, color, queue, &high, &low);

-        AIR_PRINT("Get ACL Drop precedence ");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        AIR_PRINT("(Port %u, color:%s, queue:%u):\n",

-                port,

-                dp_color[color],

-                queue);

-        AIR_PRINT("\tHigh Threshold :%u\n", high);

-        AIR_PRINT("\tLow Threshold  :%u\n", low);

-    }

-    else

-    {

-        AIR_PRINT("Fail!\n");

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclDropPbb(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T argi=0;

-    UI32_T port = 0;

-    AIR_ACL_DP_COLOR_T color;

-    UI8_T queue;

-    UI32_T pbb;

-    C8_T dp_color[AIR_ACL_DP_COLOR_LAST][7] =

-    {

-        "Green",

-        "Yellow",

-        "Red"

-    };

-

-    if(4 == argc)

-    {

-        /* acl set dropPbb <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> <probability(0..1023) */

-        port = _strtoul(argv[argi++], NULL, 0);

-        color = _strtoul(argv[argi++], NULL, 0);

-        queue = _strtoul(argv[argi++], NULL, 0);

-        pbb = _strtoul(argv[argi++], NULL, 0);

-        ret = air_acl_setDropProbability(0, port, color, queue, pbb);

-        AIR_PRINT("Set ACL Drop precedence ");

-    }

-    else if(3 == argc)

-    {

-        /* acl get dropPbb <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> */

-        port = _strtoul(argv[argi++], NULL, 0);

-        color = _strtoul(argv[argi++], NULL, 0);

-        queue = _strtoul(argv[argi++], NULL, 0);

-        ret = air_acl_getDropProbability(0, port, color, queue, &pbb);

-        AIR_PRINT("Get ACL Drop precedence ");

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(ret == AIR_E_OK)

-    {

-        AIR_PRINT("(Port %u, color:%s, queue %u):\n",

-                port,

-                dp_color[color],

-                queue);

-        AIR_PRINT("\tDrop probability:%u(unit=1/1023)\n", pbb);

-    }

-    else

-    {

-        AIR_PRINT("Fail!\n");

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclMeter(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T argi = 0;

-    UI32_T meter_idx, state, rate;

-

-    if(3 == argc)

-    {

-        /* acl set meter <idx(0..31)> <en(1:En,0:Dis)> <rate(0..65535)>

-           Note: Limit rate = rate * 64Kbps */

-        meter_idx = _strtoul(argv[argi++], NULL, 0);

-        state = _strtoul(argv[argi++], NULL, 2);

-        rate = _strtoul(argv[argi++], NULL, 0);

-

-        ret = air_acl_setMeterTable(0, meter_idx, state, rate);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Set ACL Meter(%u): %s\n", meter_idx, air_error_getString(ret));

-    }

-    else if(1 == argc)

-    {

-        /* acl get meter <idx(0..31)> */

-        meter_idx = _strtoul(argv[argi++], NULL, 0);

-        ret = air_acl_getMeterTable(0, meter_idx, &state, &rate);

-        if(ret < AIR_E_LAST)

-            AIR_PRINT("Get ACL Meter(%u): %s\n", meter_idx, air_error_getString(ret));

-    }

-    else

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if(AIR_E_OK == ret)

-    {

-        AIR_PRINT("\t State: %s\n", (TRUE == state)?"Enable":"Disable");

-        if(TRUE == state)

-        {

-            AIR_PRINT("\t Rate : %u(unit:64Kbps)\n", rate);

-        }

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclDump(

-    UI32_T argc,

-    C8_T *argv[])

-{

-    AIR_ERROR_NO_T ret = AIR_E_OK;

-    UI32_T i, cnt = 0;

-    AIR_ACL_CTRL_T ctrl;

-

-    if(0 != argc)

-    {

-        AIR_PRINT("Unrecognized command.\n");

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    for(i=0; i<ACL_MAX_RULE_NUM; i++)

-    {

-        memset(&ctrl, 0, sizeof(AIR_ACL_CTRL_T));

-        ret = air_acl_getRuleCtrl(0, i, &ctrl);

-        if(AIR_E_OK == ret)

-        {

-            if(TRUE == ctrl.rule_en)

-            {

-                cnt++;

-                AIR_PRINT("\t Entry-%d vaild\n", i);

-            }

-        }

-    }

-    if(0 == cnt)

-    {

-        AIR_PRINT("\t No entry vaild\n");

-    }

-

-    return ret;

-}

-

-static AIR_ERROR_NO_T

-doAclSet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(aclSetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doAclGet(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(aclGetCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doAclDel(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(aclDelCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doAclClear(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(aclClearCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-doAcl(

-        UI32_T argc,

-        C8_T *argv[])

-{

-    return subcmd(aclCmds, argc, argv);

-}

-

-static AIR_ERROR_NO_T

-subcmd(

-        const AIR_CMD_T tab[],

-        UI32_T argc,

-        C8_T *argv[])

-{

-    const AIR_CMD_T *cmdp;

-    I32_T found = 0;

-    I32_T i, len;

-

-    if (argc < 1)

-    {

-        goto print_out_cmds;

-    }

-

-    for (cmdp = tab; cmdp->name != NULL; cmdp++)

-    {

-        if (strlen(argv[0]) == strlen(cmdp->name))

-        {

-            if (strncmp(argv[0], cmdp->name, strlen(argv[0])) == 0)

-            {

-                found = 1;

-                break;

-            }

-        }

-    }

-

-    if(!found)

-    {

-        C8_T buf[66];

-

-print_out_cmds:

-        AIR_PRINT("valid subcommands:\n");

-        memset(buf, ' ', sizeof(buf));

-        buf[64] = '\n';

-        buf[65] = '\0';

-

-        for (i=0, cmdp = tab; cmdp->name != NULL; cmdp++)

-        {

-            len = strlen(cmdp->name);

-            strncpy(&buf[i*16], cmdp->name, (len > 16) ? 16 : len);

-            if(3 == i)

-            {

-                AIR_PRINT("%s\n", buf);

-                memset(buf, ' ', sizeof(buf));

-                buf[64] = '\n';

-                buf[65] = '\0';

-            }

-            i = (i + 1) % 4;

-        }

-

-        if (0 != i)

-            AIR_PRINT("%s\n", buf);

-

-        return AIR_E_BAD_PARAMETER;

-    }

-

-    if (CMD_NO_PARA == cmdp->argc_min)

-    {

-        if (argc != 1)

-        {

-            if (cmdp->argc_errmsg != NULL)

-            {

-                AIR_PRINT("Usage: %s\n", cmdp->argc_errmsg);

-            }

-

-            return AIR_E_BAD_PARAMETER;

-        }

-    }

-    else if (CMD_VARIABLE_PARA == cmdp->argc_min)

-    {

-        if (argc < 3)

-        {

-            if (cmdp->argc_errmsg != NULL)

-            {

-                AIR_PRINT("Usage: %s\n", cmdp->argc_errmsg);

-            }

-

-            return AIR_E_BAD_PARAMETER;

-        }

-    }

-    else

-    {

-        if ((argc <= cmdp->argc_min) || ((cmdp->argc_min != 0) && (argc != (cmdp->argc_min + 1))))

-        {

-            if (cmdp->argc_errmsg != NULL)

-            {

-                AIR_PRINT("Usage: %s\n", cmdp->argc_errmsg);

-            }

-

-            return AIR_E_BAD_PARAMETER;

-        }

-    }

-

-    if (cmdp->func)

-    {

-        argc--;

-        argv++;

-        return (*cmdp->func)(argc, argv);

-    }

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_parse_cmd

- * PURPOSE:

- *      This function is used process diagnostic cmd

- * INPUT:

- *      argc         -- parameter number

- *      argv         -- parameter strings

- * OUTPUT:

- *      None

- * RETURN:

- *      NPS_E_OK     -- Successfully read the data.

- *      NPS_E_OTHERS -- Failed to read the data.

- * NOTES:

- *

- */

-AIR_ERROR_NO_T

-air_parse_cmd(

-        const UI32_T argc,

-        const C8_T **argv)

-{

-    return subcmd(Cmds, argc, (C8_T **)argv);

-}

-

+/* FILE NAME:   air_cmd.c
+ * PURPOSE:
+ *      Define the command line function in AIR SDK.
+ * NOTES:
+ */
+
+/* INCLUDE FILE DECLARATIONS
+*/
+#include "air.h"
+
+/* NAMING CONSTANT DECLARATIONS
+*/
+
+/* MACRO FUNCTION DECLARATIONS
+*/
+#define MAC_STR         "%02X%02X%02X%02X%02X%02X"
+#define MAC2STR(m)      (m)[0],(m)[1],(m)[2],(m)[3],(m)[4],(m)[5]
+#define AIR_MAC_LEN    (12)
+#define CMD_NO_PARA     (0xFFFFFFFF)
+#define CMD_VARIABLE_PARA (0xFFFFFFFE)
+#define L2_WDOG_KICK_NUM            (100)
+
+#define TOLOWER(x)      ((x) | 0x20)
+#define isxdigit(c)     (('0' <= (c) && (c) <= '9') || ('a' <= (c) && (c) <= 'f') || ('A' <= (c) && (c) <= 'F'))
+#define isdigit(c)      ('0' <= (c) && (c) <= '9')
+#define CMD_CHECK_PARA(__shift__, __op__, __size__) do          \
+{                                                               \
+    if ((__shift__) __op__ (__size__))                          \
+    {                                                           \
+        ;                                                       \
+    }                                                           \
+    else                                                        \
+    {                                                           \
+        return (AIR_E_BAD_PARAMETER);                           \
+    }                                                           \
+} while(0)
+
+/* DATA TYPE DECLARATIONS
+*/
+typedef struct {
+    C8_T*               name;
+    AIR_ERROR_NO_T     (*func)(UI32_T argc, C8_T *argv[]);
+    UI32_T              argc_min;
+    C8_T*               argc_errmsg;
+} AIR_CMD_T;
+
+/* GLOBAL VARIABLE DECLARATIONS
+*/
+
+/* LOCAL SUBPROGRAM DECLARATIONS
+*/
+/* String Utility */
+static BOOL_T _strcmp(const char *s1, const char *s2);
+static C8_T * _strtok_r(C8_T *s, const C8_T *delim, C8_T **last);
+static C8_T * _strtok(C8_T *s, const C8_T *delim, C8_T **last);
+UI32_T _strtoul(const C8_T *cp, C8_T **endp, UI32_T base);
+static I32_T _strtol(const C8_T *cp, C8_T **endp, UI32_T base);
+
+/* Type Converter */
+static AIR_ERROR_NO_T _str2mac(C8_T *str, C8_T *mac);
+static AIR_ERROR_NO_T _hex2bit(const UI32_T hex, UI32_T *ptr_bit);
+static AIR_ERROR_NO_T _hex2bitstr(const UI32_T hex, C8_T *ptr_bit_str, UI32_T str_len);
+static AIR_ERROR_NO_T _portListStr2Ary(const C8_T *str, UI32_T *ary, const UI32_T ary_num);
+
+/* Register Operation */
+static AIR_ERROR_NO_T doRegRead(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doRegWrite(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doReg(UI32_T argc, C8_T *argv[]);
+
+/* PHY Operation */
+static AIR_ERROR_NO_T doPhyCL22Read(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPhyCL22Write(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPhyCL22(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPhyCL45Read(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPhyCL45Write(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPhyCL45(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPhy(UI32_T argc, C8_T *argv[]);
+
+/* Porting setting */
+static AIR_ERROR_NO_T doPortSetMatrix(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortSetVlanMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortSet(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doPortGetMatrix(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortGetVlanMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortGet(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doPort(UI32_T argc, C8_T *argv[]);
+
+/* Vlan setting */
+static AIR_ERROR_NO_T doVlanInitiate(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanCreate(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanDestroy(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanDestroyAll(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanDump(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanAddPortMem(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanDelPortMem(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doVlanSetFid(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetMemPort(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetIVL(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetPortBaseStag(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetStag(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetEgsTagCtlEn(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetEgsTagCtlCon(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetEgsTagCtl(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetPortActFrame(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetLeakyVlanEn(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetPortVlanAttr(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetIgsPortETagAttr(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetPortETagAttr(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetPortOuterTPID(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSetPvid(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanSet(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doVlanGetPortActFrame(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanGetLeakyVlanEn(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanGetPortVlanAttr(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanGetIgsPortETagAttr(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanGetPortETagAttr(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanGetPortOuterTPID(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanGetPvid(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doVlanGet(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doVlan(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doFlowCtrl(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doJumbo(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doL2Add(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doL2Del(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doL2Clear(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doL2Get(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doL2Set(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doL2Dump(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doL2(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doAnMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLocalAdv(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doRemoteAdv(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortSpeed(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortDuplex(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortStatus(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortBckPres(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortPsMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortSmtSpdDwn(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortSpTag(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortEnable(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPort5GBaseRMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortHsgmiiMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortSgmiiMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortRmiiMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doPortRgmiiMode(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doSptagEn(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSptagMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSptagDecode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSptagEncode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSptag(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doMacAddr(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T _printMacEntry(AIR_MAC_ENTRY_T * mt, UI32_T age_unit, UI8_T count, UI8_T title);
+static AIR_ERROR_NO_T doGetMacAddr(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMacAddrAgeOut(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doDumpMacAddr(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doLagMember(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLagMemberCnt(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLagPtseed(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLagHashtype(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLagDstInfo(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLagState(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLagSpsel(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLagGet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLagSet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLag(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doStpPortstate(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doStpGet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doStpSet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doStp(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doMirrorGetSid(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMirrorDelSid(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMirrorAddRlist(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMirrorAddTlist(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMirrorSetSessionEnable(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMirrorSetSession(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMirrorSet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMirrorAdd(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMirrorGet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMirrorDel(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMirror(UI32_T argc,C8_T *argv[]);
+
+static AIR_ERROR_NO_T doMibClearPort(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMibClearAcl(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMibGetPort(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMibGetAcl(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMibClear(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMibGet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doMib(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doQosScheduleAlgo(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doQosTrustMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doQosPri2Queue(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doQosDscp2Pri(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doQosRateLimitEnable(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doQosRateLimit(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doQosPortPriority(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doQosRateLimitExMngFrm(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doQosGet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doQosSet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doQos(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doDiagTxComply(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doDiagSet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doDiagGet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doDiag(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doLedMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLedState(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLedUsrDef(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLedBlkTime(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLedSet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLedGet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doLed(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doSwitchCpuPortEn(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSwitchCpuPort(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSwitchPhyLCIntrEn(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSwitchPhyLCIntrSts(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSwitchSet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSwitchGet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSwitch(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doShowVersion(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doShow(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T doStormEnable(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doStormRate(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doFldMode(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSaLearning(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSaLimit(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSecGet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSecSet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doSec(UI32_T argc, C8_T *argv[]);
+
+static void _air_acl_printRuleMap(UI32_T *rule_map, UI32_T ary_num);
+static AIR_ERROR_NO_T doAclEn(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclRule(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclUdfRule(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclRmvRule(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclRmvUdfRule(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclAction(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclRmvAction(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclDumpAction(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclTrtcm(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclTrtcmEn(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclRmvTrtcm(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclPortEn(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclDropEn(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclDropThrsh(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclDropPbb(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclMeter(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclDump(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclSet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclGet(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclDel(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAclClear(UI32_T argc, C8_T *argv[]);
+static AIR_ERROR_NO_T doAcl(UI32_T argc, C8_T *argv[]);
+
+static AIR_ERROR_NO_T subcmd(const AIR_CMD_T tab[], UI32_T argc, C8_T *argv[]);
+
+/* STATIC VARIABLE DECLARATIONS
+*/
+const static C8_T *_sptag_vpm[] =
+{
+    "untagged",
+    "8100",
+    "predefined",
+    "unknown"
+};
+
+const static C8_T *_sptag_pt[] =
+{
+    "disable pass through",
+    "enable pass through"
+};
+
+const static C8_T *_air_mac_address_forward_control_string [] =
+{
+    "Default",
+    "CPU include",
+    "CPU exclude",
+    "CPU only",
+    "Drop"
+};
+
+static AIR_CMD_T regCmds[] =
+{
+    {"r",           doRegRead,      1,      "reg r <reg(4'hex)>"},
+    {"w",           doRegWrite,     2,      "reg w <reg(4'hex)> <value(8'hex)>"},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T phyCL22Cmds[] =
+{
+    {"r",           doPhyCL22Read,  2,      "phy cl22 r <port(0..4)> <reg(2'hex)>"},
+    {"w",           doPhyCL22Write, 3,      "phy cl22 w <port(0..4)> <reg(2'hex)> <value(4'hex)>"},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T phyCL45Cmds[] =
+{
+    {"r",           doPhyCL45Read,  3,      "phy cl45 r <port(0..4)> <dev(2'hex)> <reg(3'hex)>"},
+    {"w",           doPhyCL45Write, 4,      "phy cl45 w <port(0..4)> <dev(2'hex)> <reg(3'hex)> <value(4'hex)>"},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T phyCmds[] =
+{
+    {"cl22",         doPhyCL22,     0,      NULL},
+    {"cl45",         doPhyCL45,     0,      NULL},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T portSetCmds[] =
+{
+    {"matrix",      doPortSetMatrix,        2,                "port set matrix <port(0..6)> <matrix(6:0)>"},
+    {"vlanMode",    doPortSetVlanMode,      2,                "port set vlanMode <port(0..6)> <vlanMode(0:matrix,1:fallback,2:check,3:security)>"},
+    {"flowCtrl",    doFlowCtrl,             3,                "port set flowCtrl <port(0..6)> <dir(0:Tx,1:Rx)> <fc_en(1:En,0:Dis)>"},
+    {"jumbo",       doJumbo,                2,                "port set jumbo <pkt_len(0:1518,1:1536,2:1552,3:max)> <frame_len(2..15)>"},
+    {"anMode",      doAnMode,               2,                "port set anMode <port(0..4)> <en(0:force,1:AN)>"},
+    {"localAdv",    doLocalAdv,             7,                "port set localAdv <port(0..4)> <10H(1:En,0:Dis)> <10F(1:En,0:Dis)> <100H(1:En,0:Dis)> <100F(1:En,0:Dis)> <1000F(1:En,0:Dis)> <pause(1:En,0:Dis)>"},
+    {"speed",       doPortSpeed,            2,                "port set speed <port(0..4)> <speed(0:10M,1:100M,2:1G,3:2.5G)>"},
+    {"duplex",      doPortDuplex,           2,                "port set duplex <port(0..4)> <duplex(0:half,1:full)>"},
+    {"bckPres",     doPortBckPres,          2,                "port set bckPres <port(0..6)> <bckPres(1:En,0:Dis)>"},
+    {"psMode",      doPortPsMode,           3,                "port set psMode <port(0..4)> <ls(1:En,0:Dis)> <eee(1:En,0:Dis)>"},
+    {"smtSpdDwn",   doPortSmtSpdDwn,        3,                "port set smtSpdDwn <port(0..4)> <en(1:En,0:Dis)> <retry(2..5)>"},
+    {"spTag",       doPortSpTag,            2,                "port set spTag <port(0..6)> <en(1:En,0:Dis)>"},
+    {"enable",      doPortEnable,           2,                "port set enable <port(0..4)> <en(1:En,0:Dis)>"},
+    {"5GBaseRMode", doPort5GBaseRMode,      CMD_NO_PARA,      "port set 5GBaseRMode"},
+    {"hsgmiiMode",  doPortHsgmiiMode,       CMD_NO_PARA,      "port set hsgmiiMode"},
+    {"sgmiiMode",   doPortSgmiiMode,        2,                "port set sgmiiMode <mode(0:AN,1:Force)> <speed(0:10M,1:100M,2:1G)>"},
+    {"rmiiMode",    doPortRmiiMode,         1,                "port set rmiiMode <speed(0:10M,1:100M)>"},
+    {"rgmiiMode",   doPortRgmiiMode,        1,                "port set rgmiiMode <speed(0:10M,1:100M,2:1G)>"},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T portGetCmds[] =
+{
+    {"matrix",      doPortGetMatrix,        1,                "port get matrix <port(0..6)>"},
+    {"vlanMode",    doPortGetVlanMode,      1,                "port get vlanMode <port(0..6)>"},
+    {"flowCtrl",    doFlowCtrl,             2,                "port get flowCtrl <port(0..6)> <dir(0:Tx,1:Rx)>"},
+    {"jumbo",       doJumbo,                CMD_NO_PARA,      "port get jumbo"},
+    {"anMode",      doAnMode,               1,                "port get anMode <port(0..4)>"},
+    {"localAdv",    doLocalAdv,             1,                "port get localAdv <port(0..4)>"},
+    {"remoteAdv",   doRemoteAdv,            1,                "port get remoteAdv <port(0..4)>"},
+    {"speed",       doPortSpeed,            1,                "port get speed <port(0..4)>"},
+    {"duplex",      doPortDuplex,           1,                "port get duplex <port(0..4)>"},
+    {"status",      doPortStatus,           1,                "port get status <port(0..4)>"},
+    {"bckPres",     doPortBckPres,          1,                "port get bckPres <port(0..6)>"},
+    {"psMode",      doPortPsMode,           1,                "port get psMode <port(0..4)>"},
+    {"smtSpdDwn",   doPortSmtSpdDwn,        1,                "port get smtSpdDwn <port(0..4)>"},
+    {"spTag",       doPortSpTag,            1,                "port get spTag <port(0..6)>"},
+    {"enable",      doPortEnable,           1,                "port get enable <port(0..4)>"},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T portCmds[] =
+{
+    {"set",         doPortSet,      0,      NULL},
+    {"get",         doPortGet,      0,      NULL},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T sptagCmds[] =
+{
+    {"setEnable",       doSptagEn,          2,      "sptag setEnable port<port(0..6)> enable<1:enable 0:disable>"},
+    {"getEnable",       doSptagEn,          1,      "sptag getEnable port<port(0..6)>"},
+    {"setmode",         doSptagMode,        2,      "sptag setmode port<port(0..6)> mode<0:inset 1:replace>"},
+    {"getmode",         doSptagMode,        1,      "sptag getmode port<port(0..6)>"},
+    {"encode",          doSptagEncode,      7,      "sptag encode mode={ insert | replace } opc={ portmap | portid | lookup } dp={bitimap hex} vpm={ untagged | 8100 | 88a8 } pri=<UINT> cfi=<UINT> vid=<UINT> "},
+    {"decode",          doSptagDecode,      4,      "sptag decode <byte(hex)> <byte(hex)> <byte(hex)> <byte(hex)>"},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T vlanSetCmds[] =
+{
+    {"fid",                 doVlanSetFid,               2,      "vlan set fid <vid(0..4095)> <fid(0..7)>"},
+    {"memPort",             doVlanSetMemPort,           2,      "vlan set memPort <vid(0..4095)> <bitmap(6:0)>"},
+    {"ivl",                 doVlanSetIVL,               2,      "vlan set ivl <vid(0..4095)> <(1:En,0:Dis)>"},
+    {"portBaseStag",        doVlanSetPortBaseStag,      2,      "vlan set portBaseStag <vid(0..4095)> <(1:En,0:Dis)>"},
+    {"stag",                doVlanSetStag,              2,      "vlan set stag <vid(0..4095)> <stag(0..4095)>"},
+    {"egsTagCtlEn",         doVlanSetEgsTagCtlEn,       2,      "vlan set egsTagCtlEn <vid(0..4095)> <(1:En,0:Dis)>"},
+    {"egsTagCtlCon",        doVlanSetEgsTagCtlCon,      2,      "vlan set egsTagCtlCon <vid(0..4095)> <(1:En,0:Dis)>"},
+    {"egsTagCtl",           doVlanSetEgsTagCtl,         3,      "vlan set egsTagCtl <vid(0..4095)> <port(0..6)> <ctlType(0:untag,2:tagged)>"},
+
+    {"portActFrame",        doVlanSetPortActFrame,      2,      "vlan set portActFrame <port(0..6)> <frameType(0:all,1:tagged,2:untagged)>"},
+    {"leakyVlanEn",         doVlanSetLeakyVlanEn,       3,      "vlan set LeakyVlanEn <port(0..6)> <pktType(0:uc,1:mc,2:bc,3:ipmc)> <(1:En,0:Dis)>"},
+    {"portVlanAttr",        doVlanSetPortVlanAttr,      2,      "vlan set portVlanAttr <port(0..6)> <vlanAttr(0:user,1:stack,2:translation,3:transparent)>"},
+    {"igsPortETagAttr",     doVlanSetIgsPortETagAttr,   2,      "vlan set igsPortETagAttr <port(0..6)> <egsTagAttr(0:disable,1:consistent,4:untagged,5:swap,6:tagged,7:stack)>"},
+    {"portEgsTagAttr",      doVlanSetPortETagAttr,      2,      "vlan set portEgsTagAttr <port(0..6)> <egsTagAttr(0:untagged,1:swap,2:tagged,3:stack)>"},
+    {"portOuterTPID",       doVlanSetPortOuterTPID,     2,      "vlan set portOuterTPID <port(0..6)> <TPID(hex)>"},
+    {"pvid",                doVlanSetPvid,              2,      "vlan set pvid <port(0..6)> <vid(0..4095)>"},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T vlanGetCmds[] =
+{
+    {"portActFrame",        doVlanGetPortActFrame,      1,      "vlan get portActFrame <port(0..6)>"},
+    {"leakyVlanEn",         doVlanGetLeakyVlanEn,       1,      "vlan get leakyVlanEn <port(0..6)>"},
+    {"portVlanAttr",        doVlanGetPortVlanAttr,      1,      "vlan get portVlanAttr <port(0..6)>"},
+    {"igsPortETagAttr",     doVlanGetIgsPortETagAttr,   1,      "vlan get igsPortETagAttr <port(0..6)>"},
+    {"portEgsTagAttr",      doVlanGetPortETagAttr,      1,      "vlan get portEgsTagAttr <port(0..6)>"},
+    {"portOuterTPID",       doVlanGetPortOuterTPID,     1,      "vlan get portOuterTPID <port(0..6)>"},
+    {"pvid",                doVlanGetPvid,              1,      "vlan get pvid <port(0..6)>"},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T vlanCmds[] =
+{
+    {"initiate",        doVlanInitiate,         9,      "vlan initiate <vid(0..4095)> <fid(0..7)> <bitmap(6:0)> <ivl(1:En,0:Dis)> <portbasestag(1:En,0:Dis)> <stag(0..4095)> <egstagctlen(1:En,0:Dis)> <egstagcon(1:En,0:Dis)> <taggedbitmap(6:0)>"},
+    {"create",          doVlanCreate,           1,      "vlan create <vid(0..4095)>"},
+    {"destroy",         doVlanDestroy,          1,      "vlan destroy [ <vid(0..4095)> | <vidRange(vid0-vid1)> ]"},
+    {"destroyAll",      doVlanDestroyAll,       0,      "vlan destroyAll [ <restoreDefVlan(0:false,1:true)> | ]"},
+    {"dump",            doVlanDump,             0,      "vlan dump [ <vid(0..4095)> | <vidRange(vid0-vid1)> | ]"},
+    {"addPortMem",      doVlanAddPortMem,       2,      "vlan addPortMem <vid(0..4095)> <port(0..6)>"},
+    {"delPortMem",      doVlanDelPortMem,       2,      "vlan addPortMem <vid(0..4095)> <port(0..6)>"},
+    {"set",             doVlanSet,              0,      NULL},
+    {"get",             doVlanGet,              0,      NULL},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T l2ClearCmds[] =
+{
+    {"mac",              doMacAddr,          CMD_NO_PARA,    "l2 clear mac"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T l2DelCmds[] =
+{
+    {"mac",             doMacAddr,           3,    "l2 del mac <mac(12'hex)> [ vid <vid(0..4095)> | fid <fid(0..15)> ]"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T l2AddCmds[] =
+{
+    {"mac",             doMacAddr,           7,    "l2 add mac <static(0:dynamic,1:static)> <unauth(0:auth,1:unauth)> <mac(12'hex)> <portlist(uintlist)> [ vid <vid(0..4095)> | fid <fid(0..15)> ] <src_mac_forward=(0:default,1:cpu-exclude,2:cpu-include,3:cpu-only,4:drop)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T l2SetCmds[] =
+{
+    {"macAddrAgeOut",   doMacAddrAgeOut,    1,    "l2 set macAddrAgeOut <time(1, 1000000)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T l2GetCmds[] =
+{
+    {"mac",             doGetMacAddr,       3,              "l2 get mac <mac(12'hex)> [ vid <vid(0..4095)> | fid <fid(0..15)> ]"},
+    {"macAddrAgeOut",   doMacAddrAgeOut,    CMD_NO_PARA,    "l2 get macAddrAgeOut"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T l2DumpCmds[] =
+{
+    {"mac",                doDumpMacAddr,        0,    "l2 dump mac"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T l2Cmds[] =
+{
+    {"add",         doL2Add,        0,        NULL},
+    {"del",         doL2Del,        0,        NULL},
+    {"clear",       doL2Clear,      0,        NULL},
+    {"get",         doL2Get,        0,        NULL},
+    {"set",         doL2Set,        0,        NULL},
+    {"dump",        doL2Dump,       0,        NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T lagGetCmds[] =
+{
+    {"member",      doLagMember,    1,              "lag get member group_id(0 or 1)"},
+    {"dstInfo",     doLagDstInfo,   CMD_NO_PARA,    "lag get dstInfo"},
+    {"ptseed",      doLagPtseed,    CMD_NO_PARA,    "lag get ptseed"},
+    {"hashtype",    doLagHashtype,  CMD_NO_PARA,    "lag get hashtype"},
+    {"state",       doLagState,     CMD_NO_PARA,    "lag get state"},
+    {"spsel",       doLagSpsel,     CMD_NO_PARA,    "lag get spsel"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T lagSetCmds[] =
+{
+    {"member",       doLagMember,        4,    "lag set member <group_id(0 or 1)> <member_index(0..3)> <enable(0,1)> <port index(0..6)>"},
+    {"dstInfo",      doLagDstInfo,       7,    "lag set dstInfo <sp(1:En,0:Dis)> <sa(1:En,0:Dis)> <da(1:En,0:Dis)> <sip(1:En,0:Dis)> <dip(1:En,0:Dis)> <sport(1:En,0:Dis)> <dport(1:En,0:Dis)>"},
+    {"ptseed",       doLagPtseed,        1,    "lag set ptseed <hex32>"},
+    {"hashtype",     doLagHashtype,      1,    "lag set hashtype <0-crc32lsb;1-crc32msb;2-crc16;3-xor4>"},
+    {"state",        doLagState,         1,    "lag set state <state(1:En,0:Dis)>"},
+    {"spsel",        doLagSpsel,         1,    "lag set spsel <soure port enable(1:En,0:Dis)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T lagCmds[] =
+{
+    {"get",          doLagGet,        0,        NULL},
+    {"set",          doLagSet,        0,        NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T stpGetCmds[] =
+{
+    {"portstate",    doStpPortstate,  2,    "stp get portstate <port(0..6)> <fid(0..15)>"},
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T stpSetCmds[] =
+{
+    {"portstate",    doStpPortstate,  3,    "stp set portstate <port(0..6)> <fid(0..15)> <state(0:disable,1:listen,2:learn,3:forward)>"},
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T stpCmds[] =
+{
+    {"get",         doStpGet,           0,      NULL},
+    {"set",         doStpSet,           0,      NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T mirrorSetCmds[] =
+{
+    {"session",        doMirrorSetSession,       6,      "mirror set session <sid(0,1)> <dst_port(UINT)> <state(1:En,0:Dis)> <tag(1:on, 0:off)> <list(UINTLIST)> <dir(0:none,1:tx,2:rx,3:both)>"},
+    {"session-enable", doMirrorSetSessionEnable, 2,      "mirror set session-enable <sid(0,1)> <state(1:En,0:Dis)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T mirrorAddCmds[] =
+{
+    {"session-rlist",  doMirrorAddRlist,       2,      "mirror add session-rlist <sid(0,1)> <list(UINTLIST)>"},
+    {"session-tlist",  doMirrorAddTlist,       2,      "mirror add session-tlist <sid(0,1)> <list(UINTLIST)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T mirrorGetCmds[] =
+{
+    {"session",        doMirrorGetSid,       1,      "mirror get session <sid(0,1)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T mirrorDelCmds[] =
+{
+    {"session",        doMirrorDelSid,       1,      "mirror del session <sid(0,1)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T mirrorCmds[] =
+{
+    {"set",         doMirrorSet,        0,      NULL},
+    {"add",         doMirrorAdd,        0,      NULL},
+    {"get",         doMirrorGet,        0,      NULL},
+    {"del",         doMirrorDel,        0,      NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T mibClearCmds[] =
+{
+    {"port",        doMibClearPort,     1,      "mib clear port <port(0..6)>"},
+    {"all",         doMibClearPort,     0,      "mib clear all"},
+    {"acl",         doMibClearAcl,      0,      "mib clear acl"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T mibGetCmds[] =
+{
+    {"port",        doMibGetPort,       1,      "mib get port <port(0..6)>"},
+    {"acl",         doMibGetAcl,        1,      "mib get acl <event(0..7)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T mibCmds[] =
+{
+    {"clear",       doMibClear,         0,      NULL},
+    {"get",         doMibGet,           0,      NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T qosGetCmds[] =
+{
+    {"scheduleAlgo",    doQosScheduleAlgo,      2,  "qos get scheduleAlgo <portlist(UINTLIST)> <queue(UINT)>"},
+    {"trustMode",       doQosTrustMode,         1,  "qos get trustMode <portlist(UINTLIST)>"},
+    {"pri2Queue",       doQosPri2Queue,         0,  "qos get pri2Queue"},
+    {"dscp2Pri",        doQosDscp2Pri,          1,  "qos get dscp2Pri <dscp(0..63)>"},
+    {"rateLimitEnable", doQosRateLimitEnable,   1,  "qos get rateLimitEnable <portlist(UINTLIST)>"},
+    {"rateLimit",       doQosRateLimit,         1,  "qos get rateLimit <portlist(UINTLIST)>"},
+    {"portPriority",    doQosPortPriority,      1,  "qos get portPriority <portlist(UINTLIST)>"},
+    {"rateLmtExMngFrm", doQosRateLimitExMngFrm, 0,  "qos get rateLmtExMngFrm"},
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T qosSetCmds[] =
+{
+    {"scheduleAlgo",    doQosScheduleAlgo,      4,  "qos set scheduleAlgo <portlist(UINTLIST)> <queue(UINT)> <scheduler(0:SP,1:WRR,2:WFQ)> <weight(0..128)>, weight 0 is valid only on sp mode"},
+    {"trustMode",       doQosTrustMode,         2,  "qos set trustMode <portlist(UINTLIST)> <mode(0:port,1:1p-port,2:dscp-port,3:dscp-1p-port>"},
+    {"pri2Queue",       doQosPri2Queue,         2,  "qos set pri2Queue <priority(0..7)> <queue(0..7)>"},
+    {"dscp2Pri",        doQosDscp2Pri,          2,  "qos set dscp2Pri <dscp(0..63)> <priority(0..7)>"},
+    {"rateLimitEnable", doQosRateLimitEnable,   3,  "qos set rateLimitEnable <portlist(UINTLIST)> <dir(0:egress,1:ingress)> <rate_en(1:En,0:Dis)>"},
+    {"rateLimit",       doQosRateLimit,         5,  "qos set rateLimit <portlist(UINTLIST)> <I_CIR(0..80000)> <I_CBS(0..127)> <E_CIR(0..80000)> <E_CBS(0..127)>"},
+    {"portPriority",    doQosPortPriority,      2,  "qos set portPriority <portlist(UINTLIST)> <priority(0..7)>"},
+    {"rateLmtExMngFrm", doQosRateLimitExMngFrm, 2,  "qos set rateLmtExMngFrm <dir(0:egress)> <en(0:include,1:exclude)>"},
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T qosCmds[] =
+{
+    {"get",          doQosGet,        0,        NULL},
+    {"set",          doQosSet,        0,        NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T diagSetCmds[] =
+{
+    {"txComply",    doDiagTxComply,     2,      "diag set txComply <phy(0..5)> <mode(0..8)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T diagGetCmds[] =
+{
+    {"txComply",    doDiagTxComply,     1,      "diag get txComply <phy(0..5)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T diagCmds[] =
+{
+    {"set",         doDiagSet,          0,      NULL},
+    {"get",         doDiagGet,          0,      NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T ledSetCmds[] =
+{
+    {"mode",        doLedMode,          1,      "led set mode <mode(0:disable, 1..3:2 LED, 4:user-define)>"},
+    {"state",       doLedState,         2,      "led set state <led(0..1)> <state(1:En,0:Dis)>"},
+    {"usr",         doLedUsrDef,        4,      "led set usr <led(0..1)> <polarity(0:low, 1:high)> <on_evt(7'bin)> <blink_evt(10'bin)>"},
+    {"time",        doLedBlkTime,       1,      "led set time <time(0..5:32ms~1024ms)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T ledGetCmds[] =
+{
+    {"mode",        doLedMode,          CMD_NO_PARA,      "led get mode"},
+    {"state",       doLedState,         1,                "led get state <led(0..1)>"},
+    {"usr",         doLedUsrDef,        1,                "led get usr <led(0..1)>"},
+    {"time",        doLedBlkTime,       CMD_NO_PARA,      "led get time"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T ledCmds[] =
+{
+    {"set",         doLedSet,           0,      NULL},
+    {"get",         doLedGet,           0,      NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T showCmds[] =
+{
+    {"version",     doShowVersion,        0,        NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T secGetCmds[] =
+{
+    {"stormEnable",     doStormEnable,   2,  "sec get stormEnable <port(0..6)> <type(0:bcst,1:mcst,2:ucst)>"},
+    {"stormRate",       doStormRate,     2,  "sec get stormRate <port(0..6)> <type(0:bcst,1:mcst,2:ucst)>"},
+    {"fldMode",         doFldMode,       2,  "sec get fldMode <port(0..6)> <type(0:bcst,1:mcst,2:ucst,3:qury>"},
+    {"saLearning",      doSaLearning,    1,  "sec get saLearning <port(0..6)>"},
+    {"saLimit",         doSaLimit,       1,  "sec get saLimit <port(0..6)>"},
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T secSetCmds[] =
+{
+    {"stormEnable",     doStormEnable,   3,  "sec set stormEnable <port(0..6)> <type(0:bcst,1:mcst,2:ucst)> <en(1:En,0:Dis)>"},
+    {"stormRate",       doStormRate,     4,  "sec set stormRate <port(0..6)> <type(0:bcst,1:mcst,2:ucst)> <count(0..255)> <unit(0:64k,1:256k,2:1M,3:4M,4:16M)>"},
+    {"fldMode",         doFldMode,       3,  "sec set fldMode <port(0..6)> <type(0:bcst,1:mcst,2:ucst,3:qury> <en(1:En,0:Dis)>"},
+    {"saLearning",      doSaLearning,    2,  "sec set saLearning <port(0..6)> <learn(0:disable,1:enable)>"},
+    {"saLimit",         doSaLimit,       3,  "sec set saLimit <port(0..6)> <mode(0:disable,1:enable)> <count(0..4095)>"},
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T secCmds[] =
+{
+    {"get",          doSecGet,        0,        NULL},
+    {"set",          doSecSet,        0,        NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T switchSetCmds[] =
+{
+    {"cpuPortEn",   doSwitchCpuPortEn,   1,              "switch set cpuPortEn <cpu_en(1:En,0:Dis)>"},
+    {"cpuPort",     doSwitchCpuPort,     1,              "switch set cpuPort <port_number>"},
+    {"phyLCIntrEn",     doSwitchPhyLCIntrEn,     2,      "switch set phyLCIntrEn <phy(0..6)> <(1:En,0:Dis)>"},
+    {"phyLCIntrSts",    doSwitchPhyLCIntrSts,    2,      "switch set phyLCIntrSts <phy(0..6)> <(1:Clear)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T switchGetCmds[] =
+{
+    {"cpuPortEn",   doSwitchCpuPortEn,   CMD_NO_PARA,      "switch get cpuPortEn"},
+    {"cpuPort",     doSwitchCpuPort,     CMD_NO_PARA,      "switch get cpuPort"},
+    {"phyLCIntrEn",     doSwitchPhyLCIntrEn,     1,        "switch get phyLCIntrEn <phy(0..6)>"},
+    {"phyLCIntrSts",    doSwitchPhyLCIntrSts,    1,        "switch get phyLCIntrSts <phy(0..6)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T switchCmds[] =
+{
+    {"set",         doSwitchSet,        0,      NULL},
+    {"get",         doSwitchGet,        0,      NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T aclSetCmds[] =
+{
+    {"en",              doAclEn,            1,                     "acl set en <en(1:En,0:Dis)>"},
+    {"rule",            doAclRule,          CMD_VARIABLE_PARA,     "acl set rule <idx(0..127)>\n <state(0:Dis,1:En)> <reverse(0:Dis,1:En)> <end(0:Dis,1:En)>\n <portmap(7'bin)><ipv6(0:Dis,1:En,2:Not care)>\n[ dmac <dmac(12'hex)> <dmac_mask(12'hex)> ]\n[ smac <smac(12'hex)> <smac_mask(12'hex)> ]\n[ stag <stag(4'hex)> <stag_mask(4'hex)> ]\n[ ctag <ctag(4'hex)> <ctag_mask(4'hex)> ]\n[ etype <etype(4'hex)> <etype_mask(4'hex)> ]\n[ dip <dip(IPADDR)> <dip_mask(IPADDR)> ]\n[ sip <sip(IPADDR)> <sip_mask(IPADDR)> ]\n[ dscp <dscp(2'hex)> <dscp_mask(2'hex)> ]\n[ protocol <protocol(12'hex)> <protocol_mask(12'hex)> ]\n[ dport <dport(4'hex)> <dport_mask(4'hex)> ]\n[ sport <sport(4'hex)> <sport_mask(4'hex)> ]\n[ flow_label <flow_label(4'hex)> <flow_label_mask(4'hex)> ]\n[ udf <udf(4'hex)> <udf_mask(4'hex)> ] "},
+    {"udfRule",         doAclUdfRule,       7,                     "acl set udfRule <idx(0..15)> <mode(0:pattern, 1:threshold)> [ <pat(4'hex)> <mask(4'hex)> | <low(4'hex)> <high(4'hex)> ] <start(0:MAC header, 1:L2 payload, 2:IPv4 header, 3:IPv6 header, 4:L3 payload, 5:TCP header, 6:UDP header, 7: L4 payload)> <offset(0..127,unit:2 bytes)> <portmap(7'bin)>"},
+    {"action",          doAclAction,        CMD_VARIABLE_PARA,     "acl set action <idx(0..127)> \n[ forward <forward(0:Default,4:Exclude CPU,5:Include CPU,6:CPU only,7:Drop)> ]\n[ egtag <egtag(0:Default,1:Consistent,4:Untag,5:Swap,6:Tag,7:Stack)> ]\n[ mirrormap <mirrormap(2'bin)> ]\n[ priority <priority(0..7)> ]\n[ redirect <redirect(0:Dst,1:Vlan)> <portmap(7'bin)> ]\n[ leaky_vlan <leaky_vlan(1:En,0:Dis)> ]\n[ cnt_idx <cnt_idx(0..63)> ]\n[ rate_idx <rate_idx(0..31)> ] \n[ attack_idx <attack_idx(0..95)> ] \n[ vid <vid(0..4095)> ] \n[ manage <manage(1:En,0:Dis)> ] \n[ bpdu <bpdu(1:En,0:Dis)> ]\n[ class <class(0:Original,1:Defined)>[0..7] ]\n[ drop_pcd <drop_pcd(0:Original,1:Defined)> [red <red(0..7)>][yellow <yellow(0..7)>][green <green(0..7)>] ]\n[ color <color(0:Defined,1:Trtcm)> [ <defined_color(0:Dis,1:Green,2:Yellow,3:Red)> | <trtcm_idx(0..31)> ] ]"},
+    {"trtcm",           doAclTrtcm,         5,                     "acl set trtcm <idx(1..31)> <cir(4'hex)> <pir(4'hex)> <cbs(4'hex)> <pbs(4'hex)>"},
+    {"trtcmEn",         doAclTrtcmEn,       1,                     "acl set trtcmEn <en(1:En,0:Dis)>"},
+    {"portEn",          doAclPortEn,        2,                     "acl set portEn <port(0..6)> <en(1:En,0:Dis)>"},
+    {"dropEn",          doAclDropEn,        2,                     "acl set dropEn <port(0..6)> <en(1:En,0:Dis)>"},
+    {"dropThrsh",       doAclDropThrsh,     5,                     "acl set dropThrsh <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> <high(0..2047)> <low(0..2047)>"},
+    {"dropPbb",         doAclDropPbb,       4,                     "acl set dropPbb <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> <probability(0..1023)>"},
+    {"meter",           doAclMeter,         3,                     "acl set meter <idx(0..31)> <en(1:En,0:Dis)> <rate(0..65535)>\n Note: Limit rate = rate * 64Kbps"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T aclGetCmds[] =
+{
+    {"en",              doAclEn,            CMD_NO_PARA,    "acl get en"},
+    {"rule",            doAclRule,          1,              "acl get rule <idx(0..127)> "},
+    {"udfRule",         doAclUdfRule,       1,              "acl get udfRule <idx(0..15)>"},
+    {"action",          doAclAction,        1,              "acl get action <idx(0..127)>"},
+    {"trtcm",           doAclTrtcm,         1,              "acl get trtcm <idx(1..31)>"},
+    {"trtcmEn",         doAclTrtcmEn,       CMD_NO_PARA,    "acl get trtcmEn"},
+    {"portEn",          doAclPortEn,        1,              "acl get portEn <port(0..6)>"},
+    {"dropEn",          doAclDropEn,        1,              "acl get dropEn <port(0..6)>"},
+    {"dropThrsh",       doAclDropThrsh,     3,              "acl get dropThrsh <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)>"},
+    {"dropPbb",         doAclDropPbb,       3,              "acl get dropPbb <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)>"},
+    {"meter",           doAclMeter,         1,              "acl get meter <idx(0..31)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T aclDelCmds[] =
+{
+    {"rule",        doAclRmvRule,          1,         "acl del rule <idx(0..127)>"},
+    {"udfRule",     doAclRmvUdfRule,       1,         "acl del udfRule <idx(0..15)>"},
+    {"action",      doAclRmvAction,        1,         "acl del action <idx(0..127)>"},
+    {"trtcm",       doAclRmvTrtcm,         1,         "acl del trtcm <idx(0..31)>"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T aclClearCmds[] =
+{
+    {"rule",        doAclRmvRule,          CMD_NO_PARA,       "acl clear rule"},
+    {"udfRule",     doAclRmvUdfRule,       CMD_NO_PARA,       "acl clear udfRule"},
+    {"action",      doAclRmvAction,        CMD_NO_PARA,       "acl clear action"},
+    {"trtcm",       doAclRmvTrtcm,         CMD_NO_PARA,       "acl clear trtcm"},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T aclCmds[] =
+{
+    {"set",         doAclSet,           0,      NULL},
+    {"get",         doAclGet,           0,      NULL},
+    {"del",         doAclDel,           0,      NULL},
+    {"clear",       doAclClear,         0,      NULL},
+    {"dump",        doAclDump,          0,      NULL},
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+static AIR_CMD_T Cmds[] =
+{
+    {"reg",         doReg,          0,      NULL},
+    {"phy",         doPhy,          0,      NULL},
+    {"port",        doPort,         0,      NULL},
+    {"vlan",        doVlan,         0,      NULL},
+    {"l2",          doL2,           0,      NULL},
+    {"lag",         doLag,          0,      NULL},
+    {"stp",         doStp,          0,      NULL},
+    {"mirror",      doMirror,       0,      NULL},
+    {"mib",         doMib,          0,      NULL},
+    {"qos",         doQos,          0,      NULL},
+    {"diag",        doDiag,         0,      NULL},
+    {"led",         doLed,          0,      NULL},
+    {"switch",      doSwitch,       0,      NULL},
+    {"show",        doShow,         0,      NULL},
+    {"sec",         doSec,          0,      NULL},
+    {"acl",         doAcl,          0,      NULL},
+    {"sptag",       doSptag,        0,      NULL},
+
+    /* last entry, do not modify this entry */
+    {NULL, NULL, 0, NULL},
+};
+
+/* EXPORTED SUBPROGRAM BODIES
+*/
+
+/* LOCAL SUBPROGRAM BODIES
+*/
+static BOOL_T
+_strcmp(const char *s1, const char *s2)
+{
+    while(*s1 == *s2++)
+        if (*s1++ == '\0')
+            return (0);
+    return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 -1));
+}
+
+static C8_T *
+_strtok_r(
+    C8_T *s,
+    const C8_T *delim,
+    C8_T **last)
+{
+    char *spanp;
+    int c = 0, sc = 0;
+    char *tok;
+
+    if (s == NULL && (s = *last) == NULL)
+    {
+        return (NULL);
+    }
+
+    /*
+     * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
+     */
+    for (;;)
+    {
+        c = *s++;
+        spanp = (char *)delim;
+        do
+        {
+            if (c == (sc = *spanp++))
+            {
+                break;
+            }
+        } while (sc != 0);
+        if (sc == 0)
+        {
+            break;
+        }
+    }
+
+    if (c == 0)
+    {   /* no non-delimiter characters */
+        *last = NULL;
+        return (NULL);
+    }
+    tok = s - 1;
+
+    /*
+     * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
+     * Note that delim must have one NUL; we stop if we see that, too.
+     */
+    for (;;)
+    {
+        c = *s++;
+        spanp = (char *)delim;
+        do
+        {
+            if ((sc = *spanp++) == c)
+            {
+                if (c == 0)
+                {
+                    s = NULL;
+                }
+                else
+                {
+                    s[-1] = 0;
+                }
+                *last = s;
+                return (tok);
+            }
+        } while (sc != 0);
+    }
+    /* NOTREACHED */
+}
+
+static C8_T *
+_strtok(
+    C8_T *s,
+    const C8_T *delim,
+    C8_T **last)
+{
+    return _strtok_r(s, delim, last);
+}
+
+UI32_T
+_strtoul(
+    const C8_T *cp,
+    C8_T **endp,
+    UI32_T base)
+{
+    UI32_T result = 0, value = 0;
+
+    if (!base)
+    {
+        base = 10;
+        if (*cp == '0')
+        {
+            base = 8;
+            cp++;
+            if ((TOLOWER(*cp) == 'x') && isxdigit(cp[1]))
+            {
+                cp++;
+                base = 16;
+            }
+        }
+    }
+    else if (base == 16)
+    {
+        if (cp[0] == '0' && TOLOWER(cp[1]) == 'x')
+        {
+            cp += 2;
+        }
+    }
+    while (isxdigit(*cp) &&
+           (value = isdigit(*cp) ? *cp-'0' : TOLOWER(*cp)-'a'+10) < base)
+    {
+        result = result*base + value;
+        cp++;
+    }
+    if (endp)
+    {
+        *endp = (char *)cp;
+    }
+    return result;
+}
+
+static I32_T
+_strtol(
+    const C8_T *cp,
+    C8_T **endp,
+    UI32_T base)
+{
+    if(*cp=='-')
+    {
+        return -_strtoul(cp + 1, endp, base);
+    }
+    return _strtoul(cp, endp, base);
+}
+
+static AIR_ERROR_NO_T
+_str2mac(
+        C8_T *str,
+        C8_T *mac)
+{
+    UI32_T i = 0;
+    C8_T tmpstr[3];
+
+    /* check str */
+    AIR_CHECK_PTR(str);
+    AIR_PARAM_CHK(strlen(str) != AIR_MAC_LEN, AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(mac);
+
+    for(i=0; i<6; i++)
+    {
+        strncpy(tmpstr, str+(i*2), 2);
+        tmpstr[2] = '\0';
+        mac[i] = _strtoul(tmpstr, NULL, 16);
+    }
+
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+_str2ipv4(
+    const C8_T *ptr_str,
+    UI32_T     *ptr_addr)
+{
+    UI32_T value = 0, idx = 0, shift = 0;
+
+    AIR_CHECK_PTR(ptr_str);
+    AIR_CHECK_PTR(ptr_addr);
+
+    /* e.g. 192.168.1.2, strlen = 11 */
+    for (idx = 0; idx < strlen(ptr_str); idx++)
+    {
+        if (('0' <= ptr_str[idx]) && ('9' >= ptr_str[idx]))
+        {
+            value = (value * 10) + (ptr_str[idx] - '0');
+        }
+        else if ('.' == ptr_str[idx])
+        {
+            CMD_CHECK_PARA(value, <, 256); /* Error: invalid value */
+            CMD_CHECK_PARA(shift, <, 4);   /* Error: mem-overwrite */
+            *ptr_addr |= value << (24 - shift * 8);
+            shift += 1;
+            value = 0;
+        }
+        else
+        {
+            return AIR_E_BAD_PARAMETER; /* Error: not a digit number or dot */
+        }
+    }
+    CMD_CHECK_PARA(value, <, 256); /* Error: invalid value */
+    CMD_CHECK_PARA(shift, ==, 3);  /* Error: not an ipv4 addr */
+    *ptr_addr |= value << (24 - shift * 8);
+
+    return AIR_E_OK;
+}
+
+AIR_ERROR_NO_T
+_str2ipv6(
+    const C8_T  *ptr_str,
+    UI8_T       *ptr_addr)
+{
+    UI32_T              hex_value = 0, dec_value = 0, idx = 0;
+    BOOL_T              double_colon = FALSE, ipv4_compatible = FALSE;
+    UI32_T              double_colon_pos = 0, last_pos = 0;
+    UI8_T               tmp_ipv6[16] = {0};
+
+    AIR_CHECK_PTR(ptr_str);
+    AIR_CHECK_PTR(ptr_addr);
+
+    /* e.g. invalid:
+     * 3ffe::c0a8:0:      last cannot be colon except double-colon
+     * 3ffe:::c0a8:0      triple-colon
+     * 3ffe::c0a8::0      two double-colons
+     */
+
+    /* e.g. valid:
+     * 3ffe::c0a8:0       strlen = 12 (double-colon in middle)
+     * 3ffe:c0a8:0::      strlen = 13 (double-colon in last)
+     * ::3ffe:c0a8:0      strlen = 13 (double-colon in first)
+     * 3ffe::192.168.0.0  strlen = 17 (IPv4-compatible address)
+     */
+    for (idx = 0; idx < strlen(ptr_str); idx++)
+    {
+        if (('0' <= ptr_str[idx]) && ('9' >= ptr_str[idx]))
+        {
+            hex_value = (hex_value << 4) + (ptr_str[idx] - '0');
+            dec_value = (dec_value * 10) + (ptr_str[idx] - '0');
+        }
+        else if (('a' <= ptr_str[idx]) && ('f' >= ptr_str[idx]))
+        {
+            hex_value = (hex_value << 4) + (ptr_str[idx] - 'a') + 10;
+        }
+        else if (('A' <= ptr_str[idx]) && ('F' >= ptr_str[idx]))
+        {
+            hex_value = (hex_value << 4) + (ptr_str[idx] - 'A') + 10;
+        }
+        else if (':' == ptr_str[idx])
+        {
+            /* must belong to double-colon, calculate from last */
+            if (0 == idx)
+            {
+                continue;
+            }
+            /* not the first ch but a double-colon */
+            else if (':' == ptr_str[idx - 1])
+            {
+                CMD_CHECK_PARA(double_colon, ==, FALSE); /* Error: triple-colon or two double-colons */
+                double_colon = TRUE;
+            }
+            /* not the first ch and a double-colon */
+            else
+            {
+                CMD_CHECK_PARA(double_colon_pos, <, 15); /* Error: only 16 units for UI8_T  */
+                CMD_CHECK_PARA(last_pos,         <, 15); /* Error: only 16 units for UI8_T  */
+                tmp_ipv6[last_pos]     = (UI8_T)((hex_value >> 8) & 0xff);
+                tmp_ipv6[last_pos + 1] = (UI8_T)((hex_value >> 0) & 0xff);
+                double_colon_pos += (FALSE == double_colon)? 2 : 0;
+                last_pos += 2;
+                hex_value = 0;
+                dec_value = 0;
+            }
+        }
+        else if ('.' == ptr_str[idx])
+        {
+            CMD_CHECK_PARA(last_pos, <, 16); /* Error: only 16 units for UI8_T  */
+            tmp_ipv6[last_pos] = dec_value;
+            last_pos += 1;
+            dec_value = 0;
+            ipv4_compatible = TRUE;
+        }
+        else
+        {
+            return AIR_E_BAD_PARAMETER; /* Error: not a hex number or colon */
+        }
+    }
+
+    /* last data */
+    if ((idx != 0) && (':' != ptr_str[idx - 1]))
+    {
+        if (FALSE == ipv4_compatible)
+        {
+            CMD_CHECK_PARA(last_pos, <, 15); /* Error: only 16 units for UI8_T  */
+            tmp_ipv6[last_pos]     = (UI8_T)((hex_value >> 8) & 0xff);
+            tmp_ipv6[last_pos + 1] = (UI8_T)((hex_value >> 0) & 0xff);
+            last_pos += 2;
+        }
+        else
+        {
+            CMD_CHECK_PARA(last_pos, <, 16); /* Error: only 16 units for UI8_T  */
+            tmp_ipv6[last_pos] = dec_value;
+            last_pos += 1;
+        }
+    }
+    else
+    {
+        if ((idx >= 2) && (':' != ptr_str[idx - 2]))
+        {
+            return AIR_E_BAD_PARAMETER; /* Error: last cannot be colon except double-colon */
+        }
+    }
+
+    /* move tmp_ipv6 to ptr_value */
+    if (TRUE == double_colon)
+    {
+        /* e.g.
+         * 3ffe::c0a8:0       double_colon_pos = 2, last_pos = 4+2, tmp_ipv6 = {3f,fe,c0,a8,00,00,...}
+         * 3ffe:c0a8:0::      double_colon_pos = 6, last_pos = 6,   tmp_ipv6 = {3f,fe,c0,a8,00,00,...}
+         * ::3ffe:c0a8:0      double_colon_pos = 0, last_pos = 4+2, tmp_ipv6 = {3f,fe,c0,a8,00,00,...}
+         * 3ffe::192.168.0.0  double_colon_pos = 2, last_pos = 5+1, tmp_ipv6 = {3f,fe,c0,a8,00,00,...}
+         *
+         *                                 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
+         * 3ffe::c0a8:0       ptr_value = {3f,fe,--,--,--,--,--,--,--,--,--,--,--,--,--,--}
+         * 3ffe:c0a8:0::      ptr_value = {3f,fe,c0,a8,00,00,--,--,--,--,--,--,--,--,--,--}
+         * ::3ffe:c0a8:0      ptr_value = {--,--,--,--,--,--,--,--,--,--,--,--,--,--,--,--}
+         * 3ffe::192.168.0.0  ptr_value = {3f,fe,--,--,--,--,--,--,--,--,--,--,--,--,--,--}
+         */
+        for (idx = 0; idx < double_colon_pos; idx++)
+        {
+            ptr_addr[idx] = tmp_ipv6[idx];
+        }
+        /* e.g.
+         *                                 0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
+         * 3ffe::c0a8:0       ptr_value = {3f,fe,--,--,--,--,--,--,--,--,--,--,c0,a8,00,00}
+         * 3ffe:c0a8:0::      ptr_value = {3f,fe,c0,a8,00,00,--,--,--,--,--,--,--,--,--,--}
+         * ::3ffe:c0a8:0      ptr_value = {--,--,--,--,--,--,--,--,--,--,3f,fe,c0,a8,00,00}
+         * 3ffe::192.168.0.0  ptr_value = {3f,fe,--,--,--,--,--,--,--,--,--,--,c0,a8,00,00}
+         */
+        for (idx = double_colon_pos; idx < last_pos; idx++)
+        {
+            ptr_addr[16 - (last_pos - idx)] = tmp_ipv6[idx];
+        }
+    }
+    else
+    {
+        for (idx = 0; idx < 16; idx++)
+        {
+            ptr_addr[idx] = tmp_ipv6[idx];
+        }
+    }
+
+    return AIR_E_OK;
+}
+
+void
+_showIpv6Str(
+    const UI8_T *ptr_ipv6,
+    C8_T *ptr_str)
+{
+    UI32_T idx = 0, next = 0, last = 16;
+    UI32_T cont_zero = 0;
+
+    while (idx < last)
+    {
+        if ((0 == cont_zero) && (0 == ptr_ipv6[idx]) && (0 == ptr_ipv6[idx + 1]))
+        {
+            next = idx + 2;
+
+            while (next < last)
+            {
+                if ((ptr_ipv6[next]) || (ptr_ipv6[next + 1]))
+                {
+                    AIR_PRINT(
+                            ptr_str + strlen(ptr_str),
+                            40 - strlen(ptr_str),
+                            "%s", (cont_zero) ? (":") : (":0"));
+                    break;
+                }
+
+                if (0 == cont_zero)
+                {
+                    cont_zero = 1;
+                }
+                next += 2;
+            }
+
+            if (next == last)
+            {
+
+                AIR_PRINT(
+                        ptr_str + strlen(ptr_str),
+                        40 - strlen(ptr_str),
+                        "%s", (cont_zero) ? ("::") : (":0"));
+            }
+
+            idx = next;
+        }
+        else
+        {
+            if (idx)
+            {
+                AIR_PRINT(
+                    ptr_str + strlen(ptr_str),
+                    40 - strlen(ptr_str),
+                    ":");
+            }
+
+            if (ptr_ipv6[idx])
+            {
+                AIR_PRINT(
+                    ptr_str + strlen(ptr_str),
+                    40 - strlen(ptr_str),
+                    "%0x%02x", ptr_ipv6[idx], ptr_ipv6[idx + 1]);
+            }
+            else
+            {
+                AIR_PRINT(
+                    ptr_str + strlen(ptr_str),
+                    40 - strlen(ptr_str),
+                    "%0x", ptr_ipv6[idx + 1]);
+            }
+
+            idx += 2;
+        }
+    }
+}
+
+static AIR_ERROR_NO_T
+_hex2bit(
+        const UI32_T hex,
+        UI32_T *ptr_bit)
+{
+    UI32_T i = 0;
+
+    /* Mistake proofing */
+    AIR_CHECK_PTR(ptr_bit);
+
+    (*ptr_bit) = 0;
+    for(i=0; i<AIR_MAX_NUM_OF_PORTS; i++)
+    {
+        if(hex & BIT(i))
+        {
+            (*ptr_bit) |= BITS_OFF_L(1UL, 4*(AIR_MAX_NUM_OF_PORTS - i - 1), 4);
+        }
+    }
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+_hex2bitstr(
+        const UI32_T hex,
+        C8_T *ptr_bit_str,
+        UI32_T str_len)
+{
+    UI32_T i = 0;
+    C8_T str_bitmap[AIR_MAX_NUM_OF_PORTS+1];
+
+    /* Mistake proofing */
+    AIR_CHECK_PTR(ptr_bit_str);
+    AIR_PARAM_CHK(str_len <= AIR_MAX_NUM_OF_PORTS, AIR_E_BAD_PARAMETER);
+
+    memset(str_bitmap, 0, AIR_MAX_NUM_OF_PORTS+1);
+
+    for(i=0; i<AIR_MAX_NUM_OF_PORTS; i++)
+    {
+        if(hex & BIT(i))
+        {
+            str_bitmap[i] = '1';
+        }
+        else
+        {
+            str_bitmap[i] = '-';
+        }
+    }
+    str_bitmap[i] = '\0';
+    strncpy(ptr_bit_str, str_bitmap, i+1);
+
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+_portListStr2Ary(
+    const C8_T *str,
+    UI32_T *ary,
+    const UI32_T ary_num)
+{
+    UI32_T i = 0;
+    UI32_T str_len = 0;
+    UI32_T val = 0;
+    C8_T *str2;
+    C8_T *pch;
+    C8_T *last;
+
+    /* Mistake proofing */
+    AIR_CHECK_PTR(str);
+    AIR_CHECK_PTR(ary);
+    AIR_PARAM_CHK(0 == ary_num, AIR_E_BAD_PARAMETER);
+
+    /* Allocate new string */
+    str_len = strlen(str);
+    str2 = AIR_MALLOC(str_len+1);
+    AIR_CHECK_PTR(str2);
+    memset(str2, 0, str_len+1);
+    strncpy(str2, str, str_len+1);
+
+    /* clear array */
+    memset(ary, 0, ary_num*4);
+
+    /* split string by ',' */
+    pch = _strtok(str2, ",", &last);
+    while(NULL != pch)
+    {
+        val = _strtoul(pch, NULL, 0);
+        ary[val/32] |= BIT(val%32);
+        pch = _strtok(NULL, ",", &last);
+    }
+
+    AIR_FREE(str2);
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+doRegRead(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    UI32_T reg = 0, val = 0;
+
+    reg = _strtoul(argv[0], NULL, 16);
+    aml_readReg(0, reg, &val);
+    AIR_PRINT("Read reg=0x%x, value=0x%x\n", reg, val);
+
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+doRegWrite(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    UI32_T reg = 0, val = 0;
+
+    reg = _strtoul(argv[0], NULL, 16);
+    val = _strtoul(argv[1], NULL, 16);
+    aml_writeReg(0, reg, val);
+    AIR_PRINT("Write reg=0x%x, value=0x%x\n", reg, val);
+
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+doReg(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(regCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doPhyCL22Read(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    UI32_T port = 0, reg = 0, val = 0;
+
+    port = _strtoul(argv[0], NULL, 0);
+    reg  = _strtoul(argv[1], NULL, 16);
+    aml_readPhyReg(0, port, reg, &val);
+    AIR_PRINT("Phy read port=%d, reg=0x%x, value=0x%x\n", port, reg, val);
+
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+doPhyCL22Write(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    UI32_T port = 0, reg = 0, val = 0;
+
+    port = _strtoul(argv[0], NULL, 0);
+    reg  = _strtoul(argv[1], NULL, 16);
+    val  = _strtoul(argv[2], NULL, 16);
+    aml_writePhyReg(0, port, reg, val);
+    AIR_PRINT("Phy write port=%d, reg=0x%x, value=0x%x\n", port, reg, val);
+
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+doPhyCL22(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(phyCL22Cmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doPhyCL45Read(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    UI32_T port = 0, dev = 0, reg = 0, val = 0;
+
+    port = _strtoul(argv[0], NULL, 0);
+    dev  = _strtoul(argv[1], NULL, 16);
+    reg  = _strtoul(argv[2], NULL, 16);
+    aml_readPhyRegCL45(0, port, dev, reg, &val);
+    AIR_PRINT("Phy read port=%d, dev=0x%x, reg=0x%x, value=0x%x\n", port, dev, reg, val);
+
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+doPhyCL45Write(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    UI32_T port = 0, dev = 0, reg = 0, val = 0;
+
+    port = _strtoul(argv[0], NULL, 0);
+    dev  = _strtoul(argv[1], NULL, 16);
+    reg  = _strtoul(argv[2], NULL, 16);
+    val  = _strtoul(argv[3], NULL, 16);
+    aml_writePhyRegCL45(0, port, dev, reg, val);
+    AIR_PRINT("Phy write port=%d, dev=0x%x, reg=0x%x, value=0x%x\n", port, dev, reg, val);
+
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+doPhyCL45(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(phyCL45Cmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doPhy(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(phyCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doPortSetMatrix(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    UI32_T matrix = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port   = _strtoul(argv[0], NULL, 0);
+    matrix = _strtoul(argv[1], NULL, 16);
+    rc = air_port_setPortMatrix(0, port, matrix);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doPortSetVlanMode(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    AIR_PORT_VLAN_MODE_T vlan_mode;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port      = _strtoul(argv[0], NULL, 0);
+    vlan_mode = _strtoul(argv[1], NULL, 0);
+    rc = air_port_setVlanMode(0, port, vlan_mode);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doPortSet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(portSetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doPortGetMatrix(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    UI32_T matrix = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    rc = air_port_getPortMatrix(0, port, &matrix);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+        return rc;
+    }
+    AIR_PRINT("Port %d Matrix: %2x\n", port, matrix);
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doPortGetVlanMode(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    AIR_PORT_VLAN_MODE_T vlan_mode;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    rc = air_port_getVlanMode(0, port, &vlan_mode);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+        return rc;
+    }
+    AIR_PRINT("Port %d Vlan Mode: ", port);
+    switch(vlan_mode)
+    {
+        case AIR_PORT_VLAN_MODE_PORT_MATRIX:
+            AIR_PRINT("matrix(%d)\n", vlan_mode);
+            break;
+        case AIR_PORT_VLAN_MODE_FALLBACK:
+            AIR_PRINT("fallback(%d)\n", vlan_mode);
+            break;
+        case AIR_PORT_VLAN_MODE_CHECK:
+            AIR_PRINT("check(%d)\n", vlan_mode);
+            break;
+        case AIR_PORT_VLAN_MODE_SECURITY:
+            AIR_PRINT("security(%d)\n", vlan_mode);
+            break;
+        default:
+            AIR_PRINT("unknown(%d)\n", vlan_mode);
+            break;
+    };
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doPortGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(portGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doPort(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(portCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doVlanInitiate(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0;
+    AIR_VLAN_ENTRY_ATTR_T vlan_entry = {0};
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid = _strtoul(argv[0], NULL, 0);
+    if (9 == argc)
+    {
+        vlan_entry.vlan_entry_format.fid           = _strtoul(argv[1], NULL, 0);
+        vlan_entry.vlan_entry_format.port_mem      = _strtoul(argv[2], NULL, 0);
+        vlan_entry.vlan_entry_format.ivl           = _strtoul(argv[3], NULL, 0);
+        vlan_entry.vlan_entry_format.port_stag     = _strtoul(argv[4], NULL, 0);
+        vlan_entry.vlan_entry_format.stag          = _strtoul(argv[5], NULL, 0);
+        vlan_entry.vlan_entry_format.eg_ctrl_en    = _strtoul(argv[6], NULL, 0);
+        vlan_entry.vlan_entry_format.eg_con        = _strtoul(argv[7], NULL, 0);
+        vlan_entry.vlan_entry_format.eg_ctrl       = _strtoul(argv[8], NULL, 0);
+
+        rc = air_vlan_create(0, vid, &vlan_entry);
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        rc = AIR_E_BAD_PARAMETER;
+    }
+
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                            break;
+        case     AIR_E_ENTRY_EXISTS:  AIR_PRINT("VLAN already exist!\n");             break;
+        default:                      AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanCreate(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid = _strtoul(argv[0], NULL, 0);
+    rc  = air_vlan_create(0, vid, NULL);
+
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                            break;
+        case     AIR_E_ENTRY_EXISTS:  AIR_PRINT("VLAN already exist!\n");             break;
+        default:                      AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanDestroy(UI32_T argc, C8_T *argv[])
+{
+    C8_T *token = NULL;
+    UI16_T vid = 0, vid_limit = AIR_VLAN_ID_MAX;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    if (argc > 0)
+    {
+        if (isdigit(argv[0][0]))
+        {
+            token = _strtok(argv[0], "-", &argv[0]);
+            vid = _strtoul(token, NULL, 0);
+            if ((token = _strtok(argv[0], "-", &argv[0])))
+                vid_limit = _strtoul(token, NULL, 0);
+            else
+                vid_limit = vid;
+            if (AIR_VLAN_ID_MAX < vid_limit)
+            {
+                AIR_PRINT("vid number should less than %d!\n", AIR_VLAN_ID_MAX);
+                return AIR_E_BAD_PARAMETER;
+            }
+            if (vid > vid_limit)
+            {
+                AIR_PRINT("vid0 should less than vid1!\n");
+                return AIR_E_BAD_PARAMETER;
+            }
+        }
+        else
+        {
+            AIR_PRINT("Bad parameter!\n");
+            return AIR_E_BAD_PARAMETER;
+        }
+    }
+
+    for (; vid <= vid_limit; vid++)
+    {
+        rc = air_vlan_destroy(0, vid);
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanDestroyAll(UI32_T argc, C8_T *argv[])
+{
+    UI32_T restore_def_vlan = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    if (argc > 0)
+    {
+        restore_def_vlan = _strtoul(argv[0], NULL, 0);
+    }
+
+    rc = air_vlan_destroyAll(0, restore_def_vlan);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanDump(UI32_T argc, C8_T *argv[])
+{
+    C8_T *token = NULL;
+    UI16_T port = 0, valid_count = 0, vid = 0, vid_limit = AIR_VLAN_ID_MAX;
+    AIR_PORT_EGS_TAG_ATTR_T tag_ctl[AIR_MAX_NUM_OF_PORTS] = {0};
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    if (argc > 0)
+    {
+        if (isdigit(argv[0][0]))
+        {
+            token = _strtok(argv[0], "-", &argv[0]);
+            vid = _strtoul(token, NULL, 0);
+            if ((token = _strtok(argv[0], "-", &argv[0])))
+                vid_limit = _strtoul(token, NULL, 0);
+            else
+                vid_limit = vid;
+            if (AIR_VLAN_ID_MAX < vid_limit)
+            {
+                AIR_PRINT("vid number should less than %d!\n", AIR_VLAN_ID_MAX);
+                return AIR_E_BAD_PARAMETER;
+            }
+            if (vid > vid_limit)
+            {
+                AIR_PRINT("vid0 should less than vid1!\n");
+                return AIR_E_BAD_PARAMETER;
+            }
+        }
+        else
+        {
+            AIR_PRINT("Bad parameter!\n");
+            return AIR_E_BAD_PARAMETER;
+        }
+    }
+
+    for (valid_count = 0; vid <= vid_limit; vid++)
+    {
+        _air_vlan_readEntry(0, vid, &vlan_entry);
+        if (vlan_entry.valid)
+        {
+            valid_count++;
+            if (1 == valid_count)
+                AIR_PRINT(" Vid Fid MemPort Ivl PortBaseStag Stag EgsTagCtlEn EgsTagCon EgsTagCtl\n======================================================================\n");
+            for (port = 0; port < AIR_MAX_NUM_OF_PORTS; port++)
+                tag_ctl[port] = (vlan_entry.vlan_entry_format.eg_ctrl >> (port * 2)) & 0x3;
+            AIR_PRINT("%4d %3d      %2x %3d %12d %4d %11d %9d   %1x%1x%1x%1x%1x%1x%1x\n",
+                vid, vlan_entry.vlan_entry_format.fid, vlan_entry.vlan_entry_format.port_mem, vlan_entry.vlan_entry_format.ivl,
+                vlan_entry.vlan_entry_format.port_stag, vlan_entry.vlan_entry_format.stag, vlan_entry.vlan_entry_format.eg_ctrl_en, vlan_entry.vlan_entry_format.eg_con,
+                tag_ctl[6], tag_ctl[5], tag_ctl[4], tag_ctl[3], tag_ctl[2], tag_ctl[1], tag_ctl[0]);
+        }
+    }
+
+    if (!valid_count)
+        AIR_PRINT("not found!\n");
+    else
+        AIR_PRINT("Found %d valid entries!\n", valid_count);
+
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+doVlanAddPortMem(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0, port = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid  = _strtoul(argv[0], NULL, 0);
+    port = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_addMemberPort(0, vid, port);
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                               break;
+        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;
+        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanDelPortMem(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0, port = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid  = _strtoul(argv[0], NULL, 0);
+    port = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_delMemberPort(0, vid, port);
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                               break;
+        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;
+        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetFid(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0;
+    UI8_T  fid = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid = _strtoul(argv[0], NULL, 0);
+    fid = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_setFid(0, vid, fid);
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                               break;
+        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;
+        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetMemPort(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0, port_bitmap = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid         = _strtoul(argv[0], NULL, 0);
+    port_bitmap = _strtoul(argv[1], NULL, 16);
+    rc = air_vlan_setMemberPort(0, vid, port_bitmap);
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                               break;
+        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;
+        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetIVL(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0;
+    BOOL_T enable = TRUE;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid    = _strtoul(argv[0], NULL, 0);
+    enable = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_setIVL(0, vid, enable);
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                               break;
+        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;
+        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetPortBaseStag(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0;
+    BOOL_T enable = TRUE;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid    = _strtoul(argv[0], NULL, 0);
+    enable = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_setPortBasedStag(0, vid, enable);
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                               break;
+        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;
+        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetStag(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0, stag = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid  = _strtoul(argv[0], NULL, 0);
+    stag = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_setServiceTag(0, vid, stag);
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                               break;
+        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;
+        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetEgsTagCtlEn(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0;
+    BOOL_T enable = TRUE;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid    = _strtoul(argv[0], NULL, 0);
+    enable = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_setEgsTagCtlEnable(0, vid, enable);
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                               break;
+        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;
+        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetEgsTagCtlCon(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0;
+    BOOL_T enable = TRUE;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid    = _strtoul(argv[0], NULL, 0);
+    enable = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_setEgsTagConsistent(0, vid, enable);
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                               break;
+        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;
+        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetEgsTagCtl(UI32_T argc, C8_T *argv[])
+{
+    UI16_T vid = 0, port = 0;
+    AIR_PORT_EGS_TAG_ATTR_T tag_ctl = AIR_PORT_EGS_TAG_ATTR_UNTAGGED;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    vid     = _strtoul(argv[0], NULL, 0);
+    port    = _strtoul(argv[1], NULL, 0);
+    tag_ctl = _strtoul(argv[2], NULL, 0);
+    rc = air_vlan_setPortEgsTagCtl(0, vid, port, tag_ctl);
+    switch (rc)
+    {
+        case     AIR_E_OK:                                                               break;
+        case     AIR_E_ENTRY_NOT_FOUND:  AIR_PRINT("VLAN not found!\n");                 break;
+        default:                         AIR_PRINT("Error %d: Operation failed!\n", rc); break;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetPortActFrame(UI32_T argc, C8_T *argv[])
+{
+    UI16_T port = 0;
+    AIR_VLAN_ACCEPT_FRAME_TYPE_T type = AIR_VLAN_ACCEPT_FRAME_TYPE_ALL;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    type = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_setPortAcceptFrameType(0, port, type);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetLeakyVlanEn(UI32_T argc, C8_T *argv[])
+{
+    UI16_T port = 0;
+    AIR_LEAKY_PKT_TYPE_T pkt_type = AIR_LEAKY_PKT_TYPE_UNICAST;
+    BOOL_T enable = TRUE;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port     = _strtoul(argv[0], NULL, 0);
+    pkt_type = _strtoul(argv[1], NULL, 0);
+    enable   = _strtoul(argv[2], NULL, 0);
+    rc = air_vlan_setPortLeakyVlanEnable(0, port, pkt_type, enable);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetPortVlanAttr(UI32_T argc, C8_T *argv[])
+{
+    UI16_T port = 0;
+    AIR_VLAN_PORT_ATTR_T attr = AIR_VLAN_PORT_ATTR_USER_PORT;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    attr = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_setPortAttr(0, port, attr);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetIgsPortETagAttr(UI32_T argc, C8_T *argv[])
+{
+    UI16_T port = 0;
+    AIR_IGR_PORT_EG_TAG_ATTR_T attr = AIR_IGR_PORT_EG_TAG_ATTR_DISABLE;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    attr = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_setIgrPortTagAttr(0, port, attr);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetPortETagAttr(UI32_T argc, C8_T *argv[])
+{
+    UI16_T port = 0;
+    AIR_PORT_EGS_TAG_ATTR_T attr = AIR_PORT_EGS_TAG_ATTR_UNTAGGED;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    attr = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_setPortEgsTagAttr(0, port, attr);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetPortOuterTPID(UI32_T argc, C8_T *argv[])
+{
+    UI16_T port = 0, tpid = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    tpid = _strtoul(argv[1], NULL, 16);
+    rc = air_vlan_setPortOuterTPID(0, port, tpid);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSetPvid(UI32_T argc, C8_T *argv[])
+{
+    UI16_T port = 0, pvid = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    pvid = _strtoul(argv[1], NULL, 0);
+    rc = air_vlan_setPortPVID(0, port, pvid);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanSet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(vlanSetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doVlanGetPortActFrame(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    AIR_VLAN_ACCEPT_FRAME_TYPE_T type;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    rc = air_vlan_getPortAcceptFrameType(0, port, &type);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+        return rc;
+    }
+    AIR_PRINT("Port %d Acceptable Frame Type: ", port);
+    switch(type)
+    {
+        case AIR_VLAN_ACCEPT_FRAME_TYPE_ALL:
+            AIR_PRINT("all(%d)\n", type);
+            break;
+        case AIR_VLAN_ACCEPT_FRAME_TYPE_TAG_ONLY:
+            AIR_PRINT("tagged-only(%d)\n", type);
+            break;
+        case AIR_VLAN_ACCEPT_FRAME_TYPE_UNTAG_ONLY:
+            AIR_PRINT("untagged-only(%d)\n", type);
+            break;
+        default:
+            AIR_PRINT("unknown(%d)\n", type);
+            break;
+    };
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanGetLeakyVlanEn(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    BOOL_T uc = FALSE, mc = FALSE, bc = FALSE;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    rc += air_vlan_getPortLeakyVlanEnable(0, port, AIR_LEAKY_PKT_TYPE_UNICAST, &uc);
+    rc += air_vlan_getPortLeakyVlanEnable(0, port, AIR_LEAKY_PKT_TYPE_MULTICAST, &mc);
+    rc += air_vlan_getPortLeakyVlanEnable(0, port, AIR_LEAKY_PKT_TYPE_BROADCAST, &bc);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+        return rc;
+    }
+
+    AIR_PRINT("Port %d Leaky Vlan Enable\n", port);
+    AIR_PRINT("Unicast     : %s\n", uc ? "TRUE" : "FALSE");
+    AIR_PRINT("Multicast   : %s\n", mc ? "TRUE" : "FALSE");
+    AIR_PRINT("Broadcast   : %s\n", bc ? "TRUE" : "FALSE");
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanGetPortVlanAttr(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    AIR_VLAN_PORT_ATTR_T attr;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    rc = air_vlan_getPortAttr(0, port, &attr);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+        return rc;
+    }
+    AIR_PRINT("Port %d Vlan Attr: ", port);
+    switch(attr)
+    {
+        case AIR_VLAN_PORT_ATTR_USER_PORT:
+            AIR_PRINT("user port(%d)\n", attr);
+            break;
+        case AIR_VLAN_PORT_ATTR_STACK_PORT:
+            AIR_PRINT("stack port(%d)\n", attr);
+            break;
+        case AIR_VLAN_PORT_ATTR_TRANSLATION_PORT:
+            AIR_PRINT("translation port(%d)\n", attr);
+            break;
+        case AIR_VLAN_PORT_ATTR_TRANSPARENT_PORT:
+            AIR_PRINT("transparent port(%d)\n", attr);
+            break;
+        default:
+            AIR_PRINT("unknown(%d)\n", attr);
+            break;
+    };
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanGetIgsPortETagAttr(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    AIR_IGR_PORT_EG_TAG_ATTR_T attr;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    rc = air_vlan_getIgrPortTagAttr(0, port, &attr);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+        return rc;
+    }
+    AIR_PRINT("Port %d Incomming Port Egress Tag Attr: ", port);
+    switch(attr)
+    {
+        case AIR_IGR_PORT_EG_TAG_ATTR_DISABLE:
+            AIR_PRINT("disable(%d)\n", attr);
+            break;
+        case AIR_IGR_PORT_EG_TAG_ATTR_CONSISTENT:
+            AIR_PRINT("consistent(%d)\n", attr);
+            break;
+        case AIR_IGR_PORT_EG_TAG_ATTR_UNTAGGED:
+            AIR_PRINT("untagged(%d)\n", attr);
+            break;
+        case AIR_IGR_PORT_EG_TAG_ATTR_SWAP:
+            AIR_PRINT("swap(%d)\n", attr);
+            break;
+        case AIR_IGR_PORT_EG_TAG_ATTR_TAGGED:
+            AIR_PRINT("tagged(%d)\n", attr);
+            break;
+        case AIR_IGR_PORT_EG_TAG_ATTR_STACK:
+            AIR_PRINT("stack(%d)\n", attr);
+            break;
+        default:
+            AIR_PRINT("unknown(%d)\n", attr);
+            break;
+    };
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanGetPortETagAttr(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    AIR_PORT_EGS_TAG_ATTR_T attr;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    rc = air_vlan_getPortEgsTagAttr(0, port, &attr);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+        return rc;
+    }
+    AIR_PRINT("Port %d Egress Tag Attr: ", port);
+    switch(attr)
+    {
+        case AIR_PORT_EGS_TAG_ATTR_UNTAGGED:
+            AIR_PRINT("untagged(%d)\n", attr);
+            break;
+        case AIR_PORT_EGS_TAG_ATTR_SWAP:
+            AIR_PRINT("swap(%d)\n", attr);
+            break;
+        case AIR_PORT_EGS_TAG_ATTR_TAGGED:
+            AIR_PRINT("tagged(%d)\n", attr);
+            break;
+        case AIR_PORT_EGS_TAG_ATTR_STACK:
+            AIR_PRINT("stack(%d)\n", attr);
+            break;
+        default:
+            AIR_PRINT("unknown(%d)\n", attr);
+            break;
+    };
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanGetPortOuterTPID(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    UI16_T tpid = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    rc = air_vlan_getPortOuterTPID(0, port, &tpid);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+        return rc;
+    }
+    AIR_PRINT("Port %d Outer TPID: %4x\n", port, tpid);
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanGetPvid(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    UI16_T pvid = 0;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    rc = air_vlan_getPortPVID(0, port, &pvid);
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("Error: Operation failed!\n");
+        return rc;
+    }
+    AIR_PRINT("Port %d PVID: %d\n", port, pvid);
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doVlanGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(vlanGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doVlan(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(vlanCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doJumbo(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    I32_T pkt_len = 0, frame_len = 0;
+
+    if(0 == argc)
+    {
+        /* get command */
+        ret = air_port_getJumbo(0, &pkt_len, &frame_len);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get ");
+            switch(pkt_len)
+            {
+                case 0:
+                    AIR_PRINT("RX_1518 ");
+                    break;
+                case 1:
+                    AIR_PRINT("RX_1536 ");
+                    break;
+                case 2:
+                    AIR_PRINT("RX_1552 ");
+                    break;
+                case 3:
+                    AIR_PRINT("RX_JUMBO ");
+                    break;
+            }
+            AIR_PRINT("frames lengths %d KBytes\n", frame_len);
+        }
+        else
+        {
+            AIR_PRINT("Get Jumbo Fail.\n");
+        }
+    }
+    else
+    {
+        /* set command */
+        pkt_len = _strtol(argv[0], NULL, 10);
+        frame_len = _strtol(argv[1], NULL, 10);
+
+        ret = air_port_setJumbo(0, pkt_len, frame_len);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set ");
+            switch(pkt_len)
+            {
+                case 0:
+                    AIR_PRINT("RX_1518 ");
+                    break;
+                case 1:
+                    AIR_PRINT("RX_1536 ");
+                    break;
+                case 2:
+                    AIR_PRINT("RX_1552 ");
+                    break;
+                case 3:
+                    AIR_PRINT("RX_JUMBO ");
+                    break;
+            }
+            AIR_PRINT("frames lengths %d KBytes\n", frame_len);
+        }
+        else
+            AIR_PRINT("Set Jumbo Fail.\n");
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doFlowCtrl(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    BOOL_T fc_en = 0, dir = 0;
+    I32_T port = 0;
+
+    port = _strtol(argv[0], NULL, 10);
+    dir = _strtol(argv[1], NULL, 10);
+
+    if(2 == argc)
+    {
+        /* get command */
+        ret = air_port_getFlowCtrl(0, port, dir, &fc_en);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Get Port%02d %s Flow Control %s\n", port, ((dir)?"RX":"TX"), ((fc_en)?"Enable":"Disable"));
+        else
+            AIR_PRINT("Get Flow Control Fail.\n");
+    }
+    else
+    {
+        /* set command */
+        fc_en = _strtol(argv[2], NULL, 10);
+
+        ret = air_port_setFlowCtrl(0, port, dir, fc_en);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Set Port%02d %s Flow Control %s\n", port, ((dir)?"RX":"TX"), ((fc_en)?"Enable":"Disable"));
+        else
+            AIR_PRINT("Set Flow Control Fail.\n");
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doL2Set(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(l2SetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doL2Get(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(l2GetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doL2Clear(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(l2ClearCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doL2Del(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(l2DelCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doL2Add(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(l2AddCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doL2(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(l2Cmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doAnMode(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    BOOL_T en = 0;
+
+    port = _strtol(argv[0], NULL, 10);
+
+    if(1 == argc)
+    {
+        /* port get anCap <port> */
+        ret = air_port_getAnMode(0, port, &en);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Get Port%02d Auto-Negotiation %s\n", port, ((en)?"Enabled":"Disabled"));
+        else
+            AIR_PRINT("Get Port%02d Auto-Negotiation Fail.\n", port);
+    }
+    else if(2 == argc)
+    {
+        /* "port set anMode <port> <en> */
+        en = _strtol(argv[1], NULL, 10);
+        ret = air_port_setAnMode(0, port, en);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Set Port%02d Auto-Negotiation Mode:%s\n", port, ((en)?"Enabled":"Disabled"));
+        else
+            AIR_PRINT("Set Port%02d Auto-Negotiation Fail.\n", port);
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doLocalAdv(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    AIR_AN_ADV_T adv;
+
+    memset(&adv, 0, sizeof(AIR_AN_ADV_T));
+    port = _strtol(argv[0], NULL, 10);
+
+    if(1 == argc)
+    {
+        /* port get localAdv <port> */
+        ret = air_port_getLocalAdvAbility(0, port, &adv);
+        AIR_PRINT("Get Port%02d Local Auto-Negotiation Advertisement: ", port);
+        if(AIR_E_OK != ret)
+        {
+            AIR_PRINT("Fail!\n");
+        }
+    }
+    else if(7 == argc)
+    {
+        /* port set localAdv <port> <10H> <10F> <100H> <100F> <1000F> <pause> */
+        adv.advCap10HDX = _strtol(argv[1], NULL, 0) & BIT(0);
+        adv.advCap10FDX = _strtol(argv[2], NULL, 0) & BIT(0);
+        adv.advCap100HDX = _strtol(argv[3], NULL, 0) & BIT(0);
+        adv.advCap100FDX = _strtol(argv[4], NULL, 0) & BIT(0);
+        adv.advCap1000FDX = _strtol(argv[5], NULL, 0) & BIT(0);
+        adv.advPause = _strtol(argv[6], NULL, 0) & BIT(0);
+        ret = air_port_setLocalAdvAbility(0, port, adv);
+        AIR_PRINT("Set Port%02d Local Auto-Negotiation Advertisement: ", port);
+        if(AIR_E_OK != ret)
+        {
+            AIR_PRINT("Fail!\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        AIR_PRINT("\n");
+        AIR_PRINT("\tAdvertise 10BASE-T Half Duplex: %s\n", (adv.advCap10HDX)?"Effective":"Not Effective" );
+        AIR_PRINT("\tAdvertise 10BASE-T Full Duplex: %s\n", (adv.advCap10FDX)?"Effective":"Not Effective" );
+        AIR_PRINT("\tAdvertise 100BASE-T Half Duplex: %s\n", (adv.advCap100HDX)?"Effective":"Not Effective" );
+        AIR_PRINT("\tAdvertise 100BASE-T Full Duplex: %s\n", (adv.advCap100FDX)?"Effective":"Not Effective" );
+        AIR_PRINT("\tAdvertise 1000BASE-T Full Duplex: %s\n", (adv.advCap1000FDX)?"Effective":"Not Effective" );
+        AIR_PRINT("\tAdvertise Asynchronous Pause: %s\n", (adv.advPause)?"Effective":"Not Effective" );
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doRemoteAdv(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    AIR_AN_ADV_T lp_adv;
+
+    memset(&lp_adv, 0, sizeof(AIR_AN_ADV_T));
+    port = _strtol(argv[0], NULL, 10);
+
+    if(1 == argc)
+    {
+        /* port get remoteAdv <port> */
+        ret = air_port_getRemoteAdvAbility(0, port, &lp_adv);
+        AIR_PRINT("Get Port%02d Remote Auto-Negotiation Advertisement: ", port);
+        if(AIR_E_OK != ret)
+        {
+            AIR_PRINT("Fail!\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        AIR_PRINT("\n");
+        AIR_PRINT("\tAdvertise 10BASE-T Half Duplex: %s\n", lp_adv.advCap10HDX?"Effective":"Not Effective" );
+        AIR_PRINT("\tAdvertise 10BASE-T Full Duplex: %s\n", lp_adv.advCap10FDX?"Effective":"Not Effective" );
+        AIR_PRINT("\tAdvertise 100BASE-T Half Duplex: %s\n", lp_adv.advCap100HDX?"Effective":"Not Effective" );
+        AIR_PRINT("\tAdvertise 100BASE-T Full Duplex: %s\n", lp_adv.advCap100FDX?"Effective":"Not Effective" );
+        AIR_PRINT("\tAdvertise 1000BASE-T Full Duplex: %s\n", (lp_adv.advCap1000FDX)?"Effective":"Not Effective" );
+        AIR_PRINT("\tAdvertise Asynchronous Pause: %s\n", (lp_adv.advPause)?"Effective":"Not Effective" );
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortSpeed(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    UI32_T speed = 0;
+
+    port = _strtol(argv[0], NULL, 10);
+
+    if(1 == argc)
+    {
+        /* port get speed <port> */
+        ret = air_port_getSpeed(0, port, &speed);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get Port%02d Speed:", port);
+        }
+        else
+        {
+            AIR_PRINT("Get Port%02d Speed Fail!\n", port);
+        }
+    }
+    else if(2 == argc)
+    {
+        /* port set speed <port> <speed> */
+        speed = _strtol(argv[1], NULL, 10);
+        ret = air_port_setSpeed(0, port, speed);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set Port%02d Speed:", port);
+        }
+        else
+        {
+            AIR_PRINT("Set Port%02d Speed Fail!\n", port);
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        switch(speed)
+        {
+            case AIR_PORT_SPEED_10M:
+                AIR_PRINT(" 10 Mbps\n");
+                break;
+            case AIR_PORT_SPEED_100M:
+                AIR_PRINT(" 100 Mbps\n");
+                break;
+            case AIR_PORT_SPEED_1000M:
+                AIR_PRINT(" 1 Gbps\n");
+                break;
+            case AIR_PORT_SPEED_2500M:
+                AIR_PRINT(" 2.5 Gbps\n");
+                break;
+            default:
+                AIR_PRINT(" Reserved\n");
+                break;
+        }
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortDuplex(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    UI32_T duplex = 0;
+
+    port = _strtol(argv[0], NULL, 10);
+
+    if(1 == argc)
+    {
+        /* port get duplex <port> */
+        ret = air_port_getDuplex(0, port, &duplex);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get Port%02d Duplex:%s\n", port, duplex?"Full":"Half");
+        }
+        else
+        {
+            AIR_PRINT("Get Port%02d Duplex Fail!\n", port);
+        }
+    }
+    else if(2 == argc)
+    {
+        /* port set duplex <port> <duplex> */
+        duplex = _strtol(argv[1], NULL, 10);
+        ret = air_port_setDuplex(0, port, duplex);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set Port%02d Duplex:%s\n", port, duplex?"Full":"Half");
+        }
+        else
+        {
+            AIR_PRINT("Set Port%02d Duplex Fail!\n", port);
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortStatus(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    AIR_PORT_STATUS_T ps;
+
+    memset(&ps, 0, sizeof(AIR_PORT_STATUS_T));
+    port = _strtol(argv[0], NULL, 10);
+
+    if(1 == argc)
+    {
+        /* port get status <port> */
+        ret = air_port_getLink(0, port, &ps);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get Port%02d Link-Status\n", port);
+            AIR_PRINT("\tLink: %s\n", ps.link?"Up":"Down");
+            AIR_PRINT("\tDuplex: %s\n", ps.duplex?"Full":"Half");
+            AIR_PRINT("\tSpeed: ");
+            switch(ps.speed)
+            {
+                case AIR_PORT_SPEED_10M:
+                    AIR_PRINT("10 Mbps\n");
+                    break;
+                case AIR_PORT_SPEED_100M:
+                    AIR_PRINT("100 Mbps\n");
+                    break;
+                case AIR_PORT_SPEED_1000M:
+                    AIR_PRINT("1 Gbps\n");
+                    break;
+                case AIR_PORT_SPEED_2500M:
+                    AIR_PRINT("2.5 Gbps\n");
+                    break;
+                default:
+                    AIR_PRINT("Reserved\n");
+                    break;
+            }
+        }
+        else
+            AIR_PRINT("Get Port%02d Link-Status Fail!", port);
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortBckPres(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    UI32_T bckPres = 0;
+
+    port = _strtol(argv[0], NULL, 10);
+
+    if(1 == argc)
+    {
+        /* port get bckPres <port> */
+        ret = air_port_getBckPres(0, port, &bckPres);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Get Port%02d BckPres:%s\n", port, bckPres?"Enabled":"Disabled");
+        else
+            AIR_PRINT("Get Port%02d BckPres Fail!\n", port);
+    }
+    else if(2 == argc)
+    {
+        /* port set bckPres <port> <bckPres> */
+        bckPres = _strtol(argv[1], NULL, 10);
+        ret = air_port_setBckPres(0, port, bckPres);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Set Port%02d BckPres:%s\n", port, bckPres?"Enabled":"Disabled");
+        else
+            AIR_PRINT("Set Port%02d BckPres Fail!\n", port);
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortPsMode(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    UI32_T mode = 0;
+    BOOL_T ls_en = 0;
+    BOOL_T eee_en = 0;
+
+    port = _strtol(argv[0], NULL, 10);
+
+    if(1 == argc)
+    {
+        /* port get psMode <port> */
+        ret = air_port_getPsMode(0, port, &mode);
+        AIR_PRINT("Get Port%02d Power-Saving: ", port);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Done\n");
+        }
+        else
+        {
+            AIR_PRINT("Fail!\n");
+        }
+    }
+    else if(3 == argc)
+    {
+        /* port set psMode <port> <ls> <eee> */
+        ls_en = _strtol(argv[1], NULL, 0);
+        eee_en = _strtol(argv[2], NULL, 0);
+        if(TRUE == ls_en)
+        {
+            mode |= AIR_PORT_PS_LINKSTATUS;
+        }
+        if(TRUE == eee_en)
+        {
+            mode |= AIR_PORT_PS_EEE;
+        }
+        ret = air_port_setPsMode(0, port, mode);
+        AIR_PRINT("Set Port%02d Power-Saving: ", port);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Done\n");
+        }
+        else
+        {
+            AIR_PRINT("Fail!\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+    if(ret == AIR_E_OK)
+    {
+        AIR_PRINT("\tLink status:%s\n", (mode & AIR_PORT_PS_LINKSTATUS)?"Enable":"Disable");
+        AIR_PRINT("\tEEE:%s\n", (mode & AIR_PORT_PS_EEE)?"Enable":"Disable");
+    }
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortSmtSpdDwn(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    UI32_T state = 0;
+    UI32_T retry = 0;
+
+    port = _strtol(argv[0], NULL, 10);
+
+    if(1 == argc)
+    {
+        /* port get smtSpdDwn <port> */
+        ret = air_port_getSmtSpdDwn(0, port, &state, &retry);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get Port%02d Smart Speed Down: %s\n", port, state?"Enabled":"Disabled");
+            AIR_PRINT("Get Port%02d Retry Time: %d\n", port, retry + 2);
+        }
+        else
+            AIR_PRINT("Get Port%02d Smart-SpeedDown Fail!\n", port);
+    }
+    else if(3 == argc)
+    {
+        /* port set smtSpdDwn <port> <en> <retry> */
+        state = _strtol(argv[1], NULL, 10);
+        retry = _strtol(argv[2], NULL, 10);
+        if(retry >= 2)
+        {
+            ret = air_port_setSmtSpdDwn(0, port, state, retry - 2);
+            if(ret == AIR_E_OK)
+            {
+                AIR_PRINT("Set Port%02d Smart Speed Down: %s\n", port, state?"Enabled":"Disabled");
+                AIR_PRINT("Set Port%02d Retry Time: %d\n", port, retry);
+            }
+            else
+                AIR_PRINT("Set Port%02d Smart-SpeedDown Fail!\n", port);
+        }
+        else
+        {
+            ret = AIR_E_BAD_PARAMETER;
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortSpTag(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    BOOL_T sptag_en = FALSE;
+
+    port = _strtol(argv[0], NULL, 10);
+
+    if(1 == argc)
+    {
+        /* port get spTag <port> */
+        ret = air_port_getSpTag(0, port, &sptag_en);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Get Port%02d Special Tag %s\n", port, ((sptag_en)?"Enabled":"Disabled"));
+        }
+        else
+        {
+            AIR_PRINT("Get Port%02d Special Tag Fail.\n", port);
+        }
+    }
+    else if(2 == argc)
+    {
+        /* port set spTag <port> <en> */
+        sptag_en = _strtol(argv[1], NULL, 10);
+        ret = air_port_setSpTag(0, port, sptag_en);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Set Port%02d Special Tag:%s\n", port, ((sptag_en)?"Enabled":"Disabled"));
+        }
+        else
+        {
+            AIR_PRINT("Set Port%02d Special Tag Fail.\n", port);
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortEnable(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    UI32_T state = 0;
+
+    port = _strtol(argv[0], NULL, 10);
+
+    if(1 == argc)
+    {
+        /* port get enable <port> */
+        ret = air_port_getEnable(0, port, &state);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Get Port%02d State:%s\n", port, state?"Enable":"Disable");
+        else
+            AIR_PRINT("Get Port%02d State Fail!\n", port);
+    }
+    else if(2 == argc)
+    {
+        /* port set enable <port> <en> */
+        state = _strtol(argv[1], NULL, 10);
+        ret = air_port_setEnable(0, port, state);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Set Port%02d State:%s\n", port, state?"Enable":"Disable");
+        else
+            AIR_PRINT("Set Port%02d State Fail!\n", port);
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPort5GBaseRMode(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+
+    if(0 == argc)
+    {
+        /* port set 5GBaseRMode */
+        ret = air_port_set5GBaseRModeEn(0);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Set Port05 Mode: 5GBase-R\n");
+        else
+            AIR_PRINT("Set Port05 HSGMII Mode Fail.\n");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortHsgmiiMode(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+
+    if(0 == argc)
+    {
+        /* port set hsgmiiMode */
+        ret = air_port_setHsgmiiModeEn(0);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Set Port05 Mode: HSGMII\n");
+        else
+            AIR_PRINT("Set Port05 HSGMII Mode Fail.\n");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortSgmiiMode(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T mode = 0;
+    UI32_T speed = 0;
+
+    if(2 == argc)
+    {
+        /* port set sgmiiMode <mode(0:AN,1:Force)> <speed> */
+        mode = _strtol(argv[0], NULL, 10);
+        speed = _strtol(argv[1], NULL, 10);
+        ret = air_port_setSgmiiMode(0, mode, speed);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Set Port05 SGMII Mode:%s\nIf in Force Mode, speed:", mode?"Force":"AN");
+        else
+            AIR_PRINT("Set Port05 SGMII Mode Fail.\n");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        switch(speed)
+        {
+            case AIR_PORT_SPEED_10M:
+                AIR_PRINT(" 10 Mbps\n");
+                break;
+            case AIR_PORT_SPEED_100M:
+                AIR_PRINT(" 100 Mbps\n");
+                break;
+            case AIR_PORT_SPEED_1000M:
+                AIR_PRINT(" 1 Gbps\n");
+                break;
+            default:
+                AIR_PRINT(" Reserved\n");
+                break;
+        }
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortRmiiMode(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T speed = 0;
+
+    if(1 == argc)
+    {
+        /* port set rmiiMode <speed> */
+        speed = _strtol(argv[0], NULL, 10);
+        ret = air_port_setRmiiMode(0, speed);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set Port05 RMII Mode Speed:");
+        }
+        else
+        {
+            AIR_PRINT("Set Port05 RMII Mode Fail!\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        switch(speed)
+        {
+            case AIR_PORT_SPEED_10M:
+                AIR_PRINT(" 10 Mbps\n");
+                break;
+            case AIR_PORT_SPEED_100M:
+                AIR_PRINT(" 100 Mbps\n");
+                break;
+            default:
+                AIR_PRINT(" Reserved\n");
+                break;
+        }
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doPortRgmiiMode(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T speed = 0;
+
+    if(1 == argc)
+    {
+        /* port set rgmiiMode <speed> */
+        speed = _strtol(argv[0], NULL, 10);
+        ret = air_port_setRgmiiMode(0, speed);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set Port05 RGMII Mode Speed:");
+        }
+        else
+        {
+            AIR_PRINT("Set Port05 RGMII Mode Fail!\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        switch(speed)
+        {
+            case AIR_PORT_SPEED_10M:
+                AIR_PRINT(" 10 Mbps\n");
+                break;
+            case AIR_PORT_SPEED_100M:
+                AIR_PRINT(" 100 Mbps\n");
+                break;
+            case AIR_PORT_SPEED_1000M:
+                AIR_PRINT(" 1 Gbps\n");
+                break;
+            default:
+                AIR_PRINT(" Reserved\n");
+                break;
+        }
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doSptagEn(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    BOOL_T sp_en = FALSE;
+
+    port =  _strtol(argv[0], NULL, 10);
+    if (2 == argc)
+    {
+        sp_en =  _strtol(argv[1], NULL, 10);
+        ret = air_sptag_setState(0,port,sp_en);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("set port %d SpTag state %s sucess\n", port,sp_en?"Enable":"Disable");
+        }
+        else
+        {
+            AIR_PRINT("set port %d SpTag state %s fail\n", port,sp_en?"Enable":"Disable");
+        }
+    }
+    else if(1 == argc)
+    {
+        air_sptag_getState(0,port,&sp_en);
+        AIR_PRINT("get port %d SpTag state: %s \n", port,sp_en?"Enable":"Disable");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doSptagMode(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    BOOL_T sp_mode = FALSE;
+
+
+    port =  _strtol(argv[0], NULL, 10);
+    if (2 == argc)
+    {
+        sp_mode  =  _strtol(argv[1], NULL, 10);
+        ret = air_sptag_setMode(0,port,sp_mode);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("set port %d SpTag Mode  %s sucess\n", port,sp_mode?"replace":"insert");
+        }
+        else
+        {
+            AIR_PRINT("set port %d SpTag state %s fail\n", port,sp_mode?"replace":"insert");
+        }
+    }
+    else if(1 == argc)
+    {
+        air_sptag_getMode(0,port,&sp_mode);
+        AIR_PRINT("get port %d SpTag state: %s \n", port,sp_mode?"replace":"insert");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doSptagDecode(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    AIR_SPTAG_RX_PARA_T sptag_rx = {0};
+    UI8_T buf[AIR_STAG_BUF_LEN] = {0};
+    UI32_T len = AIR_STAG_BUF_LEN, i = 0;
+
+    if (4 == argc)
+    {
+        for(i = 0; i < len; i++)
+        {
+            buf[i] = _strtoul(argv[i], NULL, 16);
+        }
+
+        ret = air_sptag_decodeRx(0, buf, len, &sptag_rx);
+        if (AIR_E_OK != ret)
+        {
+            AIR_PRINT("SpTag decode fail\n");
+            return ret;
+        }
+
+        AIR_PRINT("SpTag decode success:\n");
+        AIR_PRINT("RSN : %s\n", _sptag_pt[sptag_rx.rsn]);
+        AIR_PRINT("VPM : %s\n", _sptag_vpm[sptag_rx.vpm]);
+        AIR_PRINT("SPN : %d\n", sptag_rx.spn);
+        AIR_PRINT("PRI : %d\n", sptag_rx.pri);
+        AIR_PRINT("CFI : %d\n", sptag_rx.cfi);
+        AIR_PRINT("VID : %d\n", sptag_rx.vid);
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doSptagEncode(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    AIR_STAG_TX_PARA_T sptag_tx = {0};
+    C8_T *token = NULL;
+    UI8_T buf[AIR_STAG_BUF_LEN] = {0};
+    UI32_T len = AIR_STAG_BUF_LEN;
+    char str[128] = {'\0'};
+    UI32_T data = 0;
+    AIR_STAG_MODE_T mode = AIR_STAG_MODE_LAST;
+
+    if (7 == argc)
+    {
+        if(_strcmp(argv[0],"mode=replace") == 0)
+            mode = AIR_STAG_MODE_REPLACE;
+        else if(_strcmp(argv[0],"mode=insert") == 0)
+            mode = AIR_STAG_MODE_INSERT;
+        else
+            printf("mode is wrong!!");
+
+        if(_strcmp(argv[1],"opc=portmap") == 0)
+            sptag_tx.opc = AIR_STAG_OPC_PORTMAP;
+        else if(_strcmp(argv[1],"opc=portid") == 0)
+            sptag_tx.opc = AIR_STAG_OPC_PORTID;
+        else if(_strcmp(argv[1],"opc=lookup") == 0)
+            sptag_tx.opc = AIR_STAG_OPC_LOOKUP;
+        else
+            printf("opc is wrong!!");
+
+        token = _strtok(argv[2], "=", &argv[2]);
+        if(_strcmp(token,"dp") != 0) {
+            AIR_PRINT("Bad parameter\r\n");
+        } else {
+            if ((token = _strtok(argv[2], "=", &argv[2]))) {
+                data = _strtoul(token, NULL, 16);
+                sptag_tx.pbm = data;
+                AIR_PRINT("sptag_tx.pbm %x\n",sptag_tx.pbm);
+            }
+        }
+
+        if(_strcmp(argv[3],"vpm=untagged") == 0)
+            sptag_tx.vpm = AIR_STAG_VPM_UNTAG;
+        else if(_strcmp(argv[3],"vpm=8100") == 0)
+            sptag_tx.vpm = AIR_STAG_VPM_TPID_8100;
+        else if(_strcmp(argv[3],"vpm=88a8") == 0)
+            sptag_tx.vpm = AIR_STAG_VPM_TPID_88A8;
+        else
+            printf("vpm is wrong!!");
+
+        token = _strtok(argv[4], "=", &argv[4]);
+        if(_strcmp(token, "pri") != 0) {
+            AIR_PRINT("Bad parameter\r\n");
+        } else {
+            if ((token = _strtok(argv[4], "=", &argv[4]))) {
+                data = _strtoul(token, NULL, 0);
+                sptag_tx.pri = data;
+                AIR_PRINT("sptag_tx.pri %d\n",sptag_tx.pri);
+            }
+        }
+
+        token = _strtok(argv[5], "=", &argv[5]);
+        if(_strcmp(token, "cfi") != 0) {
+            AIR_PRINT("Bad parameter\r\n");
+        } else {
+            if ((token = _strtok(argv[5], "=", &argv[5]))) {
+                data = _strtoul(token, NULL, 0);
+                sptag_tx.cfi  = data;
+                AIR_PRINT("sptag_tx.cfi %d\n",sptag_tx.cfi);
+            }
+        }
+
+        token = _strtok(argv[6], "=", &argv[6]);
+        if(_strcmp(token, "vid") != 0) {
+            AIR_PRINT("Bad parameter\r\n");
+        } else {
+            if ((token = _strtok(argv[6], "=", &argv[6]))) {
+                data = _strtoul(token, NULL, 0);
+                sptag_tx.vid = data;
+                AIR_PRINT("sptag_tx.vid %d\n",sptag_tx.vid);
+            }
+        }
+
+        ret = air_sptag_encodeTx(0,mode, &sptag_tx, (UI8_T *)&buf, &len);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("SpTag encode sucess, returned len=%d\n", len);
+            AIR_PRINT("Encoded SpTag: %02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]);
+        }
+        else
+        {
+            AIR_PRINT("SpTag encode fail\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doSptag(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(sptagCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doL2Dump(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(l2DumpCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doMacAddr(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    AIR_MAC_ENTRY_T mt;
+    UI32_T fwd = 0;
+
+    memset(&mt, 0, sizeof(AIR_MAC_ENTRY_T));
+
+    if(0 == argc)
+    {
+        /* l2 clear mac */
+        ret = air_l2_clearMacAddr(0);
+        if(ret == AIR_E_OK)
+            AIR_PRINT("Clear MAC Address Table Done.\n");
+        else
+            AIR_PRINT("Clear MAC Address Table Fail.\n");
+    }
+    else if(3 == argc)
+    {
+        /* l2 del mac <mac(12'hex)> { vid <vid(0..4095)> | fid <fid(0..15)> } */
+        ret = _str2mac(argv[0], (C8_T *)mt.mac);
+        if(ret != AIR_E_OK)
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            return ret;
+        }
+
+        /* check argument 1 */
+        if(FALSE == _strcmp(argv[1], "vid"))
+        {
+            /* get mac entry by MAC address & vid */
+            mt.cvid = _strtoul(argv[2], NULL, 0);
+            mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_IVL;
+            AIR_PRINT("Get MAC Address:" MAC_STR " with vid:%u", MAC2STR(mt.mac), mt.cvid);
+        }
+        else if(FALSE == _strcmp(argv[1], "fid"))
+        {
+            /* get mac entry by MAC address & fid */
+            mt.fid = _strtoul(argv[2], NULL, 0);
+            AIR_PRINT("Get MAC Address:" MAC_STR " with fid:%u", MAC2STR(mt.mac), mt.fid);
+        }
+        else
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            return AIR_E_BAD_PARAMETER;
+        }
+        ret = air_l2_delMacAddr(0, &mt);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT(" Done.\n");
+        }
+        else
+            AIR_PRINT("\n Fail!\n");
+    }
+    else if(7 == argc)
+    {
+        /* l2 add mac <static(0:dynamic,1:static)> <unauth(0:auth,1:unauth)> <mac(12'hex)> <portlist(uintlist)> [ vid <vid(0..4095)> | fid <fid(0..15)> ] <src_mac_forward=(0:default,1:cpu-include,2:cpu-exclude,3:cpu-only,4:drop)> */
+        if(argv[0])
+            mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_STATIC;
+
+        if(argv[1])
+            mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_UNAUTH;
+
+        ret = _str2mac(argv[2], (C8_T *)mt.mac);
+        if(ret != AIR_E_OK)
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            return ret;
+        }
+
+        ret = _portListStr2Ary(argv[3], mt.port_bitmap, 1);
+        if(ret != AIR_E_OK)
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            return ret;
+        }
+
+        /* check argument fid or vid */
+        if(FALSE == _strcmp(argv[4], "vid"))
+        {
+            /* get mac entry by MAC address & vid */
+            mt.cvid = _strtoul(argv[5], NULL, 0);
+            mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_IVL;
+        }
+        else if(FALSE == _strcmp(argv[4], "fid"))
+        {
+            /* get mac entry by MAC address & fid */
+            mt.fid = _strtoul(argv[5], NULL, 0);
+        }
+        else
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            return AIR_E_BAD_PARAMETER;
+        }
+        fwd = _strtoul(argv[6], NULL, 0);
+        if(0 == fwd)
+            mt.sa_fwd = AIR_L2_FWD_CTRL_DEFAULT;
+        else if(1 == fwd)
+            mt.sa_fwd = AIR_L2_FWD_CTRL_CPU_INCLUDE;
+        else if(2 == fwd)
+            mt.sa_fwd = AIR_L2_FWD_CTRL_CPU_EXCLUDE;
+        else if(3 == fwd)
+            mt.sa_fwd = AIR_L2_FWD_CTRL_CPU_ONLY;
+        else if(4 == fwd)
+            mt.sa_fwd = AIR_L2_FWD_CTRL_DROP;
+        else
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            return AIR_E_BAD_PARAMETER;
+        }
+        ret = air_l2_addMacAddr(0, &mt);
+        AIR_PRINT("Add MAC Address:" MAC_STR, MAC2STR(mt.mac));
+        if(ret == AIR_E_OK)
+            AIR_PRINT(" Done.\n");
+        else
+            AIR_PRINT(" Fail.\n");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+_printMacEntry(
+        AIR_MAC_ENTRY_T *mt,
+        UI32_T age_unit,
+        UI8_T count,
+        UI8_T title)
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    I32_T i = 0, j = 0;
+    UI8_T first = 0;
+    UI8_T find = 0;
+    if(title)
+    {
+        AIR_PRINT("%-6s%-15s%-5s%-5s%-5s%-10s%-10s%-6s\n",
+                "unit",
+                "mac",
+                "ivl",
+                "vid",
+                "fid",
+                "age-time",
+                "forward",
+                "port");
+        return ret;
+    }
+    for(i = 0; i < count; i++)
+    {
+        AIR_PRINT("%-6d", age_unit);
+        AIR_PRINT(MAC_STR, MAC2STR(mt[i].mac));
+        AIR_PRINT("...");
+        if(mt[i].flags & AIR_L2_MAC_ENTRY_FLAGS_IVL)
+        {
+            AIR_PRINT("%-3s..", "ivl");
+            AIR_PRINT("%-5d", mt[i].cvid);
+            AIR_PRINT("%-5s", ".....");
+        }
+        else
+        {
+            AIR_PRINT("%-3s..", "svl");
+            AIR_PRINT("%-5s", ".....");
+            AIR_PRINT("%-5d", mt[i].fid);
+        }
+        if(mt[i].flags & AIR_L2_MAC_ENTRY_FLAGS_STATIC)
+        {
+            AIR_PRINT("%-10s.", "static");
+        }
+        else
+        {
+            AIR_PRINT("%d sec..", mt[i].timer);
+        }
+        AIR_PRINT("%-10s", _air_mac_address_forward_control_string[mt[i].sa_fwd]);
+        first = 0;
+        find = 0;
+        for (j = (AIR_MAX_NUM_OF_PORTS - 1); j >= 0; j--)
+        {
+            if((mt[i].port_bitmap[0]) & (1 << j))
+            {
+                first = j;
+                find = 1;
+                break;
+            }
+        }
+        if(find)
+        {
+            for (j = 0; j < AIR_MAX_NUM_OF_PORTS; j++)
+            {
+                if((mt[i].port_bitmap[0]) & (1 << j))
+                {
+                    if(j == first)
+                        AIR_PRINT("%-2d", j);
+                    else
+                        AIR_PRINT("%-2d,", j);
+                }
+            }
+        }
+        else
+            AIR_PRINT("no dst port");
+        AIR_PRINT("\n");
+    }
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doGetMacAddr(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI8_T count = 0;
+    AIR_MAC_ENTRY_T * ptr_mt;
+
+    if(3 == argc)
+    {
+        ptr_mt = AIR_MALLOC(sizeof(AIR_MAC_ENTRY_T));
+        if (NULL == ptr_mt)
+        {
+            AIR_PRINT("***Error***, allocate memory fail\n");
+            return AIR_E_OTHERS;
+        }
+        memset(ptr_mt, 0, sizeof(AIR_MAC_ENTRY_T));
+        /* l2 get mac <mac(12'hex)> { vid <vid(0..4095)> | fid <fid(0..15)> } */
+        ret = _str2mac(argv[0], (C8_T *)ptr_mt->mac);
+        if(ret != AIR_E_OK)
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            AIR_FREE(ptr_mt);
+            return ret;
+        }
+
+        /* check argument 1 */
+        if(FALSE == _strcmp(argv[1], "vid"))
+        {
+            /* get mac entry by MAC address & vid */
+            ptr_mt->cvid = _strtoul(argv[2], NULL, 0);
+            ptr_mt->flags |= AIR_L2_MAC_ENTRY_FLAGS_IVL;
+            AIR_PRINT("Get MAC Address:" MAC_STR " with vid:%u", MAC2STR(ptr_mt->mac), ptr_mt->cvid);
+        }
+        else if(FALSE == _strcmp(argv[1], "fid"))
+        {
+            /* get mac entry by MAC address & fid */
+            ptr_mt->fid = _strtoul(argv[2], NULL, 0);
+            AIR_PRINT("Get MAC Address:" MAC_STR " with fid:%u", MAC2STR(ptr_mt->mac), ptr_mt->fid);
+        }
+        else
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            AIR_FREE(ptr_mt);
+            return AIR_E_BAD_PARAMETER;
+        }
+        ret = air_l2_getMacAddr(0, &count, ptr_mt);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT(" Done.\n");
+            _printMacEntry(ptr_mt, 0, 1, TRUE);
+            _printMacEntry(ptr_mt, 0, 1, FALSE);
+        }
+        else
+            AIR_PRINT("\n Not found!\n");
+        AIR_FREE(ptr_mt);
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doMacAddrAgeOut(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T time = 0;
+    if(0 == argc)
+    {
+        /* l2 get macAddrAgeOut */
+        ret = air_l2_getMacAddrAgeOut(0, &time);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get MAC Address Age Out Time Done.\n");
+        }
+        else
+        {
+            AIR_PRINT("Get MAC Address Age Out Time Fail.\n");
+        }
+    }
+    else if(1 == argc)
+    {
+        /* l2 set macAddrAgeOut <time(1, 1000000)> */
+        time = _strtoul(argv[0], NULL, 0);
+        if(time < 1 || time > 1000000)
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            return AIR_E_BAD_PARAMETER;
+        }
+        ret = air_l2_setMacAddrAgeOut(0, time);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set MAC Address Age Out Time Done.\n");
+        }
+        else
+        {
+            AIR_PRINT("Set MAC Address Age Out Time Fail.\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        AIR_PRINT("MAC Address Age Out Time: %u seconds.\n", time);
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doDumpMacAddr(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    AIR_MAC_ENTRY_T *ptr_mt;
+    UI8_T count = 0;
+    UI32_T bucket_size = 0;
+    UI32_T total_count = 0;
+
+    if(0 != argc)
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+    /* get unit of aging time */
+    ret = air_l2_getMacBucketSize(0, &bucket_size);
+    if(ret != AIR_E_OK)
+    {
+        AIR_PRINT("Get MAC Age Time Fail!\n");
+        return ret;
+    }
+    ptr_mt = AIR_MALLOC(sizeof(AIR_MAC_ENTRY_T) * bucket_size);
+    if (NULL == ptr_mt)
+    {
+        AIR_PRINT("***Error***, allocate memory fail\n");
+        return AIR_E_OTHERS;
+    }
+    memset(ptr_mt, 0, sizeof(AIR_MAC_ENTRY_T) * bucket_size);
+    _printMacEntry(ptr_mt, 0, count, TRUE);
+    /* get 1st entry of MAC table */
+    ret = air_l2_getMacAddr(0, &count, ptr_mt);
+    switch(ret)
+    {
+        case AIR_E_ENTRY_NOT_FOUND:
+            AIR_FREE(ptr_mt);
+            AIR_PRINT("Not Found!\n");
+            return ret;
+        case AIR_E_TIMEOUT:
+            AIR_FREE(ptr_mt);
+            AIR_PRINT("Time Out!\n");
+            return ret;
+        case AIR_E_BAD_PARAMETER:
+            AIR_FREE(ptr_mt);
+            AIR_PRINT("Bad Parameter!\n");
+            return ret;
+        default:
+            break;
+    }
+    total_count += count;
+    _printMacEntry(ptr_mt, 0, count, FALSE);
+
+    /* get other entries of MAC table */
+    while(1)
+    {
+        memset(ptr_mt, 0, sizeof(AIR_MAC_ENTRY_T) * bucket_size);
+        ret = air_l2_getNextMacAddr(0, &count, ptr_mt);
+        if(AIR_E_OK != ret)
+        {
+            break;
+        }
+        total_count += count;
+        _printMacEntry(ptr_mt, 0, count, FALSE);
+    }
+    switch(ret)
+    {
+        case AIR_E_TIMEOUT:
+            AIR_PRINT("Time Out!\n");
+            break;
+        case AIR_E_BAD_PARAMETER:
+            AIR_PRINT("Bad Parameter!\n");
+            break;
+        default:
+            AIR_PRINT("Found %u %s\n", total_count, (total_count>1)?"entries":"entry");
+            break;
+    }
+    AIR_FREE(ptr_mt);
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doLagMember(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T portrunk_index = 0, member_index = 0, member_enable = 0, port_index = 0, i = 0;
+    AIR_LAG_PTGINFO_T  member;
+    memset(&member,0,sizeof(AIR_LAG_PTGINFO_T));
+
+    if(4 == argc)
+    {
+        /* lag set member <port trunk index> <member index> <member enable> <port_index>*/
+        portrunk_index  = _strtol(argv[0], NULL, 10);
+        member_index    = _strtol(argv[1], NULL, 10);
+        member_enable   = _strtol(argv[2], NULL, 10);
+        port_index      = _strtol(argv[3], NULL, 10);
+        ret = air_lag_setMember(0, portrunk_index, member_index, member_enable,port_index);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set port trunk index %d member_index:%d member_enable:%d, port_index:%d ok.\n", portrunk_index, member_index, member_enable,port_index);
+        }
+        else
+        {
+            AIR_PRINT("Set port trunk index %d member_index:%d member_enable:%d, port_index:%d fail.\n", portrunk_index, member_index, member_enable,port_index);
+        }
+        memset(&member,0,sizeof(member));
+        air_lag_getMember(0, portrunk_index, &member);
+        if(! member.csr_gp_enable[0])
+        {
+            AIR_PRINT("\r\n!!!!!!!!!Port trunk index %d member_index:0 must be set,or else have taffic issues.\n", portrunk_index);
+        }
+    }
+    else if(1 == argc)
+    {
+        portrunk_index = _strtol(argv[0], NULL, 10);
+
+        /* lag get member <port> */
+        memset(&member,0,sizeof(member));
+        ret = air_lag_getMember(0, portrunk_index, &member);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get port trunk %u member:\n", portrunk_index);
+            for(i = 0; i < AIR_LAG_MAX_MEM_NUM; i++)
+            {
+                if(member.csr_gp_enable[i])
+                    AIR_PRINT("port %d \r\n", member.csr_gp_port[i]);
+            }
+            AIR_PRINT("\r\n");
+        }
+        else
+        {
+            AIR_PRINT("Get port trunk:%u Member Fail.\n", portrunk_index);
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+
+static AIR_ERROR_NO_T
+doLagDstInfo(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    AIR_LAG_DISTINFO_T dstInfo;
+
+    memset(&dstInfo, 0, sizeof(AIR_LAG_DISTINFO_T));
+    if(7 == argc)
+    {
+        /* lag set dstInfo <sp> <sa> <da> <sip> <dip> <sport> <dport> */
+        dstInfo.sp = _strtol(argv[0], NULL, 10) & BIT(0);
+        dstInfo.sa = _strtol(argv[1], NULL, 10) & BIT(0);
+        dstInfo.da = _strtol(argv[2], NULL, 10) & BIT(0);
+        dstInfo.sip = _strtol(argv[3], NULL, 10) & BIT(0);
+        dstInfo.dip = _strtol(argv[4], NULL, 10) & BIT(0);
+        dstInfo.sport = _strtol(argv[5], NULL, 10) & BIT(0);
+        dstInfo.dport = _strtol(argv[6], NULL, 10) & BIT(0);
+        ret = air_lag_setDstInfo(0, dstInfo);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set LAG packet distrubution.\n");
+        }
+        else
+        {
+            AIR_PRINT("Set LAG packet distrubution Fail.\n");
+        }
+    }
+    else if(0 == argc)
+    {
+        /* lag get dstInfo */
+        ret = air_lag_getDstInfo(0, &dstInfo);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get LAG packet distrubution:\n");
+        }
+        else
+        {
+            AIR_PRINT("Get LAG packet distrubution Fail.\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+    if(ret == AIR_E_OK)
+    {
+        AIR_PRINT("%-5s|%-5s|%-5s|%-5s|%-5s|%-5s|%-5s\n",
+                "SP", "SA", "DA", "SIP", "DIP", "SPORT", "DPORT");
+        AIR_PRINT("%-5s|%-5s|%-5s|%-5s|%-5s|%-5s|%-5s\n",
+                (dstInfo.sp)?"En":"Dis",
+                (dstInfo.sa)?"En":"Dis",
+                (dstInfo.da)?"En":"Dis",
+                (dstInfo.sip)?"En":"Dis",
+                (dstInfo.dip)?"En":"Dis",
+                (dstInfo.sport)?"En":"Dis",
+                (dstInfo.dport)?"En":"Dis");
+    }
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doLagHashtype(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T hashtype = 0;
+
+    if(1 == argc)
+    {
+        hashtype = _strtol(argv[0], NULL, 10);
+        ret = air_lag_sethashtype(0, hashtype);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set LAG hashtype Ok.\n");
+        }
+        else
+        {
+            AIR_PRINT("Set LAG hashtype Fail.\n");
+        }
+    }
+    else if(0 == argc)
+    {
+        /* lag get dstInfo */
+        ret = air_lag_gethashtype(0, &hashtype);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get LAG hashtype:\n");
+        }
+        else
+        {
+            AIR_PRINT("Get LLAG hashtype Fail.\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+    if(ret == AIR_E_OK)
+    {
+        switch (hashtype)
+        {
+            case 0:
+                AIR_PRINT("hashtype:crc32lsb.\n");
+                break;
+            case 1:
+                AIR_PRINT("hashtype:crc32msb.\n");
+                break;
+            case 2:
+                AIR_PRINT("hashtype:crc16.\n");
+                break;
+            case 3:
+                AIR_PRINT("hashtype:xor4.\n");
+                break;
+            default:
+                AIR_PRINT("wrong hashtype:%d.\n",hashtype);
+        }
+
+    }
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doLagPtseed(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T ptseed = 0;
+
+    if(1 == argc)
+    {
+        ptseed = _strtol(argv[0], NULL, 16);
+        ret = air_lag_setPTSeed(0, ptseed);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set LAG Port Seed:%x(hex) ok\n",ptseed);
+        }
+        else
+        {
+            AIR_PRINT("Set LAG Port Seed:%x(hex) fail\n",ptseed);
+        }
+    }
+    else if(0 == argc)
+    {
+        /* lag get seed */
+        ret = air_lag_getPTSeed(0, &ptseed);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get port trunk seed: %x(hex)\n",ptseed);
+        }
+        else
+        {
+            AIR_PRINT("Get port trunk seed Fail.\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doLagSpsel(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    UI32_T state = 0;
+
+    if(1 == argc)
+    {
+        /* lag set spsel <state> */
+        state = _strtol(argv[0], NULL, 10);
+        ret = air_lag_setSpSel(0,state);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set source port compare function:%s.\n", (state)?"Enabled":"Disabled");
+        }
+        else
+        {
+            AIR_PRINT("Set source port compare function Fail.\n");
+        }
+    }
+    else if(0 == argc)
+    {
+        /* lag get spsel*/
+        ret = air_lag_getSpSel(0, &state);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get source port compare function:%s.\n", (state)?"Enabled":"Disabled");
+        }
+        else
+        {
+            AIR_PRINT("Get source port compare function Fail.\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+
+static AIR_ERROR_NO_T
+doLagState(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    UI32_T state = 0;
+
+    if(1 == argc)
+    {
+        /* lag set state <state> */
+        state = _strtol(argv[0], NULL, 10);
+        ret = air_lag_set_ptgc_state(0,state);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set LAG Port Trunk State:%s.\n", (state)?"Enabled":"Disabled");
+        }
+        else
+        {
+            AIR_PRINT("Set LAG Port Trunk State Fail.\n");
+        }
+    }
+    else if(0 == argc)
+    {
+        /* lag get state*/
+        ret = air_lag_get_ptgc_state(0, &state);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get LAG Port Trunk State:%s.\n", (state)?"Enabled":"Disabled");
+        }
+        else
+        {
+            AIR_PRINT("Get LAG Port Trunk State Fail.\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doLagGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(lagGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doLagSet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(lagSetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doLag(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(lagCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doStpPortstate(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    UI32_T fid = 0;
+    UI32_T state = 0;
+
+    port = _strtol(argv[0], NULL, 10);
+    fid = _strtol(argv[1], NULL, 10);
+    if(3 == argc)
+    {
+        /* stp set portstate <port> <fid(0..15)> <state> */
+        state = _strtol(argv[2], NULL, 10);
+        ret = air_stp_setPortstate(0, port, fid, state);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Set STP Port:%u FID:%u State:", port, fid);
+            switch(state)
+            {
+                case AIR_STP_STATE_DISABLE:
+                    AIR_PRINT("Disable(STP) / Discard(RSTP).\n");
+                    break;
+                case AIR_STP_STATE_LISTEN:
+                    AIR_PRINT("Listening(STP) / Discard(RSTP).\n");
+                    break;
+                case AIR_STP_STATE_LEARN:
+                    AIR_PRINT("Learning(STP) / Learning(RSTP).\n");
+                    break;
+                case AIR_STP_STATE_FORWARD:
+                    AIR_PRINT("Forwarding(STP) / Forwarding(RSTP).\n");
+                    break;
+                default:
+                    break;
+            }
+        }
+        else
+        {
+            AIR_PRINT("Set STP Port:%u FID:%u State Fail.", port, fid);
+        }
+    }
+    else if(2 == argc)
+    {
+        /* stp get portstate <port> <fid(0..15)> */
+        ret = air_stp_getPortstate(0, port, fid, &state);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Get STP Port:%u FID:%u State:", port, fid);
+            switch(state)
+            {
+                case AIR_STP_STATE_DISABLE:
+                    AIR_PRINT("Disable(STP) / Discard(RSTP).\n");
+                    break;
+                case AIR_STP_STATE_LISTEN:
+                    AIR_PRINT("Listening(STP) / Discard(RSTP).\n");
+                    break;
+                case AIR_STP_STATE_LEARN:
+                    AIR_PRINT("Learning(STP) / Learning(RSTP).\n");
+                    break;
+                case AIR_STP_STATE_FORWARD:
+                    AIR_PRINT("Forwarding(STP) / Forwarding(RSTP).\n");
+                    break;
+                default:
+                    break;
+            }
+        }
+        else
+        {
+            AIR_PRINT("Get STP Port:%u FID:%u State Fail.", port, fid);
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doStpGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(stpGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doStpSet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(stpSetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doStp(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(stpCmds, argc, argv);
+}
+
+static void
+_mir_printPortList(UI32_T * mt)
+{
+    I8_T j = 0;
+    UI8_T first = 0;
+    UI8_T find = 0;
+    for(j = (AIR_MAX_NUM_OF_PORTS - 1); j >= 0; j--)
+    {
+        if((*mt) & (1 << j))
+        {
+            first = j;
+            find = 1;
+            break;
+        }
+    }
+    if(find)
+    {
+        for(j = 0; j < AIR_MAX_NUM_OF_PORTS; j++)
+        {
+            if((*mt) & (1 << j))
+            {
+                if(j == first)
+                    AIR_PRINT("%-2d", j);
+                else
+                    AIR_PRINT("%-2d,", j);
+            }
+        }
+    }
+    else
+        AIR_PRINT("NULL");
+    AIR_PRINT("\n");
+}
+
+static void
+_mir_printSrcPortList(
+    const UI32_T         unit,
+    const UI32_T         sessionid)
+{
+    I8_T i = 0;
+    AIR_MIR_SESSION_T   session;
+    AIR_PORT_BITMAP_T txPbm = {0}, rxPbm = {0};
+	AIR_ERROR_NO_T      rc = AIR_E_OK;
+
+    for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+    {
+         memset(&session, 0, sizeof(session));
+         session.src_port = i;
+         rc = air_mir_getMirrorPort(unit, sessionid, &session);
+		 if (AIR_E_OK != rc)
+		 {
+			AIR_PRINT("***Error***,get port=%u error\n", i);
+			return rc;
+		 }
+
+         if(session.flags & AIR_MIR_SESSION_FLAGS_DIR_TX)
+         {
+            txPbm[0] |= (1 << i);
+         }
+         if(session.flags & AIR_MIR_SESSION_FLAGS_DIR_RX)
+         {
+            rxPbm[0] |= (1 << i);
+         }
+    }
+    AIR_PRINT("Src PortList\n");
+    AIR_PRINT(" - Rx portlist = ");
+    _mir_printPortList(rxPbm);
+    AIR_PRINT(" - Tx portlist = ");
+    _mir_printPortList(txPbm);
+}
+
+static void
+_mir_printSession(
+    const UI32_T            unit,
+    const UI32_T            session_id,
+    const AIR_MIR_SESSION_T *ptr_session)
+{
+
+    AIR_PRINT("Session id: %d\n", session_id);
+    AIR_PRINT("State: %s \n", (ptr_session->flags & AIR_MIR_SESSION_FLAGS_ENABLE)? "enable": "disable");
+    AIR_PRINT("Tx tag: %s \n", (ptr_session->flags & AIR_MIR_SESSION_FLAGS_TX_TAG_OBEY_CFG)? "On": "Off");
+    AIR_PRINT("Dst port: %d \n", ptr_session->dst_port);
+    _mir_printSrcPortList(unit,session_id);
+}
+
+static AIR_ERROR_NO_T
+doMirrorGetSid(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T      rc = AIR_E_OK;
+    UI32_T              session_id = 0;
+    AIR_MIR_SESSION_T   session = {0};
+    I8_T i = 0;
+
+    session_id = _strtoul(argv[0], NULL, 0);
+    rc = air_mir_getSession(0, session_id, &session);
+    if (AIR_E_OK != rc)
+    {
+        AIR_PRINT("***Error***, get mirror session fail\n");
+        return rc;
+    }
+    /* print session information */
+    if(session.dst_port == AIR_PORT_INVALID)
+    {
+        AIR_PRINT("Session id %d not found\n", session_id);
+    }
+    else
+    {
+        _mir_printSession(0, session_id, &session);
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doMirrorDelSid(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T      rc = AIR_E_OK;
+    UI32_T              session_id = 0;
+    AIR_MIR_SESSION_T   session = {0};
+    UI8_T i = 0;
+
+    session_id = _strtoul(argv[0], NULL, 0);
+    rc = air_mir_delSession(0, session_id);
+    if (AIR_E_OK != rc)
+    {
+        AIR_PRINT("***Error***, del mirror session fail\n");
+        return rc;
+    }
+    for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+    {
+        session.src_port = i;
+        rc = air_mir_setMirrorPort(0, session_id, &session);
+        if (AIR_E_OK != rc)
+        {
+            AIR_PRINT("***Error***,port=%u error\n", i);
+            return rc;
+        }
+    }
+    if (rc != AIR_E_OK)
+    {
+        AIR_PRINT("***Error***, delete mirror session fail\n");
+    }
+    else
+        AIR_PRINT("***OK***, delete mirror session success\n");
+
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doMirrorAddRlist(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T      rc = AIR_E_OK;
+    UI32_T              session_id = 0;
+    AIR_MIR_SESSION_T   session = {0};
+    AIR_PORT_BITMAP_T rxPbm = {0};
+    UI8_T i = 0;
+
+    /*mirror add session-rlist <sid(0..3)> <list(UINTLIST)>*/
+    session_id = _strtoul(argv[0], NULL, 0);
+    rc = _portListStr2Ary(argv[1], rxPbm, 1);
+    if(rc != AIR_E_OK)
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return rc;
+    }
+    if(!rxPbm[0])
+    {
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            memset(&session, 0, sizeof(AIR_MIR_SESSION_T));
+            session.src_port = i;
+            rc = air_mir_getMirrorPort(0, session_id, &session);
+            if (AIR_E_OK != rc)
+            {
+                AIR_PRINT("***Error***,get port=%u error\n", i);
+                return rc;
+            }
+
+            session.flags &= ~AIR_MIR_SESSION_FLAGS_DIR_RX;
+            session.src_port = i;
+            rc = air_mir_setMirrorPort(0, session_id, &session);
+            if (AIR_E_OK != rc)
+            {
+                AIR_PRINT("***Error***,set rx port=%u error\n", i);
+                return rc;
+            }
+        }
+    }
+    else
+    {
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(rxPbm[0] & (1 << i))
+            {
+                memset(&session, 0, sizeof(AIR_MIR_SESSION_T));
+                session.src_port = i;
+                rc = air_mir_getMirrorPort(0, session_id, &session);
+                if (AIR_E_OK != rc)
+                {
+                    AIR_PRINT("***Error***,get port=%u error\n", i);
+                    return rc;
+                }
+
+                session.flags |= AIR_MIR_SESSION_FLAGS_DIR_RX;
+                session.src_port = i;
+                rc = air_mir_setMirrorPort(0, session_id, &session);
+                if (AIR_E_OK != rc)
+                {
+                    AIR_PRINT("***Error***,port=%u error\n", i);
+                    return rc;
+                }
+            }
+        }
+    }
+
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doMirrorAddTlist(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T      rc = AIR_E_OK;
+    UI32_T              session_id = 0;
+    AIR_MIR_SESSION_T   session = {0};
+    AIR_PORT_BITMAP_T txPbm = {0};
+    UI8_T i = 0;
+
+    /*mirror add session-tlist <sid(0..3)> <list(UINTLIST)>*/
+    session_id = _strtoul(argv[0], NULL, 0);
+    rc = _portListStr2Ary(argv[1], txPbm, 1);
+    if(rc != AIR_E_OK)
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return rc;
+    }
+    if(!txPbm[0])
+    {
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            memset(&session, 0, sizeof(AIR_MIR_SESSION_T));
+            session.src_port = i;
+            rc = air_mir_getMirrorPort(0, session_id, &session);
+            if (AIR_E_OK != rc)
+            {
+                AIR_PRINT("***Error***,get port=%u error\n", i);
+                return rc;
+            }
+
+            session.flags &= ~AIR_MIR_SESSION_FLAGS_DIR_TX;
+            session.src_port = i;
+            rc = air_mir_setMirrorPort(0, session_id, &session);
+            if (AIR_E_OK != rc)
+            {
+                AIR_PRINT("***Error***,set rx port=%u error\n", i);
+                return rc;
+            }
+        }
+    }
+    else
+    {
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(txPbm[0] & (1 << i))
+            {
+                memset(&session, 0, sizeof(AIR_MIR_SESSION_T));
+                session.src_port = i;
+                rc = air_mir_getMirrorPort(0, session_id, &session);
+                if (AIR_E_OK != rc)
+                {
+                    AIR_PRINT("***Error***,get port=%u error\n", i);
+                    return rc;
+                }
+
+                session.flags |= AIR_MIR_SESSION_FLAGS_DIR_TX;
+                session.src_port = i;
+                rc = air_mir_setMirrorPort(0, session_id, &session);
+                if (AIR_E_OK != rc)
+                {
+                    AIR_PRINT("***Error***,port=%u error\n", i);
+                    return rc;
+                }
+            }
+        }
+    }
+
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doMirrorSetSessionEnable(
+    UI32_T argc,
+    C8_T *argv[])
+
+{
+    AIR_ERROR_NO_T      rc = AIR_E_OK;
+    UI32_T              session_id = 0;
+    UI32_T              enable = 0;
+    BOOL_T              tmp_en = FALSE;
+
+    /*mirror set session-enable <sid(0..3)> <state(1:En,0:Dis)>*/
+    session_id = _strtoul(argv[0], NULL, 0);
+    enable = _strtoul(argv[1], NULL, 0);
+    if(enable)
+        tmp_en = TRUE;
+    /* set port mirror state */
+    rc = air_mir_setSessionAdminMode(0, session_id, tmp_en);
+    if(AIR_E_OK!=rc)
+    {
+        AIR_PRINT("***Error***\n");
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doMirrorSetSession(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T      rc = AIR_E_OK;
+    UI32_T              session_id = 0;
+    UI32_T              dst_port = 0;
+    UI8_T               enable = 0;
+    UI8_T               tag_en = 0;
+    UI8_T               dir = 0;
+    AIR_MIR_SESSION_T  session = {0};
+    AIR_PORT_BITMAP_T   rxPbm = {0};
+    I8_T               i = 0;
+
+    /*mirror set session <sid(0..3)> <dst_port(UINT)> <state(1:En,0:Dis)> <tag(1:on, 0:off)> <list(UINTLIST)> <dir(0:none,1:tx,2:rx,3:both)>*/
+    session_id = _strtoul(argv[0], NULL, 0);
+    dst_port = _strtoul(argv[1], NULL, 0);
+    AIR_PRINT("session id %d dst port %d.\n", session_id, dst_port);
+    session.dst_port = dst_port;
+    enable = _strtoul(argv[2], NULL, 0);
+    if(enable)
+    {
+        session.flags |= AIR_MIR_SESSION_FLAGS_ENABLE;
+    }
+    else
+    {
+        session.flags &= ~AIR_MIR_SESSION_FLAGS_ENABLE;
+    }
+    tag_en = _strtoul(argv[3], NULL, 0);
+    if(tag_en)
+    {
+        session.flags |= AIR_MIR_SESSION_FLAGS_TX_TAG_OBEY_CFG;
+    }
+    else
+    {
+        session.flags &= ~AIR_MIR_SESSION_FLAGS_TX_TAG_OBEY_CFG;
+    }
+    rc = _portListStr2Ary(argv[4], rxPbm, 1);
+    if(rc != AIR_E_OK)
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return rc;
+    }
+    AIR_PRINT("pbm %x.\n", rxPbm);
+    dir = _strtoul(argv[5], NULL, 0);
+    if(dir == 1)
+    {
+        session.flags |= AIR_MIR_SESSION_FLAGS_DIR_TX;
+    }
+    else if(dir == 2)
+    {
+        session.flags |= AIR_MIR_SESSION_FLAGS_DIR_RX;
+    }
+    else if(dir == 3)
+    {
+        session.flags |= AIR_MIR_SESSION_FLAGS_DIR_TX;
+        session.flags |= AIR_MIR_SESSION_FLAGS_DIR_RX;
+    }
+    else if (!dir)
+    {
+        session.flags &= ~AIR_MIR_SESSION_FLAGS_DIR_TX;
+        session.flags &= ~AIR_MIR_SESSION_FLAGS_DIR_RX;
+    }
+    else
+    {
+        return AIR_E_BAD_PARAMETER;
+    }
+    for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+    {
+        if(rxPbm[0] & (1 << i))
+        {
+            session.src_port = i;
+            /* set port mirror session */
+            rc = air_mir_addSession(0, session_id, &session);
+
+            if(AIR_E_OK!=rc)
+            {
+                AIR_PRINT("***Error***,dst-port=%u, src-port=%u error\n", session.dst_port, session.src_port);
+                return rc;
+            }
+            else
+                AIR_PRINT("add session %d,dst-port=%u, src-port=%u\n", session_id, session.dst_port, session.src_port);
+        }
+    }
+
+    return rc;
+}
+
+
+
+static AIR_ERROR_NO_T
+doMirrorSet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(mirrorSetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doMirrorAdd(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(mirrorAddCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doMirrorGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(mirrorGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doMirrorDel(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(mirrorDelCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doMirror(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(mirrorCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doMibClearPort(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+
+    if(1 == argc)
+    {
+        /* mib clear port */
+        port = _strtoul(argv[0], NULL, 0);
+        ret = air_mib_clear_by_port(0,port);
+        AIR_PRINT("Clear port %d mib stats",port);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Done.\n");
+        }
+        else
+        {
+            AIR_PRINT("Fail.\n");
+        }
+    }
+    else if(0 == argc)
+    {
+        /*restart mib counter*/
+        air_mib_clear(0);
+        AIR_PRINT("Clear all mib stats",port);
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doMibClearAcl(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+
+    if(0 == argc)
+    {
+        /* mib clear acl */
+        ret = air_mib_clearAclEvent(0);
+        AIR_PRINT("Clear ACL Event Counter ");
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Done.\n");
+        }
+        else
+        {
+            AIR_PRINT("Fail.\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doMibGetPort(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0;
+    UI32_T tmp32 = 0xffffffff;
+    AIR_MIB_CNT_RX_T rx_mib = {0};
+    AIR_MIB_CNT_TX_T tx_mib = {0};
+
+    port = _strtoul(argv[0], NULL, 0);
+    if(1 == argc)
+    {
+        /* mib get <port(0..6)> */
+        ret = air_mib_get(0, port, &rx_mib, &tx_mib);
+        AIR_PRINT("Get MIB Counter of Port %u ", port);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Done.\n");
+            AIR_PRINT("RX Drop Packet                    : %u\n", rx_mib.RDPC);
+            AIR_PRINT("RX filtering Packet               : %u\n", rx_mib.RFPC);
+            AIR_PRINT("RX Unicast Packet                 : %u\n", rx_mib.RUPC);
+            AIR_PRINT("RX Multicast Packet               : %u\n", rx_mib.RMPC);
+            AIR_PRINT("RX Broadcast Packet               : %u\n", rx_mib.RBPC);
+            AIR_PRINT("RX Alignment Error Packet         : %u\n", rx_mib.RAEPC);
+            AIR_PRINT("RX CRC Packet                     : %u\n", rx_mib.RCEPC);
+            AIR_PRINT("RX Undersize Packet               : %u\n", rx_mib.RUSPC);
+            AIR_PRINT("RX Fragment Error Packet          : %u\n", rx_mib.RFEPC);
+            AIR_PRINT("RX Oversize Packet                : %u\n", rx_mib.ROSPC);
+            AIR_PRINT("RX Jabber Error Packet            : %u\n", rx_mib.RJEPC);
+            AIR_PRINT("RX Pause Packet                   : %u\n", rx_mib.RPPC);
+            AIR_PRINT("RX Packet Length 64 bytes         : %u\n", rx_mib.RL64PC);
+            AIR_PRINT("RX Packet Length 65 ~ 127 bytes   : %u\n", rx_mib.RL65PC);
+            AIR_PRINT("RX Packet Length 128 ~ 255 bytes  : %u\n", rx_mib.RL128PC);
+            AIR_PRINT("RX Packet Length 256 ~ 511 bytes  : %u\n", rx_mib.RL256PC);
+            AIR_PRINT("RX Packet Length 512 ~ 1023 bytes : %u\n", rx_mib.RL512PC);
+            AIR_PRINT("RX Packet Length 1024 ~ 1518 bytes: %u\n", rx_mib.RL1024PC);
+            AIR_PRINT("RX Packet Length 1519 ~ max bytes : %u\n", rx_mib.RL1519PC);
+            AIR_PRINT("RX_CTRL Drop Packet               : %u\n", rx_mib.RCDPC);
+            AIR_PRINT("RX Ingress Drop Packet            : %u\n", rx_mib.RIDPC);
+            AIR_PRINT("RX ARL Drop Packet                : %u\n", rx_mib.RADPC);
+            AIR_PRINT("FLow Control Drop Packet          : %u\n", rx_mib.FCDPC);
+            AIR_PRINT("WRED Drop Packtet                 : %u\n", rx_mib.WRDPC);
+            AIR_PRINT("Mirror Drop Packet                : %u\n", rx_mib.MRDPC);
+            AIR_PRINT("RX  sFlow Sampling Packet         : %u\n", rx_mib.SFSPC);
+            AIR_PRINT("Rx sFlow Total Packet             : %u\n", rx_mib.SFTPC);
+            AIR_PRINT("Port Control Drop Packet          : %u\n", rx_mib.RXC_DPC);
+            AIR_PRINT("RX Octets good or bad packtes l32 : %u\n", (UI32_T)(rx_mib.ROC & tmp32));
+            AIR_PRINT("RX Octets good or bad packtes h32 : %u\n", (UI32_T)((rx_mib.ROC >> 32) & tmp32));
+            AIR_PRINT("RX Octets bad packets l32         : %u\n", (UI32_T)(rx_mib.ROC2 & tmp32));
+            AIR_PRINT("RX Octets bad packets h32         : %u\n", (UI32_T)((rx_mib.ROC2 >> 32) & tmp32));
+            AIR_PRINT("\n");
+            AIR_PRINT("TX Drop Packet                    : %u\n", tx_mib.TDPC);
+            AIR_PRINT("TX CRC Packet                     : %u\n", tx_mib.TCRC);
+            AIR_PRINT("TX Unicast Packet                 : %u\n", tx_mib.TUPC);
+            AIR_PRINT("TX Multicast Packet               : %u\n", tx_mib.TMPC);
+            AIR_PRINT("TX Broadcast Packet               : %u\n", tx_mib.TBPC);
+            AIR_PRINT("TX Collision Event Count          : %u\n", tx_mib.TCEC);
+            AIR_PRINT("TX Single Collision Event Count   : %u\n", tx_mib.TSCEC);
+            AIR_PRINT("TX Multiple Conllision Event Count: %u\n", tx_mib.TMCEC);
+            AIR_PRINT("TX Deferred Event Count           : %u\n", tx_mib.TDEC);
+            AIR_PRINT("TX Late Collision Event Count     : %u\n", tx_mib.TLCEC);
+            AIR_PRINT("TX Excessive Collision Event Count: %u\n", tx_mib.TXCEC);
+            AIR_PRINT("TX Pause Packet                   : %u\n", tx_mib.TPPC);
+            AIR_PRINT("TX Packet Length 64 bytes         : %u\n", tx_mib.TL64PC);
+            AIR_PRINT("TX Packet Length 65 ~ 127 bytes   : %u\n", tx_mib.TL65PC);
+            AIR_PRINT("TX Packet Length 128 ~ 255 bytes  : %u\n", tx_mib.TL128PC);
+            AIR_PRINT("TX Packet Length 256 ~ 511 bytes  : %u\n", tx_mib.TL256PC);
+            AIR_PRINT("TX Packet Length 512 ~ 1023 bytes : %u\n", tx_mib.TL512PC);
+            AIR_PRINT("TX Packet Length 1024 ~ 1518 bytes: %u\n", tx_mib.TL1024PC);
+            AIR_PRINT("TX Packet Length 1519 ~ max bytes : %u\n", tx_mib.TL1519PC);
+            AIR_PRINT("TX Oversize Drop Packet           : %u\n", tx_mib.TODPC);
+            AIR_PRINT("TX Octets good or bad packtes l32 : %u\n", (UI32_T)(tx_mib.TOC & tmp32));
+            AIR_PRINT("TX Octets good or bad packtes h32 : %u\n", (UI32_T)((tx_mib.TOC >> 32) & tmp32));
+            AIR_PRINT("TX Octets bad packets l32         : %u\n", (UI32_T)(tx_mib.TOC2 & tmp32));
+            AIR_PRINT("TX Octets bad packets h32         : %u\n", (UI32_T)((tx_mib.TOC2 >> 32) & tmp32));
+        }
+        else
+        {
+            AIR_PRINT("Fail.\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doMibGetAcl(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T event = 0;
+    UI32_T cnt = 0;
+
+    if(1 == argc)
+    {
+        /* mib get acl <event(0..7)> */
+        event = _strtoul(argv[0], NULL, 0);
+        ret = air_mib_getAclEvent(0, event, &cnt);
+        AIR_PRINT("Get counter of ACL event %u ", event);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Done.\n");
+            AIR_PRINT("ACL Event Counter:%u\n", cnt);
+        }
+        else
+        {
+            AIR_PRINT("Fail.\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doMibClear(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(mibClearCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doMibGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(mibGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doMib(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(mibCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doQosRateLimitExMngFrm(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T dir = 0;
+    BOOL_T enable = FALSE;
+
+    if(2 == argc)
+    {
+		dir = _strtoul(argv[0], NULL, 0);
+        if(dir == 0)
+            dir = AIR_QOS_RATE_DIR_EGRESS;
+        else if(dir == 1)
+            dir = AIR_QOS_RATE_DIR_INGRESS;
+        else
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            ret = AIR_E_BAD_PARAMETER;
+            return ret;
+        }
+        enable = _strtoul(argv[1], NULL, 0);
+        ret = air_qos_setRateLimitExMngFrm(0, dir, enable);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Success.\n");
+            AIR_PRINT("Set %s Rate Limit Control %s management frame.\n",
+                    (AIR_QOS_RATE_DIR_INGRESS == dir)?"Ingress":"Egress",
+                    (TRUE == enable)?"exclude":"include");
+        }
+        else
+        {
+            AIR_PRINT("Fail.\n");
+            return ret;
+        }
+    }
+    else if(0 == argc)
+    {
+        dir = AIR_QOS_RATE_DIR_EGRESS;
+        ret = air_qos_getRateLimitExMngFrm(0, dir, &enable);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Success.\n");
+            AIR_PRINT("Get %s Rate Limit Control %s management frame.\n",
+                    (AIR_QOS_RATE_DIR_INGRESS == dir)?"Ingress":"Egress",
+                    (TRUE == enable)?"exclude":"include");
+        }
+        else
+        {
+            AIR_PRINT("Fail.\n");
+            return ret;
+        }
+        dir = AIR_QOS_RATE_DIR_INGRESS;
+        ret = air_qos_getRateLimitExMngFrm(0, dir, &enable);
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT("Success.\n");
+            AIR_PRINT("Get %s Rate Limit Control %s management frame.\n",
+                    (AIR_QOS_RATE_DIR_INGRESS == dir)?"Ingress":"Egress",
+                    (TRUE == enable)?"exclude":"include");
+        }
+        else
+        {
+            AIR_PRINT("Fail.\n");
+            return ret;
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+
+}
+
+static AIR_ERROR_NO_T
+doQosPortPriority(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    AIR_PORT_BITMAP_T portlist = {0};
+    UI32_T priority = 0;
+    UI8_T i = 0;
+
+    ret = _portListStr2Ary(argv[0], portlist, 1);
+    if(ret != AIR_E_OK)
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return ret;
+    }
+    if(2 == argc)
+    {
+        priority = _strtoul(argv[1], NULL, 0);
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(portlist[0] & (1 << i))
+            {
+                ret = air_qos_setPortPriority(0, i, priority);
+                if(ret == AIR_E_OK)
+                {
+                    AIR_PRINT("Set Port%02d port based priority %d Success.\n", i, priority);
+                }
+                else
+                {
+                    AIR_PRINT("Set Port%02d port based priority %d Fail.\n", i, priority);
+                }
+            }
+        }
+    }
+    else if(1 == argc)
+    {
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(portlist[0] & (1 << i))
+            {
+                ret = air_qos_getPortPriority(0, i, &priority);
+                if(ret == AIR_E_OK)
+                {
+                    AIR_PRINT("Get Port%d port based priority %d.\n", i, priority);
+                }
+                else
+                {
+                    AIR_PRINT("Get Port%d port based priority Fail.\n", i);
+                }
+            }
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doQosRateLimit(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    AIR_PORT_BITMAP_T portlist = {0};
+    AIR_QOS_RATE_LIMIT_CFG_T rl = {0};
+    UI8_T i = 0;
+
+    ret = _portListStr2Ary(argv[0], portlist, 1);
+    if(ret != AIR_E_OK)
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return ret;
+    }
+    if(5 == argc)
+    {
+        rl.ingress_cir = _strtoul(argv[1], NULL, 0);
+        rl.ingress_cbs = _strtoul(argv[2], NULL, 0);
+        rl.egress_cir = _strtoul(argv[3], NULL, 0);
+        rl.egress_cbs = _strtoul(argv[4], NULL, 0);
+        rl.flags |= AIR_QOS_RATE_LIMIT_CFG_FLAGS_ENABLE_INGRESS;
+        rl.flags |= AIR_QOS_RATE_LIMIT_CFG_FLAGS_ENABLE_EGRESS;
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(portlist[0] & (1 << i))
+            {
+                ret = air_qos_setRateLimit(0, i, &rl);
+                if(ret == AIR_E_OK)
+                {
+                    AIR_PRINT("Set Port%02d Ingress CIR %d CBS %d Egress CIR %d CBS %d Success.\n", i, rl.ingress_cir, rl.ingress_cbs, rl.egress_cir, rl.egress_cbs);
+                }
+                else
+                {
+                    AIR_PRINT("Set Port%02d Ingress CIR %d CBS %d Egress CIR %d CBS %d Fail.\n", i, rl.ingress_cir, rl.ingress_cbs, rl.egress_cir, rl.egress_cbs);
+                }
+            }
+        }
+    }
+    else if(1 == argc)
+    {
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(portlist[0] & (1 << i))
+            {
+                ret = air_qos_getRateLimit(0, i, &rl);
+                if(ret == AIR_E_OK)
+                {
+                    AIR_PRINT("Get Port%02d Ingress CIR %d CBS %d Egress CIR %d CBS %d\n", i, rl.ingress_cir, rl.ingress_cbs, rl.egress_cir, rl.egress_cbs);
+                }
+                else
+                {
+                    AIR_PRINT("Get Port%02d Rate Info Fail.\n", i);
+                }
+            }
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doQosRateLimitEnable(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    AIR_PORT_BITMAP_T portlist = {0};
+    C8_T sten[2][10] = {"Disable", "Enable"};
+    C8_T stdir[2][10] = {"Egress", "Ingress"};
+    UI32_T dir = 0, en = 0;
+    AIR_QOS_RATE_DIR_T tmp_dir = AIR_QOS_RATE_DIR_LAST;
+    BOOL_T state = FALSE;
+    UI8_T i = 0;
+
+    ret = _portListStr2Ary(argv[0], portlist, 1);
+    if(ret != AIR_E_OK)
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return ret;
+    }
+    if(3 == argc)
+    {
+        dir = _strtoul(argv[1], NULL, 0);
+        en = _strtoul(argv[2], NULL, 0);
+        if(dir == 0)
+            tmp_dir = AIR_QOS_RATE_DIR_EGRESS;
+        else if(dir == 1)
+            tmp_dir = AIR_QOS_RATE_DIR_INGRESS;
+        else
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            return AIR_E_BAD_PARAMETER;
+        }
+        if(en)
+            state= TRUE;
+        else
+            state = FALSE;
+
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(portlist[0] & (1 << i))
+            {
+                ret = air_qos_setRateLimitEnable(0, i, tmp_dir, state);
+                if(AIR_E_OK == ret)
+                {
+                    AIR_PRINT("Set Port%02d %s rate %s Success.\n", i, stdir[dir], sten[en]);
+                }
+                else
+                {
+                    AIR_PRINT("Set Port%02d %s rate %s Fail.\n", i, stdir[dir], sten[en]);
+                }
+            }
+        }
+    }
+    else if(1 == argc)
+    {
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(portlist[0] & (1 << i))
+            {
+                tmp_dir = AIR_QOS_RATE_DIR_EGRESS;
+                dir = 0;
+                ret = air_qos_getRateLimitEnable(0, i, tmp_dir, &state);
+                if(AIR_E_OK == ret)
+                {
+                    AIR_PRINT("Get Port%02d %s rate %s Success.\n", i, stdir[dir], sten[state]);
+                }
+                else
+                {
+                    AIR_PRINT("Get Port%02d %s rate state Fail.\n", i, stdir[dir]);
+                }
+                tmp_dir = AIR_QOS_RATE_DIR_INGRESS;
+                dir = 1;
+                ret = air_qos_getRateLimitEnable(0, i, tmp_dir, &state);
+                if(AIR_E_OK == ret)
+                {
+                    AIR_PRINT("Get Port%02d %s rate %s Success.\n", i, stdir[dir], sten[state]);
+                }
+                else
+                {
+                    AIR_PRINT("Get Port%02d %s rate state Fail.\n", i, stdir[dir]);
+                }
+            }
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+
+}
+
+static AIR_ERROR_NO_T
+doQosDscp2Pri(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T dscp = 0, priority = 0;
+
+    dscp = _strtoul(argv[0], NULL, 0);
+    if(2 == argc)
+    {
+        priority = _strtoul(argv[1], NULL, 0);
+        ret = air_qos_setDscp2Pri(0, dscp, priority);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Set DSCP %d to priority %d Success.\n", dscp, priority);
+        }
+        else
+        {
+            AIR_PRINT("Set DSCP %d to priority %d Fail.\n", dscp, priority);
+        }
+    }
+    else if(1 == argc)
+    {
+        ret = air_qos_getDscp2Pri(0, dscp, &priority);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Get DSCP %d to priority %d\n", dscp, priority);
+        }
+        else
+        {
+            AIR_PRINT("Get DSCP %d to priority Fail.\n", dscp);
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doQosPri2Queue(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T priority = 0, queue = 0;
+
+    priority = _strtoul(argv[1], NULL, 0);
+
+    if(2 == argc)
+    {
+        priority = _strtoul(argv[0], NULL, 0);
+        queue = _strtoul(argv[1], NULL, 0);
+        ret = air_qos_setPri2Queue(0, priority, queue);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Set priority %d to queue %d Success.\n", priority, queue);
+        }
+        else
+        {
+            AIR_PRINT("Set priority %d to queue %d Fail.\n", priority, queue);
+        }
+    }
+    else
+    {
+        for(; priority < AIR_QOS_QUEUE_MAX_NUM; priority++)
+        {
+            ret = air_qos_getPri2Queue(0, priority, &queue);
+            if(AIR_E_OK == ret)
+            {
+                AIR_PRINT("Get priority %d to queue %d\n", priority, queue);
+            }
+            else
+            {
+                AIR_PRINT("Get priority %d to queue Fail.\n", priority);
+            }
+        }
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doQosTrustMode(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T mode = 0;
+    C8_T bs[4][13] = {"port", "1p_port", "dscp_port", "dscp_1p_port"};
+    AIR_QOS_TRUST_MODE_T mode_t = AIR_QOS_TRUST_MODE_LAST;
+    AIR_PORT_BITMAP_T portlist = {0};
+    UI8_T i = 0;
+
+    ret = _portListStr2Ary(argv[0], portlist, 1);
+    if(ret != AIR_E_OK)
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return ret;
+    }
+    if(2 == argc)
+    {
+        mode = _strtoul(argv[1], NULL, 0);
+        if(mode == 0)
+            mode_t = AIR_QOS_TRUST_MODE_PORT;
+        else if(mode == 1)
+            mode_t = AIR_QOS_TRUST_MODE_1P_PORT;
+        else if(mode == 2)
+            mode_t = AIR_QOS_TRUST_MODE_DSCP_PORT;
+        else if(mode == 3)
+            mode_t = AIR_QOS_TRUST_MODE_DSCP_1P_PORT;
+        else
+        {
+            AIR_PRINT("Unrecognized command.\n");
+            return AIR_E_BAD_PARAMETER;
+        }
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(portlist[0] & (1 << i))
+            {
+                ret = air_qos_setTrustMode(0, i, mode_t);
+                if(AIR_E_OK == ret)
+                {
+                    AIR_PRINT("port %d Set Trust mode %s Success.\n", i, bs[mode]);
+                }
+                else
+                {
+                    AIR_PRINT("port %d Set Trust mode %s Fail.\n", i, bs[mode]);
+                }
+            }
+        }
+    }
+    else if(1 == argc)
+    {
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(portlist[0] & (1 << i))
+            {
+                mode_t = AIR_QOS_TRUST_MODE_LAST;
+                ret = air_qos_getTrustMode(0, i, &mode_t);
+                if(AIR_E_OK == ret)
+                {
+                    if(mode_t == AIR_QOS_TRUST_MODE_PORT)
+                        mode = 0;
+                    else if(mode_t == AIR_QOS_TRUST_MODE_1P_PORT)
+                        mode = 1;
+                    else if(mode_t == AIR_QOS_TRUST_MODE_DSCP_PORT)
+                        mode = 2;
+                    else if(mode_t == AIR_QOS_TRUST_MODE_DSCP_1P_PORT)
+                        mode = 3;
+                    else
+                    {
+                        AIR_PRINT("port %d Get Trust mode Fail.\n", i);
+                        return AIR_E_OTHERS;
+                    }
+                    AIR_PRINT("port %d Get Trust mode %s\n", i, bs[mode]);
+                }
+                else
+                {
+                    AIR_PRINT("port %d Get Trust mode Fail.\n", i);
+                }
+            }
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doQosScheduleAlgo(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    AIR_PORT_BITMAP_T portlist = {0};
+    AIR_QOS_SCH_MODE_T sch_mode = AIR_QOS_SCH_MODE_LAST;
+    UI32_T scheduler = 0;
+    UI8_T queue = 0;
+    C8_T sche[3][5] = {"SP", "WRR", "WFQ"};
+    UI32_T weight = AIR_QOS_SHAPER_NOSETTING;
+    UI8_T i = 0;
+
+    ret = _portListStr2Ary(argv[0], portlist, 1);
+    if(ret != AIR_E_OK)
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return ret;
+    }
+    AIR_PRINT("port list is %d\n", portlist[0]);
+    if(4 == argc)
+    {
+        queue = _strtoul(argv[1], NULL, 0);
+        AIR_PRINT("queue is %d\n", queue);
+        scheduler = _strtoul(argv[2], NULL, 0);
+        AIR_PRINT("scheduler is %d\n", scheduler);
+        weight = _strtoul(argv[3], NULL, 0);
+        AIR_PRINT("weight is %d\n", weight);
+        if(scheduler == 0)
+        {
+            sch_mode = AIR_QOS_SCH_MODE_SP;
+            weight = AIR_QOS_SHAPER_NOSETTING;
+            if(weight != AIR_QOS_SHAPER_NOSETTING)
+                AIR_PRINT("[Warning] SP schedule mode no need weight\n");
+        }
+        else if(scheduler == 1)
+        {
+            sch_mode = AIR_QOS_SCH_MODE_WRR;
+            if(weight == AIR_QOS_SHAPER_NOSETTING)
+            {
+                AIR_PRINT("[Warning] No weight value input , plz check\n");
+                return AIR_E_BAD_PARAMETER;
+            }
+            AIR_PRINT("sch_mode is 1\n");
+        }
+        else if(scheduler == 2)
+        {
+            sch_mode = AIR_QOS_SCH_MODE_WFQ;
+            if(weight == AIR_QOS_SHAPER_NOSETTING)
+            {
+                AIR_PRINT("[Warning] No weight value input , plz check\n");
+                return AIR_E_BAD_PARAMETER;
+            }
+        }
+        else
+        {
+            AIR_PRINT("Unknown schedule mode, plz check again\n");
+            return AIR_E_BAD_PARAMETER;
+        }
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(portlist[0] & (1 << i))
+            {
+                AIR_PRINT("port %d\n", i);
+                ret = air_qos_setScheduleAlgo(0, i, queue, sch_mode, weight);
+                if(AIR_E_OK == ret)
+                {
+                    AIR_PRINT("Set Port%02d Scheduler %s Success.\n", i, sche[scheduler]);
+                }
+                else
+                {
+                    AIR_PRINT("Set Port%02d Scheduler %s Fail.\n", i, sche[scheduler]);
+                }
+            }
+        }
+    }
+    else if(2 == argc)
+    {
+        queue = _strtoul(argv[1], NULL, 0);
+        for(i = 0; i < AIR_MAX_NUM_OF_PORTS; i++)
+        {
+            if(portlist[0] & (1 << i))
+            {
+                ret = air_qos_getScheduleAlgo(0, i, queue, &sch_mode, &weight);
+                if(AIR_E_OK == ret)
+                {
+                    if(sch_mode == AIR_QOS_SCH_MODE_SP)
+                        AIR_PRINT("Get Port%02d queue %d Scheduler %s\n", i, queue, sche[sch_mode]);
+                    else if((sch_mode == AIR_QOS_SCH_MODE_WRR) || (sch_mode == AIR_QOS_SCH_MODE_WFQ))
+                        AIR_PRINT("Get Port%02d queue %d Scheduler %s weight %d\n", i, queue, sche[sch_mode], weight);
+                    else
+                        AIR_PRINT("Get Port%02d queue %d Scheduler unknown\n", i, queue);
+                }
+                else
+                {
+                    AIR_PRINT("Get Port%02d queue %d Scheduler Fail.\n", i, queue);
+                }
+            }
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doQosGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(qosGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doQosSet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(qosSetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doQos(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(qosCmds, argc, argv);
+}
+static AIR_ERROR_NO_T
+doDiagTxComply(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T phy = 0;
+    UI32_T mode = 0;
+
+    phy = _strtoul(argv[0], NULL, 0);
+    if(2 == argc)
+    {
+        /* diag set txComply <phy(0~5)> <mode(0~8)> */
+        mode = _strtoul(argv[1], NULL, 0);
+        ret = air_diag_setTxComplyMode(0, phy, mode);
+        AIR_PRINT("Set diagnostic function: PHY %u Tx Compliance mode = %u ", phy, mode);
+    }
+    else if(1 == argc)
+    {
+        /* diag get txComply <phy(0~5)> */
+        ret = air_diag_getTxComplyMode(0, phy, &mode);
+        AIR_PRINT("Get diagnostic function: PHY %u Tx Compliance mode ", phy);
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(AIR_E_OK == ret)
+    {
+        AIR_PRINT("Done.\n\tMode=");
+        switch(mode)
+        {
+            case AIR_DIAG_TXCOMPLY_MODE_10M_NLP:
+                AIR_PRINT("%s\n", "10M_NLP");
+                break;
+            case AIR_DIAG_TXCOMPLY_MODE_10M_RANDOM:
+                AIR_PRINT("%s\n", "10M_Random");
+                break;
+            case AIR_DIAG_TXCOMPLY_MODE_10M_SINE:
+                AIR_PRINT("%s\n", "10M_Sine");
+                break;
+            case AIR_DIAG_TXCOMPLY_MODE_100M_PAIR_A:
+                AIR_PRINT("%s\n", "100M_Pair_a");
+                break;
+            case AIR_DIAG_TXCOMPLY_MODE_100M_PAIR_B:
+                AIR_PRINT("%s\n", "100M_Pair_b");
+                break;
+            case AIR_DIAG_TXCOMPLY_MODE_1000M_TM1:
+                AIR_PRINT("%s\n", "1000M_TM1");
+                break;
+            case AIR_DIAG_TXCOMPLY_MODE_1000M_TM2:
+                AIR_PRINT("%s\n", "1000M_TM2");
+                break;
+            case AIR_DIAG_TXCOMPLY_MODE_1000M_TM3:
+                AIR_PRINT("%s\n", "1000M_TM3");
+                break;
+            case AIR_DIAG_TXCOMPLY_MODE_1000M_TM4:
+                AIR_PRINT("%s\n", "1000M_TM4");
+                break;
+            default:
+                break;
+        }
+    }
+    else
+    if(AIR_E_OTHERS == ret)
+    {
+        AIR_PRINT("isn't setting.\n");
+    }
+    else
+    {
+        AIR_PRINT("Fail.\n");
+    }
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doDiagSet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(diagSetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doDiagGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(diagGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doDiag(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(diagCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doLedMode(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T mode = 0;
+
+    if(1 == argc)
+    {
+        /* led set mode <mode(0:disable, 1~3:2 LED, 4:User-Define)> */
+        mode = _strtoul(argv[0], NULL, 0);
+        ret = air_led_setMode(0, 0, mode);
+        AIR_PRINT("Set LED mode ");
+    }
+    else if(0 == argc)
+    {
+        /* led get mode */
+        ret = air_led_getMode(0, 0, &mode);
+        AIR_PRINT("Get LED mode ");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(AIR_E_OK == ret)
+    {
+        switch(mode)
+        {
+            case AIR_LED_MODE_DISABLE:
+                AIR_PRINT(": Disabled.\n");
+                break;
+            case AIR_LED_MODE_2LED_MODE0:
+                AIR_PRINT(": LED 0:Link / LED 1:Activity.\n");
+                break;
+            case AIR_LED_MODE_2LED_MODE1:
+                AIR_PRINT(": LED 0:1000M Activity / LED 1:100M Activity.\n");
+                break;
+            case AIR_LED_MODE_2LED_MODE2:
+                AIR_PRINT(": LED 0:1000M Activity / LED 1:10&100M Activity.\n");
+                break;
+            case AIR_LED_MODE_USER_DEFINE:
+                AIR_PRINT(": User-Defined.\n");
+                break;
+            default:
+                AIR_PRINT(": Fail.\n");
+                break;
+        }
+    }
+    else
+    if(AIR_E_OTHERS == ret)
+    {
+        AIR_PRINT(": Unrecognized.\n");
+    }
+    else
+    {
+        AIR_PRINT("Fail.\n");
+    }
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doLedState(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI8_T entity = 0;
+    BOOL_T state = FALSE;
+
+    entity = _strtoul(argv[0], NULL, 0);
+    if(2 == argc)
+    {
+        /* led set state <led(0..1)> <state(1:En 0:Dis)> */
+        state = _strtoul(argv[1], NULL, 0);
+        ret = air_led_setState(0, 0, entity, state);
+        AIR_PRINT("Set LED %u state ", entity);
+    }
+    else if(1 == argc)
+    {
+        /* led get state <led(0..1)> */
+        ret = air_led_getState(0, 0, entity, &state);
+        AIR_PRINT("Get LED %u state ", entity );
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(AIR_E_OK == ret)
+    {
+        AIR_PRINT(": %s.\n", (state)?"Enable":"Disabled");
+    }
+    else
+    if(AIR_E_OTHERS == ret)
+    {
+        AIR_PRINT(": Unrecognized.\n");
+    }
+    else
+    {
+        AIR_PRINT("Fail.\n");
+    }
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doLedUsrDef(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T i = 0;
+    UI8_T entity = 0;
+    BOOL_T polarity = LOW;
+    UI32_T on_evt_map = 0;
+    UI32_T blk_evt_map = 0;
+    AIR_LED_ON_EVT_T on_evt;
+    AIR_LED_BLK_EVT_T blk_evt;
+
+    entity = _strtoul(argv[0], NULL, 0);
+    if(4 == argc)
+    {
+        /* led set usr <led(0..1)> <polarity(0:low, 1:high)> <on_evt(7'bin)> <blink_evt(10'bin)> */
+        polarity = _strtoul(argv[1], NULL, 0);
+        on_evt_map = _strtoul(argv[2], NULL, 2);
+        blk_evt_map = _strtoul(argv[3], NULL, 2);
+
+        memset(&on_evt, 0, sizeof(AIR_LED_ON_EVT_T));
+        if(on_evt_map & BIT(0))
+        {
+            on_evt.link_1000m = TRUE;
+        }
+        if(on_evt_map & BIT(1))
+        {
+            on_evt.link_100m = TRUE;
+        }
+        if(on_evt_map & BIT(2))
+        {
+            on_evt.link_10m = TRUE;
+        }
+        if(on_evt_map & BIT(3))
+        {
+            on_evt.link_dn = TRUE;
+        }
+        if(on_evt_map & BIT(4))
+        {
+            on_evt.fdx = TRUE;
+        }
+        if(on_evt_map & BIT(5))
+        {
+            on_evt.hdx = TRUE;
+        }
+        if(on_evt_map & BIT(6))
+        {
+            on_evt.force = TRUE;
+        }
+
+        memset(&blk_evt, 0, sizeof(AIR_LED_BLK_EVT_T));
+        if(blk_evt_map & BIT(0))
+        {
+            blk_evt.tx_act_1000m = TRUE;
+        }
+        if(blk_evt_map & BIT(1))
+        {
+            blk_evt.rx_act_1000m = TRUE;
+        }
+        if(blk_evt_map & BIT(2))
+        {
+            blk_evt.tx_act_100m = TRUE;
+        }
+        if(blk_evt_map & BIT(3))
+        {
+            blk_evt.rx_act_100m = TRUE;
+        }
+        if(blk_evt_map & BIT(4))
+        {
+            blk_evt.tx_act_10m = TRUE;
+        }
+        if(blk_evt_map & BIT(5))
+        {
+            blk_evt.rx_act_10m = TRUE;
+        }
+        if(blk_evt_map & BIT(6))
+        {
+            blk_evt.cls = TRUE;
+        }
+        if(blk_evt_map & BIT(7))
+        {
+            blk_evt.rx_crc = TRUE;
+        }
+        if(blk_evt_map & BIT(8))
+        {
+            blk_evt.rx_idle = TRUE;
+        }
+        if(blk_evt_map & BIT(9))
+        {
+            blk_evt.force = TRUE;
+        }
+        ret = air_led_setUsrDef(0, 0, entity, polarity, on_evt, blk_evt);
+        AIR_PRINT("Set LED %u User-define ", entity);
+    }
+    else if(1 == argc)
+    {
+        /* led get usr <led(0..1)> */
+        ret = air_led_getUsrDef(0, 0, entity, &polarity, &on_evt, &blk_evt);
+        AIR_PRINT("Get LED %u User-define ", entity );
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(AIR_E_OK == ret)
+    {
+        AIR_PRINT("Done.\n");
+        AIR_PRINT("Polarity:%u.\n", polarity);
+        AIR_PRINT("On Event:\n");
+        i = 6;
+        AIR_PRINT("\t(%u)Force on :%s\n", i--, (on_evt.force)?"On":"Off");
+        AIR_PRINT("\t(%u)Half Duplex :%s\n", i--, (on_evt.hdx)?"On":"Off");
+        AIR_PRINT("\t(%u)Full Duplex :%s\n", i--, (on_evt.fdx)?"On":"Off");
+        AIR_PRINT("\t(%u)Link Down :%s\n", i--, (on_evt.link_dn)?"On":"Off");
+        AIR_PRINT("\t(%u)Link 10M :%s\n", i--, (on_evt.link_10m)?"On":"Off");
+        AIR_PRINT("\t(%u)Link 100M :%s\n", i--, (on_evt.link_100m)?"On":"Off");
+        AIR_PRINT("\t(%u)Link 1000M :%s\n", i, (on_evt.link_1000m)?"On":"Off");
+
+        AIR_PRINT("Blinking Event:\n");
+        i = 9;
+        AIR_PRINT("\t(%u)Force blinks :%s\n", i--, (blk_evt.force)?"On":"Off");
+        AIR_PRINT("\t(%u)Rx Idle Error :%s\n", i--, (blk_evt.rx_idle)?"On":"Off");
+        AIR_PRINT("\t(%u)Rx CRC Error :%s\n", i--, (blk_evt.rx_crc)?"On":"Off");
+        AIR_PRINT("\t(%u)Collision :%s\n", i--, (blk_evt.cls)?"On":"Off");
+        AIR_PRINT("\t(%u)10Mbps RX Activity :%s\n", i--, (blk_evt.rx_act_10m)?"On":"Off");
+        AIR_PRINT("\t(%u)10Mbps TX Activity :%s\n", i--, (blk_evt.tx_act_10m)?"On":"Off");
+        AIR_PRINT("\t(%u)100Mbps RX Activity :%s\n", i--, (blk_evt.rx_act_100m)?"On":"Off");
+        AIR_PRINT("\t(%u)100Mbps TX Activity :%s\n", i--, (blk_evt.tx_act_100m)?"On":"Off");
+        AIR_PRINT("\t(%u)1000Mbps RX Activity :%s\n", i--, (blk_evt.rx_act_1000m)?"On":"Off");
+        AIR_PRINT("\t(%u)1000Mbps TX Activity :%s\n", i, (blk_evt.tx_act_1000m)?"On":"Off");
+    }
+    else
+    {
+        AIR_PRINT("Fail.\n");
+    }
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doLedBlkTime(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    AIR_LED_BLK_DUR_T time = 0;
+
+    if(1 == argc)
+    {
+        /* led set time <time(0~5)> */
+        time = _strtoul(argv[0], NULL, 0);
+        ret = air_led_setBlkTime(0, 0, time);
+        AIR_PRINT("Set Blinking Duration ");
+    }
+    else if(0 == argc)
+    {
+        /* led get time */
+        ret = air_led_getBlkTime(0, 0, &time);
+        AIR_PRINT("Get Blinking Duration ");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(AIR_E_OK == ret)
+    {
+        AIR_PRINT("Done.\n");
+        AIR_PRINT("\tBlinking duration : %u (ms)\n", (32 << time) );
+    }
+    else
+    {
+        AIR_PRINT("Fail.\n");
+    }
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doLedSet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(ledSetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doLedGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(ledGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doLed(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(ledCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doShowVersion(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_PRINT("VERSION: %s\n", AIR_VER_SDK);
+
+    return AIR_E_OK;
+}
+
+static AIR_ERROR_NO_T
+doShow(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(showCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doStormRate(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0, type = 0;
+    UI32_T unit = 0, count = 0;
+    C8_T stype[3][5] = {"Bcst", "Mcst", "Ucst"};
+    UI32_T kb = 0;
+
+    port = _strtol(argv[0], NULL, 10);
+    type = _strtol(argv[1], NULL, 10);
+    if(4 == argc)
+    {
+        count = _strtol(argv[2], NULL, 10);
+        unit = _strtol(argv[3], NULL, 10);
+
+        if(0 == unit)
+            kb = 64;
+        else if(1 == unit)
+            kb = 256;
+        else if(2 == unit)
+            kb = 1024;
+        else if(3 == unit)
+            kb = 4096;
+        else
+            kb = 16384;
+        ret = air_sec_setStormRate(0, port, type, count, unit);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Set Port%02d %s storm rate (%d * %d) = %d Kbps\n", port, stype[type], count, kb, (count*kb));
+        }
+        else
+        {
+            AIR_PRINT("Set Port%02d %s storm rate Fail.\n", port, stype[type]);
+            AIR_PRINT("Note: Port(0..4) can only select unit(0..3), port(5..6) can only select unit(4)\n");
+        }
+    }
+    else if(2 == argc)
+    {
+        ret = air_sec_getStormRate(0, port, type, &count, &unit);
+        if(AIR_E_OK == ret)
+        {
+            if(0 == unit)
+                kb = 64;
+            else if(1 == unit)
+                kb = 256;
+            else if(2 == unit)
+                kb = 1024;
+            else if(3 == unit)
+                kb = 4096;
+            else
+                kb = 16384;
+            AIR_PRINT("Port%02d %s storm rate (%d * %d) = %d Kbps\n", port, stype[type], count, kb, (count*kb));
+        }
+        else
+        {
+            AIR_PRINT("Get Port%02d %s storm rate Fail\n", port, stype[type]);
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doFldMode(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0, type = 0;
+    BOOL_T fld_en = 0;
+    C8_T stype[4][5] = {"Bcst", "Mcst", "Ucst", "Qury"};
+    C8_T sen[2][10] = {"Disable", "Enable"};
+
+    port = _strtol(argv[0], NULL, 10);
+    type = _strtol(argv[1], NULL, 10);
+
+    if(2 == argc)
+    {
+        ret = air_sec_getFldMode(0, port, type, &fld_en);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Get Port%02d flooding %s frame %s\n", port, stype[type], sen[fld_en]);
+        }
+        else
+        {
+            AIR_PRINT("Get Port%02d flooding %s frame Fail\n", port, stype[type]);
+        }
+    }
+    else if(3 == argc)
+    {
+        fld_en = _strtol(argv[2], NULL, 10);
+        ret = air_sec_setFldMode(0, port, type, fld_en);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Set Port%02d flooding %s frame %s Success\n", port, stype[type], sen[fld_en]);
+        }
+        else
+        {
+            AIR_PRINT("Set Port%02d flooding %s frame %s Fail\n", port, stype[type], sen[fld_en]);
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doStormEnable(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T port = 0, type = 0;
+    BOOL_T en = 0;
+    C8_T sen[2][10] = {"Disable", "Enable"};
+    C8_T stype[3][5] = {"Bcst", "Mcst", "Ucst"};
+
+    port = _strtol(argv[0], NULL, 10);
+    type = _strtol(argv[1], NULL, 10);
+    if(3 == argc)
+    {
+        en = _strtol(argv[2], NULL, 10);
+        ret = air_sec_setStormEnable(0, port, type, en);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Set Port%02d %s storm %s Success.\n", port, stype[type], sen[en]);
+        }
+        else
+        {
+            AIR_PRINT("Set Port%02d %s storm %s Fail.\n", port, stype[type], sen[en]);
+        }
+    }
+    else if(2 == argc)
+    {
+        ret = air_sec_getStormEnable(0, port, type, &en);
+        if(AIR_E_OK == ret)
+        {
+            AIR_PRINT("Port%02d %s storm %s\n", port, stype[type], sen[en]);
+        }
+        else
+        {
+            AIR_PRINT("Get Port%02d %s storm Fail\n", port, stype[type]);
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doSaLearning(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    AIR_SEC_PORTSEC_PORT_CONFIG_T port_config;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    if(2 == argc)
+    {
+        memset(&port_config, 0, sizeof(AIR_SEC_PORTSEC_PORT_CONFIG_T));
+        rc = air_sec_getPortSecPortCfg(0, port, &port_config);
+        port_config.sa_lrn_en = _strtoul(argv[1], NULL, 0);
+        rc = air_sec_setPortSecPortCfg(0, port, port_config);
+        if(AIR_E_OK == rc)
+        {
+            AIR_PRINT("Set Port%02d sa learn %s Success.\n", port, port_config.sa_lrn_en?"Enable":"Disable");
+        }
+        else
+        {
+            AIR_PRINT("Set Port%02d sa learn %s Fail.\n", port, port_config.sa_lrn_en?"Enable":"Disable");
+        }
+    }
+    else if(1 == argc)
+    {
+        rc = air_sec_getPortSecPortCfg(0, port, &port_config);
+        if(AIR_E_OK == rc)
+        {
+            AIR_PRINT("Port%02d sa learn: %s\n", port, port_config.sa_lrn_en?"Enable":"Disable");
+        }
+        else
+        {
+            AIR_PRINT("Get Port%02d sa learn Fail\n", port);
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        rc = AIR_E_BAD_PARAMETER;
+    }
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doSaLimit(UI32_T argc, C8_T *argv[])
+{
+    UI32_T port = 0;
+    AIR_SEC_PORTSEC_PORT_CONFIG_T port_config;
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+
+    port = _strtoul(argv[0], NULL, 0);
+    if(3 == argc)
+    {
+        memset(&port_config, 0, sizeof(AIR_SEC_PORTSEC_PORT_CONFIG_T));
+        rc = air_sec_getPortSecPortCfg(0, port, &port_config);
+        port_config.sa_lmt_en = _strtoul(argv[1], NULL, 0);
+        port_config.sa_lmt_cnt = _strtoul(argv[2], NULL, 0);
+        rc = air_sec_setPortSecPortCfg(0, port, port_config);
+        if(AIR_E_OK == rc)
+        {
+            AIR_PRINT("Set Port%02d sa limit %s Success.\n", port, port_config.sa_lmt_en?"Enable":"Disable");
+        }
+        else
+        {
+            AIR_PRINT("Set Port%02d sa limit %s Fail.\n", port, port_config.sa_lmt_en?"Enable":"Disable");
+        }
+    }
+    else if(1 == argc)
+    {
+        rc = air_sec_getPortSecPortCfg(0, port, &port_config);
+        if(AIR_E_OK == rc)
+        {
+            AIR_PRINT("Port%02d ", port);
+            AIR_PRINT("sa limit: %s\n", port_config.sa_lmt_en?"Enable":"Disable");
+            if(TRUE == (port_config.sa_lmt_en && (AIR_MAX_NUM_OF_MAC ==  port_config.sa_lmt_cnt)))
+            {
+                AIR_PRINT("Sa learning without limitation\n");
+            }
+            else if(TRUE == (port_config.sa_lmt_en && (AIR_MAX_NUM_OF_MAC >  port_config.sa_lmt_cnt)))
+            {
+                AIR_PRINT("Rx sa allowable learning number: %d\n", port_config.sa_lmt_cnt);
+            }
+        }
+        else
+        {
+            AIR_PRINT("Get Port%02d sa limit Fail\n", port);
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        rc = AIR_E_BAD_PARAMETER;
+    }
+
+    return rc;
+}
+
+static AIR_ERROR_NO_T
+doSecGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(secGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doSecSet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(secSetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doSec(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(secCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doSwitchCpuPortEn(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    BOOL_T cpu_en = FALSE;
+
+    if(0 == argc)
+    {
+        /* switch get sysPhyEn */
+        ret = air_switch_getCpuPortEn(0, &cpu_en);
+        AIR_PRINT("Get Cpu Port State ");
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT(": %s\n", cpu_en?"Enable":"Disable");
+        }
+        else
+        {
+            AIR_PRINT("Fail!\n");
+        }
+    }
+    else if(1 == argc)
+    {
+        /* switch set sysPhyEn <phy_en> */
+        cpu_en = _strtol(argv[0], NULL, 0);
+        ret = air_switch_setCpuPortEn(0, cpu_en);
+        AIR_PRINT("Set CPU port State ");
+        if(ret == AIR_E_OK)
+        {
+            AIR_PRINT(": %s\n", cpu_en?"Enable":"Disable");
+        }
+        else
+        {
+            AIR_PRINT("Fail!\n");
+        }
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doSwitchCpuPort(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    BOOL_T cpu_en = FALSE;
+    UI32_T port = 0;
+    C8_T str_temp[AIR_MAX_NUM_OF_PORTS+1];
+
+    if(1 == argc)
+    {
+        /* switch set cpuPort <portnumber> */
+        port = _strtol(argv[0], NULL, 10);
+        ret = air_switch_setCpuPort(0, port);
+        AIR_PRINT("Set CPU Port ");
+    }
+    else if(0 == argc)
+    {
+        /* switch get cpuPort */
+        ret = air_switch_getCpuPort(0, &port);
+        AIR_PRINT("Get CPU Port ");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    if(AIR_E_OK == ret)
+    {
+        AIR_PRINT(": %d\n", port);
+    }
+    else
+    {
+        AIR_PRINT("Fail!\n");
+    }
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doSwitchPhyLCIntrEn(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T phy = 0;
+    BOOL_T enable = FALSE;
+
+    if(2 == argc)
+    {
+        /* switch set phyLCIntrEn <phy(0..6)> <(1:En,0:Dis)> */
+        phy    = _strtol(argv[0], NULL, 10);
+        enable = _strtol(argv[1], NULL, 10);
+        ret    = air_switch_setSysIntrEn(0, (phy + AIR_SYS_INTR_TYPE_PHY0_LC), enable);
+    }
+    else if(1 == argc)
+    {
+        /* switch get phyLCIntrEn <phy(0..6)> */
+        phy = _strtol(argv[0], NULL, 10);
+        ret = air_switch_getSysIntrEn(0, (phy + AIR_SYS_INTR_TYPE_PHY0_LC), &enable);
+        AIR_PRINT("PHY(%d) LinkChange interrupt : %s\n", phy, (TRUE == enable) ? "enable" : "disable");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doSwitchPhyLCIntrSts(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T phy = 0;
+    BOOL_T enable = FALSE;
+
+    if(2 == argc)
+    {
+        /* switch set phyLCIntrSts <phy(0..6)> <(1:En)> */
+        phy    = _strtol(argv[0], NULL, 10);
+        enable = _strtol(argv[1], NULL, 10);
+        ret    = air_switch_setSysIntrStatus(0, (phy + AIR_SYS_INTR_TYPE_PHY0_LC), enable);
+    }
+    else if(1 == argc)
+    {
+        /* switch get phyLCIntrSts <phy(0..6)> */
+        phy = _strtol(argv[0], NULL, 10);
+        ret = air_switch_getSysIntrStatus(0, (phy + AIR_SYS_INTR_TYPE_PHY0_LC), &enable);
+        AIR_PRINT("PHY(%d) LinkChange interrupt state : %s\n", phy, (TRUE == enable) ? "set" : "unset");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        ret = AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+
+static AIR_ERROR_NO_T
+doSwitchSet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(switchSetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doSwitchGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(switchGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doSwitch(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(switchCmds, argc, argv);
+}
+
+static void _air_acl_printRuleMap(UI32_T *rule_map, UI32_T ary_num)
+{
+    UI32_T i;
+    BOOL_T first;
+
+    first = TRUE;
+    for(i=0; i<ary_num*32; i++)
+    {
+        if(rule_map[i/32] & BIT(i%32))
+        {
+            if(TRUE == first)
+            {
+                AIR_PRINT("%u", i);
+                first = FALSE;
+            }
+            else
+            {
+                AIR_PRINT(",%u", i);
+            }
+        }
+    }
+    AIR_PRINT("\n");
+}
+
+static AIR_ERROR_NO_T
+doAclEn(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T argi=0;
+    UI32_T port = 0;
+    BOOL_T en = FALSE;
+
+    if(1 == argc)
+    {
+        /* acl set en <en(1:En,0:Dis)> */
+        en = _strtoul(argv[argi++], NULL, 2);
+        ret = air_acl_setGlobalState(0, en);
+        AIR_PRINT("Set Global ACL function ");
+    }
+    else if(0 == argc)
+    {
+        /* acl get en */
+        ret = air_acl_getGlobalState(0, &en);
+        AIR_PRINT("Get Global ACL function ");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        AIR_PRINT(": %s\n", (TRUE == en)?"Enable":"Disable");
+    }
+    else
+    {
+        AIR_PRINT("Fail!\n");
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclRule(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T rule_idx = 0;
+    BOOL_T state = FALSE, reverse = FALSE, end = FALSE;
+    UI32_T argi = 0, ipv6 = 0, i = 0;
+    AIR_ACL_RULE_T rule;
+    UI8_T tmp_ip[16] = {0};
+    C8_T str_temp[AIR_MAX_NUM_OF_PORTS+1];
+    C8_T str[40];
+
+    memset(&rule, 0, sizeof(AIR_ACL_RULE_T));
+    if(argc >= 6)
+    {
+        /* acl set rule <idx(0..255)> <state(0:Dis,1:En)> <reverse(0:Dis,1:En)> <end(0:Dis,1:En)> <portmap(7'bin)>
+        <ipv6(0:Dis,1:En,2:Not care)>
+        [ dmac <dmac(12'hex)> <dmac_mask(12'hex)> ]
+        [ smac <smac(12'hex)> <smac_mask(12'hex)> ]
+        [ stag <stag(4'hex)> <stag_mask(4'hex)> ]
+        [ ctag <ctag(4'hex)> <ctag_mask(4'hex)> ]
+        [ etype <etype(4'hex)> <etype_mask(4'hex)> ]
+        [ dip <dip(IPADDR)> <dip_mask(IPADDR)> ]
+        [ sip <sip(IPADDR)> <sip_mask(IPADDR)> ]
+        [ dscp <dscp(2'hex)> <dscp_mask(2'hex)> ]
+        [ protocol <protocol(2'hex)> <protocol_mask(2'hex)> ]
+        [ dport <dport(4'hex)> <dport_mask(4'hex)> ]
+        [ sport <sport(4'hex)> <sport_mask(4'hex)> ]
+        [ flow_label <flow_label(4'hex)> <flow_label_mask(4'hex)> ]
+        [ udf <udf(4'hex)> <udf_mask(4'hex)> ] */
+
+        rule_idx = _strtoul(argv[argi++], NULL, 0);
+
+        rule.ctrl.rule_en = _strtoul(argv[argi++], NULL, 0);
+        rule.ctrl.reverse = _strtoul(argv[argi++], NULL, 0);
+        rule.ctrl.end = _strtoul(argv[argi++], NULL, 0);
+
+        rule.key.portmap = _strtoul(argv[argi++], NULL, 2);
+        rule.mask.portmap = (~rule.key.portmap) & AIR_ALL_PORT_BITMAP;
+
+        ipv6 = _strtoul(argv[argi++], NULL, 0);
+        if(0 == ipv6)
+        {
+            rule.key.isipv6 = FALSE;
+            rule.mask.isipv6 = TRUE;
+        }
+        else if(1 == ipv6)
+        {
+            rule.key.isipv6 = TRUE;
+            rule.mask.isipv6 = TRUE;
+        }
+        else
+        {
+            rule.mask.isipv6 = FALSE;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "dmac")))
+        {
+            argi++;
+            _str2mac(argv[argi++], rule.key.dmac);
+            _str2mac(argv[argi++], rule.mask.dmac);
+            rule.key.fieldmap |= 1 << AIR_ACL_DMAC;
+        }
+        if((argi < argc) && (0 == _strcmp(argv[argi], "smac")))
+        {
+            argi++;
+            _str2mac(argv[argi++], rule.key.smac);
+            _str2mac(argv[argi++], rule.mask.smac);
+            rule.key.fieldmap |= 1 << AIR_ACL_SMAC;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "stag")))
+        {
+            argi++;
+            rule.key.stag = _strtoul(argv[argi++], NULL, 16);
+            rule.mask.stag = _strtoul(argv[argi++], NULL, 16);
+            rule.key.fieldmap |= 1 << AIR_ACL_STAG;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "ctag")))
+        {
+            argi++;
+            rule.key.ctag = _strtoul(argv[argi++], NULL, 16);
+            rule.mask.ctag = _strtoul(argv[argi++], NULL, 16);
+            rule.key.fieldmap |= 1 << AIR_ACL_CTAG;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "etype")))
+        {
+            argi++;
+            rule.key.etype= _strtoul(argv[argi++], NULL, 16);
+            rule.mask.etype = _strtoul(argv[argi++], NULL, 16);
+            rule.key.fieldmap |= 1 << AIR_ACL_ETYPE;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "dip")))
+        {
+            argi++;
+            if(0 == ipv6)
+            {
+                _str2ipv4(argv[argi++], rule.key.dip);
+                _str2ipv4(argv[argi++], rule.mask.dip);
+            }
+            else if(1 == ipv6)
+            {
+                _str2ipv6(argv[argi++], tmp_ip);
+                rule.key.dip[3] = (tmp_ip[0]<<24) | (tmp_ip[1]<<16) | (tmp_ip[2]<<8) | tmp_ip[3];
+                rule.key.dip[2] = (tmp_ip[4]<<24) | (tmp_ip[5]<<16) | (tmp_ip[6]<<8) | tmp_ip[7];
+                rule.key.dip[1] = (tmp_ip[8]<<24) | (tmp_ip[9]<<16) | (tmp_ip[10]<<8) | tmp_ip[11];
+                rule.key.dip[0] = (tmp_ip[12]<<24) | (tmp_ip[13]<<16) | (tmp_ip[14]<<8) | tmp_ip[15];
+                _str2ipv6(argv[argi++], tmp_ip);
+                rule.mask.dip[3] = (tmp_ip[0]<<24) | (tmp_ip[1]<<16) | (tmp_ip[2]<<8) | tmp_ip[3];
+                rule.mask.dip[2] = (tmp_ip[4]<<24) | (tmp_ip[5]<<16) | (tmp_ip[6]<<8) | tmp_ip[7];
+                rule.mask.dip[1] = (tmp_ip[8]<<24) | (tmp_ip[9]<<16) | (tmp_ip[10]<<8) | tmp_ip[11];
+                rule.mask.dip[0] = (tmp_ip[12]<<24) | (tmp_ip[13]<<16) | (tmp_ip[14]<<8) | tmp_ip[15];
+            }
+            rule.key.fieldmap |= 1 << AIR_ACL_DIP;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "sip")))
+        {
+            argi++;
+            if(0 == ipv6)
+            {
+                _str2ipv4(argv[argi++], rule.key.sip);
+                _str2ipv4(argv[argi++], rule.mask.sip);
+            }
+            else if(1 == ipv6)
+            {
+                _str2ipv6(argv[argi++], tmp_ip);
+                rule.key.sip[3] = (tmp_ip[0]<<24) | (tmp_ip[1]<<16) | (tmp_ip[2]<<8) | tmp_ip[3];
+                rule.key.sip[2] = (tmp_ip[4]<<24) | (tmp_ip[5]<<16) | (tmp_ip[6]<<8) | tmp_ip[7];
+                rule.key.sip[1] = (tmp_ip[8]<<24) | (tmp_ip[9]<<16) | (tmp_ip[10]<<8) | tmp_ip[11];
+                rule.key.sip[0] = (tmp_ip[12]<<24) | (tmp_ip[13]<<16) | (tmp_ip[14]<<8) | tmp_ip[15];
+                _str2ipv6(argv[argi++], tmp_ip);
+                rule.mask.sip[3] = (tmp_ip[0]<<24) | (tmp_ip[1]<<16) | (tmp_ip[2]<<8) | tmp_ip[3];
+                rule.mask.sip[2] = (tmp_ip[4]<<24) | (tmp_ip[5]<<16) | (tmp_ip[6]<<8) | tmp_ip[7];
+                rule.mask.sip[1] = (tmp_ip[8]<<24) | (tmp_ip[9]<<16) | (tmp_ip[10]<<8) | tmp_ip[11];
+                rule.mask.sip[0] = (tmp_ip[12]<<24) | (tmp_ip[13]<<16) | (tmp_ip[14]<<8) | tmp_ip[15];
+            }
+            rule.key.fieldmap |= 1 << AIR_ACL_SIP;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "dscp")))
+        {
+            argi++;
+            rule.key.dscp = _strtoul(argv[argi++], NULL, 16);
+            rule.mask.dscp = _strtoul(argv[argi++], NULL, 16);
+            rule.key.fieldmap |= 1 << AIR_ACL_DSCP;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "protocol")))
+        {
+            argi++;
+            rule.key.protocol = _strtoul(argv[argi++], NULL, 16);
+            rule.mask.protocol = _strtoul(argv[argi++], NULL, 16);
+            rule.key.fieldmap |= 1 << AIR_ACL_PROTOCOL;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "dport")))
+        {
+            argi++;
+            rule.key.dport = _strtoul(argv[argi++], NULL, 16);
+            rule.mask.dport = _strtoul(argv[argi++], NULL, 16);
+            rule.key.fieldmap |= 1 << AIR_ACL_DPORT;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "sport")))
+        {
+            argi++;
+            rule.key.sport = _strtoul(argv[argi++], NULL, 16);
+            rule.mask.sport = _strtoul(argv[argi++], NULL, 16);
+            rule.key.fieldmap |= 1 << AIR_ACL_SPORT;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "flow_label")))
+        {
+            argi++;
+            rule.key.flow_label= _strtoul(argv[argi++], NULL, 16);
+            rule.mask.flow_label= _strtoul(argv[argi++], NULL, 16);
+            rule.key.fieldmap |= 1 << AIR_ACL_FLOW_LABEL;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "udf")))
+        {
+            argi++;
+            rule.key.udf = _strtoul(argv[argi++], NULL, 16);
+            rule.mask.udf = _strtoul(argv[argi++], NULL, 16);
+            rule.key.fieldmap |= 1 << AIR_ACL_UDF;
+        }
+        rule.mask.fieldmap = rule.key.fieldmap;
+        ret = air_acl_setRule(0, rule_idx, &rule);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Set ACL Rule(%u): %s\n", rule_idx, air_error_getString(ret));
+    }
+    else if(1 == argc)
+    {
+        rule_idx = _strtoul(argv[0], NULL, 0);
+        ret = air_acl_getRule(0, rule_idx, &rule);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Get ACL Rule(%u): %s\n", rule_idx, air_error_getString(ret));
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(AIR_E_OK == ret)
+    {
+        if(TRUE == rule.ctrl.rule_en)
+        {
+            AIR_PRINT("\t Rule end          : %s\n", (TRUE == rule.ctrl.end)?"Enable":"Disable");
+            AIR_PRINT("\t Rule reverse      : %s\n", (TRUE == rule.ctrl.reverse)?"Enable":"Disable");
+            _hex2bitstr((~rule.mask.portmap) & AIR_ALL_PORT_BITMAP, str_temp, AIR_MAX_NUM_OF_PORTS+1);
+            AIR_PRINT("\t Portmap[0:6]      : %s\n", str_temp);
+            for(i = AIR_ACL_DMAC; i < AIR_ACL_FIELD_TYPE_LAST; i++)
+            {
+                if((1 << i) & rule.mask.fieldmap)
+                {
+                    switch (i)
+                    {
+                        case AIR_ACL_DMAC:
+                            AIR_PRINT("\t dmac: ");
+                            AIR_PRINT("%02x-%02x-%02x-%02x-%02x-%02x",
+                            rule.key.dmac[0], rule.key.dmac[1], rule.key.dmac[2],
+                            rule.key.dmac[3], rule.key.dmac[4], rule.key.dmac[5]);
+                            AIR_PRINT(", dmac-mask: ");
+                            AIR_PRINT("%02x-%02x-%02x-%02x-%02x-%02x\n",
+                            rule.mask.dmac[0], rule.mask.dmac[1], rule.mask.dmac[2],
+                            rule.mask.dmac[3], rule.mask.dmac[4], rule.mask.dmac[5]);
+                            break;
+                        case AIR_ACL_SMAC:
+                            AIR_PRINT("\t smac: ");
+                            AIR_PRINT("%02x-%02x-%02x-%02x-%02x-%02x",
+                            rule.key.smac[0], rule.key.smac[1], rule.key.smac[2],
+                            rule.key.smac[3], rule.key.smac[4], rule.key.smac[5]);
+                            AIR_PRINT(", smac-mask: ");
+                            AIR_PRINT("%02x-%02x-%02x-%02x-%02x-%02x\n",
+                            rule.mask.smac[0], rule.mask.smac[1], rule.mask.smac[2],
+                            rule.mask.smac[3], rule.mask.smac[4], rule.mask.smac[5]);
+                            break;
+                        case AIR_ACL_ETYPE:
+                            AIR_PRINT("\t etype: 0x%x, etype-mask: 0x%x\n", rule.key.etype, rule.mask.etype);
+                            break;
+                        case AIR_ACL_STAG:
+                            AIR_PRINT("\t stag: 0x%x, stag-mask: 0x%x\n", rule.key.stag, rule.mask.stag);
+                            break;
+                        case AIR_ACL_CTAG:
+                            AIR_PRINT("\t ctag: 0x%x, ctag-mask: 0x%x\n", rule.key.ctag, rule.mask.ctag);
+                            break;
+                        case AIR_ACL_DPORT:
+                            AIR_PRINT("\t dport: 0x%x, dport-mask: 0x%x\n", rule.key.dport, rule.mask.dport);
+                            break;
+                        case AIR_ACL_SPORT:
+                            AIR_PRINT("\t sport: 0x%x, sport-mask: 0x%x\n", rule.key.sport, rule.mask.sport);
+                            break;
+                        case AIR_ACL_UDF:
+                            AIR_PRINT("\t udf: 0x%x, udf-mask: 0x%x\n", rule.key.udf, rule.mask.udf);
+                            break;
+                        case AIR_ACL_DIP:
+                            if (0 == rule.key.isipv6)
+                            {
+                                AIR_PRINT("\t dip: ");
+                                AIR_PRINT("%d.%d.%d.%d",
+                                ((rule.key.dip[0])&0xFF000000)>>24,((rule.key.dip[0])&0x00FF0000)>>16,
+                                ((rule.key.dip[0])&0x0000FF00)>>8, ((rule.key.dip[0])&0x000000FF));
+                                AIR_PRINT(", dip-mask: ");
+                                AIR_PRINT("%d.%d.%d.%d\n ",
+                                ((rule.mask.dip[0])&0xFF000000)>>24,((rule.mask.dip[0])&0x00FF0000)>>16,
+                                ((rule.mask.dip[0])&0x0000FF00)>>8, ((rule.mask.dip[0])&0x000000FF));
+                            }
+                            else
+                            {
+                                for(i=0; i<4; i++){
+                                    tmp_ip[i] = (rule.key.dip[3] >> (8*(3-i))) & 0xff;
+                                    AIR_PRINT("get tmp_ip[%d]=0x%x\n", i, tmp_ip[i]);
+                                }
+                                for(i=4; i<8; i++){
+                                    tmp_ip[i] = (rule.key.dip[2] >> (8*(7-i))) & 0xff;
+                                }
+                                for(i=8; i<12; i++){
+                                    tmp_ip[i] = (rule.key.dip[1] >> (8*(11-i))) & 0xff;
+                                }
+                                for(i=12; i<16; i++){
+                                    tmp_ip[i] = (rule.key.dip[0] >> (8*(15-i))) & 0xff;
+                                }
+
+                                AIR_PRINT("\t dip: ");
+                                AIR_PRINT("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
+                                    tmp_ip[0], tmp_ip[1],tmp_ip[2], tmp_ip[3],tmp_ip[4], tmp_ip[5],tmp_ip[6], tmp_ip[7],
+                                    tmp_ip[8], tmp_ip[9],tmp_ip[10], tmp_ip[11],tmp_ip[12], tmp_ip[13],tmp_ip[14], tmp_ip[15]);
+                                for(i=0; i<4; i++){
+                                    tmp_ip[i] = (rule.mask.dip[3] >> (8*(3-i))) & 0xff;
+                                }
+                                for(i=4; i<8; i++){
+                                    tmp_ip[i] = (rule.mask.dip[2] >> (8*(7-i))) & 0xff;
+                                }
+                                for(i=8; i<12; i++){
+                                    tmp_ip[i] = (rule.mask.dip[1] >> (8*(11-i))) & 0xff;
+                                }
+                                for(i=12; i<16; i++){
+                                    tmp_ip[i] = (rule.mask.dip[0] >> (8*(15-i))) & 0xff;
+                                }
+                                AIR_PRINT(", dip-mask: ");
+                                AIR_PRINT("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
+                                    tmp_ip[0], tmp_ip[1],tmp_ip[2], tmp_ip[3],tmp_ip[4], tmp_ip[5],tmp_ip[6], tmp_ip[7],
+                                    tmp_ip[8], tmp_ip[9],tmp_ip[10], tmp_ip[11],tmp_ip[12], tmp_ip[13],tmp_ip[14], tmp_ip[15]);
+                            }
+                            break;
+                        case AIR_ACL_SIP:
+                            if (0 == rule.key.isipv6)
+                            {
+                                AIR_PRINT("\t sip: ");
+                                AIR_PRINT("%d.%d.%d.%d ",
+                                ((rule.key.sip[0])&0xFF000000)>>24,((rule.key.sip[0])&0x00FF0000)>>16,
+                                ((rule.key.sip[0])&0x0000FF00)>>8, ((rule.key.sip[0])&0x000000FF));
+                                AIR_PRINT(", sip-mask: ");
+                                AIR_PRINT("%d.%d.%d.%d\n ",
+                                ((rule.mask.sip[0])&0xFF000000)>>24,((rule.mask.sip[0])&0x00FF0000)>>16,
+                                ((rule.mask.sip[0])&0x0000FF00)>>8, ((rule.mask.sip[0])&0x000000FF));
+                            }
+                            else
+                            {
+                                for(i=0; i<4; i++){
+                                    tmp_ip[i] = (rule.key.sip[3] >> (8*(3-i))) & 0xff;
+                                }
+                                for(i=4; i<8; i++){
+                                    tmp_ip[i] = (rule.key.sip[2] >> (8*(7-i))) & 0xff;
+                                }
+                                for(i=8; i<12; i++){
+                                    tmp_ip[i] = (rule.key.sip[1] >> (8*(11-i))) & 0xff;
+                                }
+                                for(i=12; i<16; i++){
+                                    tmp_ip[i] = (rule.key.sip[0] >> (8*(15-i))) & 0xff;
+                                }
+                                AIR_PRINT("\t sip: ");
+                                AIR_PRINT("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x",
+                                    tmp_ip[0], tmp_ip[1],tmp_ip[2], tmp_ip[3],tmp_ip[4], tmp_ip[5],tmp_ip[6], tmp_ip[7],
+                                    tmp_ip[8], tmp_ip[9],tmp_ip[10], tmp_ip[11],tmp_ip[12], tmp_ip[13],tmp_ip[14], tmp_ip[15]);
+                                for(i=0; i<4; i++){
+                                    tmp_ip[i] = (rule.mask.sip[3] >> (8*(3-i))) & 0xff;
+                                }
+                                for(i=4; i<8; i++){
+                                    tmp_ip[i] = (rule.mask.sip[2] >> (8*(7-i))) & 0xff;
+                                }
+                                for(i=8; i<12; i++){
+                                    tmp_ip[i] = (rule.mask.sip[1] >> (8*(11-i))) & 0xff;
+                                }
+                                for(i=12; i<16; i++){
+                                    tmp_ip[i] = (rule.mask.sip[0] >> (8*(15-i))) & 0xff;
+                                }
+                                AIR_PRINT(", sip-mask: ");
+                                AIR_PRINT("%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
+                                    tmp_ip[0], tmp_ip[1],tmp_ip[2], tmp_ip[3],tmp_ip[4], tmp_ip[5],tmp_ip[6], tmp_ip[7],
+                                    tmp_ip[8], tmp_ip[9],tmp_ip[10], tmp_ip[11],tmp_ip[12], tmp_ip[13],tmp_ip[14], tmp_ip[15]);
+                            }
+                            break;
+                        case AIR_ACL_DSCP:
+                            AIR_PRINT("\t dscp: 0x%x, dscp-mask: 0x%x\n", rule.key.dscp, rule.mask.dscp);
+                            break;
+                        case AIR_ACL_PROTOCOL:
+                            AIR_PRINT("\t protocol: 0x%x, protocol-mask: 0x%x\n", rule.key.protocol, rule.mask.protocol);
+                            break;
+                        case AIR_ACL_FLOW_LABEL:
+                            AIR_PRINT("\t flow-label: 0x%x, flow-label-mask: 0x%x\n", rule.key.flow_label, rule.mask.flow_label);
+                            break;
+                        default:
+                            AIR_PRINT("error\n");
+                            break;
+                    }
+                }
+            }
+        }
+        else
+        {
+            AIR_PRINT("Entry is Invalid.\n");
+        }
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclRmvRule(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T rule_idx = 0;
+
+    if(1 == argc)
+    {
+        /* acl del rule <idx(0..127)> */
+        rule_idx = _strtoul(argv[0], NULL, 0);
+        ret = air_acl_delRule(0, rule_idx);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Delete ACL Rule(%u): %s\n", rule_idx, air_error_getString(ret));
+    }
+    else if(0 == argc)
+    {
+        /* acl clear rule */
+        ret = air_acl_clearRule(0);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Clear ACL Rule: %s\n", air_error_getString(ret));
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclUdfRule(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T rule_idx;
+    AIR_ACL_UDF_RULE_T rule;
+    C8_T start_addr[8][12]=
+    {
+        "MAC header",
+        "L2 payload",
+        "IPv4 header",
+        "IPv6 header",
+        "L3 payload",
+        "TCP header",
+        "UDP header",
+        "L4 payload"
+    };
+    C8_T str_temp[AIR_MAX_NUM_OF_PORTS+1];
+
+    memset(&rule, 0, sizeof(AIR_ACL_UDF_RULE_T));
+    if(7 == argc)
+    {
+        /* acl set rule <idx(0..255)> <mode(0:pattern, 1:threshold)> [ <pat(4'hex)> <mask(4'hex)> | <low(4'hex)> <high(4'hex)> ] <start(0:MAC,1:ether,2:IP,3:IP_data,4:TCP/UDP,5:TCP/UDP data,6:IPv6)> <offset(0..62,unit:2 bytes)> <portmap(7'bin)> */
+        rule_idx = _strtoul(argv[0], NULL, 0);
+        rule.cmp_sel = _strtoul(argv[1], NULL, 2);
+        if(AIR_ACL_RULE_CMP_SEL_PATTERN == rule.cmp_sel)
+        {
+            rule.pattern = _strtoul(argv[2], NULL, 16);
+            rule.mask = _strtoul(argv[3], NULL, 16);
+        }
+        else
+        {
+            rule.low_threshold = _strtoul(argv[2], NULL, 16);
+            rule.high_threshold = _strtoul(argv[3], NULL, 16);
+        }
+        rule.offset_format = _strtoul(argv[4], NULL, 0);
+        rule.offset = _strtoul(argv[5], NULL, 0);
+        rule.portmap = _strtoul(argv[6], NULL, 2);
+        rule.valid = TRUE;
+        ret = air_acl_setUdfRule(0, rule_idx, rule);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Set ACL UDF Rule(%u): %s\n", rule_idx, air_error_getString(ret));
+    }
+    else if(1 == argc)
+    {
+        rule_idx = _strtoul(argv[0], NULL, 0);
+        ret = air_acl_getUdfRule(0, rule_idx, &rule);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Get ACL UDF Rule(%u): %s\n", rule_idx, air_error_getString(ret));
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(AIR_E_OK == ret)
+    {
+        if(TRUE == rule.valid)
+        {
+            AIR_PRINT("\tMode          : %s\n", (AIR_ACL_RULE_CMP_SEL_PATTERN == rule.cmp_sel)?"Pattern":"Threshold");
+            if(AIR_ACL_RULE_CMP_SEL_PATTERN == rule.cmp_sel)
+            {
+                AIR_PRINT("\tPattern       : 0x%04X\n", rule.pattern);
+                AIR_PRINT("\tMask          : 0x%04X\n", rule.mask);
+            }
+            else
+            {
+                AIR_PRINT("\tLow Threshold : 0x%04X\n", rule.low_threshold);
+                AIR_PRINT("\tHigh Threshold: 0x%04X\n", rule.high_threshold);
+            }
+            AIR_PRINT("\tOffset Start  : %s\n", start_addr[rule.offset_format]);
+            AIR_PRINT("\tOffset        : %u %s\n", rule.offset*2, (0==rule.offset)?"Byte":"Bytes");
+            _hex2bitstr(rule.portmap, str_temp, AIR_MAX_NUM_OF_PORTS+1);
+            AIR_PRINT("\tPortmap[0:6]  : %s\n", str_temp);
+        }
+        else
+        {
+            AIR_PRINT("Entry is Invalid.\n");
+        }
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclRmvUdfRule(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T rule_idx;
+
+    if(1 == argc)
+    {
+        /* acl del udfRule <idx(0..15)> */
+        rule_idx = _strtoul(argv[0], NULL, 0);
+        ret = air_acl_delUdfRule(0, rule_idx);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Delete ACL UDF Rule(%u): %s\n", rule_idx, air_error_getString(ret));
+    }
+    else if(0 == argc)
+    {
+        /* acl clear udfRule */
+        ret = air_acl_clearUdfRule(0);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Clear ACL UDF Rule: %s\n", air_error_getString(ret));
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclAction(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T argi = 0;
+    UI32_T act_idx;
+    AIR_ACL_ACTION_T act;
+    UI32_T redirect, trtcm, fwd;
+    C8_T fwding[AIR_ACL_ACT_FWD_LAST][25] =
+    {
+        "Default",
+        "Default",
+        "Default",
+        "Default",
+        "Default & CPU excluded",
+        "Default & CPU included",
+        "CPU only",
+        "Drop"
+    };
+    C8_T trtcm_usr[AIR_ACL_ACT_USR_TCM_LAST][8] =
+    {
+        "Default",
+        "Green",
+        "Yellow",
+        "Red"
+    };
+    C8_T egtag[AIR_ACL_ACT_EGTAG_LAST][11] =
+    {
+        "Default",
+        "Consistent",
+        "",
+        "",
+        "Untag",
+        "Swap",
+        "Tag",
+        "Stack"
+    };
+    C8_T str_temp[20];
+
+    memset(&act, 0, sizeof(AIR_ACL_ACTION_T));
+    if(2 < argc)
+    {
+        /* acl set action <idx(0..127)>
+        [ forward <forward(0:Default,4:Exclude CPU,5:Include CPU,6:CPU only,7:Drop)> ]
+        [ egtag <egtag(0:Default,1:Consistent,4:Untag,5:Swap,6:Tag,7:Stack)> ]
+        [ mirrormap <mirrormap(2'bin)> ]
+        [ priority <priority(0..7)> ]
+        [ redirect <redirect(0:Dst,1:Vlan)> <portmap(7'bin)> ]
+        [ leaky_vlan <leaky_vlan(1:En,0:Dis)> ]
+        [ cnt_idx <cnt_idx(0..63)> ]
+        [ rate_idx <rate_idx(0..31)> ]
+        [ attack_idx <attack_idx(0..95)> ]
+        [ vid <vid(0..4095)> ]
+        [ manage <manage(1:En,0:Dis)> ]
+        [ bpdu <bpdu(1:En,0:Dis)> ]
+        [ class <class(0:Original,1:Defined)>[0..7] ]
+        [ drop_pcd <drop_pcd(0:Original,1:Defined)> [red <red(0..7)>][yellow <yellow(0..7)>][green <green(0..7)>] ]
+        [ color <color(0:Defined,1:Trtcm)> [ <defined_color(0:Dis,1:Green,2:Yellow,3:Red)> | <trtcm_idx(0..31)> ] ]*/
+
+        act_idx = _strtoul(argv[argi++], NULL, 0);
+        if((argi < argc) && (0 == _strcmp(argv[argi], "forward")))
+        {
+            argi++;
+            fwd = _strtoul(argv[argi++], NULL, 0);
+            act.fwd_en = TRUE;
+            act.fwd = fwd;
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "egtag")))
+        {
+            argi++;
+            act.egtag_en = TRUE;
+            act.egtag = _strtoul(argv[argi++], NULL, 0);
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "mirrormap")))
+        {
+            argi++;
+            act.mirrormap = _strtoul(argv[argi++], NULL, 2);
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "priority")))
+        {
+            argi++;
+            act.pri_user_en = TRUE;
+            act.pri_user= _strtoul(argv[argi++], NULL, 0);
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "redirect")))
+        {
+            argi++;
+            redirect = _strtoul(argv[argi++], NULL, 0);
+            if(0 ==  redirect)
+            {
+                act.port_en = TRUE;
+                act.dest_port_sel = TRUE;
+                act.portmap = _strtoul(argv[argi++], NULL, 2);
+            }
+            else
+            {
+                act.port_en = TRUE;
+                act.vlan_port_sel = TRUE;
+                act.portmap = _strtoul(argv[argi++], NULL, 2);
+            }
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "leaky_vlan")))
+        {
+            argi++;
+            act.lyvlan_en = TRUE;
+            act.lyvlan = _strtoul(argv[argi++], NULL, 0);
+        }
+
+        /* ACL event counter */
+        if((argi < argc) && (0 == _strcmp(argv[argi], "cnt_idx")))
+        {
+            argi++;
+            act.cnt_en = TRUE;
+            act.cnt_idx = _strtol(argv[argi++], NULL, 0);
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "rate_idx")))
+        {
+            argi++;
+            act.rate_en = TRUE;
+            act.rate_idx = _strtol(argv[argi++], NULL, 0);
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "attack_idx")))
+        {
+            argi++;
+            act.attack_en = TRUE;
+            act.attack_idx = _strtol(argv[argi++], NULL, 0);
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "vid")))
+        {
+            argi++;
+            act.vlan_en = TRUE;
+            act.vlan_idx = _strtol(argv[argi++], NULL, 0);
+        }
+
+        /* Management frame */
+        if((argi < argc) && (0 == _strcmp(argv[argi], "manage")))
+        {
+            argi++;
+            act.mang = _strtoul(argv[argi++], NULL, 2);
+        }
+
+        if((argi < argc) && (0 == _strcmp(argv[argi], "bpdu")))
+        {
+            argi++;
+            act.bpdu = _strtoul(argv[argi++], NULL, 2);
+        }
+
+        /* DSCP class remap */
+        if((argi < argc) && (0 == _strcmp(argv[argi], "class")))
+        {
+            argi++;
+            act.trtcm_en = TRUE;
+            act.trtcm.cls_slr_sel = _strtoul(argv[argi++], NULL, 2);
+            if(TRUE == act.trtcm.cls_slr_sel)
+            {
+                act.trtcm.cls_slr = _strtoul(argv[argi++], NULL, 0);
+            }
+        }
+        if((argi < argc) && (0 == _strcmp(argv[argi], "drop_pcd")))
+        {
+            argi++;
+            act.trtcm_en = TRUE;
+            act.trtcm.drop_pcd_sel = _strtoul(argv[argi++], NULL, 2);
+            if(TRUE == act.trtcm.drop_pcd_sel)
+            {
+                if(0 == _strcmp(argv[argi], "red"))
+                {
+                    argi++;
+                    act.trtcm.drop_pcd_r= _strtoul(argv[argi++], NULL, 0);
+                }
+                if(0 == _strcmp(argv[argi], "yellow"))
+                {
+                    argi++;
+                    act.trtcm.drop_pcd_y= _strtoul(argv[argi++], NULL, 0);
+                }
+                if(0 == _strcmp(argv[argi], "green"))
+                {
+                    argi++;
+                    act.trtcm.drop_pcd_g= _strtoul(argv[argi++], NULL, 0);
+                }
+            }
+        }
+
+        /* trTCM */
+        if((argi < argc) && (0 == _strcmp(argv[argi], "color")))
+        {
+            argi++;
+            act.trtcm_en = TRUE;
+            act.trtcm.tcm_sel = _strtoul(argv[argi++], NULL, 2);
+            trtcm = _strtoul(argv[argi++], NULL, 0);
+            if(FALSE == act.trtcm.tcm_sel)
+            {
+                act.trtcm.usr_tcm = trtcm;
+            }
+            else
+            {
+                act.trtcm.tcm_idx = trtcm;
+            }
+        }
+        ret = air_acl_setAction(0, act_idx, act);
+        AIR_PRINT("Set ACL Action(%u): %s\n", act_idx, air_error_getString(ret));
+    }
+    else if(1 == argc)
+    {
+        /* acl get action <idx(0..127)> */
+        act_idx = _strtoul(argv[argi++], NULL, 0);
+        ret = air_acl_getAction(0, act_idx, &act);
+        AIR_PRINT("Get ACL Action(%u): %s\n", act_idx, air_error_getString(ret));
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(AIR_E_OK == ret)
+    {
+        if(TRUE == act.fwd_en)
+        {
+            AIR_PRINT("\t Forwarding           : %s\n", fwding[act.fwd]);
+        }
+
+        if(TRUE == act.egtag_en)
+        {
+            AIR_PRINT("\t Egress tag           : %s\n", egtag[act.egtag]);
+        }
+
+        if(act.mirrormap)
+        {
+            AIR_PRINT("\t Mirror Session Map   : %u\n", act.mirrormap);
+        }
+
+        if(TRUE == act.pri_user_en)
+        {
+            AIR_PRINT("\t User Priority        : %u\n", act.pri_user);
+        }
+
+        if(TRUE == act.port_en)
+        {
+            _hex2bitstr(act.portmap, str_temp, AIR_MAX_NUM_OF_PORTS+1);
+            if(TRUE == act.dest_port_sel)
+            {
+                AIR_PRINT("\t Destination Port[0:6]: %s\n", str_temp);
+            }
+            else
+            {
+                AIR_PRINT("\t VLAN Port[0:6]       : %s\n", str_temp);
+            }
+        }
+
+        if(TRUE == act.lyvlan_en)
+        {
+            AIR_PRINT("\t Leaky VLAN           : %s\n", (TRUE == act.lyvlan)?"Enable":"Disable");
+        }
+        AIR_PRINT("\t Management Frame     : %s\n", (TRUE == act.mang)?"Enable":"Disable");
+        AIR_PRINT("\t BPDU Frame           : %s\n", (TRUE == act.bpdu)?"Enable":"Disable");
+
+        if(TRUE == act.cnt_en)
+        {
+            AIR_PRINT("\t Event Index          : %u\n", act.cnt_idx);
+        }
+
+        /* trTCM*/
+        if(TRUE == act.trtcm_en)
+        {
+            if(TRUE == act.trtcm.cls_slr_sel)
+            {
+                AIR_PRINT("\t Class Selector Remap : %u\n", act.trtcm.cls_slr);
+            }
+            else
+            {
+                AIR_PRINT("\t Class Selector Remap : %s\n", "Disable");
+            }
+            if(TRUE == act.trtcm.drop_pcd_sel)
+            {
+                AIR_PRINT("\t Drop Precedence Remap(Red): %u\n", act.trtcm.drop_pcd_r);
+                AIR_PRINT("\t Drop Precedence Remap(Yel): %u\n", act.trtcm.drop_pcd_y);
+                AIR_PRINT("\t Drop Precedence Remap(Gre): %u\n", act.trtcm.drop_pcd_g);
+            }
+            else
+            {
+                AIR_PRINT("\t Drop Precedence Remap: %s\n", "Disable");
+            }
+
+            if(TRUE == act.trtcm.tcm_sel)
+            {
+                AIR_PRINT("\t trTCM Meter Index    : %u\n", act.trtcm.tcm_idx);
+            }
+            else
+            {
+                AIR_PRINT("\t trTCM User Defined   : %s\n", trtcm_usr[act.trtcm.usr_tcm]);
+            }
+        }
+        /* rate control */
+        if(TRUE == act.rate_en)
+        {
+            AIR_PRINT("\t Rate Control Index   : %u\n", act.rate_idx);
+        }
+
+        if(TRUE == act.attack_en)
+        {
+            AIR_PRINT("\t Attack Rate Control Index: %u\n", act.attack_idx);
+        }
+
+        if(TRUE == act.vlan_en)
+        {
+            AIR_PRINT("\t ACL VLAN Index       : %u\n", act.vlan_idx);
+        }
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclRmvAction(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T act_idx;
+
+    if(1 == argc)
+    {
+        /* acl del action <idx(0..127)> */
+        act_idx = _strtoul(argv[0], NULL, 0);
+        ret = air_acl_delAction(0, act_idx);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Delete ACL Action(%u): %s\n", act_idx, air_error_getString(ret));
+    }
+    else if(0 == argc)
+    {
+        /* acl clear action */
+        ret = air_acl_clearAction(0);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Clear ACL Action: %s\n", air_error_getString(ret));
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclTrtcm(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T argi = 0;
+    UI32_T tcm_idx;
+    AIR_ACL_TRTCM_T tcm;
+
+    memset(&tcm, 0, sizeof(AIR_ACL_TRTCM_T));
+    if(5 == argc)
+    {
+        /* acl set trtcm <idx(0..31)> <cir(4'hex)> <pir(4'hex)> <cbs(4'hex)> <pbs(4'hex)> */
+        tcm_idx = _strtoul(argv[argi++], NULL, 0);
+        tcm.cir = _strtoul(argv[argi++], NULL, 16);
+        tcm.pir = _strtoul(argv[argi++], NULL, 16);
+        tcm.cbs = _strtoul(argv[argi++], NULL, 16);
+        tcm.pbs = _strtoul(argv[argi++], NULL, 16);
+
+        ret = air_acl_setTrtcm(0, tcm_idx, tcm);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Set ACL trTCM(%u): %s\n", tcm_idx, air_error_getString(ret));
+    }
+    else if(1 == argc)
+    {
+        /* acl get trtcm <idx(1..31)> */
+        tcm_idx = _strtoul(argv[argi++], NULL, 0);
+        ret = air_acl_getTrtcm(0, tcm_idx, &tcm);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Get ACL trTCM(%u): %s\n", tcm_idx, air_error_getString(ret));
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(AIR_E_OK == ret)
+    {
+        AIR_PRINT("\t CIR: 0x%04X(unit:64Kbps)\n", tcm.cir);
+        AIR_PRINT("\t PIR: 0x%04X(unit:64Kbps)\n", tcm.pir);
+        AIR_PRINT("\t CBS: 0x%04X(unit:Byte)\n", tcm.cbs);
+        AIR_PRINT("\t PBS: 0x%04X(unit:Byte)\n", tcm.pbs);
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclTrtcmEn(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    BOOL_T state = FALSE;
+
+    if (1 == argc)
+    {
+        /* acl set trtcmEn <en(1:En,0:Dis)> */
+        state = _strtol(argv[0], NULL, 10);
+        ret = air_acl_setTrtcmEnable(0, state);
+        AIR_PRINT("Set trTCM State ");
+    }
+    else if (0 == argc)
+    {
+        /* acl get trtcmEn */
+        ret = air_acl_getTrtcmEnable(0, &state);
+        AIR_PRINT("Get trTCM State ");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if (ret == AIR_E_OK)
+    {
+        AIR_PRINT(": %s\n", (TRUE == state) ? "Enable" : "Disable");
+    }
+    else
+    {
+        AIR_PRINT("Fail!\n");
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclRmvTrtcm(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T tcm_idx;
+
+    if(1 == argc)
+    {
+        /* acl del trtcm <idx(1..31)> */
+        tcm_idx = _strtoul(argv[0], NULL, 0);
+        ret = air_acl_delTrtcm(0, tcm_idx);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Delete ACL TRTCM(%u): %s\n", tcm_idx, air_error_getString(ret));
+    }
+    else if(0 == argc)
+    {
+        /* acl clear trtcm */
+        ret = air_acl_clearTrtcm(0);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Clear ACL TRTCM: %s\n", air_error_getString(ret));
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclPortEn(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T argi=0;
+    UI32_T port = 0;
+    BOOL_T en;
+
+    if(2 == argc)
+    {
+        /* acl set portEn <port(0..6)> <en(1:En,0:Dis)> */
+        port = _strtoul(argv[argi++], NULL, 0);
+        en = _strtoul(argv[argi++], NULL, 2);
+        ret = air_acl_setPortEnable(0, port, en);
+        AIR_PRINT("Set Port:%u ACL function ", port);
+    }
+    else if(1 == argc)
+    {
+        /* acl get portEn <port(0..6)> */
+        port = _strtoul(argv[argi++], NULL, 0);
+        ret = air_acl_getPortEnable(0, port, &en);
+        AIR_PRINT("Get Port:%u ACL function ", port);
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        AIR_PRINT(": %s\n", (TRUE == en)?"Enable":"Disable");
+    }
+    else
+    {
+        AIR_PRINT("Fail!\n");
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclDropEn(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T argi=0;
+    UI32_T port = 0;
+    BOOL_T en;
+
+    if(2 == argc)
+    {
+        /* acl set dropEn <port(0..6)> <en(1:En,0:Dis)> */
+        port = _strtoul(argv[argi++], NULL, 0);
+        en = _strtoul(argv[argi++], NULL, 2);
+        ret = air_acl_setDropEnable(0, port, en);
+        AIR_PRINT("Set ACL Drop precedence ");
+    }
+    else if(1 == argc)
+    {
+        /* acl set dropEn <port(0..6)> */
+        port = _strtoul(argv[argi++], NULL, 0);
+        ret = air_acl_getDropEnable(0, port, &en);
+        AIR_PRINT("Get ACL Drop precedence ");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        AIR_PRINT("(Port %u):%s\n",
+                port,
+                (TRUE == en)?"Enable":"Disable");
+    }
+    else
+    {
+        AIR_PRINT("Fail!\n");
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclDropThrsh(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T argi=0;
+    UI32_T port = 0;
+    AIR_ACL_DP_COLOR_T color;
+    UI8_T queue;
+    UI32_T high, low;
+    C8_T dp_color[AIR_ACL_DP_COLOR_LAST][7] =
+    {
+        "Green",
+        "Yellow",
+        "Red"
+    };
+
+    if(5 == argc)
+    {
+        /* acl set dropThrsh <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> <high(0..2047)> <low(0..2047) */
+        port = _strtoul(argv[argi++], NULL, 0);
+        color = _strtoul(argv[argi++], NULL, 0);
+        queue = _strtoul(argv[argi++], NULL, 0);
+        high = _strtoul(argv[argi++], NULL, 0);
+        low = _strtoul(argv[argi++], NULL, 0);
+        ret = air_acl_setDropThreshold(0, port, color, queue, high, low);
+        AIR_PRINT("Set ACL Drop precedence ");
+    }
+    else if(3 == argc)
+    {
+        /* acl get dropThrsh <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> */
+        port = _strtoul(argv[argi++], NULL, 0);
+        color = _strtoul(argv[argi++], NULL, 0);
+        queue = _strtoul(argv[argi++], NULL, 0);
+        ret = air_acl_getDropThreshold(0, port, color, queue, &high, &low);
+        AIR_PRINT("Get ACL Drop precedence ");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        AIR_PRINT("(Port %u, color:%s, queue:%u):\n",
+                port,
+                dp_color[color],
+                queue);
+        AIR_PRINT("\tHigh Threshold :%u\n", high);
+        AIR_PRINT("\tLow Threshold  :%u\n", low);
+    }
+    else
+    {
+        AIR_PRINT("Fail!\n");
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclDropPbb(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T argi=0;
+    UI32_T port = 0;
+    AIR_ACL_DP_COLOR_T color;
+    UI8_T queue;
+    UI32_T pbb;
+    C8_T dp_color[AIR_ACL_DP_COLOR_LAST][7] =
+    {
+        "Green",
+        "Yellow",
+        "Red"
+    };
+
+    if(4 == argc)
+    {
+        /* acl set dropPbb <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> <probability(0..1023) */
+        port = _strtoul(argv[argi++], NULL, 0);
+        color = _strtoul(argv[argi++], NULL, 0);
+        queue = _strtoul(argv[argi++], NULL, 0);
+        pbb = _strtoul(argv[argi++], NULL, 0);
+        ret = air_acl_setDropProbability(0, port, color, queue, pbb);
+        AIR_PRINT("Set ACL Drop precedence ");
+    }
+    else if(3 == argc)
+    {
+        /* acl get dropPbb <port(0..6)> <color(0:green,1:yellow,2:red)> <queue(0..7)> */
+        port = _strtoul(argv[argi++], NULL, 0);
+        color = _strtoul(argv[argi++], NULL, 0);
+        queue = _strtoul(argv[argi++], NULL, 0);
+        ret = air_acl_getDropProbability(0, port, color, queue, &pbb);
+        AIR_PRINT("Get ACL Drop precedence ");
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(ret == AIR_E_OK)
+    {
+        AIR_PRINT("(Port %u, color:%s, queue %u):\n",
+                port,
+                dp_color[color],
+                queue);
+        AIR_PRINT("\tDrop probability:%u(unit=1/1023)\n", pbb);
+    }
+    else
+    {
+        AIR_PRINT("Fail!\n");
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclMeter(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T argi = 0;
+    UI32_T meter_idx, state, rate;
+
+    if(3 == argc)
+    {
+        /* acl set meter <idx(0..31)> <en(1:En,0:Dis)> <rate(0..65535)>
+           Note: Limit rate = rate * 64Kbps */
+        meter_idx = _strtoul(argv[argi++], NULL, 0);
+        state = _strtoul(argv[argi++], NULL, 2);
+        rate = _strtoul(argv[argi++], NULL, 0);
+
+        ret = air_acl_setMeterTable(0, meter_idx, state, rate);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Set ACL Meter(%u): %s\n", meter_idx, air_error_getString(ret));
+    }
+    else if(1 == argc)
+    {
+        /* acl get meter <idx(0..31)> */
+        meter_idx = _strtoul(argv[argi++], NULL, 0);
+        ret = air_acl_getMeterTable(0, meter_idx, &state, &rate);
+        if(ret < AIR_E_LAST)
+            AIR_PRINT("Get ACL Meter(%u): %s\n", meter_idx, air_error_getString(ret));
+    }
+    else
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if(AIR_E_OK == ret)
+    {
+        AIR_PRINT("\t State: %s\n", (TRUE == state)?"Enable":"Disable");
+        if(TRUE == state)
+        {
+            AIR_PRINT("\t Rate : %u(unit:64Kbps)\n", rate);
+        }
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclDump(
+    UI32_T argc,
+    C8_T *argv[])
+{
+    AIR_ERROR_NO_T ret = AIR_E_OK;
+    UI32_T i, cnt = 0;
+    AIR_ACL_CTRL_T ctrl;
+
+    if(0 != argc)
+    {
+        AIR_PRINT("Unrecognized command.\n");
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    for(i=0; i<ACL_MAX_RULE_NUM; i++)
+    {
+        memset(&ctrl, 0, sizeof(AIR_ACL_CTRL_T));
+        ret = air_acl_getRuleCtrl(0, i, &ctrl);
+        if(AIR_E_OK == ret)
+        {
+            if(TRUE == ctrl.rule_en)
+            {
+                cnt++;
+                AIR_PRINT("\t Entry-%d vaild\n", i);
+            }
+        }
+    }
+    if(0 == cnt)
+    {
+        AIR_PRINT("\t No entry vaild\n");
+    }
+
+    return ret;
+}
+
+static AIR_ERROR_NO_T
+doAclSet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(aclSetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doAclGet(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(aclGetCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doAclDel(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(aclDelCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doAclClear(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(aclClearCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+doAcl(
+        UI32_T argc,
+        C8_T *argv[])
+{
+    return subcmd(aclCmds, argc, argv);
+}
+
+static AIR_ERROR_NO_T
+subcmd(
+        const AIR_CMD_T tab[],
+        UI32_T argc,
+        C8_T *argv[])
+{
+    const AIR_CMD_T *cmdp;
+    I32_T found = 0;
+    I32_T i, len;
+
+    if (argc < 1)
+    {
+        goto print_out_cmds;
+    }
+
+    for (cmdp = tab; cmdp->name != NULL; cmdp++)
+    {
+        if (strlen(argv[0]) == strlen(cmdp->name))
+        {
+            if (strncmp(argv[0], cmdp->name, strlen(argv[0])) == 0)
+            {
+                found = 1;
+                break;
+            }
+        }
+    }
+
+    if(!found)
+    {
+        C8_T buf[66];
+
+print_out_cmds:
+        AIR_PRINT("valid subcommands:\n");
+        memset(buf, ' ', sizeof(buf));
+        buf[64] = '\n';
+        buf[65] = '\0';
+
+        for (i=0, cmdp = tab; cmdp->name != NULL; cmdp++)
+        {
+            len = strlen(cmdp->name);
+            strncpy(&buf[i*16], cmdp->name, (len > 16) ? 16 : len);
+            if(3 == i)
+            {
+                AIR_PRINT("%s\n", buf);
+                memset(buf, ' ', sizeof(buf));
+                buf[64] = '\n';
+                buf[65] = '\0';
+            }
+            i = (i + 1) % 4;
+        }
+
+        if (0 != i)
+            AIR_PRINT("%s\n", buf);
+
+        return AIR_E_BAD_PARAMETER;
+    }
+
+    if (CMD_NO_PARA == cmdp->argc_min)
+    {
+        if (argc != 1)
+        {
+            if (cmdp->argc_errmsg != NULL)
+            {
+                AIR_PRINT("Usage: %s\n", cmdp->argc_errmsg);
+            }
+
+            return AIR_E_BAD_PARAMETER;
+        }
+    }
+    else if (CMD_VARIABLE_PARA == cmdp->argc_min)
+    {
+        if (argc < 3)
+        {
+            if (cmdp->argc_errmsg != NULL)
+            {
+                AIR_PRINT("Usage: %s\n", cmdp->argc_errmsg);
+            }
+
+            return AIR_E_BAD_PARAMETER;
+        }
+    }
+    else
+    {
+        if ((argc <= cmdp->argc_min) || ((cmdp->argc_min != 0) && (argc != (cmdp->argc_min + 1))))
+        {
+            if (cmdp->argc_errmsg != NULL)
+            {
+                AIR_PRINT("Usage: %s\n", cmdp->argc_errmsg);
+            }
+
+            return AIR_E_BAD_PARAMETER;
+        }
+    }
+
+    if (cmdp->func)
+    {
+        argc--;
+        argv++;
+        return (*cmdp->func)(argc, argv);
+    }
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_parse_cmd
+ * PURPOSE:
+ *      This function is used process diagnostic cmd
+ * INPUT:
+ *      argc         -- parameter number
+ *      argv         -- parameter strings
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      NPS_E_OK     -- Successfully read the data.
+ *      NPS_E_OTHERS -- Failed to read the data.
+ * NOTES:
+ *
+ */
+AIR_ERROR_NO_T
+air_parse_cmd(
+        const UI32_T argc,
+        const C8_T **argv)
+{
+    return subcmd(Cmds, argc, (C8_T **)argv);
+}
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_error.c b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_error.c
index 3323e54..abe27dd 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_error.c
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_error.c
@@ -1,73 +1,73 @@
-/* FILE NAME:   air_error.c

- * PURPOSE:

- *      Define the software modules in AIR SDK.

- * NOTES:

- */

-

-/* INCLUDE FILE DECLARATIONS

- */

-#include "air.h"

-

-/* NAMING CONSTANT DECLARATIONS

- */

-

-/* MACRO FUNCTION DECLARATIONS

- */

-

-/* DATA TYPE DECLARATIONS

- */

-

-/* GLOBAL VARIABLE DECLARATIONS

- */

-

-/* LOCAL SUBPROGRAM DECLARATIONS

- */

-

-/* STATIC VARIABLE DECLARATIONS

- */

-static C8_T *_air_error_cause[AIR_E_LAST] =

-{

-    "OK",

-    "NOT_OK",

-    "BAD_PARAMETER",

-    "TABLE_FULL",

-    "ENTRY_NOT_FOUND",

-    "ENTRY_EXISTS",

-    "NOT_SUPPORT",

-    "TIMEOUT",

-};

-

-/* EXPORTED SUBPROGRAM BODIES

- */

-

-/* LOCAL SUBPROGRAM BODIES

- */

-/* FUNCTION NAME:   air_error_getString

- * PURPOSE:

- *      To obtain the error string of the specified error code

- *

- * INPUT:

- *      The specified error code

- * OUTPUT:

- *      None

- * RETURN:

- *      Pointer to the target error string

- *

- * NOTES:

- *

- *

- */

-C8_T *

-air_error_getString(

-const AIR_ERROR_NO_T cause )

-{

-    if(cause < AIR_E_LAST)

-    {

-        return _air_error_cause[cause];

-    }

-    else

-    {

-        return "";

-    }

-}

-

+/* FILE NAME:   air_error.c
+ * PURPOSE:
+ *      Define the software modules in AIR SDK.
+ * NOTES:
+ */
+
+/* INCLUDE FILE DECLARATIONS
+ */
+#include "air.h"
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+
+/* DATA TYPE DECLARATIONS
+ */
+
+/* GLOBAL VARIABLE DECLARATIONS
+ */
+
+/* LOCAL SUBPROGRAM DECLARATIONS
+ */
+
+/* STATIC VARIABLE DECLARATIONS
+ */
+static C8_T *_air_error_cause[AIR_E_LAST] =
+{
+    "OK",
+    "NOT_OK",
+    "BAD_PARAMETER",
+    "TABLE_FULL",
+    "ENTRY_NOT_FOUND",
+    "ENTRY_EXISTS",
+    "NOT_SUPPORT",
+    "TIMEOUT",
+};
+
+/* EXPORTED SUBPROGRAM BODIES
+ */
+
+/* LOCAL SUBPROGRAM BODIES
+ */
+/* FUNCTION NAME:   air_error_getString
+ * PURPOSE:
+ *      To obtain the error string of the specified error code
+ *
+ * INPUT:
+ *      The specified error code
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      Pointer to the target error string
+ *
+ * NOTES:
+ *
+ *
+ */
+C8_T *
+air_error_getString(
+const AIR_ERROR_NO_T cause )
+{
+    if(cause < AIR_E_LAST)
+    {
+        return _air_error_cause[cause];
+    }
+    else
+    {
+        return "";
+    }
+}
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_init.c b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_init.c
index 8a4f96f..63664dc 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_init.c
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_init.c
@@ -1,147 +1,147 @@
-/* FILE NAME:   air_init.c

- * PURPOSE:

- *      Define the initialization function in AIR SDK.

- *

- * NOTES:

- *      None

- */

-

-/* INCLUDE FILE DECLARATIONS

- */

-#include "air.h"

-

-/* NAMING CONSTANT DECLARATIONS

- */

-

-/* MACRO FUNCTION DECLARATIONS

- */

-

-/* DATA TYPE DECLARATIONS

- */

-

-/* GLOBAL VARIABLE DECLARATIONS

- */

-AIR_PRINTF _ext_printf;

-AIR_UDELAY _ext_udelay;

-AIR_MALLOC _ext_malloc;

-AIR_FREE   _ext_free;

-

-/* LOCAL SUBPROGRAM DECLARATIONS

- */

-

-/* STATIC VARIABLE DECLARATIONS

- */

-

-/* EXPORTED SUBPROGRAM BODIES

- */

-

-/* LOCAL SUBPROGRAM BODIES

- */

-

-/* FUNCTION NAME:   air_init

- * PURPOSE:

- *      This API is used to initialize the SDK.

- *

- * INPUT:

- *      unit            --  The device unit

- *      ptr_init_param  --  The sdk callback functions.

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_OTHERS

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_init(

-    const UI32_T unit,

-    AIR_INIT_PARAM_T *ptr_init_param)

-{

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-    UI32_T u32dat = 0;

-    UI8_T port = 0;

-    AIR_LED_ON_EVT_T on_evt;

-    AIR_LED_BLK_EVT_T blk_evt;

-

-    /* check point */

-    AIR_CHECK_PTR(ptr_init_param);

-

-    _ext_dev_access.read_callback = ptr_init_param->dev_access.read_callback;

-    _ext_dev_access.write_callback = ptr_init_param->dev_access.write_callback;

-    _ext_dev_access.phy_read_callback = ptr_init_param->dev_access.phy_read_callback;

-    _ext_dev_access.phy_write_callback = ptr_init_param->dev_access.phy_write_callback;

-    _ext_dev_access.phy_cl45_read_callback = ptr_init_param->dev_access.phy_cl45_read_callback;

-    _ext_dev_access.phy_cl45_write_callback = ptr_init_param->dev_access.phy_cl45_write_callback;

-    _ext_printf = ptr_init_param->printf;

-    _ext_udelay = ptr_init_param->udelay;

-    _ext_malloc = ptr_init_param->malloc;

-    _ext_free   = ptr_init_param->free;

-    

-    return rc;

-}

-

-/* FUNCTION NAME:   air_hw_reset

- * PURPOSE:

- *      This API is used to reset hardware.

- *

- * INPUT:

- *      unit            --  The device unit

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_OTHERS

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_hw_reset(

-    const UI32_T unit)

-{

-    AIR_PRINT(">>>>> enct_hw_reset\n");

-    /* Set an8855 reset pin to 0 */

-

-    /* Delay 100ms */

-

-    /* Set an8855 reset pin to 1 */

-

-    /* Delay 600ms */

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_set_gpio_pin_mux

- * PURPOSE:

- *      This API is used to set gpio pin mux.

- *

- * INPUT:

- *      unit            --  The device unit

- *

- * OUTPUT:

- *      None

- *

- * RETURN:

- *      AIR_E_OK

- *      AIR_E_OTHERS

- *

- * NOTES:

- *      None

- */

-AIR_ERROR_NO_T

-air_set_gpio_pin_mux(

-    const UI32_T unit)

-{

-    AIR_PRINT(">>>>> enct_set_gpio_pin_mux\n");

-    /* Set GPIO_MODE0 */

-    /* Implementation for SLT HW */

-    aml_writeReg(unit, GPIO_MODE0, 0x11111111);

-

-    return AIR_E_OK;

-}

+/* FILE NAME:   air_init.c
+ * PURPOSE:
+ *      Define the initialization function in AIR SDK.
+ *
+ * NOTES:
+ *      None
+ */
+
+/* INCLUDE FILE DECLARATIONS
+ */
+#include "air.h"
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+
+/* DATA TYPE DECLARATIONS
+ */
+
+/* GLOBAL VARIABLE DECLARATIONS
+ */
+AIR_PRINTF _ext_printf;
+AIR_UDELAY _ext_udelay;
+AIR_MALLOC _ext_malloc;
+AIR_FREE   _ext_free;
+
+/* LOCAL SUBPROGRAM DECLARATIONS
+ */
+
+/* STATIC VARIABLE DECLARATIONS
+ */
+
+/* EXPORTED SUBPROGRAM BODIES
+ */
+
+/* LOCAL SUBPROGRAM BODIES
+ */
+
+/* FUNCTION NAME:   air_init
+ * PURPOSE:
+ *      This API is used to initialize the SDK.
+ *
+ * INPUT:
+ *      unit            --  The device unit
+ *      ptr_init_param  --  The sdk callback functions.
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_OTHERS
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_init(
+    const UI32_T unit,
+    AIR_INIT_PARAM_T *ptr_init_param)
+{
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+    UI32_T u32dat = 0;
+    UI8_T port = 0;
+    AIR_LED_ON_EVT_T on_evt;
+    AIR_LED_BLK_EVT_T blk_evt;
+
+    /* check point */
+    AIR_CHECK_PTR(ptr_init_param);
+
+    _ext_dev_access.read_callback = ptr_init_param->dev_access.read_callback;
+    _ext_dev_access.write_callback = ptr_init_param->dev_access.write_callback;
+    _ext_dev_access.phy_read_callback = ptr_init_param->dev_access.phy_read_callback;
+    _ext_dev_access.phy_write_callback = ptr_init_param->dev_access.phy_write_callback;
+    _ext_dev_access.phy_cl45_read_callback = ptr_init_param->dev_access.phy_cl45_read_callback;
+    _ext_dev_access.phy_cl45_write_callback = ptr_init_param->dev_access.phy_cl45_write_callback;
+    _ext_printf = ptr_init_param->printf;
+    _ext_udelay = ptr_init_param->udelay;
+    _ext_malloc = ptr_init_param->malloc;
+    _ext_free   = ptr_init_param->free;
+    
+    return rc;
+}
+
+/* FUNCTION NAME:   air_hw_reset
+ * PURPOSE:
+ *      This API is used to reset hardware.
+ *
+ * INPUT:
+ *      unit            --  The device unit
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_OTHERS
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_hw_reset(
+    const UI32_T unit)
+{
+    AIR_PRINT(">>>>> enct_hw_reset\n");
+    /* Set an8855 reset pin to 0 */
+
+    /* Delay 100ms */
+
+    /* Set an8855 reset pin to 1 */
+
+    /* Delay 600ms */
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_set_gpio_pin_mux
+ * PURPOSE:
+ *      This API is used to set gpio pin mux.
+ *
+ * INPUT:
+ *      unit            --  The device unit
+ *
+ * OUTPUT:
+ *      None
+ *
+ * RETURN:
+ *      AIR_E_OK
+ *      AIR_E_OTHERS
+ *
+ * NOTES:
+ *      None
+ */
+AIR_ERROR_NO_T
+air_set_gpio_pin_mux(
+    const UI32_T unit)
+{
+    AIR_PRINT(">>>>> enct_set_gpio_pin_mux\n");
+    /* Set GPIO_MODE0 */
+    /* Implementation for SLT HW */
+    aml_writeReg(unit, GPIO_MODE0, 0x11111111);
+
+    return AIR_E_OK;
+}
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_port.c b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_port.c
index 09dcef1..d33bf70 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_port.c
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_port.c
@@ -390,8 +390,8 @@
     AIR_CHECK_PTR(ptr_speed);
 
     /* Read data from register */
-    aml_readPhyReg(unit, port, 0x0, &u32dat);
-    (*ptr_speed) = (BITS_OFF_R(u32dat, 6, 1) << 1) | BITS_OFF_R(u32dat, 13, 1);
+	aml_readReg(unit, PMSR(port), &u32dat);
+	(*ptr_speed) = BITS_OFF_R(u32dat, 28, 3);
 
     return ret;
 }
@@ -491,8 +491,8 @@
     AIR_CHECK_PTR(ptr_duplex);
 
     /* Read data from register */
-    aml_readPhyReg(unit, port, 0x0, &u32dat);
-    (*ptr_duplex) = BITS_OFF_R(u32dat, 8, 1);
+	aml_readReg(unit, PMSR(port), &u32dat);
+	(*ptr_duplex) = BITS_OFF_R(u32dat, 25, 1);
 
     return AIR_E_OK;
 }
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_vlan.c b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_vlan.c
index 6629165..94f296e 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_vlan.c
+++ b/recipes-devtools/switch/files/src/an8855_sdk/api/src/air_vlan.c
@@ -1,1448 +1,1449 @@
-/* FILE NAME:   air_vlan.c

- * PURPOSE:

- *      Define the VLAN function in AIR SDK.

- * NOTES:

- */

-

-/* INCLUDE FILE DECLARATIONS

- */

-#include "air.h"

-

-/* NAMING CONSTANT DECLARATIONS

- */

-

-/* MACRO FUNCTION DECLARATIONS

- */

-

-/* DATA TYPE DECLARATIONS

- */

-

-/* GLOBAL VARIABLE DECLARATIONS

- */

-

-/* LOCAL SUBPROGRAM DECLARATIONS

- */

-

-/* STATIC VARIABLE DECLARATIONS

- */

-

-/* EXPORTED SUBPROGRAM BODIES

- */

-

-/* LOCAL SUBPROGRAM BODIES

-*/

-void

-_air_vlan_readEntry(

-    const UI32_T unit,

-    const UI16_T vid,

-    AIR_VLAN_ENTRY_T* vlan_entry)

-{

-    UI32_T val = 0;

-    val = (0x80000000 + vid); //r_vid_cmd

-    aml_writeReg(unit, VTCR, val);

-

-    for (;;)

-    {

-        aml_readReg(unit, VTCR, &val);

-        if ((val & 0x80000000) == 0)

-            break;

-        AIR_UDELAY(10);

-    }

-

-    aml_readReg(unit, VLNRDATA0, &(vlan_entry->vlan_table.vlan_table0));

-    aml_readReg(unit, VLNRDATA1, &(vlan_entry->vlan_table.vlan_table1));

-}

-

-void

-_air_vlan_writeEntry(

-    const UI32_T unit,

-    const UI16_T vid,

-    AIR_VLAN_ENTRY_T* vlan_entry)

-{

-    UI32_T val = 0;

-

-    aml_writeReg(unit, VLNWDATA0, vlan_entry->vlan_table.vlan_table0);

-    aml_writeReg(unit, VLNWDATA1, vlan_entry->vlan_table.vlan_table1);

-    aml_writeReg(unit, VLNWDATA2, 0);

-    aml_writeReg(unit, VLNWDATA3, 0);

-    aml_writeReg(unit, VLNWDATA4, 0);

-

-    val = (0x80001000 + vid); //w_vid_cmd

-    aml_writeReg(unit, VTCR, val);

-

-    for (;;)

-    {

-        aml_readReg(unit, VTCR, &val);

-        if ((val & 0x80000000) == 0)

-            break;

-        AIR_UDELAY(10);

-    }

-}

-

-void

-_air_untagged_vlan_readEntry(

-    const UI32_T unit,

-    const UI16_T vid,

-    AIR_VLAN_ENTRY_ATTR_T* vlan_entry)

-{

-    UI32_T val = 0;

-    val = (0x80000000 + vid); //r_vid_cmd

-    aml_writeReg(unit, VTCR, val);

-

-    for (;;)

-    {

-        aml_readReg(unit, VTCR, &val);

-        if ((val & 0x80000000) == 0)

-            break;

-        AIR_UDELAY(10);

-    }

-

-    aml_readReg(unit, VLNRDATA0, &(vlan_entry->vlan_table.vlan_table0));

-    aml_readReg(unit, VLNRDATA1, &(vlan_entry->vlan_table.vlan_table1));

-    aml_readReg(unit, VLNRDATA2, &(vlan_entry->vlan_table.vlan_table2));

-    aml_readReg(unit, VLNRDATA3, &(vlan_entry->vlan_table.vlan_table3));

-    aml_readReg(unit, VLNRDATA4, &(vlan_entry->vlan_table.vlan_table4));

-}

-

-void

-_air_untagged_vlan_writeEntry(

-    const UI32_T unit,

-    const UI16_T vid,

-    AIR_VLAN_ENTRY_ATTR_T* vlan_entry)

-{

-    UI32_T val = 0;

-

-    aml_writeReg(unit, VLNWDATA0, vlan_entry->vlan_table.vlan_table0);

-    aml_writeReg(unit, VLNWDATA1, vlan_entry->vlan_table.vlan_table1);

-    aml_writeReg(unit, VLNWDATA2, vlan_entry->vlan_table.vlan_table2);

-    aml_writeReg(unit, VLNWDATA3, vlan_entry->vlan_table.vlan_table3);

-    aml_writeReg(unit, VLNWDATA4, vlan_entry->vlan_table.vlan_table4);

-

-    val = (0x80001000 + vid); //w_vid_cmd

-    aml_writeReg(unit, VTCR, val);

-

-    for (;;)

-    {

-        aml_readReg(unit, VTCR, &val);

-        if ((val & 0x80000000) == 0)

-            break;

-        AIR_UDELAY(10);

-    }

-}

-

-/* FUNCTION NAME:   air_vlan_create

- * PURPOSE:

- *      Create the vlan in the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      p_attr      -- vlan attr

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Vlan creation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_create(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    AIR_VLAN_ENTRY_ATTR_T *p_attr)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (vlan_entry.valid)

-        return AIR_E_ENTRY_EXISTS;

-

-    if (NULL != p_attr)

-    {

-        p_attr->valid = 1;

-        _air_untagged_vlan_writeEntry(unit, vid, p_attr);

-    }

-    else

-    {

-        memset(&vlan_entry, 0, sizeof(vlan_entry));

-        vlan_entry.valid = 1;

-        _air_untagged_vlan_writeEntry(unit, vid, &vlan_entry);

-    }

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_destroy

- * PURPOSE:

- *      Destroy the vlan in the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK     -- Successfully read the data.

- *      AIR_E_OTHERS -- Vlan destroy failed.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_destroy(

-    const UI32_T    unit,

-    const UI16_T    vid)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_destroyAll

- * PURPOSE:

- *      Destroy the vlan in the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK     -- Successfully read the data.

- *      AIR_E_OTHERS -- Vlan destroy failed.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_destroyAll(

-    const UI32_T    unit,

-    const UI32_T    keep_and_restore_default_vlan)

-{

-    UI16_T vid = 0;

-

-    for (vid = AIR_VLAN_ID_MIN; vid <= AIR_VLAN_ID_MAX; vid++)

-    {

-        if (keep_and_restore_default_vlan)

-        {

-            air_vlan_reset(unit, vid);

-        }

-        else

-        {

-            air_vlan_destroy(unit, vid);

-        }

-    }

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_reset

- * PURPOSE:

- *      Destroy the vlan in the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK     -- Successfully reset the data.

- *      AIR_E_OTHERS -- Vlan reset failed.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_reset(

-    const UI32_T    unit,

-    const UI16_T    vid)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-

-    vlan_entry.vlan_entry_format.port_mem = AIR_ALL_PORT_BITMAP;

-    vlan_entry.valid = TRUE;

-

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setFid

- * PURPOSE:

- *      Set the filter id of the vlan to the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      fid         -- filter id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setFid(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI8_T     fid)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    /* VID check */

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((fid > AIR_FILTER_ID_MAX), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    vlan_entry.vlan_entry_format.fid = fid;

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getFid

- * PURPOSE:

- *      Get the filter id of the vlan from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id to be created

- * OUTPUT:

- *      ptr_fid     -- filter id

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getFid(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    UI8_T           *ptr_fid)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_fid);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    *ptr_fid = vlan_entry.vlan_entry_format.fid;

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_addMemberPort

- * PURPOSE:

- *      Add one vlan member to the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      port        -- port id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_addMemberPort(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI32_T    port)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    vlan_entry.vlan_entry_format.port_mem |= 1 << port;

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_delMemberPort

- * PURPOSE:

- *      Delete one vlan member from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      port        -- port id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_delMemberPort(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI32_T    port)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    vlan_entry.vlan_entry_format.port_mem &= ~(1 << port);

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setMemberPort

- * PURPOSE:

- *      Replace the vlan members in the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      port_bitmap -- member port bitmap

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setMemberPort(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI32_T    port_bitmap)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((port_bitmap & (~AIR_ALL_PORT_BITMAP)), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    vlan_entry.vlan_entry_format.port_mem = port_bitmap;

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getMemberPort

- * PURPOSE:

- *      Get the vlan members from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      port_bitmap -- member port bitmap

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getMemberPort(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    UI32_T          *ptr_port_bitmap)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_port_bitmap);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    *ptr_port_bitmap = vlan_entry.vlan_entry_format.port_mem;

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setIVL

- * PURPOSE:

- *      Set L2 lookup mode IVL/SVL for L2 traffic.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      enable      -- enable IVL

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setIVL(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const BOOL_T    enable)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    vlan_entry.vlan_entry_format.ivl = enable ? 1 : 0;

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getIVL

- * PURPOSE:

- *      Get L2 lookup mode IVL/SVL for L2 traffic.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      ptr_enable  -- enable IVL

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getIVL(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    BOOL_T          *ptr_enable)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_enable);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    *ptr_enable = vlan_entry.vlan_entry_format.ivl;

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setPortAcceptFrameType

- * PURPOSE:

- *      Set vlan accept frame type of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      type        -- accept frame type

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortAcceptFrameType(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const AIR_VLAN_ACCEPT_FRAME_TYPE_T type)

-{

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((type >= AIR_VLAN_ACCEPT_FRAME_TYPE_LAST), AIR_E_BAD_PARAMETER);

-

-    aml_readReg(unit, PVC(port), &val);

-    val &= ~PVC_ACC_FRM_MASK;

-    val |= (type & PVC_ACC_FRM_RELMASK) << PVC_ACC_FRM_OFFT;

-    aml_writeReg(unit, PVC(port), val);

-

-    return rc;

-}

-

-/* FUNCTION NAME:   air_vlan_getPortAcceptFrameType

- * PURPOSE:

- *      Get vlan accept frame type of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      ptr_type    -- accept frame type

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortAcceptFrameType(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_VLAN_ACCEPT_FRAME_TYPE_T *ptr_type)

-{

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_type);

-

-    aml_readReg(unit, PVC(port), &val);

-    *ptr_type = (val >> PVC_ACC_FRM_OFFT) & PVC_ACC_FRM_RELMASK;

-

-    return rc;

-}

-

-/* FUNCTION NAME:   air_vlan_setPortLeakyVlanEnable

- * PURPOSE:

- *      Set leaky vlan enable of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      pkt_type    -- packet type

- *      enable      -- enable leaky

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortLeakyVlanEnable(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_LEAKY_PKT_TYPE_T   pkt_type,

-    const BOOL_T    enable)

-{

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((pkt_type >= AIR_LEAKY_PKT_TYPE_LAST), AIR_E_BAD_PARAMETER);

-

-    aml_readReg(unit, PVC(port), &val);

-

-    if (pkt_type == AIR_LEAKY_PKT_TYPE_UNICAST)

-    {

-        if (enable)

-        {

-            val |= PVC_UC_LKYV_EN_MASK;

-        }

-        else

-        {

-            val &= ~PVC_UC_LKYV_EN_MASK;

-        }

-    }

-    else if (pkt_type == AIR_LEAKY_PKT_TYPE_MULTICAST)

-    {

-        if (enable)

-        {

-            val |= PVC_MC_LKYV_EN_MASK;

-        }

-        else

-        {

-            val &= ~PVC_MC_LKYV_EN_MASK;

-        }

-    }

-    else

-    {

-        if (enable)

-        {

-            val |= PVC_BC_LKYV_EN_MASK;

-        }

-        else

-        {

-            val &= ~PVC_BC_LKYV_EN_MASK;

-        }

-    }

-

-    aml_writeReg(unit, PVC(port), val);

-

-    return rc;

-}

-

-/* FUNCTION NAME:   air_vlan_getPortLeakyVlanEnable

- * PURPOSE:

- *      Get leaky vlan enable of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      pkt_type    -- packet type

- * OUTPUT:

- *      ptr_enable  -- enable leaky

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortLeakyVlanEnable(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_LEAKY_PKT_TYPE_T   pkt_type,

-    BOOL_T          *ptr_enable)

-{

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((pkt_type >= AIR_LEAKY_PKT_TYPE_LAST), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_enable);

-

-    aml_readReg(unit, PVC(port), &val);

-

-    if (pkt_type == AIR_LEAKY_PKT_TYPE_UNICAST)

-    {

-        *ptr_enable = val & PVC_UC_LKYV_EN_MASK ? TRUE : FALSE;

-    }

-    else if (pkt_type == AIR_LEAKY_PKT_TYPE_MULTICAST)

-    {

-        *ptr_enable = val & PVC_MC_LKYV_EN_MASK ? TRUE : FALSE;

-    }

-    else

-    {

-        *ptr_enable = val & PVC_BC_LKYV_EN_MASK ? TRUE : FALSE;

-    }

-

-    return rc;

-}

-

-/* FUNCTION NAME:   air_vlan_setPortAttr

- * PURPOSE:

- *      Set vlan port attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      attr        -- vlan port attr

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const AIR_VLAN_PORT_ATTR_T attr)

-{

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((attr >= AIR_VLAN_PORT_ATTR_LAST), AIR_E_BAD_PARAMETER);

-

-    aml_readReg(unit, PVC(port), &val);

-    val &= ~PVC_VLAN_ATTR_MASK;

-    val |= (attr & PVC_VLAN_ATTR_RELMASK) << PVC_VLAN_ATTR_OFFT;

-    aml_writeReg(unit, PVC(port), val);

-

-    return rc;

-}

-

-/* FUNCTION NAME:   air_vlan_getPortAttr

- * PURPOSE:

- *      Get vlan port attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      ptr_attr    -- vlan port attr

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_VLAN_PORT_ATTR_T *ptr_attr)

-{

-    AIR_ERROR_NO_T rc = AIR_E_OK;

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_attr);

-

-    aml_readReg(unit, PVC(port), &val);

-    *ptr_attr = (val >> PVC_VLAN_ATTR_OFFT) & PVC_VLAN_ATTR_RELMASK;

-

-    return rc;

-}

-

-/* FUNCTION NAME:   air_vlan_setIgrPortTagAttr

- * PURPOSE:

- *      Set vlan incoming port egress tag attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      attr        -- egress tag attr

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setIgrPortTagAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const AIR_IGR_PORT_EG_TAG_ATTR_T attr)

-{

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((attr >= AIR_IGR_PORT_EG_TAG_ATTR_LAST), AIR_E_BAD_PARAMETER);

-

-    aml_readReg(unit, PVC(port), &val);

-    val &= ~PVC_EG_TAG_MASK;

-    val |= (attr & PVC_EG_TAG_RELMASK) << PVC_EG_TAG_OFFT;

-    aml_writeReg(unit, PVC(port), val);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getIgrPortTagAttr

- * PURPOSE:

- *      Get vlan incoming port egress tag attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      ptr_attr    -- egress tag attr

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getIgrPortTagAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_IGR_PORT_EG_TAG_ATTR_T *ptr_attr)

-{

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_attr);

-

-    aml_readReg(unit, PVC(port), &val);

-    *ptr_attr = (val >> PVC_EG_TAG_OFFT) & PVC_EG_TAG_RELMASK;

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setPortEgsTagAttr

- * PURPOSE:

- *      Set vlan port egress tag attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      attr        -- egress tag attr

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortEgsTagAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const AIR_PORT_EGS_TAG_ATTR_T attr)

-{

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((attr >= AIR_PORT_EGS_TAG_ATTR_LAST), AIR_E_BAD_PARAMETER);

-

-    aml_readReg(unit, PCR(port), &val);

-    val &= ~PCR_EG_TAG_MASK;

-    val |= (attr & PCR_EG_TAG_RELMASK) << PCR_EG_TAG_OFFT;

-    aml_writeReg(unit, PCR(port), val);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getPortEgsTagAttr

- * PURPOSE:

- *      Get vlan port egress tag attribute from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      ptr_attr    -- egress tag attr

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortEgsTagAttr(

-    const UI32_T    unit,

-    const UI32_T    port,

-    AIR_PORT_EGS_TAG_ATTR_T *ptr_attr)

-{

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_attr);

-

-    aml_readReg(unit, PCR(port), &val);

-    *ptr_attr = (val >> PCR_EG_TAG_OFFT) & PCR_EG_TAG_RELMASK;

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setPortOuterTPID

- * PURPOSE:

- *      Set stack tag TPID of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      tpid        -- TPID

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortOuterTPID(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const UI16_T    tpid)

-{

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-

-    aml_readReg(unit, PVC(port), &val);

-    val &= ~PVC_STAG_VPID_MASK;

-    val |= (tpid & PVC_STAG_VPID_RELMASK) << PVC_STAG_VPID_OFFT;

-    aml_writeReg(unit, PVC(port), val);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getPortOuterTPID

- * PURPOSE:

- *      Get stack tag TPID of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      ptr_tpid    -- TPID

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortOuterTPID(

-    const UI32_T    unit,

-    const UI32_T    port,

-    UI16_T          *ptr_tpid)

-{

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_tpid);

-

-    aml_readReg(unit, PVC(port), &val);

-    *ptr_tpid = (val >> PVC_STAG_VPID_OFFT) & PVC_STAG_VPID_RELMASK;

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setPortPVID

- * PURPOSE:

- *      Set PVID of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- *      pvid        -- native vlan id

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortPVID(

-    const UI32_T    unit,

-    const UI32_T    port,

-    const UI16_T    pvid)

-{

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((pvid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-

-    aml_readReg(unit, PVID(port), &val);

-    val &= ~PVID_PCVID_MASK;

-    val |= (pvid & PVID_PCVID_RELMASK) << PVID_PCVID_OFFT;

-    aml_writeReg(unit, PVID(port), val);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getPortPVID

- * PURPOSE:

- *      Get PVID of the port from the specified device.

- * INPUT:

- *      unit        -- unit id

- *      port        -- port id

- * OUTPUT:

- *      ptr_pvid    -- native vlan id

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortPVID(

-    const UI32_T    unit,

-    const UI32_T    port,

-    UI16_T          *ptr_pvid)

-{

-    UI32_T val = 0;

-

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_pvid);

-

-    aml_readReg(unit, PVID(port), &val);

-    *ptr_pvid = (val >> PVID_PCVID_OFFT) & PVID_PCVID_RELMASK;

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setServiceTag

- * PURPOSE:

- *      Set Vlan service tag.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      stag        -- service stag

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setServiceTag(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI16_T    stag)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((stag > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    vlan_entry.vlan_entry_format.stag = stag;

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getServiceTag

- * PURPOSE:

- *      Get Vlan service tag.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      ptr_stag    -- service stag

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getServiceTag(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    UI16_T          *ptr_stag)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_stag);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    *ptr_stag = vlan_entry.vlan_entry_format.stag;

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setEgsTagCtlEnable

- * PURPOSE:

- *      Set per vlan egress tag control.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      enable      -- enable vlan egress tag control

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setEgsTagCtlEnable(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const BOOL_T    enable)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    vlan_entry.vlan_entry_format.eg_ctrl_en = enable ? 1 : 0;

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getEgsTagCtlEnable

- * PURPOSE:

- *      Get per vlan egress tag control.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      ptr_enable  -- enable vlan egress tag control

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getEgsTagCtlEnable(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    BOOL_T          *ptr_enable)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_enable);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    *ptr_enable = vlan_entry.vlan_entry_format.eg_ctrl_en;

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setEgsTagConsistent

- * PURPOSE:

- *      Set per vlan egress tag consistent.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      enable      -- enable vlan egress tag consistent

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setEgsTagConsistent(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const BOOL_T    enable)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    vlan_entry.vlan_entry_format.eg_con = enable;

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getEgsTagConsistent

- * PURPOSE:

- *      Get per vlan egress tag consistent.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      ptr_enable  -- enable vlan egress tag consistent

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getEgsTagConsistent(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    BOOL_T          *ptr_enable)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_enable);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    *ptr_enable = vlan_entry.vlan_entry_format.eg_con;

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setPortBasedStag

- * PURPOSE:

- *      Set vlan port based stag enable.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      enable      -- vlan port based stag enable

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortBasedStag(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const BOOL_T    enable)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    vlan_entry.vlan_entry_format.port_stag = enable;

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getPortBasedStag

- * PURPOSE:

- *      Get vlan port based stag enable.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      ptr_enable  -- vlan port based stag enable

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortBasedStag(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    BOOL_T          *ptr_enable)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_enable);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    *ptr_enable = vlan_entry.vlan_entry_format.port_stag;

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_setPortEgsTagCtl

- * PURPOSE:

- *      Set vlan port egress tag control.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- *      port        -- port id

- *      tag_ctl     -- egress tag control

- * OUTPUT:

- *      None

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_setPortEgsTagCtl(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI32_T    port,

-    const AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_T    tag_ctl)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((tag_ctl >= AIR_PORT_EGS_TAG_ATTR_LAST), AIR_E_BAD_PARAMETER);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    vlan_entry.vlan_entry_format.eg_ctrl &= ~(0x3 << (port * 2));

-    vlan_entry.vlan_entry_format.eg_ctrl |= (tag_ctl & 0x3) << (port * 2);

-    _air_vlan_writeEntry(unit, vid, &vlan_entry);

-

-    return AIR_E_OK;

-}

-

-/* FUNCTION NAME:   air_vlan_getPortEgsTagCtl

- * PURPOSE:

- *      Get vlan port egress tag control.

- * INPUT:

- *      unit        -- unit id

- *      vid         -- vlan id

- * OUTPUT:

- *      ptr_tag_ctl -- egress tag control

- * RETURN:

- *      AIR_E_OK                -- Successfully read the data.

- *      AIR_E_OTHERS            -- Operation failed.

- *      AIR_E_BAD_PARAMETER     -- Invalid parameter.

- * NOTES:

- *      none

- */

-AIR_ERROR_NO_T

-air_vlan_getPortEgsTagCtl(

-    const UI32_T    unit,

-    const UI16_T    vid,

-    const UI32_T    port,

-    AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_T   *ptr_tag_ctl)

-{

-    AIR_VLAN_ENTRY_T vlan_entry = {0};

-

-    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);

-    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);

-    AIR_CHECK_PTR(ptr_tag_ctl);

-

-    _air_vlan_readEntry(unit, vid, &vlan_entry);

-    if (!vlan_entry.valid)

-        return AIR_E_ENTRY_NOT_FOUND;

-

-    *ptr_tag_ctl = (vlan_entry.vlan_entry_format.eg_ctrl >> (port * 2)) & 0x3;

-

-    return AIR_E_OK;

-}

+/* FILE NAME:   air_vlan.c
+ * PURPOSE:
+ *      Define the VLAN function in AIR SDK.
+ * NOTES:
+ */
+
+/* INCLUDE FILE DECLARATIONS
+ */
+#include "air.h"
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+
+/* DATA TYPE DECLARATIONS
+ */
+
+/* GLOBAL VARIABLE DECLARATIONS
+ */
+
+/* LOCAL SUBPROGRAM DECLARATIONS
+ */
+
+/* STATIC VARIABLE DECLARATIONS
+ */
+
+/* EXPORTED SUBPROGRAM BODIES
+ */
+
+/* LOCAL SUBPROGRAM BODIES
+*/
+void
+_air_vlan_readEntry(
+    const UI32_T unit,
+    const UI16_T vid,
+    AIR_VLAN_ENTRY_T* vlan_entry)
+{
+    UI32_T val = 0;
+    val = (0x80000000 + vid); //r_vid_cmd
+    aml_writeReg(unit, VTCR, val);
+
+    for (;;)
+    {
+        aml_readReg(unit, VTCR, &val);
+        if ((val & 0x80000000) == 0)
+            break;
+        AIR_UDELAY(10);
+    }
+
+    aml_readReg(unit, VLNRDATA0, &(vlan_entry->vlan_table.vlan_table0));
+    aml_readReg(unit, VLNRDATA1, &(vlan_entry->vlan_table.vlan_table1));
+}
+
+void
+_air_vlan_writeEntry(
+    const UI32_T unit,
+    const UI16_T vid,
+    AIR_VLAN_ENTRY_T* vlan_entry)
+{
+    UI32_T val = 0;
+
+    aml_writeReg(unit, VLNWDATA0, vlan_entry->vlan_table.vlan_table0);
+    aml_writeReg(unit, VLNWDATA1, vlan_entry->vlan_table.vlan_table1);
+    aml_writeReg(unit, VLNWDATA2, 0);
+    aml_writeReg(unit, VLNWDATA3, 0);
+    aml_writeReg(unit, VLNWDATA4, 0);
+
+    val = (0x80001000 + vid); //w_vid_cmd
+    aml_writeReg(unit, VTCR, val);
+
+    for (;;)
+    {
+        aml_readReg(unit, VTCR, &val);
+        if ((val & 0x80000000) == 0)
+            break;
+        AIR_UDELAY(10);
+    }
+}
+
+void
+_air_untagged_vlan_readEntry(
+    const UI32_T unit,
+    const UI16_T vid,
+    AIR_VLAN_ENTRY_ATTR_T* vlan_entry)
+{
+    UI32_T val = 0;
+    val = (0x80000000 + vid); //r_vid_cmd
+    aml_writeReg(unit, VTCR, val);
+
+    for (;;)
+    {
+        aml_readReg(unit, VTCR, &val);
+        if ((val & 0x80000000) == 0)
+            break;
+        AIR_UDELAY(10);
+    }
+
+    aml_readReg(unit, VLNRDATA0, &(vlan_entry->vlan_table.vlan_table0));
+    aml_readReg(unit, VLNRDATA1, &(vlan_entry->vlan_table.vlan_table1));
+    aml_readReg(unit, VLNRDATA2, &(vlan_entry->vlan_table.vlan_table2));
+    aml_readReg(unit, VLNRDATA3, &(vlan_entry->vlan_table.vlan_table3));
+    aml_readReg(unit, VLNRDATA4, &(vlan_entry->vlan_table.vlan_table4));
+}
+
+void
+_air_untagged_vlan_writeEntry(
+    const UI32_T unit,
+    const UI16_T vid,
+    AIR_VLAN_ENTRY_ATTR_T* vlan_entry)
+{
+    UI32_T val = 0;
+
+    aml_writeReg(unit, VLNWDATA0, vlan_entry->vlan_table.vlan_table0);
+    aml_writeReg(unit, VLNWDATA1, vlan_entry->vlan_table.vlan_table1);
+    aml_writeReg(unit, VLNWDATA2, vlan_entry->vlan_table.vlan_table2);
+    aml_writeReg(unit, VLNWDATA3, vlan_entry->vlan_table.vlan_table3);
+    aml_writeReg(unit, VLNWDATA4, vlan_entry->vlan_table.vlan_table4);
+
+    val = (0x80001000 + vid); //w_vid_cmd
+    aml_writeReg(unit, VTCR, val);
+
+    for (;;)
+    {
+        aml_readReg(unit, VTCR, &val);
+        if ((val & 0x80000000) == 0)
+            break;
+        AIR_UDELAY(10);
+    }
+}
+
+/* FUNCTION NAME:   air_vlan_create
+ * PURPOSE:
+ *      Create the vlan in the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      p_attr      -- vlan attr
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Vlan creation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_create(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    AIR_VLAN_ENTRY_ATTR_T *p_attr)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+    AIR_VLAN_ENTRY_ATTR_T vlan_attr_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (vlan_entry.valid)
+        return AIR_E_ENTRY_EXISTS;
+
+    if (NULL != p_attr)
+    {
+        p_attr->valid = 1;
+        _air_untagged_vlan_writeEntry(unit, vid, p_attr);
+    }
+    else
+    {
+        memset(&vlan_attr_entry, 0, sizeof(vlan_attr_entry));
+        vlan_attr_entry.valid = 1;
+        _air_untagged_vlan_writeEntry(unit, vid, &vlan_attr_entry);
+    }
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_destroy
+ * PURPOSE:
+ *      Destroy the vlan in the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK     -- Successfully read the data.
+ *      AIR_E_OTHERS -- Vlan destroy failed.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_destroy(
+    const UI32_T    unit,
+    const UI16_T    vid)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_destroyAll
+ * PURPOSE:
+ *      Destroy the vlan in the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK     -- Successfully read the data.
+ *      AIR_E_OTHERS -- Vlan destroy failed.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_destroyAll(
+    const UI32_T    unit,
+    const UI32_T    keep_and_restore_default_vlan)
+{
+    UI16_T vid = 0;
+
+    for (vid = AIR_VLAN_ID_MIN; vid <= AIR_VLAN_ID_MAX; vid++)
+    {
+        if (keep_and_restore_default_vlan)
+        {
+            air_vlan_reset(unit, vid);
+        }
+        else
+        {
+            air_vlan_destroy(unit, vid);
+        }
+    }
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_reset
+ * PURPOSE:
+ *      Destroy the vlan in the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK     -- Successfully reset the data.
+ *      AIR_E_OTHERS -- Vlan reset failed.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_reset(
+    const UI32_T    unit,
+    const UI16_T    vid)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+
+    vlan_entry.vlan_entry_format.port_mem = AIR_ALL_PORT_BITMAP;
+    vlan_entry.valid = TRUE;
+
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setFid
+ * PURPOSE:
+ *      Set the filter id of the vlan to the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      fid         -- filter id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setFid(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI8_T     fid)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    /* VID check */
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((fid > AIR_FILTER_ID_MAX), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    vlan_entry.vlan_entry_format.fid = fid;
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getFid
+ * PURPOSE:
+ *      Get the filter id of the vlan from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id to be created
+ * OUTPUT:
+ *      ptr_fid     -- filter id
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getFid(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    UI8_T           *ptr_fid)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_fid);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    *ptr_fid = vlan_entry.vlan_entry_format.fid;
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_addMemberPort
+ * PURPOSE:
+ *      Add one vlan member to the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      port        -- port id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_addMemberPort(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI32_T    port)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    vlan_entry.vlan_entry_format.port_mem |= 1 << port;
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_delMemberPort
+ * PURPOSE:
+ *      Delete one vlan member from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      port        -- port id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_delMemberPort(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI32_T    port)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    vlan_entry.vlan_entry_format.port_mem &= ~(1 << port);
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setMemberPort
+ * PURPOSE:
+ *      Replace the vlan members in the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      port_bitmap -- member port bitmap
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setMemberPort(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI32_T    port_bitmap)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((port_bitmap & (~AIR_ALL_PORT_BITMAP)), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    vlan_entry.vlan_entry_format.port_mem = port_bitmap;
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getMemberPort
+ * PURPOSE:
+ *      Get the vlan members from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      port_bitmap -- member port bitmap
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getMemberPort(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    UI32_T          *ptr_port_bitmap)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_port_bitmap);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    *ptr_port_bitmap = vlan_entry.vlan_entry_format.port_mem;
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setIVL
+ * PURPOSE:
+ *      Set L2 lookup mode IVL/SVL for L2 traffic.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      enable      -- enable IVL
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setIVL(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const BOOL_T    enable)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    vlan_entry.vlan_entry_format.ivl = enable ? 1 : 0;
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getIVL
+ * PURPOSE:
+ *      Get L2 lookup mode IVL/SVL for L2 traffic.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      ptr_enable  -- enable IVL
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getIVL(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    BOOL_T          *ptr_enable)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_enable);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    *ptr_enable = vlan_entry.vlan_entry_format.ivl;
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setPortAcceptFrameType
+ * PURPOSE:
+ *      Set vlan accept frame type of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      type        -- accept frame type
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortAcceptFrameType(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const AIR_VLAN_ACCEPT_FRAME_TYPE_T type)
+{
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((type >= AIR_VLAN_ACCEPT_FRAME_TYPE_LAST), AIR_E_BAD_PARAMETER);
+
+    aml_readReg(unit, PVC(port), &val);
+    val &= ~PVC_ACC_FRM_MASK;
+    val |= (type & PVC_ACC_FRM_RELMASK) << PVC_ACC_FRM_OFFT;
+    aml_writeReg(unit, PVC(port), val);
+
+    return rc;
+}
+
+/* FUNCTION NAME:   air_vlan_getPortAcceptFrameType
+ * PURPOSE:
+ *      Get vlan accept frame type of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      ptr_type    -- accept frame type
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortAcceptFrameType(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_VLAN_ACCEPT_FRAME_TYPE_T *ptr_type)
+{
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_type);
+
+    aml_readReg(unit, PVC(port), &val);
+    *ptr_type = (val >> PVC_ACC_FRM_OFFT) & PVC_ACC_FRM_RELMASK;
+
+    return rc;
+}
+
+/* FUNCTION NAME:   air_vlan_setPortLeakyVlanEnable
+ * PURPOSE:
+ *      Set leaky vlan enable of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      pkt_type    -- packet type
+ *      enable      -- enable leaky
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortLeakyVlanEnable(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_LEAKY_PKT_TYPE_T   pkt_type,
+    const BOOL_T    enable)
+{
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((pkt_type >= AIR_LEAKY_PKT_TYPE_LAST), AIR_E_BAD_PARAMETER);
+
+    aml_readReg(unit, PVC(port), &val);
+
+    if (pkt_type == AIR_LEAKY_PKT_TYPE_UNICAST)
+    {
+        if (enable)
+        {
+            val |= PVC_UC_LKYV_EN_MASK;
+        }
+        else
+        {
+            val &= ~PVC_UC_LKYV_EN_MASK;
+        }
+    }
+    else if (pkt_type == AIR_LEAKY_PKT_TYPE_MULTICAST)
+    {
+        if (enable)
+        {
+            val |= PVC_MC_LKYV_EN_MASK;
+        }
+        else
+        {
+            val &= ~PVC_MC_LKYV_EN_MASK;
+        }
+    }
+    else
+    {
+        if (enable)
+        {
+            val |= PVC_BC_LKYV_EN_MASK;
+        }
+        else
+        {
+            val &= ~PVC_BC_LKYV_EN_MASK;
+        }
+    }
+
+    aml_writeReg(unit, PVC(port), val);
+
+    return rc;
+}
+
+/* FUNCTION NAME:   air_vlan_getPortLeakyVlanEnable
+ * PURPOSE:
+ *      Get leaky vlan enable of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      pkt_type    -- packet type
+ * OUTPUT:
+ *      ptr_enable  -- enable leaky
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortLeakyVlanEnable(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_LEAKY_PKT_TYPE_T   pkt_type,
+    BOOL_T          *ptr_enable)
+{
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((pkt_type >= AIR_LEAKY_PKT_TYPE_LAST), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_enable);
+
+    aml_readReg(unit, PVC(port), &val);
+
+    if (pkt_type == AIR_LEAKY_PKT_TYPE_UNICAST)
+    {
+        *ptr_enable = val & PVC_UC_LKYV_EN_MASK ? TRUE : FALSE;
+    }
+    else if (pkt_type == AIR_LEAKY_PKT_TYPE_MULTICAST)
+    {
+        *ptr_enable = val & PVC_MC_LKYV_EN_MASK ? TRUE : FALSE;
+    }
+    else
+    {
+        *ptr_enable = val & PVC_BC_LKYV_EN_MASK ? TRUE : FALSE;
+    }
+
+    return rc;
+}
+
+/* FUNCTION NAME:   air_vlan_setPortAttr
+ * PURPOSE:
+ *      Set vlan port attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      attr        -- vlan port attr
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const AIR_VLAN_PORT_ATTR_T attr)
+{
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((attr >= AIR_VLAN_PORT_ATTR_LAST), AIR_E_BAD_PARAMETER);
+
+    aml_readReg(unit, PVC(port), &val);
+    val &= ~PVC_VLAN_ATTR_MASK;
+    val |= (attr & PVC_VLAN_ATTR_RELMASK) << PVC_VLAN_ATTR_OFFT;
+    aml_writeReg(unit, PVC(port), val);
+
+    return rc;
+}
+
+/* FUNCTION NAME:   air_vlan_getPortAttr
+ * PURPOSE:
+ *      Get vlan port attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      ptr_attr    -- vlan port attr
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_VLAN_PORT_ATTR_T *ptr_attr)
+{
+    AIR_ERROR_NO_T rc = AIR_E_OK;
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_attr);
+
+    aml_readReg(unit, PVC(port), &val);
+    *ptr_attr = (val >> PVC_VLAN_ATTR_OFFT) & PVC_VLAN_ATTR_RELMASK;
+
+    return rc;
+}
+
+/* FUNCTION NAME:   air_vlan_setIgrPortTagAttr
+ * PURPOSE:
+ *      Set vlan incoming port egress tag attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      attr        -- egress tag attr
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setIgrPortTagAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const AIR_IGR_PORT_EG_TAG_ATTR_T attr)
+{
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((attr >= AIR_IGR_PORT_EG_TAG_ATTR_LAST), AIR_E_BAD_PARAMETER);
+
+    aml_readReg(unit, PVC(port), &val);
+    val &= ~PVC_EG_TAG_MASK;
+    val |= (attr & PVC_EG_TAG_RELMASK) << PVC_EG_TAG_OFFT;
+    aml_writeReg(unit, PVC(port), val);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getIgrPortTagAttr
+ * PURPOSE:
+ *      Get vlan incoming port egress tag attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      ptr_attr    -- egress tag attr
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getIgrPortTagAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_IGR_PORT_EG_TAG_ATTR_T *ptr_attr)
+{
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_attr);
+
+    aml_readReg(unit, PVC(port), &val);
+    *ptr_attr = (val >> PVC_EG_TAG_OFFT) & PVC_EG_TAG_RELMASK;
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setPortEgsTagAttr
+ * PURPOSE:
+ *      Set vlan port egress tag attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      attr        -- egress tag attr
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortEgsTagAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const AIR_PORT_EGS_TAG_ATTR_T attr)
+{
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((attr >= AIR_PORT_EGS_TAG_ATTR_LAST), AIR_E_BAD_PARAMETER);
+
+    aml_readReg(unit, PCR(port), &val);
+    val &= ~PCR_EG_TAG_MASK;
+    val |= (attr & PCR_EG_TAG_RELMASK) << PCR_EG_TAG_OFFT;
+    aml_writeReg(unit, PCR(port), val);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getPortEgsTagAttr
+ * PURPOSE:
+ *      Get vlan port egress tag attribute from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      ptr_attr    -- egress tag attr
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortEgsTagAttr(
+    const UI32_T    unit,
+    const UI32_T    port,
+    AIR_PORT_EGS_TAG_ATTR_T *ptr_attr)
+{
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_attr);
+
+    aml_readReg(unit, PCR(port), &val);
+    *ptr_attr = (val >> PCR_EG_TAG_OFFT) & PCR_EG_TAG_RELMASK;
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setPortOuterTPID
+ * PURPOSE:
+ *      Set stack tag TPID of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      tpid        -- TPID
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortOuterTPID(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const UI16_T    tpid)
+{
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+
+    aml_readReg(unit, PVC(port), &val);
+    val &= ~PVC_STAG_VPID_MASK;
+    val |= (tpid & PVC_STAG_VPID_RELMASK) << PVC_STAG_VPID_OFFT;
+    aml_writeReg(unit, PVC(port), val);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getPortOuterTPID
+ * PURPOSE:
+ *      Get stack tag TPID of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      ptr_tpid    -- TPID
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortOuterTPID(
+    const UI32_T    unit,
+    const UI32_T    port,
+    UI16_T          *ptr_tpid)
+{
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_tpid);
+
+    aml_readReg(unit, PVC(port), &val);
+    *ptr_tpid = (val >> PVC_STAG_VPID_OFFT) & PVC_STAG_VPID_RELMASK;
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setPortPVID
+ * PURPOSE:
+ *      Set PVID of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ *      pvid        -- native vlan id
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortPVID(
+    const UI32_T    unit,
+    const UI32_T    port,
+    const UI16_T    pvid)
+{
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((pvid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+
+    aml_readReg(unit, PVID(port), &val);
+    val &= ~PVID_PCVID_MASK;
+    val |= (pvid & PVID_PCVID_RELMASK) << PVID_PCVID_OFFT;
+    aml_writeReg(unit, PVID(port), val);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getPortPVID
+ * PURPOSE:
+ *      Get PVID of the port from the specified device.
+ * INPUT:
+ *      unit        -- unit id
+ *      port        -- port id
+ * OUTPUT:
+ *      ptr_pvid    -- native vlan id
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortPVID(
+    const UI32_T    unit,
+    const UI32_T    port,
+    UI16_T          *ptr_pvid)
+{
+    UI32_T val = 0;
+
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_pvid);
+
+    aml_readReg(unit, PVID(port), &val);
+    *ptr_pvid = (val >> PVID_PCVID_OFFT) & PVID_PCVID_RELMASK;
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setServiceTag
+ * PURPOSE:
+ *      Set Vlan service tag.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      stag        -- service stag
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setServiceTag(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI16_T    stag)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((stag > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    vlan_entry.vlan_entry_format.stag = stag;
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getServiceTag
+ * PURPOSE:
+ *      Get Vlan service tag.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      ptr_stag    -- service stag
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getServiceTag(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    UI16_T          *ptr_stag)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_stag);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    *ptr_stag = vlan_entry.vlan_entry_format.stag;
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setEgsTagCtlEnable
+ * PURPOSE:
+ *      Set per vlan egress tag control.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      enable      -- enable vlan egress tag control
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setEgsTagCtlEnable(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const BOOL_T    enable)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    vlan_entry.vlan_entry_format.eg_ctrl_en = enable ? 1 : 0;
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getEgsTagCtlEnable
+ * PURPOSE:
+ *      Get per vlan egress tag control.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      ptr_enable  -- enable vlan egress tag control
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getEgsTagCtlEnable(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    BOOL_T          *ptr_enable)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_enable);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    *ptr_enable = vlan_entry.vlan_entry_format.eg_ctrl_en;
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setEgsTagConsistent
+ * PURPOSE:
+ *      Set per vlan egress tag consistent.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      enable      -- enable vlan egress tag consistent
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setEgsTagConsistent(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const BOOL_T    enable)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    vlan_entry.vlan_entry_format.eg_con = enable;
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getEgsTagConsistent
+ * PURPOSE:
+ *      Get per vlan egress tag consistent.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      ptr_enable  -- enable vlan egress tag consistent
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getEgsTagConsistent(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    BOOL_T          *ptr_enable)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_enable);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    *ptr_enable = vlan_entry.vlan_entry_format.eg_con;
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setPortBasedStag
+ * PURPOSE:
+ *      Set vlan port based stag enable.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      enable      -- vlan port based stag enable
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortBasedStag(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const BOOL_T    enable)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    vlan_entry.vlan_entry_format.port_stag = enable;
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getPortBasedStag
+ * PURPOSE:
+ *      Get vlan port based stag enable.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      ptr_enable  -- vlan port based stag enable
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortBasedStag(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    BOOL_T          *ptr_enable)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_enable);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    *ptr_enable = vlan_entry.vlan_entry_format.port_stag;
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_setPortEgsTagCtl
+ * PURPOSE:
+ *      Set vlan port egress tag control.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ *      port        -- port id
+ *      tag_ctl     -- egress tag control
+ * OUTPUT:
+ *      None
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_setPortEgsTagCtl(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI32_T    port,
+    const AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_T    tag_ctl)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((tag_ctl >= AIR_PORT_EGS_TAG_ATTR_LAST), AIR_E_BAD_PARAMETER);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    vlan_entry.vlan_entry_format.eg_ctrl &= ~(0x3 << (port * 2));
+    vlan_entry.vlan_entry_format.eg_ctrl |= (tag_ctl & 0x3) << (port * 2);
+    _air_vlan_writeEntry(unit, vid, &vlan_entry);
+
+    return AIR_E_OK;
+}
+
+/* FUNCTION NAME:   air_vlan_getPortEgsTagCtl
+ * PURPOSE:
+ *      Get vlan port egress tag control.
+ * INPUT:
+ *      unit        -- unit id
+ *      vid         -- vlan id
+ * OUTPUT:
+ *      ptr_tag_ctl -- egress tag control
+ * RETURN:
+ *      AIR_E_OK                -- Successfully read the data.
+ *      AIR_E_OTHERS            -- Operation failed.
+ *      AIR_E_BAD_PARAMETER     -- Invalid parameter.
+ * NOTES:
+ *      none
+ */
+AIR_ERROR_NO_T
+air_vlan_getPortEgsTagCtl(
+    const UI32_T    unit,
+    const UI16_T    vid,
+    const UI32_T    port,
+    AIR_VLAN_PORT_EGS_TAG_CTL_TYPE_T   *ptr_tag_ctl)
+{
+    AIR_VLAN_ENTRY_T vlan_entry = {0};
+
+    AIR_PARAM_CHK((vid > AIR_VLAN_ID_MAX), AIR_E_BAD_PARAMETER);
+    AIR_PARAM_CHK((port >= AIR_MAX_NUM_OF_PORTS), AIR_E_BAD_PARAMETER);
+    AIR_CHECK_PTR(ptr_tag_ctl);
+
+    _air_vlan_readEntry(unit, vid, &vlan_entry);
+    if (!vlan_entry.valid)
+        return AIR_E_ENTRY_NOT_FOUND;
+
+    *ptr_tag_ctl = (vlan_entry.vlan_entry_format.eg_ctrl >> (port * 2)) & 0x3;
+
+    return AIR_E_OK;
+}
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_mdio.h b/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_mdio.h
index c2d4bd7..5322393 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_mdio.h
+++ b/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_mdio.h
@@ -1,203 +1,203 @@
-/* FILE NAME:  an8855_mdio.h

- * PURPOSE:

- *      It provides AN8855 mdio access API.

- * NOTES:

- *

- */

-

-#ifndef AN8855_MDIO_H

-#define AN8855_MDIO_H

-

-/* INCLUDE FILE DECLARATIONS

- */

-//#include "CTP_type.h"

-//#include "CTP_shell.h"

-//#include "common.h"

-//#include "eth.h"

-

-/* NAMING CONSTANT DECLARATIONS

- */

-

-/* MACRO FUNCTION DECLARATIONS

- */

-/* Attention!! Customer should define udelay function */

-void delayUs(int usecond);

-#define an8855_udelay(us) delayUs(us)

-

-/* Attention!! Customer should define dbg_print to get dbg output */

-#ifndef dbg_print

-#define dbg_print(...)

-#endif

-

-#define AN8855_PHY_NUM                      5

-

-/* DATA TYPE DECLARATIONS

- */

-#ifndef NULL

-#define NULL 0L

-#endif

-

-#ifndef u32

-#define u32 unsigned int

-#endif

-

-#ifndef u16

-#define u16 unsigned short

-#endif

-

-#ifndef u8

-#define u8 unsigned char

-#endif

-

-typedef u32 (*AIR_MII_READ_FUNC_T) (u32 phy_addr, u32 reg, u32 *p_data);

-

-typedef u32 (*AIR_MII_WRITE_FUNC_T) (u32 phy_addr, u32 reg, u32 data);

-

-typedef u32 (*AIR_MII_C45_READ_FUNC_T) (u32 phy_addr, u32 dev, u32 reg, u32 *p_data);

-

-typedef u32 (*AIR_MII_C45_WRITE_FUNC_T) (u32 phy_addr, u32 dev, u32 reg, u32 data);

-

-extern u32 g_smi_addr;

-

-/* EXPORTED SUBPROGRAM SPECIFICATIONS

- */

-

-/* FUNCTION NAME:   an8855_set_smi_addr

- * PURPOSE:

- *      This API is used to set an8855 smi address.

- * INPUT:

- *      smi_addr -- AN8855 smi address

- * OUTPUT:

- * RETURN:

- * NOTES:

- *      None

- */

-void

-an8855_set_smi_addr(u32 smi_addr);

-

-/* FUNCTION NAME:   an8855_set_mii_callback

- * PURPOSE:

- *      This API is used to set an8855 mii access callbacks.

- * INPUT:

- *      mii_read -- mii read api function

- *      mii_write -- mii write api function

- * OUTPUT:

- * RETURN:

- *      0     -- Successfully set callback.

- *      -1    -- Setting callback failed.

- * NOTES:

- *      None

- */

-int

-an8855_set_mii_callback(

-    AIR_MII_READ_FUNC_T mii_read, 

-    AIR_MII_WRITE_FUNC_T mii_write,

-    AIR_MII_C45_READ_FUNC_T mii_c45_read, 

-    AIR_MII_C45_WRITE_FUNC_T mii_c45_write);

-

-/* FUNCTION NAME:   an8855_reg_read

- * PURPOSE:

- *      This API is used read an8855 registers.

- * INPUT:

- *      reg -- register offset

- * OUTPUT:

- * RETURN:

- *      Register value

- * NOTES:

- *      Attention!! Customer should implement mdio mutex

- *      lock in this func

- */

-u32

-an8855_reg_read(u32 reg);

-

-/* FUNCTION NAME:   an8855_reg_write

- * PURPOSE:

- *      This API is used write an8855 registers.

- * INPUT:

- *      reg -- register offset

- *      val -- register value

- * OUTPUT:

- * RETURN:

- * NOTES:

- *      Attention!! Customer should implement mdio mutex

- *      lock in this func

- */

-void

-an8855_reg_write(u32 reg, u32 val);

-

-/* FUNCTION NAME:   an8855_phy_read

- * PURPOSE:

- *      This API is used read an8855 phy registers.

- * INPUT:

- *      port_num -- port number, 0~4

- *      reg -- phy register offset

- * OUTPUT:

- *      p_val -- phy register value

- * RETURN:

- *      0 -- read success

- *      -1 -- read failure

- * NOTES:

- *      Attention!! Customer should implement mii mutex

- *      lock in this func

- */

-int

-an8855_phy_read(u32 port_num, u32 reg, u32 *p_val);

-

-/* FUNCTION NAME:   an8855_phy_write

- * PURPOSE:

- *      This API is used write an8855 phy registers.

- * INPUT:

- *      port_num -- port number, 0~4

- *      reg -- phy register offset

- *      val -- phy register value

- * OUTPUT:

- * RETURN:

- *      0 -- write success

- *      -1 -- write failure

- * NOTES:

- *      Attention!! Customer should implement mii mutex

- *      lock in this func

- */

-int

-an8855_phy_write(u32 port_num, u32 reg, u32 val);

-

-/* FUNCTION NAME:   an8855_phy_read_cl45

- * PURPOSE:

- *      This API is used read an8855 phy registers.

- * INPUT:

- *      port_num -- port number, 0~4

- *      dev_addr -- phy device type

- *      reg_addr -- phy register offset

- * OUTPUT:

- *      p_val -- phy register value

- * RETURN:

- *      0 -- read success

- *      -1 -- read failure

- * NOTES:

- *      Attention!! Customer should implement mii mutex

- *      lock in this func or before/after calling this func

- */

-u32

-an8855_phy_read_cl45(u32 port_num, u32 dev_addr, u32 reg_addr, u32 *p_val);

-

-/* FUNCTION NAME:   an8855_phy_write_cl45

- * PURPOSE:

- *      This API is used write an8855 phy registers.

- * INPUT:

- *      port_num -- port number, 0~4

- *      dev_addr -- phy device type

- *      reg_addr -- phy register offset

- *      val -- phy register value

- * OUTPUT:

- * RETURN:

- *      0 -- write success

- *      -1 -- write failure

- * NOTES:

- *      Attention!! Customer should implement mii mutex

- *      lock in this func or before/after calling this func

- */

-int

-an8855_phy_write_cl45(u32 port_num, u32 dev_addr, u32 reg_addr, u32 val);

-

-#endif  /* End of AN8855_MDIO_H */

-

+/* FILE NAME:  an8855_mdio.h
+ * PURPOSE:
+ *      It provides AN8855 mdio access API.
+ * NOTES:
+ *
+ */
+
+#ifndef AN8855_MDIO_H
+#define AN8855_MDIO_H
+
+/* INCLUDE FILE DECLARATIONS
+ */
+//#include "CTP_type.h"
+//#include "CTP_shell.h"
+//#include "common.h"
+//#include "eth.h"
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+
+/* MACRO FUNCTION DECLARATIONS
+ */
+/* Attention!! Customer should define udelay function */
+void delayUs(int usecond);
+#define an8855_udelay(us) delayUs(us)
+
+/* Attention!! Customer should define dbg_print to get dbg output */
+#ifndef dbg_print
+#define dbg_print(...)
+#endif
+
+#define AN8855_PHY_NUM                      5
+
+/* DATA TYPE DECLARATIONS
+ */
+#ifndef NULL
+#define NULL 0L
+#endif
+
+#ifndef u32
+#define u32 unsigned int
+#endif
+
+#ifndef u16
+#define u16 unsigned short
+#endif
+
+#ifndef u8
+#define u8 unsigned char
+#endif
+
+typedef u32 (*AIR_MII_READ_FUNC_T) (u32 phy_addr, u32 reg, u32 *p_data);
+
+typedef u32 (*AIR_MII_WRITE_FUNC_T) (u32 phy_addr, u32 reg, u32 data);
+
+typedef u32 (*AIR_MII_C45_READ_FUNC_T) (u32 phy_addr, u32 dev, u32 reg, u32 *p_data);
+
+typedef u32 (*AIR_MII_C45_WRITE_FUNC_T) (u32 phy_addr, u32 dev, u32 reg, u32 data);
+
+extern u32 g_smi_addr;
+
+/* EXPORTED SUBPROGRAM SPECIFICATIONS
+ */
+
+/* FUNCTION NAME:   an8855_set_smi_addr
+ * PURPOSE:
+ *      This API is used to set an8855 smi address.
+ * INPUT:
+ *      smi_addr -- AN8855 smi address
+ * OUTPUT:
+ * RETURN:
+ * NOTES:
+ *      None
+ */
+void
+an8855_set_smi_addr(u32 smi_addr);
+
+/* FUNCTION NAME:   an8855_set_mii_callback
+ * PURPOSE:
+ *      This API is used to set an8855 mii access callbacks.
+ * INPUT:
+ *      mii_read -- mii read api function
+ *      mii_write -- mii write api function
+ * OUTPUT:
+ * RETURN:
+ *      0     -- Successfully set callback.
+ *      -1    -- Setting callback failed.
+ * NOTES:
+ *      None
+ */
+int
+an8855_set_mii_callback(
+    AIR_MII_READ_FUNC_T mii_read, 
+    AIR_MII_WRITE_FUNC_T mii_write,
+    AIR_MII_C45_READ_FUNC_T mii_c45_read, 
+    AIR_MII_C45_WRITE_FUNC_T mii_c45_write);
+
+/* FUNCTION NAME:   an8855_reg_read
+ * PURPOSE:
+ *      This API is used read an8855 registers.
+ * INPUT:
+ *      reg -- register offset
+ * OUTPUT:
+ * RETURN:
+ *      Register value
+ * NOTES:
+ *      Attention!! Customer should implement mdio mutex
+ *      lock in this func
+ */
+u32
+an8855_reg_read(u32 reg);
+
+/* FUNCTION NAME:   an8855_reg_write
+ * PURPOSE:
+ *      This API is used write an8855 registers.
+ * INPUT:
+ *      reg -- register offset
+ *      val -- register value
+ * OUTPUT:
+ * RETURN:
+ * NOTES:
+ *      Attention!! Customer should implement mdio mutex
+ *      lock in this func
+ */
+void
+an8855_reg_write(u32 reg, u32 val);
+
+/* FUNCTION NAME:   an8855_phy_read
+ * PURPOSE:
+ *      This API is used read an8855 phy registers.
+ * INPUT:
+ *      port_num -- port number, 0~4
+ *      reg -- phy register offset
+ * OUTPUT:
+ *      p_val -- phy register value
+ * RETURN:
+ *      0 -- read success
+ *      -1 -- read failure
+ * NOTES:
+ *      Attention!! Customer should implement mii mutex
+ *      lock in this func
+ */
+int
+an8855_phy_read(u32 port_num, u32 reg, u32 *p_val);
+
+/* FUNCTION NAME:   an8855_phy_write
+ * PURPOSE:
+ *      This API is used write an8855 phy registers.
+ * INPUT:
+ *      port_num -- port number, 0~4
+ *      reg -- phy register offset
+ *      val -- phy register value
+ * OUTPUT:
+ * RETURN:
+ *      0 -- write success
+ *      -1 -- write failure
+ * NOTES:
+ *      Attention!! Customer should implement mii mutex
+ *      lock in this func
+ */
+int
+an8855_phy_write(u32 port_num, u32 reg, u32 val);
+
+/* FUNCTION NAME:   an8855_phy_read_cl45
+ * PURPOSE:
+ *      This API is used read an8855 phy registers.
+ * INPUT:
+ *      port_num -- port number, 0~4
+ *      dev_addr -- phy device type
+ *      reg_addr -- phy register offset
+ * OUTPUT:
+ *      p_val -- phy register value
+ * RETURN:
+ *      0 -- read success
+ *      -1 -- read failure
+ * NOTES:
+ *      Attention!! Customer should implement mii mutex
+ *      lock in this func or before/after calling this func
+ */
+u32
+an8855_phy_read_cl45(u32 port_num, u32 dev_addr, u32 reg_addr, u32 *p_val);
+
+/* FUNCTION NAME:   an8855_phy_write_cl45
+ * PURPOSE:
+ *      This API is used write an8855 phy registers.
+ * INPUT:
+ *      port_num -- port number, 0~4
+ *      dev_addr -- phy device type
+ *      reg_addr -- phy register offset
+ *      val -- phy register value
+ * OUTPUT:
+ * RETURN:
+ *      0 -- write success
+ *      -1 -- write failure
+ * NOTES:
+ *      Attention!! Customer should implement mii mutex
+ *      lock in this func or before/after calling this func
+ */
+int
+an8855_phy_write_cl45(u32 port_num, u32 dev_addr, u32 reg_addr, u32 val);
+
+#endif  /* End of AN8855_MDIO_H */
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_phy.h b/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_phy.h
index 3c810e7..70836e8 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_phy.h
+++ b/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_phy.h
@@ -1,409 +1,409 @@
-/* FILE NAME:  an8855_phy.h

- * PURPOSE:

- *      It provides AN8855 phy definition.

- * NOTES:

- *

- */

-

-#ifndef _AN8855_PHY_H_

-#define _AN8855_PHY_H_

-

-

-/* Type Definitions */

-#define int8_t char

-#define uint8_t unsigned char

-#define int16_t short

-#define uint16_t unsigned short

-#define int32_t int

-#define uint32_t unsigned int

-/* DATA TYPE DECLARATIONS

- */

-typedef int                 BOOL_T;

-typedef signed char         I8_T;

-typedef unsigned char       UI8_T;

-typedef signed short        I16_T;

-typedef unsigned short      UI16_T;

-typedef signed int          I32_T;

-typedef unsigned int        UI32_T;

-typedef char                C8_T;

-typedef unsigned long long  UI64_T;

-

-typedef UI8_T   AIR_MAC_T[6];

-

-/* Debug flags */

-//#define _MDIO_BOOTS_MODE     1 // Boots for preamble

-#define _DEBUG_PRINT         1 // Debug print for Arduino

-//#define _DEBUG_PRINT_eFuse     1

-#define _write_eFuse     1

-

-#define _DEBUG_SCAN_ALL      0 // Scan all Code for SerDes Calibration

-#define _WRITE_RG_DIR        1 // Write RG directly for Calibration

-#define _USER_DEFINE_MODE    0 // Replace to user-defined RG for Calibration

-#define _DEBUG_MANUAL        1 // dbg_20210604  // manual dbg_20210604

-/**************************************************************************/

-

-/* Phy Address */

-//#define phyadd_common 0x1d            // EN8801

-//#define PHY_NUM 1             // EN8801

-//#define phyadd_common 0x9         // EN7523

-//#define PHY_NUM 4             // EN7523

-//#define phyadd_common 0x0         // EN8850

-//#define PHY_NUM   5           // EN8850

-#define PHY_NUM   4             // EN8851

-#define CALIPOLARITY  1

-

-#define TXAMP_offset  0    // for 8851

-

-/* On/Off */

-//#define ENABLE  1

-//#define DISABLE 0

-#define Relay_ENABLE  1

-#define Relay_DISABLE 0

-

-/* FT Pattern */

-#define _MDIO     0x0

-#define _I2C      0x1

-#define FT_USB3_T101    0x0

-#define FT_PCIE0_T101   0x1

-#define FT_PCIE1_T101   0x2

-#define FT_PON_T101     0x3

-

-/********* Digital pin definition *************/

-#define Relay_Tx_PN         22   // relay 1

-#define Relay_R_R50         23   // relay 2

-#define Relay_Tx_Vol        24   // relay 3

-#define Relay_Rx_Vol        25   // relay 4

-#define Relay_DUT_GND       26   // relay 5

-#define Relay_I2C           27   // PIN for SCL&SDA , relay 6

-//#define Relay_I2C_SCL       27   // PIN for SCL&SDA , relay 6

-//#define Relay_I2C_SDA       28   // PIN for SCL&SDA , relay 6

-

-#define pin_MDIO           36   // PIN for MDIO

-#define pin_MDC            37   // PIN for MDC

-#define FT_PATTERN_bit0    49   // PIN for FT0

-#define FT_PATTERN_bit1    48   // PIN for FT1

-#define Relay_MDIO         35   // PIN for MDIO relay, relay 7

-

-/***********************************************/

-/* Use for I/O register PORTA control */

-#define POR_Relay_Tx_PN    D22   // use for PORTA control, relay 1

-#define POR_Relay_R_R50    D23   // use for PORTA control, relay 2

-#define POR_Relay_Tx_Vol   D24   // use for PORTA control, relay 3

-#define POR_Relay_Rx_Vol   D25   // use for PORTA control, relay 4

-#define POR_Relay_DUT_GND  D26   // use for PORTA control, relay 5

-//#define POR_Relay_I2C      D27   // use for PORTA control, relay 6

-#define POR_Relay_I2C_SCL  D27   // use for PORTA control, relay 6

-#define POR_Relay_I2C_SDA  D28   // use for PORTA control, relay 7

-

-/* Use for I/O register PORTC control */

-#define POR_MDIO               D36  // use for PORTC control

-#define POR_MDC                D37  // use for PORTC control

-#define POR_Relay_MDIO         D35  // use for PORTC control, relay 7

-

-/* Use for I/O register PORTL control */

-#define POR_FT_PATTERN_bit0    D49  // use for PORTL control

-#define POR_FT_PATTERN_bit1    D48  // use for PORTL control

-

-

-/* I/O register Port A */

-#define D22   0

-#define D23   1

-#define D24   2

-#define D25   3

-#define D26   4

-#define D27   5

-#define D28   6

-#define D29   7

-

-/* I/O register Port C */

-#define D37   0

-#define D36   1

-#define D35   2

-#define D34   3

-#define D33   4

-#define D32   5

-#define D31   6

-#define D30   7

-

-/* I/O register Port L */

-#define D49   0

-#define D48   1

-#define D47   2

-#define D46   3

-#define D45   4

-#define D44   5

-#define D43   6

-#define D42   7

-

-/* I/O register Port D */

-#define D21   0

-#define D20   1

-#define D19   2

-#define D18   3

-

-

-/***************************************************************************

-**************************************************************************

-* MDC/MDIO

-***************************************************************************

-***************************************************************************/

-#define SET_HIGH(data, nbit) ((data)|=(nbit))

-#define SET_LOW(data, nbit) ((data)&=~(nbit))

-

-#define MDIO_ONE  _BV(POR_MDIO)

-#define MDIO_ZERO 0x00

-#define MDC_ONE   _BV(POR_MDC)

-#define MDC_ZERO  0x00

-

-#define delay_us delayMicroseconds(0)

-

-#define ANACAL_INIT        0x01

-#define ANACAL_ERROR       0xFD

-#define ANACAL_SATURATION  0xFE

-#define ANACAL_FINISH      0xFF

-#define ANACAL_PAIR_A      0

-#define ANACAL_PAIR_B      1

-#define ANACAL_PAIR_C      2

-#define ANACAL_PAIR_D      3

-#define DAC_IN_0V          0x000

-#define DAC_IN_2V          0x0f0  // +/-1V

-

-#define ZCAL_MIDDLE        0x20

-#define TX_OFFSET_0mV_idx  31

-#define TX_AMP_MIDDLE      0x20

-

-#define TX_i2mpb_hbt_ofs  0x4   // 8851 fine tune 100M v1 (20220414)

-#define R50_OFFSET_VALUE  0x5

-

-//============== definition value for GbE ===================//

-#define BG_VOLTAGE_OUT     0xc0

-#define FORCE_MDI          2

-#define FORCE_MDIX         3

-#define LDO_1p15_VOSEL_1   1

-#define RX_CAL_VALUE_9       0x3

-#define RX_CAL_HVGA_BW_2     0x2

-#define RX_CAL_DCO_Normal    0x0

-#define RX_CAL_DCO_BYPASS_TX_RX  0x3

-#define RX_CAL_DCO_0xF    0xF

-

-#define TANA_MON_DCV_SEL__MASK         0xE0

-#define TANA_MON_DCV_SEL__MPX_TANA_A   0x20

-#define TANA_MON_DCV_SEL__MPX_TANA_B   0x40

-#define TANA_MON_DCV_SEL__MPX_TANA_C   0x60

-#define TANA_MON_DCV_SEL__MPX_TANA_D   0x80

-#define TANA_MON_DCV_SEL__MONVC__MASK  0x008000C8

-#define TANA_MON_DCV__TANA__VBG_MON    0x000000C0

-#define TANA_MON_DCV__TANA__MONVC      0x000000C8

-

-#define AN_disable_force_1000M 0x0140

-#define BG_voltage_output 0xc000

-#define Fix_mdi 0x1010

-#define Disable_tx_slew_control 0x0000

-#define LDO_control 0x0100

-#define Cal_control_BG 0x1110

-#define Cal_control_R50 0x1100

-#define Cal_control_TX_AMP 0x1100

-#define Cal_control_TX_OFST 0x0100

-#define Cal_control_R50_pairA_ENABLE 0x1101

-#define Disable_all 0x0

-#define Zcalen_A_ENABLE 0x0000

-#define Zcalen_B_ENABLE 0x1000

-#define Zcalen_C_ENABLE 0x0100

-#define Zcalen_D_ENABLE 0x0010

-#define MASK_MSB_8bit 0xff00

-#define MASK_LSB_8bit 0x00ff

-#define MASK_r50ohm_rsel_tx_a 0x7f00

-#define MASK_r50ohm_rsel_tx_b 0x007f

-#define MASK_r50ohm_rsel_tx_c 0x7f00

-#define MASK_r50ohm_rsel_tx_d 0x007f

-#define Rg_r50ohm_rsel_tx_a_en 0x8000

-#define Rg_r50ohm_rsel_tx_b_en 0x0080

-#define Rg_r50ohm_rsel_tx_c_en 0x8000

-#define Rg_r50ohm_rsel_tx_d_en 0x0080

-#define Rg_txvos_calen_ENABLE 0x0001

-#define Bypass_tx_offset_cal 0x8000

-#define Enable_Tx_VLD 0xf808

-#define Rg_txg_calen_a_ENABLE 0x1000

-#define Rg_txg_calen_b_ENABLE 0x0100

-#define Rg_txg_calen_c_ENABLE 0x0010

-#define Rg_txg_calen_d_ENABLE 0x0001

-#define Force_dasn_dac_in0_ENABLE 0x8000

-#define Force_dasn_dac_in1_ENABLE 0x8000

-#define MASK_cr_tx_amp_offset_MSB 0x3f00

-#define MASK_cr_tx_amp_offset_LSB 0x003f

-#define Rg_cal_refsel_ENABLE 0x0010

-#define MASK_da_tx_i2mpb_a_gbe 0xfc00

-#define MASK_da_tx_i2mpb_b_c_d_gbe 0x3f00

-

-#define LED_basic_control_en_active_low 0x800a

-#define LED_led0_en_active_high 0xc007

-#define LED_led0_force_blinking 0x0200

-

-

-

-/*phy calibration use*/

-//Type defines

-typedef unsigned char    UINT8;

-typedef unsigned short   UINT16;

-typedef unsigned long    UINT32;

-

-typedef struct

-{

-  UINT16 DATA_Lo;

-  UINT8  DATA_Hi;

-}TR_DATA_T;

-

-//CL22 Reg Support Page Select//

-#define RgAddr_Reg1Fh        0x1f

-#define CL22_Page_Reg        0x0000

-#define CL22_Page_ExtReg     0x0001

-#define CL22_Page_MiscReg    0x0002

-#define CL22_Page_LpiReg     0x0003

-#define CL22_Page_tReg       0x02A3

-#define CL22_Page_TrReg      0x52B5

-

-//CL45 Reg Support DEVID//

-#define DEVID_03             0x03

-#define DEVID_07             0x07

-#define DEVID_1E             0x1E

-#define DEVID_1F             0x1F

-

-//TokenRing Reg Access//

-#define TrReg_PKT_XMT_STA    0x8000

-#define TrReg_WR             0x8000

-#define TrReg_RD             0xA000

-

-/* ----------------- gephy_all Bit Field Definitions ------------------- */

-

-

-

-//-------------------------------------

-//0x0000

-#define RgAddr_Reg00h                               0x00

-

-//0x51e01200

-#define RgAddr_dev1Eh_reg120h                       0x0120

-//0x51e01220

-#define RgAddr_dev1Eh_reg122h                       0x0122

-//0x51e01440

-#define RgAddr_dev1Eh_reg144h                       0x0144

-//0x51e014a0

-#define RgAddr_dev1Eh_reg14Ah                       0x014a

-//0x51e019b0

-#define RgAddr_dev1Eh_reg19Bh                       0x019b

-//0x51e02340

-#define RgAddr_dev1Eh_reg234h                       0x0234

-//0x51e02380

-#define RgAddr_dev1Eh_reg238h                       0x0238

-//0x51e02390

-#define RgAddr_dev1Eh_reg239h                       0x0239

-//0x51f02680

-#define RgAddr_dev1Fh_reg268h                       0x0268

-//0x51e02d10

-#define RgAddr_dev1Eh_reg2D1h                       0x02d1

-//0x51e03230

-#define RgAddr_dev1Eh_reg323h                       0x0323

-//0x51e03240

-#define RgAddr_dev1Eh_reg324h                       0x0324

-//0x51e03260

-#define RgAddr_dev1Eh_reg326h                       0x0326

-

-//0x51f01000

-#define RgAddr_dev1Fh_reg100h                       0x0100

-//0x51e01450

-#define RgAddr_dev1Eh_reg145h                       0x0145

-//0x51f00ff0

-#define RgAddr_dev1Fh_reg0FFh                       0x00ff

-//0x51e00db0

-#define RgAddr_dev1Eh_reg0DBh                       0x00db

-//0x51e00dc0

-#define RgAddr_dev1Eh_reg0DCh                       0x00dc

-//0x51e00e00

-#define RgAddr_dev1Eh_reg0E0h                       0x00e0

-//0x51e00e10

-#define RgAddr_dev1Eh_reg0E1h                       0x00e1

-//0x51e00e00

-#define RgAddr_dev1Eh_reg0E0h                       0x00e0

-//0x51e017a0

-#define RgAddr_dev1Eh_reg17Ah                       0x017a

-//0x51f01150

-#define RgAddr_dev1Fh_reg115h                       0x0115

-//0x51f01000

-#define RgAddr_dev1Fh_reg100h                       0x0100

-//0x51e01450

-#define RgAddr_dev1Eh_reg145h                       0x0145

-//0x51e01450

-#define RgAddr_dev1Eh_reg145h                       0x0145

-//0x51e01850

-#define RgAddr_dev1Eh_reg185h                       0x0185

-//0x51e00fb0

-#define RgAddr_dev1Eh_reg0FBh                       0x00fb

-//0x51e01740

-#define RgAddr_dev1Eh_reg174h                       0x0174

-//0x51e01750

-#define RgAddr_dev1Eh_reg175h                       0x0175

-//0x51e01850

-#define RgAddr_dev1Eh_reg185h                       0x0185

-//0x51e00fb0

-#define RgAddr_dev1Eh_reg0FBh                       0x00fb

-//0x51e00960

-#define RgAddr_dev1Eh_reg096h                       0x0096

-//0x51e003e0

-#define RgAddr_dev1Eh_reg03Eh                       0x003e

-//0x51e00dd0

-#define RgAddr_dev1Eh_reg0DDh                       0x00dd

-//0x51e017d0

-#define RgAddr_dev1Eh_reg17Dh                       0x017d

-//0x51e01810

-#define RgAddr_dev1Eh_reg181h                       0x0181

-//0x51e00120

-#define RgAddr_dev1Eh_reg012h                       0x0012

-//0x51e017e0

-#define RgAddr_dev1Eh_reg17Eh                       0x017e

-//0x51e01820

-#define RgAddr_dev1Eh_reg182h                       0x0182

-//0x51e00170

-#define RgAddr_dev1Eh_reg017h                       0x0017

-//0x51e01830

-#define RgAddr_dev1Eh_reg183h                       0x0183

-//0x51e00190

-#define RgAddr_dev1Eh_reg019h                       0x0019

-//0x51e01800

-#define RgAddr_dev1Eh_reg180h                       0x0180

-//0x51e01840

-#define RgAddr_dev1Eh_reg184h                       0x0184

-//0x51e00210

-#define RgAddr_dev1Eh_reg021h                       0x0021

-//0x51e01720

-#define RgAddr_dev1Eh_reg172h                       0x0172

-//0x51e01730

-#define RgAddr_dev1Eh_reg173h                       0x0173

-//0x51e017c0

-#define RgAddr_dev1Eh_reg17Ch                       0x017c

-//0x51e017f0

-#define RgAddr_dev1Eh_reg17Fh                       0x017f

-

-//0x52b5100

-#define RgAddr_TrReg10h                             0x10

-//0x52b5110

-#define RgAddr_TrReg11h                             0x11

-//0x52b5120

-#define RgAddr_TrReg12h                             0x12

-

-//0x31c0

-#define RgAddr_LpiReg1Ch                            0x1c

-//0x31d0

-#define RgAddr_LpiReg1Dh                            0x1d

-uint8_t BG_Calibration(uint8_t phyadd, int8_t calipolarity);

-uint8_t R50_Calibration(uint8_t phyadd, uint8_t phyadd_common);

-uint8_t TX_OFS_Calibration(uint8_t phyadd, uint8_t phyadd_common);

-uint8_t TX_AMP_Calibration(uint8_t phyadd, uint8_t phyadd_common);

-//void config_gphy_port(UINT8, UINT8);

-

-void set_gphy_reg_cl22(uint8_t, uint8_t, uint16_t);

-uint16_t get_gphy_reg_cl45(uint8_t, uint8_t, uint16_t);

-void set_gphy_reg_cl45(uint8_t, uint8_t, uint16_t, uint16_t);

-void anacal_exe(uint8_t);

-

-#endif /* _AN8855_PHY_H_ */

-

+/* FILE NAME:  an8855_phy.h
+ * PURPOSE:
+ *      It provides AN8855 phy definition.
+ * NOTES:
+ *
+ */
+
+#ifndef _AN8855_PHY_H_
+#define _AN8855_PHY_H_
+
+
+/* Type Definitions */
+#define int8_t char
+#define uint8_t unsigned char
+#define int16_t short
+#define uint16_t unsigned short
+#define int32_t int
+#define uint32_t unsigned int
+/* DATA TYPE DECLARATIONS
+ */
+typedef int                 BOOL_T;
+typedef signed char         I8_T;
+typedef unsigned char       UI8_T;
+typedef signed short        I16_T;
+typedef unsigned short      UI16_T;
+typedef signed int          I32_T;
+typedef unsigned int        UI32_T;
+typedef char                C8_T;
+typedef unsigned long long  UI64_T;
+
+typedef UI8_T   AIR_MAC_T[6];
+
+/* Debug flags */
+//#define _MDIO_BOOTS_MODE     1 // Boots for preamble
+#define _DEBUG_PRINT         1 // Debug print for Arduino
+//#define _DEBUG_PRINT_eFuse     1
+#define _write_eFuse     1
+
+#define _DEBUG_SCAN_ALL      0 // Scan all Code for SerDes Calibration
+#define _WRITE_RG_DIR        1 // Write RG directly for Calibration
+#define _USER_DEFINE_MODE    0 // Replace to user-defined RG for Calibration
+#define _DEBUG_MANUAL        1 // dbg_20210604  // manual dbg_20210604
+/**************************************************************************/
+
+/* Phy Address */
+//#define phyadd_common 0x1d            // EN8801
+//#define PHY_NUM 1             // EN8801
+//#define phyadd_common 0x9         // EN7523
+//#define PHY_NUM 4             // EN7523
+//#define phyadd_common 0x0         // EN8850
+//#define PHY_NUM   5           // EN8850
+#define PHY_NUM   4             // EN8851
+#define CALIPOLARITY  1
+
+#define TXAMP_offset  0    // for 8851
+
+/* On/Off */
+//#define ENABLE  1
+//#define DISABLE 0
+#define Relay_ENABLE  1
+#define Relay_DISABLE 0
+
+/* FT Pattern */
+#define _MDIO     0x0
+#define _I2C      0x1
+#define FT_USB3_T101    0x0
+#define FT_PCIE0_T101   0x1
+#define FT_PCIE1_T101   0x2
+#define FT_PON_T101     0x3
+
+/********* Digital pin definition *************/
+#define Relay_Tx_PN         22   // relay 1
+#define Relay_R_R50         23   // relay 2
+#define Relay_Tx_Vol        24   // relay 3
+#define Relay_Rx_Vol        25   // relay 4
+#define Relay_DUT_GND       26   // relay 5
+#define Relay_I2C           27   // PIN for SCL&SDA , relay 6
+//#define Relay_I2C_SCL       27   // PIN for SCL&SDA , relay 6
+//#define Relay_I2C_SDA       28   // PIN for SCL&SDA , relay 6
+
+#define pin_MDIO           36   // PIN for MDIO
+#define pin_MDC            37   // PIN for MDC
+#define FT_PATTERN_bit0    49   // PIN for FT0
+#define FT_PATTERN_bit1    48   // PIN for FT1
+#define Relay_MDIO         35   // PIN for MDIO relay, relay 7
+
+/***********************************************/
+/* Use for I/O register PORTA control */
+#define POR_Relay_Tx_PN    D22   // use for PORTA control, relay 1
+#define POR_Relay_R_R50    D23   // use for PORTA control, relay 2
+#define POR_Relay_Tx_Vol   D24   // use for PORTA control, relay 3
+#define POR_Relay_Rx_Vol   D25   // use for PORTA control, relay 4
+#define POR_Relay_DUT_GND  D26   // use for PORTA control, relay 5
+//#define POR_Relay_I2C      D27   // use for PORTA control, relay 6
+#define POR_Relay_I2C_SCL  D27   // use for PORTA control, relay 6
+#define POR_Relay_I2C_SDA  D28   // use for PORTA control, relay 7
+
+/* Use for I/O register PORTC control */
+#define POR_MDIO               D36  // use for PORTC control
+#define POR_MDC                D37  // use for PORTC control
+#define POR_Relay_MDIO         D35  // use for PORTC control, relay 7
+
+/* Use for I/O register PORTL control */
+#define POR_FT_PATTERN_bit0    D49  // use for PORTL control
+#define POR_FT_PATTERN_bit1    D48  // use for PORTL control
+
+
+/* I/O register Port A */
+#define D22   0
+#define D23   1
+#define D24   2
+#define D25   3
+#define D26   4
+#define D27   5
+#define D28   6
+#define D29   7
+
+/* I/O register Port C */
+#define D37   0
+#define D36   1
+#define D35   2
+#define D34   3
+#define D33   4
+#define D32   5
+#define D31   6
+#define D30   7
+
+/* I/O register Port L */
+#define D49   0
+#define D48   1
+#define D47   2
+#define D46   3
+#define D45   4
+#define D44   5
+#define D43   6
+#define D42   7
+
+/* I/O register Port D */
+#define D21   0
+#define D20   1
+#define D19   2
+#define D18   3
+
+
+/***************************************************************************
+**************************************************************************
+* MDC/MDIO
+***************************************************************************
+***************************************************************************/
+#define SET_HIGH(data, nbit) ((data)|=(nbit))
+#define SET_LOW(data, nbit) ((data)&=~(nbit))
+
+#define MDIO_ONE  _BV(POR_MDIO)
+#define MDIO_ZERO 0x00
+#define MDC_ONE   _BV(POR_MDC)
+#define MDC_ZERO  0x00
+
+#define delay_us delayMicroseconds(0)
+
+#define ANACAL_INIT        0x01
+#define ANACAL_ERROR       0xFD
+#define ANACAL_SATURATION  0xFE
+#define ANACAL_FINISH      0xFF
+#define ANACAL_PAIR_A      0
+#define ANACAL_PAIR_B      1
+#define ANACAL_PAIR_C      2
+#define ANACAL_PAIR_D      3
+#define DAC_IN_0V          0x000
+#define DAC_IN_2V          0x0f0  // +/-1V
+
+#define ZCAL_MIDDLE        0x20
+#define TX_OFFSET_0mV_idx  31
+#define TX_AMP_MIDDLE      0x20
+
+#define TX_i2mpb_hbt_ofs  0x4   // 8851 fine tune 100M v1 (20220414)
+#define R50_OFFSET_VALUE  0x5
+
+//============== definition value for GbE ===================//
+#define BG_VOLTAGE_OUT     0xc0
+#define FORCE_MDI          2
+#define FORCE_MDIX         3
+#define LDO_1p15_VOSEL_1   1
+#define RX_CAL_VALUE_9       0x3
+#define RX_CAL_HVGA_BW_2     0x2
+#define RX_CAL_DCO_Normal    0x0
+#define RX_CAL_DCO_BYPASS_TX_RX  0x3
+#define RX_CAL_DCO_0xF    0xF
+
+#define TANA_MON_DCV_SEL__MASK         0xE0
+#define TANA_MON_DCV_SEL__MPX_TANA_A   0x20
+#define TANA_MON_DCV_SEL__MPX_TANA_B   0x40
+#define TANA_MON_DCV_SEL__MPX_TANA_C   0x60
+#define TANA_MON_DCV_SEL__MPX_TANA_D   0x80
+#define TANA_MON_DCV_SEL__MONVC__MASK  0x008000C8
+#define TANA_MON_DCV__TANA__VBG_MON    0x000000C0
+#define TANA_MON_DCV__TANA__MONVC      0x000000C8
+
+#define AN_disable_force_1000M 0x0140
+#define BG_voltage_output 0xc000
+#define Fix_mdi 0x1010
+#define Disable_tx_slew_control 0x0000
+#define LDO_control 0x0100
+#define Cal_control_BG 0x1110
+#define Cal_control_R50 0x1100
+#define Cal_control_TX_AMP 0x1100
+#define Cal_control_TX_OFST 0x0100
+#define Cal_control_R50_pairA_ENABLE 0x1101
+#define Disable_all 0x0
+#define Zcalen_A_ENABLE 0x0000
+#define Zcalen_B_ENABLE 0x1000
+#define Zcalen_C_ENABLE 0x0100
+#define Zcalen_D_ENABLE 0x0010
+#define MASK_MSB_8bit 0xff00
+#define MASK_LSB_8bit 0x00ff
+#define MASK_r50ohm_rsel_tx_a 0x7f00
+#define MASK_r50ohm_rsel_tx_b 0x007f
+#define MASK_r50ohm_rsel_tx_c 0x7f00
+#define MASK_r50ohm_rsel_tx_d 0x007f
+#define Rg_r50ohm_rsel_tx_a_en 0x8000
+#define Rg_r50ohm_rsel_tx_b_en 0x0080
+#define Rg_r50ohm_rsel_tx_c_en 0x8000
+#define Rg_r50ohm_rsel_tx_d_en 0x0080
+#define Rg_txvos_calen_ENABLE 0x0001
+#define Bypass_tx_offset_cal 0x8000
+#define Enable_Tx_VLD 0xf808
+#define Rg_txg_calen_a_ENABLE 0x1000
+#define Rg_txg_calen_b_ENABLE 0x0100
+#define Rg_txg_calen_c_ENABLE 0x0010
+#define Rg_txg_calen_d_ENABLE 0x0001
+#define Force_dasn_dac_in0_ENABLE 0x8000
+#define Force_dasn_dac_in1_ENABLE 0x8000
+#define MASK_cr_tx_amp_offset_MSB 0x3f00
+#define MASK_cr_tx_amp_offset_LSB 0x003f
+#define Rg_cal_refsel_ENABLE 0x0010
+#define MASK_da_tx_i2mpb_a_gbe 0xfc00
+#define MASK_da_tx_i2mpb_b_c_d_gbe 0x3f00
+
+#define LED_basic_control_en_active_low 0x800a
+#define LED_led0_en_active_high 0xc007
+#define LED_led0_force_blinking 0x0200
+
+
+
+/*phy calibration use*/
+//Type defines
+typedef unsigned char    UINT8;
+typedef unsigned short   UINT16;
+typedef unsigned long    UINT32;
+
+typedef struct
+{
+  UINT16 DATA_Lo;
+  UINT8  DATA_Hi;
+}TR_DATA_T;
+
+//CL22 Reg Support Page Select//
+#define RgAddr_Reg1Fh        0x1f
+#define CL22_Page_Reg        0x0000
+#define CL22_Page_ExtReg     0x0001
+#define CL22_Page_MiscReg    0x0002
+#define CL22_Page_LpiReg     0x0003
+#define CL22_Page_tReg       0x02A3
+#define CL22_Page_TrReg      0x52B5
+
+//CL45 Reg Support DEVID//
+#define DEVID_03             0x03
+#define DEVID_07             0x07
+#define DEVID_1E             0x1E
+#define DEVID_1F             0x1F
+
+//TokenRing Reg Access//
+#define TrReg_PKT_XMT_STA    0x8000
+#define TrReg_WR             0x8000
+#define TrReg_RD             0xA000
+
+/* ----------------- gephy_all Bit Field Definitions ------------------- */
+
+
+
+//-------------------------------------
+//0x0000
+#define RgAddr_Reg00h                               0x00
+
+//0x51e01200
+#define RgAddr_dev1Eh_reg120h                       0x0120
+//0x51e01220
+#define RgAddr_dev1Eh_reg122h                       0x0122
+//0x51e01440
+#define RgAddr_dev1Eh_reg144h                       0x0144
+//0x51e014a0
+#define RgAddr_dev1Eh_reg14Ah                       0x014a
+//0x51e019b0
+#define RgAddr_dev1Eh_reg19Bh                       0x019b
+//0x51e02340
+#define RgAddr_dev1Eh_reg234h                       0x0234
+//0x51e02380
+#define RgAddr_dev1Eh_reg238h                       0x0238
+//0x51e02390
+#define RgAddr_dev1Eh_reg239h                       0x0239
+//0x51f02680
+#define RgAddr_dev1Fh_reg268h                       0x0268
+//0x51e02d10
+#define RgAddr_dev1Eh_reg2D1h                       0x02d1
+//0x51e03230
+#define RgAddr_dev1Eh_reg323h                       0x0323
+//0x51e03240
+#define RgAddr_dev1Eh_reg324h                       0x0324
+//0x51e03260
+#define RgAddr_dev1Eh_reg326h                       0x0326
+
+//0x51f01000
+#define RgAddr_dev1Fh_reg100h                       0x0100
+//0x51e01450
+#define RgAddr_dev1Eh_reg145h                       0x0145
+//0x51f00ff0
+#define RgAddr_dev1Fh_reg0FFh                       0x00ff
+//0x51e00db0
+#define RgAddr_dev1Eh_reg0DBh                       0x00db
+//0x51e00dc0
+#define RgAddr_dev1Eh_reg0DCh                       0x00dc
+//0x51e00e00
+#define RgAddr_dev1Eh_reg0E0h                       0x00e0
+//0x51e00e10
+#define RgAddr_dev1Eh_reg0E1h                       0x00e1
+//0x51e00e00
+#define RgAddr_dev1Eh_reg0E0h                       0x00e0
+//0x51e017a0
+#define RgAddr_dev1Eh_reg17Ah                       0x017a
+//0x51f01150
+#define RgAddr_dev1Fh_reg115h                       0x0115
+//0x51f01000
+#define RgAddr_dev1Fh_reg100h                       0x0100
+//0x51e01450
+#define RgAddr_dev1Eh_reg145h                       0x0145
+//0x51e01450
+#define RgAddr_dev1Eh_reg145h                       0x0145
+//0x51e01850
+#define RgAddr_dev1Eh_reg185h                       0x0185
+//0x51e00fb0
+#define RgAddr_dev1Eh_reg0FBh                       0x00fb
+//0x51e01740
+#define RgAddr_dev1Eh_reg174h                       0x0174
+//0x51e01750
+#define RgAddr_dev1Eh_reg175h                       0x0175
+//0x51e01850
+#define RgAddr_dev1Eh_reg185h                       0x0185
+//0x51e00fb0
+#define RgAddr_dev1Eh_reg0FBh                       0x00fb
+//0x51e00960
+#define RgAddr_dev1Eh_reg096h                       0x0096
+//0x51e003e0
+#define RgAddr_dev1Eh_reg03Eh                       0x003e
+//0x51e00dd0
+#define RgAddr_dev1Eh_reg0DDh                       0x00dd
+//0x51e017d0
+#define RgAddr_dev1Eh_reg17Dh                       0x017d
+//0x51e01810
+#define RgAddr_dev1Eh_reg181h                       0x0181
+//0x51e00120
+#define RgAddr_dev1Eh_reg012h                       0x0012
+//0x51e017e0
+#define RgAddr_dev1Eh_reg17Eh                       0x017e
+//0x51e01820
+#define RgAddr_dev1Eh_reg182h                       0x0182
+//0x51e00170
+#define RgAddr_dev1Eh_reg017h                       0x0017
+//0x51e01830
+#define RgAddr_dev1Eh_reg183h                       0x0183
+//0x51e00190
+#define RgAddr_dev1Eh_reg019h                       0x0019
+//0x51e01800
+#define RgAddr_dev1Eh_reg180h                       0x0180
+//0x51e01840
+#define RgAddr_dev1Eh_reg184h                       0x0184
+//0x51e00210
+#define RgAddr_dev1Eh_reg021h                       0x0021
+//0x51e01720
+#define RgAddr_dev1Eh_reg172h                       0x0172
+//0x51e01730
+#define RgAddr_dev1Eh_reg173h                       0x0173
+//0x51e017c0
+#define RgAddr_dev1Eh_reg17Ch                       0x017c
+//0x51e017f0
+#define RgAddr_dev1Eh_reg17Fh                       0x017f
+
+//0x52b5100
+#define RgAddr_TrReg10h                             0x10
+//0x52b5110
+#define RgAddr_TrReg11h                             0x11
+//0x52b5120
+#define RgAddr_TrReg12h                             0x12
+
+//0x31c0
+#define RgAddr_LpiReg1Ch                            0x1c
+//0x31d0
+#define RgAddr_LpiReg1Dh                            0x1d
+uint8_t BG_Calibration(uint8_t phyadd, int8_t calipolarity);
+uint8_t R50_Calibration(uint8_t phyadd, uint8_t phyadd_common);
+uint8_t TX_OFS_Calibration(uint8_t phyadd, uint8_t phyadd_common);
+uint8_t TX_AMP_Calibration(uint8_t phyadd, uint8_t phyadd_common);
+//void config_gphy_port(UINT8, UINT8);
+
+void set_gphy_reg_cl22(uint8_t, uint8_t, uint16_t);
+uint16_t get_gphy_reg_cl45(uint8_t, uint8_t, uint16_t);
+void set_gphy_reg_cl45(uint8_t, uint8_t, uint16_t, uint16_t);
+void anacal_exe(uint8_t);
+
+#endif /* _AN8855_PHY_H_ */
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_phy_cal.c b/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_phy_cal.c
index c2e8e5c..9eb52e1 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_phy_cal.c
+++ b/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_phy_cal.c
@@ -1,967 +1,967 @@
-/* FILE NAME:  an8855_phy_cal.c

-* PURPOSE:

-*    It provides an8855 switch phy calibration function.

-*

-* NOTES:

-*

-*/

-

-/* INCLUDE FILE DECLARATIONS

-*/

-#include "an8855_mdio.h"

-#include "an8855_phy.h"

-//#include "swk_gphy_reg.h"

-//#include "gphy_calibration.h"

-//#include "gsw_reg.h"

-

-/* NAMING CONSTANT DECLARATIONS

- */

-#define MII_BMCR                (0)

-#define BMCR_PDOWN              (0x0800)

-/* MACRO FUNCTION DECLARATIONS

- */

-

-#define FULL_BITS(_n_) ((1UL << (_n_)) - 1)

-

-/* DATA TYPE DECLARATIONS

- */

-

-/* GLOBAL VARIABLE DECLARATIONS

- */

-/* Zcal to R50 mapping table (20220404) */

-const uint8_t ZCAL_TO_R50ohm_TBL[64] =

-{

-    127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,

-    127, 127, 127, 127, 127, 123, 118, 114, 110, 106, 102, 98, 96, 92, 88, 85,

-    82, 80, 76, 72, 70, 67, 64, 62, 60, 56, 54, 52, 49, 48, 45, 43,

-    40, 39, 36, 34, 32, 32, 30, 28, 25, 24, 22, 20, 18, 16, 16, 14

-};

-

-/* Tx offset table, value is from small to big */

-const uint8_t  EN753x_TX_OFS_TBL[64] =

-{

-    0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30,

-    0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20,

-    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,

-    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f

-};

-

-#define TOTAL_PATCH_C45_ITEMS   (15)

-#define TOTAL_PATCH_TR_ITEMS    (19)

-const uint16_t C45_PATCH_TABLE[TOTAL_PATCH_C45_ITEMS][3] =

-{

-    {0x1E, 0x120, 0x8014},

-    {0x1E, 0x122, 0xFFFF},

-    {0x1E, 0x122, 0xFFFF},

-    {0x1E, 0x144, 0x0200},

-    {0x1E, 0x14A, 0xEE20},

-    {0x1E, 0x189, 0x0110},

-    {0x1E, 0x19B, 0x0111},

-    {0x1E, 0x234, 0x0181},

-    {0x1E, 0x238, 0x0120},

-    {0x1E, 0x239, 0x0117},

-    {0x1F, 0x268, 0x07F4},

-    {0x1E, 0x2d1, 0x0733},

-    {0x1E, 0x323, 0x0011},

-    {0x1E, 0x324, 0x013F},

-    {0x1E, 0x326, 0x0037},

-};

-

-const uint32_t TR_PATCH_TABLE[TOTAL_PATCH_TR_ITEMS][2] =

-{

-    {0x83AA, 0x055a0 },

-    {0x83AE, 0x7FF3F },

-    {0x8F80, 0x0001e },

-    {0x8F82, 0x6FB90A},

-    {0x8FAE, 0x060671},

-    {0x8FB0, 0xE2F00 },

-    {0x8ECC, 0x444444},

-    {0x9686, 0x00000 },

-    {0x968C, 0x2EBAEF},

-    {0x9690, 0x00000b},

-    {0x9698, 0x0504D },

-    {0x969A, 0x2314f },

-    {0x969E, 0x03028 },

-    {0x96A0, 0x05010 },

-    {0x96A2, 0x40001 },

-    {0x96A6, 0x018670},

-    {0x96A8, 0x0024A },

-    {0x96B6, 0x00072 },

-    {0x96B8, 0x03210 },

-};

-

-#define TOTAL_NUMBER_OF_PATCH    (14)

-static uint16_t eee_patch_table[TOTAL_NUMBER_OF_PATCH][2] = {

-    {RgAddr_dev1Eh_reg120h, 0x8014},

-    {RgAddr_dev1Eh_reg122h, 0xFFFF},

-    {RgAddr_dev1Eh_reg122h, 0xFFFF},

-    {RgAddr_dev1Eh_reg144h, 0x0200},

-    {RgAddr_dev1Eh_reg14Ah, 0xEE20},

-    {RgAddr_dev1Eh_reg19Bh, 0x0111},

-    {RgAddr_dev1Eh_reg234h, 0x1181},

-    {RgAddr_dev1Eh_reg238h, 0x0120},

-    {RgAddr_dev1Eh_reg239h, 0x0117},

-    {RgAddr_dev1Fh_reg268h, 0x07F4},

-    {RgAddr_dev1Eh_reg2D1h, 0x0733},

-    {RgAddr_dev1Eh_reg323h, 0x0011},

-    {RgAddr_dev1Eh_reg324h, 0x013F},

-    {RgAddr_dev1Eh_reg326h, 0x0037}

-};

-

-#define TOTAL_NUMBER_OF_TR      (19)

-static uint16_t tr_reg_table[TOTAL_NUMBER_OF_TR][3] = {

-    {0x55A0, 0x0000, 0x83AA},

-    {0xFF3F, 0x0007, 0x83AE},

-    {0x001E, 0x0000, 0x8F80},

-    {0xB90A, 0x006F, 0x8F82},

-    {0x0671, 0x0006, 0x8FAE},

-    {0x2F00, 0x000E, 0x8FB0},

-    {0x4444, 0x0044, 0x8ECC},

-    {0x0004, 0x0000, 0x9686},

-    {0xBAEF, 0x002E, 0x968C},

-    {0x000B, 0x0000, 0x9690},

-    {0x504D, 0x0000, 0x9698},

-    {0x314F, 0x0002, 0x969A},

-    {0x3028, 0x0000, 0x969E},

-    {0x5010, 0x0000, 0x96A0},

-    {0x0001, 0x0004, 0x96A2},

-    {0x8670, 0x0001, 0x96A6},

-    {0x024A, 0x0000, 0x96A8},

-    {0x0072, 0x0000, 0x96B6},

-    {0x3210, 0x0000, 0x96B8}

-};

-

-void TR_RegWr(uint16_t phyadd, uint16_t tr_reg_addr, uint32_t tr_data);

-

-uint16_t get_gphy_reg_cl22(uint8_t phyad, uint8_t reg)

-{

-    uint32_t rdata = 0;

-

-    an8855_phy_read(phyad-g_smi_addr, reg, &rdata);

-

-    return ((uint16_t)rdata);

-    /*

-    gsw_top_reg_REG_PHY_IAC REG_PHY_IAC_val;

-    gsw_top_reg_REG_PHY_IAD REG_PHY_IAD_val;

-

-    // Wait until done

-    do

-    {

-      REG_PHY_IAC_val.Raw   = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);

-    }

-    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);

-

-    // Set address

-    REG_PHY_IAC_val.Bits.csr_mdio_st = 1;

-    REG_PHY_IAC_val.Bits.csr_mdio_cmd   = 2;

-    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = phyad;

-    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = reg;

-    REG_PHY_IAC_val.Bits.csr_phy_acs_st =   1;

-    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);

-    // Wait until done

-    do

-    {

-        REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);

-    }

-    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);

-

-    REG_PHY_IAD_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAD);

-

-    return REG_PHY_IAD_val.Raw;

-    */

-}

-

-/* EXPORTED SUBPROGRAM BODIES

- */

-void gphy_config(void)

-{

-    uint8_t port = 1;

-    uint8_t phy_base = 0, phys_in_chip = 8;

-

-    for (port = 1; port <= phys_in_chip; port++)

-    {

-        set_gphy_reg_cl45(phy_base + port, 0x7, 0x3c, 0x0006); // Enable EEE

-        set_gphy_reg_cl45(phy_base + port, 0x1e, 0x3e, 0xf000); // force on TXVLD

-    }

-}

-

-static void set_gphy_TrReg(uint8_t prtid, uint16_t parm_1, uint16_t parm_2, uint16_t parm_3)

-{

-    set_gphy_reg_cl22(prtid, RgAddr_TrReg11h, parm_1);

-    set_gphy_reg_cl22(prtid, RgAddr_TrReg12h, parm_2);

-    set_gphy_reg_cl22(prtid, RgAddr_TrReg10h, parm_3);

-}

-

-static void gphy_eee_patch(uint8_t phy_base)

-{

-    UI8_T   port = 1, index = 0, phy_addr = 1;

-    UI16_T  data = 0;

-

-    for (port = 1; port <=8; port++)

-    {

-        phy_addr = phy_base + port;

-        data = get_gphy_reg_cl22(phy_addr, MII_BMCR);

-        set_gphy_reg_cl22(phy_addr, MII_BMCR, data & ~(BMCR_PDOWN));    /* PHY power on */

-

-        /* Change EEE RG default value */

-        for (index = 0; index < TOTAL_NUMBER_OF_PATCH; index++)

-        {

-            set_gphy_reg_cl45(phy_addr, DEVID_1E, eee_patch_table[index][0], eee_patch_table[index][1]);

-        }

-

-        set_gphy_reg_cl22(phy_addr, RgAddr_Reg1Fh, CL22_Page_TrReg);   /* change CL22page to LpiReg(0x3) */

-        for (index = 0; index < TOTAL_NUMBER_OF_TR; index++)

-        {

-            set_gphy_TrReg(phy_addr, tr_reg_table[index][0], tr_reg_table[index][1], tr_reg_table[index][2]);

-        }

-

-        set_gphy_reg_cl22(phy_addr, RgAddr_Reg1Fh, CL22_Page_LpiReg);  /* change CL22page to LpiReg(0x3) */

-        set_gphy_reg_cl22(phy_addr, RgAddr_LpiReg1Ch, 0x0c92);         /* Fine turn SigDet for B2B LPI link down issue */

-        set_gphy_reg_cl22(phy_addr, RgAddr_LpiReg1Dh, 0x0001);         /* Enable "lpi_quit_waitafesigdet_en" for LPI link down issue */

-

-        set_gphy_reg_cl22(phy_addr, RgAddr_Reg1Fh, CL22_Page_Reg);     /* change CL22page to Reg(0x0) */

-    }

-}

-

-void gphy_calibration(uint8_t phy_base)

-{

-    uint8_t port = 1, phy_addr = 1 ,phy_group = 1, index = 0;

-    uint8_t phys_in_chip = 5;

-

-    BG_Calibration(phy_base, 0x1);

-    if (phys_in_chip > 4)

-    {

-        BG_Calibration(phy_base + 0x4, 0x1);

-    }

-

-    for (port = 0; port < phys_in_chip; port++)

-    {

-        if (port < 4)

-        {

-            phy_group = phy_base;     /* PHY group 1 */

-        }

-        else

-        {

-            phy_group = phy_base + 0x04;     /* PHY group 2 */

-        }

-        phy_addr = phy_base + port;

-        R50_Calibration(phy_addr, phy_group);

-        TX_OFS_Calibration(phy_addr, phy_group);

-        TX_AMP_Calibration(phy_addr, phy_group);

-    }

-

-    for (port = 0; port < phys_in_chip; port++)

-    {

-        phy_addr = phy_base + port;

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x017d, 0x0000);

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x017e, 0x0000);

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x017f, 0x0000);

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0180, 0x0000);

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0181, 0x0000);

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0182, 0x0000);

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0183, 0x0000);

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0184, 0x0000);

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x00db, 0x0000);  // disable analog calibration circuit

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x00dc, 0x0000);  // disable Tx offset calibration circuit

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x003e, 0x0000);  // disable Tx VLD force mode

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x00dd, 0x0000);  // disable Tx offset/amplitude calibration circuit

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0145, 0x1000);  // enable auto MDI/MDIX

-

-        set_gphy_reg_cl22(phy_addr, 0, 0x1200);

-        /* GPHY Rx low pass filter */

-        set_gphy_reg_cl45(phy_addr, 0x1e, 0xc7, 0xd000);

-        /* patch */

-        for (index = 0; index < TOTAL_PATCH_C45_ITEMS; index++)

-        {

-            set_gphy_reg_cl45(phy_addr, C45_PATCH_TABLE[index][0], C45_PATCH_TABLE[index][1], C45_PATCH_TABLE[index][2]);

-        }

-        for (index = 0; index < TOTAL_PATCH_TR_ITEMS; index++)

-        {

-            TR_RegWr(phy_addr, TR_PATCH_TABLE[index][0], TR_PATCH_TABLE[index][1]);

-        }

-        set_gphy_reg_cl22(phy_addr, 0x1f, 0x0  );

-        set_gphy_reg_cl22(phy_addr, 0x1f, 0x3  );

-        set_gphy_reg_cl22(phy_addr, 0x1c, 0xc92);

-        set_gphy_reg_cl22(phy_addr, 0x1d, 0x01 );

-        set_gphy_reg_cl22(phy_addr, 0x1f, 0x0  );

-    }

-    gphy_eee_patch(phy_base);

-}

-

-/* LOCAL SUBPROGRAM BODIES

- */

-void TR_RegWr(uint16_t phyadd, uint16_t tr_reg_addr, uint32_t tr_data)

-{

-    set_gphy_reg_cl22(phyadd, 0x1F, 0x52b5);       /* page select */

-    set_gphy_reg_cl22(phyadd, 0x11, (uint16_t)(tr_data & 0xffff));

-    set_gphy_reg_cl22(phyadd, 0x12, (uint16_t)(tr_data >> 16));

-    set_gphy_reg_cl22(phyadd, 0x10, (uint16_t)(tr_reg_addr | TrReg_WR));

-    set_gphy_reg_cl22(phyadd, 0x1F, 0x0);          /* page resetore */

-    return;

-}

-

-uint8_t BG_Calibration(uint8_t phyadd, int8_t calipolarity)

-{

-    int8_t rg_zcal_ctrl = 0, calibration_polarity = 0;

-    uint8_t all_ana_cal_status = 1;

-    uint16_t ad_cal_comp_out_init = 0;

-

-    /* setting */

-    set_gphy_reg_cl22(phyadd, RgAddr_Reg1Fh, CL22_Page_Reg);        // g0

-    set_gphy_reg_cl22(phyadd, RgAddr_Reg00h, AN_disable_force_1000M);  // AN disable, force 1000M

-    set_gphy_reg_cl45(phyadd, DEVID_1F, RgAddr_dev1Fh_reg100h, BG_voltage_output);// BG voltage output

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg145h, Fix_mdi);// fix mdi

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Fh_reg0FFh, 0x2);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_BG);// 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all);// 1e_dc[0]:rg_txvos_calen

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E1h, Disable_all);// 1e_e1[4]:rg_cal_refsel(0:1.2V) enable BG 1.2V to REXT PAD

-

-    /* calibrate */

-    rg_zcal_ctrl = ZCAL_MIDDLE;

-

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (uint16_t)rg_zcal_ctrl);

-

-    anacal_exe(phyadd);

-    if (all_ana_cal_status == 0)

-    {

-        all_ana_cal_status = ANACAL_ERROR;

-    }

-    ad_cal_comp_out_init = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1;

-

-

-    if (ad_cal_comp_out_init == 1)

-    {

-        calibration_polarity = -calipolarity;

-    }

-    else // ad_cal_comp_out_init == 0

-    {

-        calibration_polarity = calipolarity;

-    }

-

-    while (all_ana_cal_status < ANACAL_ERROR)

-    {

-        rg_zcal_ctrl += calibration_polarity;

-

-        set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (uint16_t)rg_zcal_ctrl);

-

-

-        anacal_exe(phyadd);

-

-        if (all_ana_cal_status == 0)

-        {

-            all_ana_cal_status = ANACAL_ERROR;

-        }

-

-        else if (((get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1) != ad_cal_comp_out_init)

-        {

-            all_ana_cal_status = ANACAL_FINISH;

-        }

-        else

-        {

-            if ((rg_zcal_ctrl == 0x3F) || (rg_zcal_ctrl == 0x00))

-            {

-                all_ana_cal_status = ANACAL_SATURATION;  // need to FT

-                rg_zcal_ctrl = ZCAL_MIDDLE;  // 0 dB

-            }

-        }

-    }

-

-    if (all_ana_cal_status == ANACAL_ERROR)

-    {

-        rg_zcal_ctrl = ZCAL_MIDDLE;  // 0 dB

-

-        set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (uint16_t)rg_zcal_ctrl);

-    }

-    else

-    {

-        // rg_zcal_ctrl[5:0] rg_rext_trim[13:8]

-        set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (uint16_t)((rg_zcal_ctrl << 8) | rg_zcal_ctrl));

-

-        // 1f_115[2:0](rg_bg_rasel) = rg_zcal_ctrl[5:3]

-        set_gphy_reg_cl45(phyadd, DEVID_1F, RgAddr_dev1Fh_reg115h, (uint16_t)((rg_zcal_ctrl & 0x3f) >> 3));

-    }

-

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all);

-    return all_ana_cal_status;

-}

-

-uint8_t R50_Calibration(uint8_t phyadd, uint8_t phyadd_common)

-{

-    int8_t rg_zcal_ctrl = 0, rg_r50ohm_rsel_tx = 0, calibration_polarity = 0;

-    uint8_t all_ana_cal_status = 1;

-    int16_t backup_dev1e_e0 = 0, ad_cal_comp_out_init = 0, calibration_pair = 0;

-

-    /* setting */

-    set_gphy_reg_cl22(phyadd, RgAddr_Reg1Fh, CL22_Page_Reg);        // g0

-    set_gphy_reg_cl22(phyadd, RgAddr_Reg00h, AN_disable_force_1000M);  // AN disable, force 1000M

-

-    set_gphy_reg_cl45(phyadd_common, DEVID_1F, RgAddr_dev1Fh_reg100h, BG_voltage_output); // BG voltage output

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg145h, Fix_mdi); // fix mdi

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg185h, Disable_tx_slew_control); // disable tx slew control

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0FBh, LDO_control); // ldo

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_R50); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all); // 1e_dc[0]:rg_txvos_calen

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0E1h, Disable_all); // 1e_e1[4]:rg_cal_refsel(0:1.2V) enable BG 1.2V to REXT PAD

-

-    for (calibration_pair = ANACAL_PAIR_A; calibration_pair <= ANACAL_PAIR_D; calibration_pair++)

-    {

-        all_ana_cal_status = 1;

-

-        if (calibration_pair == ANACAL_PAIR_A)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_R50_pairA_ENABLE); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen, [0]:rg_zcalen_a

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Zcalen_A_ENABLE);

-        }

-        else if (calibration_pair == ANACAL_PAIR_B)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_R50); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen, [0]:rg_zcalen_a

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Zcalen_B_ENABLE); // 1e_dc[12]:rg_zcalen_b

-        }

-        else if (calibration_pair == ANACAL_PAIR_C)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_R50); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen, [0]:rg_zcalen_a

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Zcalen_C_ENABLE); // 1e_dc[8]:rg_zcalen_c

-        }

-        else // if(calibration_pair == ANACAL_PAIR_D)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_R50); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen, [0]:rg_zcalen_a

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Zcalen_D_ENABLE); // 1e_dc[4]:rg_zcalen_d

-        }

-

-        /* calibrate */

-        rg_zcal_ctrl = ZCAL_MIDDLE;             // start with 0 dB

-

-        backup_dev1e_e0 = (get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0E0h)&(~0x003f));

-        set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (backup_dev1e_e0 | rg_zcal_ctrl));

-

-        anacal_exe(phyadd_common);

-        if (all_ana_cal_status == 0)

-        {

-            all_ana_cal_status = ANACAL_ERROR;

-        }

-

-        ad_cal_comp_out_init = (get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1;  // 1e_17a[8]:ad_cal_comp_out

-

-        if (ad_cal_comp_out_init == 1)

-        {

-            calibration_polarity = -1;

-        }

-        else

-        {

-            calibration_polarity = 1;

-        }

-

-        while (all_ana_cal_status < ANACAL_ERROR)

-        {

-            rg_zcal_ctrl += calibration_polarity;

-

-            set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (backup_dev1e_e0 | rg_zcal_ctrl));

-

-            anacal_exe(phyadd_common);

-

-            if (all_ana_cal_status == 0)

-            {

-                all_ana_cal_status = ANACAL_ERROR;

-            }

-            else if (((get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1) != ad_cal_comp_out_init)

-            {

-                all_ana_cal_status = ANACAL_FINISH;

-            }

-            else

-            {

-                if ((rg_zcal_ctrl == 0x3F) || (rg_zcal_ctrl == 0x00))

-                {

-                    all_ana_cal_status = ANACAL_SATURATION;  // need to FT

-                    rg_zcal_ctrl = ZCAL_MIDDLE;  // 0 dB

-                }

-            }

-        }

-

-        if (all_ana_cal_status == ANACAL_ERROR)

-        {

-            rg_r50ohm_rsel_tx = ZCAL_MIDDLE;  // 0 dB

-        }

-        else

-        {

-            if (rg_zcal_ctrl > (0x3F - R50_OFFSET_VALUE))

-            {

-                all_ana_cal_status = ANACAL_SATURATION;  // need to FT

-                rg_zcal_ctrl = ZCAL_MIDDLE;  // 0 dB

-            }

-            else

-            {

-                rg_zcal_ctrl += R50_OFFSET_VALUE;

-            }

-

-            rg_r50ohm_rsel_tx = ZCAL_TO_R50ohm_TBL[rg_zcal_ctrl];

-        }

-

-        if (calibration_pair == ANACAL_PAIR_A)

-        {

-            // cr_r50ohm_rsel_tx_a

-            ad_cal_comp_out_init = get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg174h)&(~MASK_r50ohm_rsel_tx_a);

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg174h, (ad_cal_comp_out_init | (((rg_r50ohm_rsel_tx << 8) & MASK_MSB_8bit) | Rg_r50ohm_rsel_tx_a_en))); // 1e_174[15:8]

-        }

-        else if (calibration_pair == ANACAL_PAIR_B)

-        {

-            // cr_r50ohm_rsel_tx_b

-            ad_cal_comp_out_init = get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg174h)&(~MASK_r50ohm_rsel_tx_b);

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg174h, (ad_cal_comp_out_init | (((rg_r50ohm_rsel_tx << 0) & MASK_LSB_8bit) | Rg_r50ohm_rsel_tx_b_en))); // 1e_174[7:0]

-        }

-        else if (calibration_pair == ANACAL_PAIR_C)

-        {

-            // cr_r50ohm_rsel_tx_c

-            ad_cal_comp_out_init = get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg175h)&(~MASK_r50ohm_rsel_tx_c);

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg175h, (ad_cal_comp_out_init | (((rg_r50ohm_rsel_tx << 8) & MASK_MSB_8bit) | Rg_r50ohm_rsel_tx_c_en))); // 1e_175[15:8]

-        }

-        else // if(calibration_pair == ANACAL_PAIR_D)

-        {

-            // cr_r50ohm_rsel_tx_d

-            ad_cal_comp_out_init = get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg175h)&(~MASK_r50ohm_rsel_tx_d);

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg175h, (ad_cal_comp_out_init | (((rg_r50ohm_rsel_tx << 0) & MASK_LSB_8bit) | Rg_r50ohm_rsel_tx_d_en))); // 1e_175[7:0]

-        }

-    }

-

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all);

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all);

-

-    return all_ana_cal_status;

-}

-

-uint8_t TX_OFS_Calibration(uint8_t phyadd, uint8_t phyadd_common)

-{

-    int8_t tx_offset_index = 0, calibration_polarity = 0;

-    uint8_t all_ana_cal_status = 1, tx_offset_reg_shift = 0, tbl_idx = 0;

-    int16_t ad_cal_comp_out_init = 0, calibration_pair = 0, tx_offset_reg = 0, reg_temp = 0;

-

-    /* setting */

-    set_gphy_reg_cl22(phyadd, RgAddr_Reg1Fh, CL22_Page_Reg);        // g0

-    set_gphy_reg_cl22(phyadd, RgAddr_Reg00h, AN_disable_force_1000M);  // AN disable, force 1000M

-

-    set_gphy_reg_cl45(phyadd, DEVID_1F, RgAddr_dev1Fh_reg100h, BG_voltage_output); // BG voltage output

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg145h, Fix_mdi); // fix mdi

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg185h, Disable_tx_slew_control); // disable tx slew control

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0FBh, LDO_control); // ldo

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_TX_OFST); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Rg_txvos_calen_ENABLE); // 1e_dc[0]:rg_txvos_calen

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_TX_OFST); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Rg_txvos_calen_ENABLE); // 1e_dc[0]:rg_txvos_calen

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E1h, Disable_all); // 1e_e1[4]:rg_cal_refsel(0:1.2V) enable BG 1.2V to REXT PAD

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg096h, Bypass_tx_offset_cal); // 1e_96[15]:bypass_tx_offset_cal, Hw bypass, Fw cal

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg03Eh, Enable_Tx_VLD); // 1e_3e:enable Tx VLD

-

-    for (calibration_pair = ANACAL_PAIR_A; calibration_pair <= ANACAL_PAIR_D; calibration_pair++)

-    {

-        all_ana_cal_status = 1;

-

-        tbl_idx = TX_OFFSET_0mV_idx;

-        tx_offset_index = EN753x_TX_OFS_TBL[tbl_idx];

-

-        if (calibration_pair == ANACAL_PAIR_A)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_a_ENABLE);       // 1e_dd[12]:rg_txg_calen_a

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Dh, (Force_dasn_dac_in0_ENABLE | DAC_IN_0V));  // 1e_17d:dac_in0_a

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg181h, (Force_dasn_dac_in1_ENABLE | DAC_IN_0V));  // 1e_181:dac_in1_a

-

-            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg172h)&(~MASK_cr_tx_amp_offset_MSB));

-            tx_offset_reg_shift = 8;  // 1e_172[13:8]

-            tx_offset_reg = RgAddr_dev1Eh_reg172h;

-        }

-        else if (calibration_pair == ANACAL_PAIR_B)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_b_ENABLE);       // 1e_dd[8]:rg_txg_calen_b

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Eh, (Force_dasn_dac_in0_ENABLE | DAC_IN_0V));  // 1e_17e:dac_in0_b

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg182h, (Force_dasn_dac_in1_ENABLE | DAC_IN_0V));  // 1e_182:dac_in1_b

-

-            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg172h)&(~MASK_cr_tx_amp_offset_LSB));

-            tx_offset_reg_shift = 0;  // 1e_172[5:0]

-            tx_offset_reg = RgAddr_dev1Eh_reg172h;

-        }

-        else if (calibration_pair == ANACAL_PAIR_C)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_c_ENABLE);       // 1e_dd[4]:rg_txg_calen_c

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Fh, (Force_dasn_dac_in0_ENABLE | DAC_IN_0V));  // 1e_17f:dac_in0_c

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg183h, (Force_dasn_dac_in1_ENABLE | DAC_IN_0V));  // 1e_183:dac_in1_c

-

-            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg173h)&(~MASK_cr_tx_amp_offset_MSB));

-            tx_offset_reg_shift = 8;  // 1e_173[13:8]

-            tx_offset_reg = RgAddr_dev1Eh_reg173h;

-        }

-        else // if(calibration_pair == ANACAL_PAIR_D)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_d_ENABLE);       // 1e_dd[0]:rg_txg_calen_d

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg180h, (Force_dasn_dac_in0_ENABLE | DAC_IN_0V));  // 1e_180:dac_in0_d

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg184h, (Force_dasn_dac_in1_ENABLE | DAC_IN_0V));  // 1e_184:dac_in1_d

-

-            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg173h)&(~MASK_cr_tx_amp_offset_LSB));

-            tx_offset_reg_shift = 0;  // 1e_173[5:0]

-            tx_offset_reg = RgAddr_dev1Eh_reg173h;

-        }

-

-        /* calibrate */

-        //tx_offset_index = TX_AMP_OFFSET_0mV;

-        tbl_idx = TX_OFFSET_0mV_idx;

-        tx_offset_index = EN753x_TX_OFS_TBL[tbl_idx];

-        set_gphy_reg_cl45(phyadd, DEVID_1E, tx_offset_reg, (reg_temp | (tx_offset_index << tx_offset_reg_shift)));  // 1e_172, 1e_173

-

-        anacal_exe(phyadd_common);

-        if (all_ana_cal_status == 0)

-        {

-            all_ana_cal_status = ANACAL_ERROR;

-        }

-

-        ad_cal_comp_out_init = (get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1;  // 1e_17a[8]:ad_cal_comp_out

-

-        if (ad_cal_comp_out_init == 1)

-        {

-            calibration_polarity = -1;

-        }

-        else

-        {

-            calibration_polarity = 1;

-        }

-

-        while (all_ana_cal_status < ANACAL_ERROR)

-        {

-            tbl_idx += calibration_polarity;

-            tx_offset_index = EN753x_TX_OFS_TBL[tbl_idx];

-

-            set_gphy_reg_cl45(phyadd, DEVID_1E, tx_offset_reg, (reg_temp | (tx_offset_index << tx_offset_reg_shift)));  // 1e_172, 1e_173

-

-            anacal_exe(phyadd_common);

-

-            if (all_ana_cal_status == 0)

-            {

-                all_ana_cal_status = ANACAL_ERROR;

-            }

-            else if (((get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1) != ad_cal_comp_out_init)

-            {

-                all_ana_cal_status = ANACAL_FINISH;

-            }

-            else

-            {

-                if ((tx_offset_index == 0x3f) || (tx_offset_index == 0x1f))

-                {

-                    all_ana_cal_status = ANACAL_SATURATION;  // need to FT

-                }

-            }

-        }

-

-        if (all_ana_cal_status == ANACAL_ERROR)

-        {

-            tbl_idx = TX_OFFSET_0mV_idx;

-            tx_offset_index = EN753x_TX_OFS_TBL[tbl_idx];

-

-            set_gphy_reg_cl45(phyadd, DEVID_1E, tx_offset_reg, (reg_temp | (tx_offset_index << tx_offset_reg_shift)));  // cr_tx_amp_offset_a/b/c/d, 1e_172, 1e_173

-        }

-    }

-

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Dh, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Eh, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Fh, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg180h, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg181h, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg182h, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg183h, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg184h, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all); // disable analog calibration circuit

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all); // disable Tx offset calibration circuit

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all); // disable analog calibration circuit

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all); // disable Tx offset calibration circuit

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg03Eh, Disable_all); // disable Tx VLD force mode

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Disable_all); // disable Tx offset/amplitude calibration circuit

-

-    return all_ana_cal_status;

-}

-

-uint8_t TX_AMP_Calibration(uint8_t phyadd, uint8_t phyadd_common)

-{

-    int8_t tx_amp_index = 0, calibration_polarity = 0;

-    uint8_t all_ana_cal_status = 1, tx_amp_reg_shift = 0;

-    uint8_t tx_amp_reg = 0, tx_amp_reg_100 = 0, tst_offset = 0, hbt_offset = 0, gbe_offset = 0, tbt_offset = 0;

-    uint16_t ad_cal_comp_out_init = 0, calibration_pair = 0, reg_temp = 0;

-

-  //phyadd_common = phyadd;

-

-    /* setting */

-    set_gphy_reg_cl22(phyadd, RgAddr_Reg1Fh, CL22_Page_Reg);        // g0

-    set_gphy_reg_cl22(phyadd, RgAddr_Reg00h, AN_disable_force_1000M);  // AN disable, force 1000M

-

-    set_gphy_reg_cl45(phyadd, DEVID_1F, RgAddr_dev1Fh_reg100h, BG_voltage_output); // BG voltage output

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg145h, Fix_mdi); // fix mdi

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg185h, Disable_tx_slew_control); // disable tx slew control

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0FBh, LDO_control); // ldo

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_TX_AMP); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Rg_txvos_calen_ENABLE); // 1e_dc[0]:rg_txvos_calen

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E1h, Rg_cal_refsel_ENABLE); // 1e_e1[4]:rg_cal_refsel(0:1.2V) enable BG 1.2V to REXT PAD

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_TX_AMP); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Rg_txvos_calen_ENABLE); // 1e_dc[0]:rg_txvos_calen

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0E1h, Rg_cal_refsel_ENABLE); // 1e_e1[4]:rg_cal_refsel(0:1.2V) enable BG 1.2V to REXT PAD

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg096h, Bypass_tx_offset_cal); // 1e_96[15]:bypass_tx_offset_cal, Hw bypass, Fw cal

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg03Eh, Enable_Tx_VLD); // 1e_3e:enable Tx VLD

-

-    for (calibration_pair = ANACAL_PAIR_A; calibration_pair <= ANACAL_PAIR_D; calibration_pair++)

-    //for (calibration_pair = ANACAL_PAIR_A; calibration_pair <= ANACAL_PAIR_B; calibration_pair++) // debugging

-    {

-        all_ana_cal_status = 1;

-

-        /* calibrate */

-        tx_amp_index = TX_AMP_MIDDLE;   // start with 0 dB

-        if (calibration_pair == ANACAL_PAIR_A)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_a_ENABLE);       // 1e_dd[12]:rg_txg_calen_a amp calibration enable

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Dh, (Force_dasn_dac_in0_ENABLE | DAC_IN_2V));  // 1e_17d:dac_in0_a

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg181h, (Force_dasn_dac_in1_ENABLE | DAC_IN_2V));  // 1e_181:dac_in1_a

-

-            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg012h)&(~MASK_da_tx_i2mpb_a_gbe));

-            tx_amp_reg_shift = 10;  // 1e_12[15:10]

-            tx_amp_reg = RgAddr_dev1Eh_reg012h;

-            tx_amp_reg_100 = 0x16;

-        }

-        else if (calibration_pair == ANACAL_PAIR_B)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_b_ENABLE);       // 1e_dd[8]:rg_txg_calen_b amp calibration enable

-            //Serial.println(Rg_txg_calen_b_ENABLE, HEX);

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Eh, (Force_dasn_dac_in0_ENABLE | DAC_IN_2V));  // 1e_17e:dac_in0_b

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg182h, (Force_dasn_dac_in1_ENABLE | DAC_IN_2V));  // 1e_182:dac_in1_b

-

-            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg017h)&(~MASK_da_tx_i2mpb_b_c_d_gbe));

-            tx_amp_reg_shift = 8; // 1e_17[13:8]

-            tx_amp_reg = RgAddr_dev1Eh_reg017h;

-            tx_amp_reg_100 = 0x18;

-        }

-        else if (calibration_pair == ANACAL_PAIR_C)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_c_ENABLE);       // 1e_dd[4]:rg_txg_calen_c amp calibration enable

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Fh, (Force_dasn_dac_in0_ENABLE | DAC_IN_2V));  // 1e_17f:dac_in0_c

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg183h, (Force_dasn_dac_in1_ENABLE | DAC_IN_2V));  // 1e_183:dac_in1_c

-

-            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg019h)&(~MASK_da_tx_i2mpb_b_c_d_gbe));

-            tx_amp_reg_shift = 8; // 1e_19[13:8]

-            tx_amp_reg = RgAddr_dev1Eh_reg019h;

-            tx_amp_reg_100 = 0x20;

-        }

-        else //if(calibration_pair == ANACAL_PAIR_D)

-        {

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_d_ENABLE);       // 1e_dd[0]:rg_txg_calen_d amp calibration enable

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg180h, (Force_dasn_dac_in0_ENABLE | DAC_IN_2V));  // 1e_180:dac_in0_d

-            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg184h, (Force_dasn_dac_in1_ENABLE | DAC_IN_2V));  // 1e_184:dac_in1_d

-

-            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg021h)&(~MASK_da_tx_i2mpb_b_c_d_gbe));

-            tx_amp_reg_shift = 8; // 1e_21[13:8]

-            tx_amp_reg = RgAddr_dev1Eh_reg021h;

-            tx_amp_reg_100 = 0x22;

-        }

-

-        /* calibrate */

-        tx_amp_index = TX_AMP_MIDDLE; // start with 0 dB

-

-        set_gphy_reg_cl45(phyadd, DEVID_1E, tx_amp_reg, (reg_temp | (tx_amp_index << tx_amp_reg_shift))); // 1e_12/17/19/21

-

-        anacal_exe(phyadd_common);

-        if (all_ana_cal_status == 0)

-        {

-            all_ana_cal_status = ANACAL_ERROR;

-        }

-

-

-        ad_cal_comp_out_init = (get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1;    // 1e_17a[8]:ad_cal_comp_out

-        //Serial.println(ad_cal_comp_out_init, HEX);

-

-        if (ad_cal_comp_out_init == 1)

-        {

-            calibration_polarity = -1;

-        }

-        else

-        {

-            calibration_polarity = 1;

-        }

-        while (all_ana_cal_status < ANACAL_ERROR)

-        {

-            tx_amp_index += calibration_polarity;

-            //Serial.println(tx_amp_index, HEX);

-

-            set_gphy_reg_cl45(phyadd, DEVID_1E, tx_amp_reg, (reg_temp | (tx_amp_index << tx_amp_reg_shift)));

-

-            anacal_exe(phyadd_common);

-

-            if (all_ana_cal_status == 0)

-            {

-                all_ana_cal_status = ANACAL_ERROR;

-            }

-            else if (((get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1) != ad_cal_comp_out_init)

-            {

-                all_ana_cal_status = ANACAL_FINISH;

-                //Serial.print("    tx_amp_index: ");

-                //Serial.println(tx_amp_index, HEX);

-                //reg_temp = get_gphy_reg_cl45(phyadd, 0x1e, tx_amp_reg)&(~0xff00);

-                //set_gphy_reg_cl45(phyadd, 0x1e, tx_amp_reg, (reg_temp|((tx_amp_index + tst_offset)<<tx_amp_reg_shift)));  // for gbe(DAC)

-            }

-            else

-            {

-                if ((tx_amp_index == 0x3f) || (tx_amp_index == 0x00))

-                {

-                    all_ana_cal_status = ANACAL_SATURATION;  // need to FT

-                    tx_amp_index = TX_AMP_MIDDLE;

-                }

-            }

-        }

-

-        if (all_ana_cal_status == ANACAL_ERROR)

-        {

-            tx_amp_index = TX_AMP_MIDDLE;

-        }

-

-        // da_tx_i2mpb_a_gbe / b/c/d, only GBE for now

-        set_gphy_reg_cl45(phyadd, DEVID_1E, tx_amp_reg, ((tx_amp_index - TXAMP_offset) | ((tx_amp_index - TXAMP_offset) << tx_amp_reg_shift)));  // // temp modify

-        set_gphy_reg_cl45(phyadd, DEVID_1E, tx_amp_reg_100, ((tx_amp_index - TXAMP_offset) | ((tx_amp_index + TX_i2mpb_hbt_ofs) << tx_amp_reg_shift)));

-    }

-

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Dh, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Eh, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Fh, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg180h, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg181h, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg182h, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg183h, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg184h, Disable_all);

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all); // disable analog calibration circuit

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all); // disable Tx offset calibration circuit

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg03Eh, Disable_all); // disable Tx VLD force mode

-    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Disable_all); // disable Tx offset/amplitude calibration circuit

-

-    return all_ana_cal_status;

-}

-

-void set_gphy_reg_cl22(uint8_t phyad, uint8_t reg, uint16_t value)

-{

-    an8855_phy_write(phyad-g_smi_addr, reg, value);

-    /*

-       gsw_top_reg_REG_PHY_IAC REG_PHY_IAC_val;

-       gsw_top_reg_REG_PHY_IAD REG_PHY_IAD_val;

-

-    // Wait until done

-    do

-    {

-    REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);

-    }

-    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);

-

-    // Set address

-    REG_PHY_IAC_val.Bits.csr_mdio_st = 1;

-    REG_PHY_IAC_val.Bits.csr_mdio_cmd = 1;

-    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = phyad;

-    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = reg;

-    REG_PHY_IAC_val.Bits.csr_mdio_wr_data = value;

-    REG_PHY_IAC_val.Bits.csr_phy_acs_st = 1;

-

-    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);

-    */

-}

-

-UINT16 get_gphy_reg_cl45(uint8_t prtid, uint8_t devid, uint16_t reg)

-{

-    UINT32 rdata = 0;

-

-    an8855_phy_read_cl45(prtid-g_smi_addr, devid, reg, &rdata);

-    return ((UINT16)rdata);

-    /*

-    gsw_top_reg_REG_PHY_IAC REG_PHY_IAC_val;

-    gsw_top_reg_REG_PHY_IAD REG_PHY_IAD_val;

-

-    // Wait until done

-    do

-    {

-    REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);

-    }

-    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);

-

-    // Set address

-    REG_PHY_IAC_val.Bits.csr_mdio_st = 0;

-    REG_PHY_IAC_val.Bits.csr_mdio_cmd = 0;

-    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = prtid;

-    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = devid;

-    REG_PHY_IAC_val.Bits.csr_mdio_wr_data = reg;

-    REG_PHY_IAC_val.Bits.csr_phy_acs_st = 1;

-

-    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);

-

-    // Wait until done

-    do

-    {

-    REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);

-    }

-    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);

-

-    // Read value

-    REG_PHY_IAC_val.Bits.csr_mdio_st = 0;

-    REG_PHY_IAC_val.Bits.csr_mdio_cmd = 3;

-    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = prtid;

-    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = devid;

-    REG_PHY_IAC_val.Bits.csr_mdio_wr_data = 0;

-    REG_PHY_IAC_val.Bits.csr_phy_acs_st = 1;

-    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);

-

-    // Wait until done

-    do

-    {

-    REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);

-    }

-    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);

-

-    REG_PHY_IAD_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAD);

-

-    return REG_PHY_IAD_val.Raw;

-    */

-}

-

-void set_gphy_reg_cl45(uint8_t prtid, uint8_t devid, uint16_t reg, uint16_t value)

-{

-    an8855_phy_write_cl45(prtid-g_smi_addr, devid, reg, value);

-    /*

-    gsw_top_reg_REG_PHY_IAC REG_PHY_IAC_val;

-

-    // Wait until done

-    do

-    {

-        REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);

-    }

-    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);

-

-    // Set address

-    REG_PHY_IAC_val.Bits.csr_mdio_st = 0;

-    REG_PHY_IAC_val.Bits.csr_mdio_cmd = 0;

-    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = prtid;

-    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = devid;

-    REG_PHY_IAC_val.Bits.csr_mdio_wr_data = reg;

-    REG_PHY_IAC_val.Bits.csr_phy_acs_st = 1;

-

-    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);

-

-    // Wait until done

-    do

-    {

-        REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);

-    }

-    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);

-

-    // Write value

-    REG_PHY_IAC_val.Bits.csr_mdio_st = 0;

-    REG_PHY_IAC_val.Bits.csr_mdio_cmd = 1;

-    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = prtid;

-    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = devid;

-    REG_PHY_IAC_val.Bits.csr_mdio_wr_data = value;

-    REG_PHY_IAC_val.Bits.csr_phy_acs_st = 1;

-

-    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);

-    */

-}

-

-void anacal_exe(uint8_t phyadd_common)

-{

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ch, 1);// da_calin_flag pull high

-    an8855_udelay(1000);

-    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ch, 0);// da_calin_flag pull low

-}

-

+/* FILE NAME:  an8855_phy_cal.c
+* PURPOSE:
+*    It provides an8855 switch phy calibration function.
+*
+* NOTES:
+*
+*/
+
+/* INCLUDE FILE DECLARATIONS
+*/
+#include "an8855_mdio.h"
+#include "an8855_phy.h"
+//#include "swk_gphy_reg.h"
+//#include "gphy_calibration.h"
+//#include "gsw_reg.h"
+
+/* NAMING CONSTANT DECLARATIONS
+ */
+#define MII_BMCR                (0)
+#define BMCR_PDOWN              (0x0800)
+/* MACRO FUNCTION DECLARATIONS
+ */
+
+#define FULL_BITS(_n_) ((1UL << (_n_)) - 1)
+
+/* DATA TYPE DECLARATIONS
+ */
+
+/* GLOBAL VARIABLE DECLARATIONS
+ */
+/* Zcal to R50 mapping table (20220404) */
+const uint8_t ZCAL_TO_R50ohm_TBL[64] =
+{
+    127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
+    127, 127, 127, 127, 127, 123, 118, 114, 110, 106, 102, 98, 96, 92, 88, 85,
+    82, 80, 76, 72, 70, 67, 64, 62, 60, 56, 54, 52, 49, 48, 45, 43,
+    40, 39, 36, 34, 32, 32, 30, 28, 25, 24, 22, 20, 18, 16, 16, 14
+};
+
+/* Tx offset table, value is from small to big */
+const uint8_t  EN753x_TX_OFS_TBL[64] =
+{
+    0x3f, 0x3e, 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0x30,
+    0x2f, 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0x20,
+    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+    0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
+};
+
+#define TOTAL_PATCH_C45_ITEMS   (15)
+#define TOTAL_PATCH_TR_ITEMS    (19)
+const uint16_t C45_PATCH_TABLE[TOTAL_PATCH_C45_ITEMS][3] =
+{
+    {0x1E, 0x120, 0x8014},
+    {0x1E, 0x122, 0xFFFF},
+    {0x1E, 0x122, 0xFFFF},
+    {0x1E, 0x144, 0x0200},
+    {0x1E, 0x14A, 0xEE20},
+    {0x1E, 0x189, 0x0110},
+    {0x1E, 0x19B, 0x0111},
+    {0x1E, 0x234, 0x0181},
+    {0x1E, 0x238, 0x0120},
+    {0x1E, 0x239, 0x0117},
+    {0x1F, 0x268, 0x07F4},
+    {0x1E, 0x2d1, 0x0733},
+    {0x1E, 0x323, 0x0011},
+    {0x1E, 0x324, 0x013F},
+    {0x1E, 0x326, 0x0037},
+};
+
+const uint32_t TR_PATCH_TABLE[TOTAL_PATCH_TR_ITEMS][2] =
+{
+    {0x83AA, 0x055a0 },
+    {0x83AE, 0x7FF3F },
+    {0x8F80, 0x0001e },
+    {0x8F82, 0x6FB90A},
+    {0x8FAE, 0x060671},
+    {0x8FB0, 0xE2F00 },
+    {0x8ECC, 0x444444},
+    {0x9686, 0x00000 },
+    {0x968C, 0x2EBAEF},
+    {0x9690, 0x00000b},
+    {0x9698, 0x0504D },
+    {0x969A, 0x2314f },
+    {0x969E, 0x03028 },
+    {0x96A0, 0x05010 },
+    {0x96A2, 0x40001 },
+    {0x96A6, 0x018670},
+    {0x96A8, 0x0024A },
+    {0x96B6, 0x00072 },
+    {0x96B8, 0x03210 },
+};
+
+#define TOTAL_NUMBER_OF_PATCH    (14)
+static uint16_t eee_patch_table[TOTAL_NUMBER_OF_PATCH][2] = {
+    {RgAddr_dev1Eh_reg120h, 0x8014},
+    {RgAddr_dev1Eh_reg122h, 0xFFFF},
+    {RgAddr_dev1Eh_reg122h, 0xFFFF},
+    {RgAddr_dev1Eh_reg144h, 0x0200},
+    {RgAddr_dev1Eh_reg14Ah, 0xEE20},
+    {RgAddr_dev1Eh_reg19Bh, 0x0111},
+    {RgAddr_dev1Eh_reg234h, 0x1181},
+    {RgAddr_dev1Eh_reg238h, 0x0120},
+    {RgAddr_dev1Eh_reg239h, 0x0117},
+    {RgAddr_dev1Fh_reg268h, 0x07F4},
+    {RgAddr_dev1Eh_reg2D1h, 0x0733},
+    {RgAddr_dev1Eh_reg323h, 0x0011},
+    {RgAddr_dev1Eh_reg324h, 0x013F},
+    {RgAddr_dev1Eh_reg326h, 0x0037}
+};
+
+#define TOTAL_NUMBER_OF_TR      (19)
+static uint16_t tr_reg_table[TOTAL_NUMBER_OF_TR][3] = {
+    {0x55A0, 0x0000, 0x83AA},
+    {0xFF3F, 0x0007, 0x83AE},
+    {0x001E, 0x0000, 0x8F80},
+    {0xB90A, 0x006F, 0x8F82},
+    {0x0671, 0x0006, 0x8FAE},
+    {0x2F00, 0x000E, 0x8FB0},
+    {0x4444, 0x0044, 0x8ECC},
+    {0x0004, 0x0000, 0x9686},
+    {0xBAEF, 0x002E, 0x968C},
+    {0x000B, 0x0000, 0x9690},
+    {0x504D, 0x0000, 0x9698},
+    {0x314F, 0x0002, 0x969A},
+    {0x3028, 0x0000, 0x969E},
+    {0x5010, 0x0000, 0x96A0},
+    {0x0001, 0x0004, 0x96A2},
+    {0x8670, 0x0001, 0x96A6},
+    {0x024A, 0x0000, 0x96A8},
+    {0x0072, 0x0000, 0x96B6},
+    {0x3210, 0x0000, 0x96B8}
+};
+
+void TR_RegWr(uint16_t phyadd, uint16_t tr_reg_addr, uint32_t tr_data);
+
+uint16_t get_gphy_reg_cl22(uint8_t phyad, uint8_t reg)
+{
+    uint32_t rdata = 0;
+
+    an8855_phy_read(phyad-g_smi_addr, reg, &rdata);
+
+    return ((uint16_t)rdata);
+    /*
+    gsw_top_reg_REG_PHY_IAC REG_PHY_IAC_val;
+    gsw_top_reg_REG_PHY_IAD REG_PHY_IAD_val;
+
+    // Wait until done
+    do
+    {
+      REG_PHY_IAC_val.Raw   = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);
+    }
+    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);
+
+    // Set address
+    REG_PHY_IAC_val.Bits.csr_mdio_st = 1;
+    REG_PHY_IAC_val.Bits.csr_mdio_cmd   = 2;
+    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = phyad;
+    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = reg;
+    REG_PHY_IAC_val.Bits.csr_phy_acs_st =   1;
+    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);
+    // Wait until done
+    do
+    {
+        REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);
+    }
+    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);
+
+    REG_PHY_IAD_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAD);
+
+    return REG_PHY_IAD_val.Raw;
+    */
+}
+
+/* EXPORTED SUBPROGRAM BODIES
+ */
+void gphy_config(void)
+{
+    uint8_t port = 1;
+    uint8_t phy_base = 0, phys_in_chip = 8;
+
+    for (port = 1; port <= phys_in_chip; port++)
+    {
+        set_gphy_reg_cl45(phy_base + port, 0x7, 0x3c, 0x0006); // Enable EEE
+        set_gphy_reg_cl45(phy_base + port, 0x1e, 0x3e, 0xf000); // force on TXVLD
+    }
+}
+
+static void set_gphy_TrReg(uint8_t prtid, uint16_t parm_1, uint16_t parm_2, uint16_t parm_3)
+{
+    set_gphy_reg_cl22(prtid, RgAddr_TrReg11h, parm_1);
+    set_gphy_reg_cl22(prtid, RgAddr_TrReg12h, parm_2);
+    set_gphy_reg_cl22(prtid, RgAddr_TrReg10h, parm_3);
+}
+
+static void gphy_eee_patch(uint8_t phy_base)
+{
+    UI8_T   port = 1, index = 0, phy_addr = 1;
+    UI16_T  data = 0;
+
+    for (port = 1; port <=8; port++)
+    {
+        phy_addr = phy_base + port;
+        data = get_gphy_reg_cl22(phy_addr, MII_BMCR);
+        set_gphy_reg_cl22(phy_addr, MII_BMCR, data & ~(BMCR_PDOWN));    /* PHY power on */
+
+        /* Change EEE RG default value */
+        for (index = 0; index < TOTAL_NUMBER_OF_PATCH; index++)
+        {
+            set_gphy_reg_cl45(phy_addr, DEVID_1E, eee_patch_table[index][0], eee_patch_table[index][1]);
+        }
+
+        set_gphy_reg_cl22(phy_addr, RgAddr_Reg1Fh, CL22_Page_TrReg);   /* change CL22page to LpiReg(0x3) */
+        for (index = 0; index < TOTAL_NUMBER_OF_TR; index++)
+        {
+            set_gphy_TrReg(phy_addr, tr_reg_table[index][0], tr_reg_table[index][1], tr_reg_table[index][2]);
+        }
+
+        set_gphy_reg_cl22(phy_addr, RgAddr_Reg1Fh, CL22_Page_LpiReg);  /* change CL22page to LpiReg(0x3) */
+        set_gphy_reg_cl22(phy_addr, RgAddr_LpiReg1Ch, 0x0c92);         /* Fine turn SigDet for B2B LPI link down issue */
+        set_gphy_reg_cl22(phy_addr, RgAddr_LpiReg1Dh, 0x0001);         /* Enable "lpi_quit_waitafesigdet_en" for LPI link down issue */
+
+        set_gphy_reg_cl22(phy_addr, RgAddr_Reg1Fh, CL22_Page_Reg);     /* change CL22page to Reg(0x0) */
+    }
+}
+
+void gphy_calibration(uint8_t phy_base)
+{
+    uint8_t port = 1, phy_addr = 1 ,phy_group = 1, index = 0;
+    uint8_t phys_in_chip = 5;
+
+    BG_Calibration(phy_base, 0x1);
+    if (phys_in_chip > 4)
+    {
+        BG_Calibration(phy_base + 0x4, 0x1);
+    }
+
+    for (port = 0; port < phys_in_chip; port++)
+    {
+        if (port < 4)
+        {
+            phy_group = phy_base;     /* PHY group 1 */
+        }
+        else
+        {
+            phy_group = phy_base + 0x04;     /* PHY group 2 */
+        }
+        phy_addr = phy_base + port;
+        R50_Calibration(phy_addr, phy_group);
+        TX_OFS_Calibration(phy_addr, phy_group);
+        TX_AMP_Calibration(phy_addr, phy_group);
+    }
+
+    for (port = 0; port < phys_in_chip; port++)
+    {
+        phy_addr = phy_base + port;
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x017d, 0x0000);
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x017e, 0x0000);
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x017f, 0x0000);
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0180, 0x0000);
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0181, 0x0000);
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0182, 0x0000);
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0183, 0x0000);
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0184, 0x0000);
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x00db, 0x0000);  // disable analog calibration circuit
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x00dc, 0x0000);  // disable Tx offset calibration circuit
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x003e, 0x0000);  // disable Tx VLD force mode
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x00dd, 0x0000);  // disable Tx offset/amplitude calibration circuit
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0x0145, 0x1000);  // enable auto MDI/MDIX
+
+        set_gphy_reg_cl22(phy_addr, 0, 0x1200);
+        /* GPHY Rx low pass filter */
+        set_gphy_reg_cl45(phy_addr, 0x1e, 0xc7, 0xd000);
+        /* patch */
+        for (index = 0; index < TOTAL_PATCH_C45_ITEMS; index++)
+        {
+            set_gphy_reg_cl45(phy_addr, C45_PATCH_TABLE[index][0], C45_PATCH_TABLE[index][1], C45_PATCH_TABLE[index][2]);
+        }
+        for (index = 0; index < TOTAL_PATCH_TR_ITEMS; index++)
+        {
+            TR_RegWr(phy_addr, TR_PATCH_TABLE[index][0], TR_PATCH_TABLE[index][1]);
+        }
+        set_gphy_reg_cl22(phy_addr, 0x1f, 0x0  );
+        set_gphy_reg_cl22(phy_addr, 0x1f, 0x3  );
+        set_gphy_reg_cl22(phy_addr, 0x1c, 0xc92);
+        set_gphy_reg_cl22(phy_addr, 0x1d, 0x01 );
+        set_gphy_reg_cl22(phy_addr, 0x1f, 0x0  );
+    }
+    gphy_eee_patch(phy_base);
+}
+
+/* LOCAL SUBPROGRAM BODIES
+ */
+void TR_RegWr(uint16_t phyadd, uint16_t tr_reg_addr, uint32_t tr_data)
+{
+    set_gphy_reg_cl22(phyadd, 0x1F, 0x52b5);       /* page select */
+    set_gphy_reg_cl22(phyadd, 0x11, (uint16_t)(tr_data & 0xffff));
+    set_gphy_reg_cl22(phyadd, 0x12, (uint16_t)(tr_data >> 16));
+    set_gphy_reg_cl22(phyadd, 0x10, (uint16_t)(tr_reg_addr | TrReg_WR));
+    set_gphy_reg_cl22(phyadd, 0x1F, 0x0);          /* page resetore */
+    return;
+}
+
+uint8_t BG_Calibration(uint8_t phyadd, int8_t calipolarity)
+{
+    int8_t rg_zcal_ctrl = 0, calibration_polarity = 0;
+    uint8_t all_ana_cal_status = 1;
+    uint16_t ad_cal_comp_out_init = 0;
+
+    /* setting */
+    set_gphy_reg_cl22(phyadd, RgAddr_Reg1Fh, CL22_Page_Reg);        // g0
+    set_gphy_reg_cl22(phyadd, RgAddr_Reg00h, AN_disable_force_1000M);  // AN disable, force 1000M
+    set_gphy_reg_cl45(phyadd, DEVID_1F, RgAddr_dev1Fh_reg100h, BG_voltage_output);// BG voltage output
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg145h, Fix_mdi);// fix mdi
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Fh_reg0FFh, 0x2);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_BG);// 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all);// 1e_dc[0]:rg_txvos_calen
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E1h, Disable_all);// 1e_e1[4]:rg_cal_refsel(0:1.2V) enable BG 1.2V to REXT PAD
+
+    /* calibrate */
+    rg_zcal_ctrl = ZCAL_MIDDLE;
+
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (uint16_t)rg_zcal_ctrl);
+
+    anacal_exe(phyadd);
+    if (all_ana_cal_status == 0)
+    {
+        all_ana_cal_status = ANACAL_ERROR;
+    }
+    ad_cal_comp_out_init = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1;
+
+
+    if (ad_cal_comp_out_init == 1)
+    {
+        calibration_polarity = -calipolarity;
+    }
+    else // ad_cal_comp_out_init == 0
+    {
+        calibration_polarity = calipolarity;
+    }
+
+    while (all_ana_cal_status < ANACAL_ERROR)
+    {
+        rg_zcal_ctrl += calibration_polarity;
+
+        set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (uint16_t)rg_zcal_ctrl);
+
+
+        anacal_exe(phyadd);
+
+        if (all_ana_cal_status == 0)
+        {
+            all_ana_cal_status = ANACAL_ERROR;
+        }
+
+        else if (((get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1) != ad_cal_comp_out_init)
+        {
+            all_ana_cal_status = ANACAL_FINISH;
+        }
+        else
+        {
+            if ((rg_zcal_ctrl == 0x3F) || (rg_zcal_ctrl == 0x00))
+            {
+                all_ana_cal_status = ANACAL_SATURATION;  // need to FT
+                rg_zcal_ctrl = ZCAL_MIDDLE;  // 0 dB
+            }
+        }
+    }
+
+    if (all_ana_cal_status == ANACAL_ERROR)
+    {
+        rg_zcal_ctrl = ZCAL_MIDDLE;  // 0 dB
+
+        set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (uint16_t)rg_zcal_ctrl);
+    }
+    else
+    {
+        // rg_zcal_ctrl[5:0] rg_rext_trim[13:8]
+        set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (uint16_t)((rg_zcal_ctrl << 8) | rg_zcal_ctrl));
+
+        // 1f_115[2:0](rg_bg_rasel) = rg_zcal_ctrl[5:3]
+        set_gphy_reg_cl45(phyadd, DEVID_1F, RgAddr_dev1Fh_reg115h, (uint16_t)((rg_zcal_ctrl & 0x3f) >> 3));
+    }
+
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all);
+    return all_ana_cal_status;
+}
+
+uint8_t R50_Calibration(uint8_t phyadd, uint8_t phyadd_common)
+{
+    int8_t rg_zcal_ctrl = 0, rg_r50ohm_rsel_tx = 0, calibration_polarity = 0;
+    uint8_t all_ana_cal_status = 1;
+    int16_t backup_dev1e_e0 = 0, ad_cal_comp_out_init = 0, calibration_pair = 0;
+
+    /* setting */
+    set_gphy_reg_cl22(phyadd, RgAddr_Reg1Fh, CL22_Page_Reg);        // g0
+    set_gphy_reg_cl22(phyadd, RgAddr_Reg00h, AN_disable_force_1000M);  // AN disable, force 1000M
+
+    set_gphy_reg_cl45(phyadd_common, DEVID_1F, RgAddr_dev1Fh_reg100h, BG_voltage_output); // BG voltage output
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg145h, Fix_mdi); // fix mdi
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg185h, Disable_tx_slew_control); // disable tx slew control
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0FBh, LDO_control); // ldo
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_R50); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all); // 1e_dc[0]:rg_txvos_calen
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0E1h, Disable_all); // 1e_e1[4]:rg_cal_refsel(0:1.2V) enable BG 1.2V to REXT PAD
+
+    for (calibration_pair = ANACAL_PAIR_A; calibration_pair <= ANACAL_PAIR_D; calibration_pair++)
+    {
+        all_ana_cal_status = 1;
+
+        if (calibration_pair == ANACAL_PAIR_A)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_R50_pairA_ENABLE); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen, [0]:rg_zcalen_a
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Zcalen_A_ENABLE);
+        }
+        else if (calibration_pair == ANACAL_PAIR_B)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_R50); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen, [0]:rg_zcalen_a
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Zcalen_B_ENABLE); // 1e_dc[12]:rg_zcalen_b
+        }
+        else if (calibration_pair == ANACAL_PAIR_C)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_R50); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen, [0]:rg_zcalen_a
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Zcalen_C_ENABLE); // 1e_dc[8]:rg_zcalen_c
+        }
+        else // if(calibration_pair == ANACAL_PAIR_D)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_R50); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen, [0]:rg_zcalen_a
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Zcalen_D_ENABLE); // 1e_dc[4]:rg_zcalen_d
+        }
+
+        /* calibrate */
+        rg_zcal_ctrl = ZCAL_MIDDLE;             // start with 0 dB
+
+        backup_dev1e_e0 = (get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0E0h)&(~0x003f));
+        set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (backup_dev1e_e0 | rg_zcal_ctrl));
+
+        anacal_exe(phyadd_common);
+        if (all_ana_cal_status == 0)
+        {
+            all_ana_cal_status = ANACAL_ERROR;
+        }
+
+        ad_cal_comp_out_init = (get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1;  // 1e_17a[8]:ad_cal_comp_out
+
+        if (ad_cal_comp_out_init == 1)
+        {
+            calibration_polarity = -1;
+        }
+        else
+        {
+            calibration_polarity = 1;
+        }
+
+        while (all_ana_cal_status < ANACAL_ERROR)
+        {
+            rg_zcal_ctrl += calibration_polarity;
+
+            set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0E0h, (backup_dev1e_e0 | rg_zcal_ctrl));
+
+            anacal_exe(phyadd_common);
+
+            if (all_ana_cal_status == 0)
+            {
+                all_ana_cal_status = ANACAL_ERROR;
+            }
+            else if (((get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1) != ad_cal_comp_out_init)
+            {
+                all_ana_cal_status = ANACAL_FINISH;
+            }
+            else
+            {
+                if ((rg_zcal_ctrl == 0x3F) || (rg_zcal_ctrl == 0x00))
+                {
+                    all_ana_cal_status = ANACAL_SATURATION;  // need to FT
+                    rg_zcal_ctrl = ZCAL_MIDDLE;  // 0 dB
+                }
+            }
+        }
+
+        if (all_ana_cal_status == ANACAL_ERROR)
+        {
+            rg_r50ohm_rsel_tx = ZCAL_MIDDLE;  // 0 dB
+        }
+        else
+        {
+            if (rg_zcal_ctrl > (0x3F - R50_OFFSET_VALUE))
+            {
+                all_ana_cal_status = ANACAL_SATURATION;  // need to FT
+                rg_zcal_ctrl = ZCAL_MIDDLE;  // 0 dB
+            }
+            else
+            {
+                rg_zcal_ctrl += R50_OFFSET_VALUE;
+            }
+
+            rg_r50ohm_rsel_tx = ZCAL_TO_R50ohm_TBL[rg_zcal_ctrl];
+        }
+
+        if (calibration_pair == ANACAL_PAIR_A)
+        {
+            // cr_r50ohm_rsel_tx_a
+            ad_cal_comp_out_init = get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg174h)&(~MASK_r50ohm_rsel_tx_a);
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg174h, (ad_cal_comp_out_init | (((rg_r50ohm_rsel_tx << 8) & MASK_MSB_8bit) | Rg_r50ohm_rsel_tx_a_en))); // 1e_174[15:8]
+        }
+        else if (calibration_pair == ANACAL_PAIR_B)
+        {
+            // cr_r50ohm_rsel_tx_b
+            ad_cal_comp_out_init = get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg174h)&(~MASK_r50ohm_rsel_tx_b);
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg174h, (ad_cal_comp_out_init | (((rg_r50ohm_rsel_tx << 0) & MASK_LSB_8bit) | Rg_r50ohm_rsel_tx_b_en))); // 1e_174[7:0]
+        }
+        else if (calibration_pair == ANACAL_PAIR_C)
+        {
+            // cr_r50ohm_rsel_tx_c
+            ad_cal_comp_out_init = get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg175h)&(~MASK_r50ohm_rsel_tx_c);
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg175h, (ad_cal_comp_out_init | (((rg_r50ohm_rsel_tx << 8) & MASK_MSB_8bit) | Rg_r50ohm_rsel_tx_c_en))); // 1e_175[15:8]
+        }
+        else // if(calibration_pair == ANACAL_PAIR_D)
+        {
+            // cr_r50ohm_rsel_tx_d
+            ad_cal_comp_out_init = get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg175h)&(~MASK_r50ohm_rsel_tx_d);
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg175h, (ad_cal_comp_out_init | (((rg_r50ohm_rsel_tx << 0) & MASK_LSB_8bit) | Rg_r50ohm_rsel_tx_d_en))); // 1e_175[7:0]
+        }
+    }
+
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all);
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all);
+
+    return all_ana_cal_status;
+}
+
+uint8_t TX_OFS_Calibration(uint8_t phyadd, uint8_t phyadd_common)
+{
+    int8_t tx_offset_index = 0, calibration_polarity = 0;
+    uint8_t all_ana_cal_status = 1, tx_offset_reg_shift = 0, tbl_idx = 0;
+    int16_t ad_cal_comp_out_init = 0, calibration_pair = 0, tx_offset_reg = 0, reg_temp = 0;
+
+    /* setting */
+    set_gphy_reg_cl22(phyadd, RgAddr_Reg1Fh, CL22_Page_Reg);        // g0
+    set_gphy_reg_cl22(phyadd, RgAddr_Reg00h, AN_disable_force_1000M);  // AN disable, force 1000M
+
+    set_gphy_reg_cl45(phyadd, DEVID_1F, RgAddr_dev1Fh_reg100h, BG_voltage_output); // BG voltage output
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg145h, Fix_mdi); // fix mdi
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg185h, Disable_tx_slew_control); // disable tx slew control
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0FBh, LDO_control); // ldo
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_TX_OFST); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Rg_txvos_calen_ENABLE); // 1e_dc[0]:rg_txvos_calen
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_TX_OFST); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Rg_txvos_calen_ENABLE); // 1e_dc[0]:rg_txvos_calen
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E1h, Disable_all); // 1e_e1[4]:rg_cal_refsel(0:1.2V) enable BG 1.2V to REXT PAD
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg096h, Bypass_tx_offset_cal); // 1e_96[15]:bypass_tx_offset_cal, Hw bypass, Fw cal
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg03Eh, Enable_Tx_VLD); // 1e_3e:enable Tx VLD
+
+    for (calibration_pair = ANACAL_PAIR_A; calibration_pair <= ANACAL_PAIR_D; calibration_pair++)
+    {
+        all_ana_cal_status = 1;
+
+        tbl_idx = TX_OFFSET_0mV_idx;
+        tx_offset_index = EN753x_TX_OFS_TBL[tbl_idx];
+
+        if (calibration_pair == ANACAL_PAIR_A)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_a_ENABLE);       // 1e_dd[12]:rg_txg_calen_a
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Dh, (Force_dasn_dac_in0_ENABLE | DAC_IN_0V));  // 1e_17d:dac_in0_a
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg181h, (Force_dasn_dac_in1_ENABLE | DAC_IN_0V));  // 1e_181:dac_in1_a
+
+            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg172h)&(~MASK_cr_tx_amp_offset_MSB));
+            tx_offset_reg_shift = 8;  // 1e_172[13:8]
+            tx_offset_reg = RgAddr_dev1Eh_reg172h;
+        }
+        else if (calibration_pair == ANACAL_PAIR_B)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_b_ENABLE);       // 1e_dd[8]:rg_txg_calen_b
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Eh, (Force_dasn_dac_in0_ENABLE | DAC_IN_0V));  // 1e_17e:dac_in0_b
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg182h, (Force_dasn_dac_in1_ENABLE | DAC_IN_0V));  // 1e_182:dac_in1_b
+
+            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg172h)&(~MASK_cr_tx_amp_offset_LSB));
+            tx_offset_reg_shift = 0;  // 1e_172[5:0]
+            tx_offset_reg = RgAddr_dev1Eh_reg172h;
+        }
+        else if (calibration_pair == ANACAL_PAIR_C)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_c_ENABLE);       // 1e_dd[4]:rg_txg_calen_c
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Fh, (Force_dasn_dac_in0_ENABLE | DAC_IN_0V));  // 1e_17f:dac_in0_c
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg183h, (Force_dasn_dac_in1_ENABLE | DAC_IN_0V));  // 1e_183:dac_in1_c
+
+            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg173h)&(~MASK_cr_tx_amp_offset_MSB));
+            tx_offset_reg_shift = 8;  // 1e_173[13:8]
+            tx_offset_reg = RgAddr_dev1Eh_reg173h;
+        }
+        else // if(calibration_pair == ANACAL_PAIR_D)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_d_ENABLE);       // 1e_dd[0]:rg_txg_calen_d
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg180h, (Force_dasn_dac_in0_ENABLE | DAC_IN_0V));  // 1e_180:dac_in0_d
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg184h, (Force_dasn_dac_in1_ENABLE | DAC_IN_0V));  // 1e_184:dac_in1_d
+
+            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg173h)&(~MASK_cr_tx_amp_offset_LSB));
+            tx_offset_reg_shift = 0;  // 1e_173[5:0]
+            tx_offset_reg = RgAddr_dev1Eh_reg173h;
+        }
+
+        /* calibrate */
+        //tx_offset_index = TX_AMP_OFFSET_0mV;
+        tbl_idx = TX_OFFSET_0mV_idx;
+        tx_offset_index = EN753x_TX_OFS_TBL[tbl_idx];
+        set_gphy_reg_cl45(phyadd, DEVID_1E, tx_offset_reg, (reg_temp | (tx_offset_index << tx_offset_reg_shift)));  // 1e_172, 1e_173
+
+        anacal_exe(phyadd_common);
+        if (all_ana_cal_status == 0)
+        {
+            all_ana_cal_status = ANACAL_ERROR;
+        }
+
+        ad_cal_comp_out_init = (get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1;  // 1e_17a[8]:ad_cal_comp_out
+
+        if (ad_cal_comp_out_init == 1)
+        {
+            calibration_polarity = -1;
+        }
+        else
+        {
+            calibration_polarity = 1;
+        }
+
+        while (all_ana_cal_status < ANACAL_ERROR)
+        {
+            tbl_idx += calibration_polarity;
+            tx_offset_index = EN753x_TX_OFS_TBL[tbl_idx];
+
+            set_gphy_reg_cl45(phyadd, DEVID_1E, tx_offset_reg, (reg_temp | (tx_offset_index << tx_offset_reg_shift)));  // 1e_172, 1e_173
+
+            anacal_exe(phyadd_common);
+
+            if (all_ana_cal_status == 0)
+            {
+                all_ana_cal_status = ANACAL_ERROR;
+            }
+            else if (((get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1) != ad_cal_comp_out_init)
+            {
+                all_ana_cal_status = ANACAL_FINISH;
+            }
+            else
+            {
+                if ((tx_offset_index == 0x3f) || (tx_offset_index == 0x1f))
+                {
+                    all_ana_cal_status = ANACAL_SATURATION;  // need to FT
+                }
+            }
+        }
+
+        if (all_ana_cal_status == ANACAL_ERROR)
+        {
+            tbl_idx = TX_OFFSET_0mV_idx;
+            tx_offset_index = EN753x_TX_OFS_TBL[tbl_idx];
+
+            set_gphy_reg_cl45(phyadd, DEVID_1E, tx_offset_reg, (reg_temp | (tx_offset_index << tx_offset_reg_shift)));  // cr_tx_amp_offset_a/b/c/d, 1e_172, 1e_173
+        }
+    }
+
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Dh, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Eh, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Fh, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg180h, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg181h, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg182h, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg183h, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg184h, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all); // disable analog calibration circuit
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all); // disable Tx offset calibration circuit
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all); // disable analog calibration circuit
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all); // disable Tx offset calibration circuit
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg03Eh, Disable_all); // disable Tx VLD force mode
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Disable_all); // disable Tx offset/amplitude calibration circuit
+
+    return all_ana_cal_status;
+}
+
+uint8_t TX_AMP_Calibration(uint8_t phyadd, uint8_t phyadd_common)
+{
+    int8_t tx_amp_index = 0, calibration_polarity = 0;
+    uint8_t all_ana_cal_status = 1, tx_amp_reg_shift = 0;
+    uint8_t tx_amp_reg = 0, tx_amp_reg_100 = 0, tst_offset = 0, hbt_offset = 0, gbe_offset = 0, tbt_offset = 0;
+    uint16_t ad_cal_comp_out_init = 0, calibration_pair = 0, reg_temp = 0;
+
+  //phyadd_common = phyadd;
+
+    /* setting */
+    set_gphy_reg_cl22(phyadd, RgAddr_Reg1Fh, CL22_Page_Reg);        // g0
+    set_gphy_reg_cl22(phyadd, RgAddr_Reg00h, AN_disable_force_1000M);  // AN disable, force 1000M
+
+    set_gphy_reg_cl45(phyadd, DEVID_1F, RgAddr_dev1Fh_reg100h, BG_voltage_output); // BG voltage output
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg145h, Fix_mdi); // fix mdi
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg185h, Disable_tx_slew_control); // disable tx slew control
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0FBh, LDO_control); // ldo
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_TX_AMP); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Rg_txvos_calen_ENABLE); // 1e_dc[0]:rg_txvos_calen
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0E1h, Rg_cal_refsel_ENABLE); // 1e_e1[4]:rg_cal_refsel(0:1.2V) enable BG 1.2V to REXT PAD
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Cal_control_TX_AMP); // 1e_db[12]:rg_cal_ckinv, [8]:rg_ana_calen, [4]:rg_rext_calen
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Rg_txvos_calen_ENABLE); // 1e_dc[0]:rg_txvos_calen
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg0E1h, Rg_cal_refsel_ENABLE); // 1e_e1[4]:rg_cal_refsel(0:1.2V) enable BG 1.2V to REXT PAD
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg096h, Bypass_tx_offset_cal); // 1e_96[15]:bypass_tx_offset_cal, Hw bypass, Fw cal
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg03Eh, Enable_Tx_VLD); // 1e_3e:enable Tx VLD
+
+    for (calibration_pair = ANACAL_PAIR_A; calibration_pair <= ANACAL_PAIR_D; calibration_pair++)
+    //for (calibration_pair = ANACAL_PAIR_A; calibration_pair <= ANACAL_PAIR_B; calibration_pair++) // debugging
+    {
+        all_ana_cal_status = 1;
+
+        /* calibrate */
+        tx_amp_index = TX_AMP_MIDDLE;   // start with 0 dB
+        if (calibration_pair == ANACAL_PAIR_A)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_a_ENABLE);       // 1e_dd[12]:rg_txg_calen_a amp calibration enable
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Dh, (Force_dasn_dac_in0_ENABLE | DAC_IN_2V));  // 1e_17d:dac_in0_a
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg181h, (Force_dasn_dac_in1_ENABLE | DAC_IN_2V));  // 1e_181:dac_in1_a
+
+            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg012h)&(~MASK_da_tx_i2mpb_a_gbe));
+            tx_amp_reg_shift = 10;  // 1e_12[15:10]
+            tx_amp_reg = RgAddr_dev1Eh_reg012h;
+            tx_amp_reg_100 = 0x16;
+        }
+        else if (calibration_pair == ANACAL_PAIR_B)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_b_ENABLE);       // 1e_dd[8]:rg_txg_calen_b amp calibration enable
+            //Serial.println(Rg_txg_calen_b_ENABLE, HEX);
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Eh, (Force_dasn_dac_in0_ENABLE | DAC_IN_2V));  // 1e_17e:dac_in0_b
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg182h, (Force_dasn_dac_in1_ENABLE | DAC_IN_2V));  // 1e_182:dac_in1_b
+
+            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg017h)&(~MASK_da_tx_i2mpb_b_c_d_gbe));
+            tx_amp_reg_shift = 8; // 1e_17[13:8]
+            tx_amp_reg = RgAddr_dev1Eh_reg017h;
+            tx_amp_reg_100 = 0x18;
+        }
+        else if (calibration_pair == ANACAL_PAIR_C)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_c_ENABLE);       // 1e_dd[4]:rg_txg_calen_c amp calibration enable
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Fh, (Force_dasn_dac_in0_ENABLE | DAC_IN_2V));  // 1e_17f:dac_in0_c
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg183h, (Force_dasn_dac_in1_ENABLE | DAC_IN_2V));  // 1e_183:dac_in1_c
+
+            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg019h)&(~MASK_da_tx_i2mpb_b_c_d_gbe));
+            tx_amp_reg_shift = 8; // 1e_19[13:8]
+            tx_amp_reg = RgAddr_dev1Eh_reg019h;
+            tx_amp_reg_100 = 0x20;
+        }
+        else //if(calibration_pair == ANACAL_PAIR_D)
+        {
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Rg_txg_calen_d_ENABLE);       // 1e_dd[0]:rg_txg_calen_d amp calibration enable
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg180h, (Force_dasn_dac_in0_ENABLE | DAC_IN_2V));  // 1e_180:dac_in0_d
+            set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg184h, (Force_dasn_dac_in1_ENABLE | DAC_IN_2V));  // 1e_184:dac_in1_d
+
+            reg_temp = (get_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg021h)&(~MASK_da_tx_i2mpb_b_c_d_gbe));
+            tx_amp_reg_shift = 8; // 1e_21[13:8]
+            tx_amp_reg = RgAddr_dev1Eh_reg021h;
+            tx_amp_reg_100 = 0x22;
+        }
+
+        /* calibrate */
+        tx_amp_index = TX_AMP_MIDDLE; // start with 0 dB
+
+        set_gphy_reg_cl45(phyadd, DEVID_1E, tx_amp_reg, (reg_temp | (tx_amp_index << tx_amp_reg_shift))); // 1e_12/17/19/21
+
+        anacal_exe(phyadd_common);
+        if (all_ana_cal_status == 0)
+        {
+            all_ana_cal_status = ANACAL_ERROR;
+        }
+
+
+        ad_cal_comp_out_init = (get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1;    // 1e_17a[8]:ad_cal_comp_out
+        //Serial.println(ad_cal_comp_out_init, HEX);
+
+        if (ad_cal_comp_out_init == 1)
+        {
+            calibration_polarity = -1;
+        }
+        else
+        {
+            calibration_polarity = 1;
+        }
+        while (all_ana_cal_status < ANACAL_ERROR)
+        {
+            tx_amp_index += calibration_polarity;
+            //Serial.println(tx_amp_index, HEX);
+
+            set_gphy_reg_cl45(phyadd, DEVID_1E, tx_amp_reg, (reg_temp | (tx_amp_index << tx_amp_reg_shift)));
+
+            anacal_exe(phyadd_common);
+
+            if (all_ana_cal_status == 0)
+            {
+                all_ana_cal_status = ANACAL_ERROR;
+            }
+            else if (((get_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ah) >> 8) & 0x1) != ad_cal_comp_out_init)
+            {
+                all_ana_cal_status = ANACAL_FINISH;
+                //Serial.print("    tx_amp_index: ");
+                //Serial.println(tx_amp_index, HEX);
+                //reg_temp = get_gphy_reg_cl45(phyadd, 0x1e, tx_amp_reg)&(~0xff00);
+                //set_gphy_reg_cl45(phyadd, 0x1e, tx_amp_reg, (reg_temp|((tx_amp_index + tst_offset)<<tx_amp_reg_shift)));  // for gbe(DAC)
+            }
+            else
+            {
+                if ((tx_amp_index == 0x3f) || (tx_amp_index == 0x00))
+                {
+                    all_ana_cal_status = ANACAL_SATURATION;  // need to FT
+                    tx_amp_index = TX_AMP_MIDDLE;
+                }
+            }
+        }
+
+        if (all_ana_cal_status == ANACAL_ERROR)
+        {
+            tx_amp_index = TX_AMP_MIDDLE;
+        }
+
+        // da_tx_i2mpb_a_gbe / b/c/d, only GBE for now
+        set_gphy_reg_cl45(phyadd, DEVID_1E, tx_amp_reg, ((tx_amp_index - TXAMP_offset) | ((tx_amp_index - TXAMP_offset) << tx_amp_reg_shift)));  // // temp modify
+        set_gphy_reg_cl45(phyadd, DEVID_1E, tx_amp_reg_100, ((tx_amp_index - TXAMP_offset) | ((tx_amp_index + TX_i2mpb_hbt_ofs) << tx_amp_reg_shift)));
+    }
+
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Dh, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Eh, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg17Fh, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg180h, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg181h, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg182h, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg183h, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg184h, Disable_all);
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DBh, Disable_all); // disable analog calibration circuit
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DCh, Disable_all); // disable Tx offset calibration circuit
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg03Eh, Disable_all); // disable Tx VLD force mode
+    set_gphy_reg_cl45(phyadd, DEVID_1E, RgAddr_dev1Eh_reg0DDh, Disable_all); // disable Tx offset/amplitude calibration circuit
+
+    return all_ana_cal_status;
+}
+
+void set_gphy_reg_cl22(uint8_t phyad, uint8_t reg, uint16_t value)
+{
+    an8855_phy_write(phyad-g_smi_addr, reg, value);
+    /*
+       gsw_top_reg_REG_PHY_IAC REG_PHY_IAC_val;
+       gsw_top_reg_REG_PHY_IAD REG_PHY_IAD_val;
+
+    // Wait until done
+    do
+    {
+    REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);
+    }
+    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);
+
+    // Set address
+    REG_PHY_IAC_val.Bits.csr_mdio_st = 1;
+    REG_PHY_IAC_val.Bits.csr_mdio_cmd = 1;
+    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = phyad;
+    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = reg;
+    REG_PHY_IAC_val.Bits.csr_mdio_wr_data = value;
+    REG_PHY_IAC_val.Bits.csr_phy_acs_st = 1;
+
+    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);
+    */
+}
+
+UINT16 get_gphy_reg_cl45(uint8_t prtid, uint8_t devid, uint16_t reg)
+{
+    UINT32 rdata = 0;
+
+    an8855_phy_read_cl45(prtid-g_smi_addr, devid, reg, &rdata);
+    return ((UINT16)rdata);
+    /*
+    gsw_top_reg_REG_PHY_IAC REG_PHY_IAC_val;
+    gsw_top_reg_REG_PHY_IAD REG_PHY_IAD_val;
+
+    // Wait until done
+    do
+    {
+    REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);
+    }
+    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);
+
+    // Set address
+    REG_PHY_IAC_val.Bits.csr_mdio_st = 0;
+    REG_PHY_IAC_val.Bits.csr_mdio_cmd = 0;
+    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = prtid;
+    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = devid;
+    REG_PHY_IAC_val.Bits.csr_mdio_wr_data = reg;
+    REG_PHY_IAC_val.Bits.csr_phy_acs_st = 1;
+
+    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);
+
+    // Wait until done
+    do
+    {
+    REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);
+    }
+    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);
+
+    // Read value
+    REG_PHY_IAC_val.Bits.csr_mdio_st = 0;
+    REG_PHY_IAC_val.Bits.csr_mdio_cmd = 3;
+    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = prtid;
+    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = devid;
+    REG_PHY_IAC_val.Bits.csr_mdio_wr_data = 0;
+    REG_PHY_IAC_val.Bits.csr_phy_acs_st = 1;
+    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);
+
+    // Wait until done
+    do
+    {
+    REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);
+    }
+    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);
+
+    REG_PHY_IAD_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAD);
+
+    return REG_PHY_IAD_val.Raw;
+    */
+}
+
+void set_gphy_reg_cl45(uint8_t prtid, uint8_t devid, uint16_t reg, uint16_t value)
+{
+    an8855_phy_write_cl45(prtid-g_smi_addr, devid, reg, value);
+    /*
+    gsw_top_reg_REG_PHY_IAC REG_PHY_IAC_val;
+
+    // Wait until done
+    do
+    {
+        REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);
+    }
+    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);
+
+    // Set address
+    REG_PHY_IAC_val.Bits.csr_mdio_st = 0;
+    REG_PHY_IAC_val.Bits.csr_mdio_cmd = 0;
+    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = prtid;
+    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = devid;
+    REG_PHY_IAC_val.Bits.csr_mdio_wr_data = reg;
+    REG_PHY_IAC_val.Bits.csr_phy_acs_st = 1;
+
+    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);
+
+    // Wait until done
+    do
+    {
+        REG_PHY_IAC_val.Raw = io_read32(RgAddr_gsw_top_reg_REG_PHY_IAC);
+    }
+    while(REG_PHY_IAC_val.Bits.csr_phy_acs_st);
+
+    // Write value
+    REG_PHY_IAC_val.Bits.csr_mdio_st = 0;
+    REG_PHY_IAC_val.Bits.csr_mdio_cmd = 1;
+    REG_PHY_IAC_val.Bits.csr_mdio_phy_addr = prtid;
+    REG_PHY_IAC_val.Bits.csr_mdio_reg_addr = devid;
+    REG_PHY_IAC_val.Bits.csr_mdio_wr_data = value;
+    REG_PHY_IAC_val.Bits.csr_phy_acs_st = 1;
+
+    io_write32(RgAddr_gsw_top_reg_REG_PHY_IAC, REG_PHY_IAC_val.Raw);
+    */
+}
+
+void anacal_exe(uint8_t phyadd_common)
+{
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ch, 1);// da_calin_flag pull high
+    an8855_udelay(1000);
+    set_gphy_reg_cl45(phyadd_common, DEVID_1E, RgAddr_dev1Eh_reg17Ch, 0);// da_calin_flag pull low
+}
+
diff --git a/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_reg.h b/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_reg.h
index 3459cef..b444697 100644
--- a/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_reg.h
+++ b/recipes-devtools/switch/files/src/an8855_sdk/core/an8855_reg.h
@@ -1,191 +1,191 @@
-    /* FILE NAME:  an8855_reg.h

- * PURPOSE:

- *      It provides AN8855 register definition.

- * NOTES:

- *

- */

-

-#ifndef AN8855_REG_H

-#define AN8855_REG_H

-

-#define PORT_CTRL_BASE                      0x10208000

-#define PORT_CTRL_PORT_OFFSET               0x200

-#define PORT_CTRL_REG(p, r)                 (PORT_CTRL_BASE + (p) * PORT_CTRL_PORT_OFFSET + (r))

-#define PCR(p)                              PORT_CTRL_REG(p, 0x04)

-

-#define PORT_MAC_CTRL_BASE                  0x10210000

-#define PORT_MAC_CTRL_PORT_OFFSET           0x200

-#define PORT_MAC_CTRL_REG(p, r)             (PORT_MAC_CTRL_BASE + (p) * PORT_MAC_CTRL_PORT_OFFSET + (r))

-#define PMCR(p)                             PORT_MAC_CTRL_REG(p, 0x00)

-

-/* Port debug count register */

-#define DBG_CNT_BASE                        0x3018

-#define DBG_CNT_PORT_BASE                   0x100

-#define DBG_CNT(p)                          (DBG_CNT_BASE + (p) * DBG_CNT_PORT_BASE)

-#define DIS_CLR                             (1 << 31)

-

-#define GMACCR                              (PORT_MAC_CTRL_BASE + 0x30e0)

-#define MTCC_LMT_S                          8

-#define MAX_RX_JUMBO_S                      4

-

-/* Values of MAX_RX_PKT_LEN */

-#define RX_PKT_LEN_1518                     0

-#define RX_PKT_LEN_1536                     1

-#define RX_PKT_LEN_1522                     2

-#define RX_PKT_LEN_MAX_JUMBO                3

-

-/* Fields of PMCR */

-#define FORCE_MODE                          (1 << 31)

-#define IPG_CFG_S                           20

-#define IPG_CFG_M                           0x300000

-#define EXT_PHY                             (1 << 19)

-#define MAC_MODE                            (1 << 18)

-#define MAC_TX_EN                           (1 << 16)

-#define MAC_RX_EN                           (1 << 15)

-#define MAC_PRE                             (1 << 14)

-#define BKOFF_EN                            (1 << 12)

-#define BACKPR_EN                           (1 << 11)

-#define FORCE_EEE1G                         (1 << 7)

-#define FORCE_EEE100                        (1 << 6)

-#define FORCE_RX_FC                         (1 << 5)

-#define FORCE_TX_FC                         (1 << 4)

-#define FORCE_SPD_S                         28

-#define FORCE_SPD_M                         0x70000000

-#define FORCE_DPX                           (1 << 25)

-#define FORCE_LINK                          (1 << 24)

-

-/* Fields of PMSR */

-#define EEE1G_STS                           (1 << 7)

-#define EEE100_STS                          (1 << 6)

-#define RX_FC_STS                           (1 << 5)

-#define TX_FC_STS                           (1 << 4)

-#define MAC_SPD_STS_S                       28

-#define MAC_SPD_STS_M                       0x70000000

-#define MAC_DPX_STS                         (1 << 25)

-#define MAC_LNK_STS                         (1 << 24)

-

-/* Values of MAC_SPD_STS */

-#define MAC_SPD_10                          0

-#define MAC_SPD_100                         1

-#define MAC_SPD_1000                        2

-#define MAC_SPD_2500                        3

-

-/* Values of IPG_CFG */

-#define IPG_96BIT                           0

-#define IPG_96BIT_WITH_SHORT_IPG            1

-#define IPG_64BIT                           2

-

-#define SGMII_REG_BASE                      0x5000

-#define SGMII_REG_PORT_BASE                 0x1000

-#define SGMII_REG(p, r)                     (SGMII_REG_BASE + (p) * SGMII_REG_PORT_BASE + (r))

-#define PCS_CONTROL_1(p)                    SGMII_REG(p, 0x00)

-#define SGMII_MODE(p)                       SGMII_REG(p, 0x20)

-#define QPHY_PWR_STATE_CTRL(p)              SGMII_REG(p, 0xe8)

-#define PHYA_CTRL_SIGNAL3(p)                SGMII_REG(p, 0x128)

-

-/* Fields of PCS_CONTROL_1 */

-#define SGMII_LINK_STATUS                   (1 << 18)

-#define SGMII_AN_ENABLE                     (1 << 12)

-#define SGMII_AN_RESTART                    (1 << 9)

-

-/* Fields of SGMII_MODE */

-#define SGMII_REMOTE_FAULT_DIS              (1 << 8)

-#define SGMII_IF_MODE_FORCE_DUPLEX          (1 << 4)

-#define SGMII_IF_MODE_FORCE_SPEED_S         0x2

-#define SGMII_IF_MODE_FORCE_SPEED_M         0x0c

-#define SGMII_IF_MODE_ADVERT_AN             (1 << 1)

-

-/* Values of SGMII_IF_MODE_FORCE_SPEED */

-#define SGMII_IF_MODE_FORCE_SPEED_10        0

-#define SGMII_IF_MODE_FORCE_SPEED_100       1

-#define SGMII_IF_MODE_FORCE_SPEED_1000      2

-

-/* Fields of QPHY_PWR_STATE_CTRL */

-#define PHYA_PWD                            (1 << 4)

-

-/* Fields of PHYA_CTRL_SIGNAL3 */

-#define RG_TPHY_SPEED_S                     2

-#define RG_TPHY_SPEED_M                     0x0c

-

-/* Values of RG_TPHY_SPEED */

-#define RG_TPHY_SPEED_1000                  0

-#define RG_TPHY_SPEED_2500                  1

-

-#define SYS_CTRL                            0x7000

-#define SW_PHY_RST                          (1 << 2)

-#define SW_SYS_RST                          (1 << 1)

-#define SW_REG_RST                          (1 << 0)

-

-#define PHY_IAC                             (0x1000e000)

-#define IAC_MAX_BUSY_TIME                   (1000)

-

-#define CLKGEN_CTRL                         0x7500

-#define CLK_SKEW_OUT_S                      8

-#define CLK_SKEW_OUT_M                      0x300

-#define CLK_SKEW_IN_S                       6

-#define CLK_SKEW_IN_M                       0xc0

-#define RXCLK_NO_DELAY                      (1 << 5)

-#define TXCLK_NO_REVERSE                    (1 << 4)

-#define GP_MODE_S                           1

-#define GP_MODE_M                           0x06

-#define GP_CLK_EN                           (1 << 0)

-

-/* Values of GP_MODE */

-#define GP_MODE_RGMII                       0

-#define GP_MODE_MII                         1

-#define GP_MODE_REV_MII                     2

-

-/* Values of CLK_SKEW_IN */

-#define CLK_SKEW_IN_NO_CHANGE               0

-#define CLK_SKEW_IN_DELAY_100PPS            1

-#define CLK_SKEW_IN_DELAY_200PPS            2

-#define CLK_SKEW_IN_REVERSE                 3

-

-/* Values of CLK_SKEW_OUT */

-#define CLK_SKEW_OUT_NO_CHANGE              0

-#define CLK_SKEW_OUT_DELAY_100PPS           1

-#define CLK_SKEW_OUT_DELAY_200PPS           2

-#define CLK_SKEW_OUT_REVERSE                3

-

-#define HWSTRAP                             0x7800

-#define XTAL_FSEL_S                         7

-#define XTAL_FSEL_M                         (1 << 7)

-

-#define XTAL_40MHZ                          0

-#define XTAL_25MHZ                          1

-

-#define PLLGP_EN                            0x7820

-#define EN_COREPLL                          (1 << 2)

-#define SW_CLKSW                            (1 << 1)

-#define SW_PLLGP                            (1 << 0)

-

-#define PLLGP_CR0                           0x78a8

-#define RG_COREPLL_EN                       (1 << 22)

-#define RG_COREPLL_POSDIV_S                 23

-#define RG_COREPLL_POSDIV_M                 0x3800000

-#define RG_COREPLL_SDM_PCW_S                1

-#define RG_COREPLL_SDM_PCW_M                0x3ffffe

-#define RG_COREPLL_SDM_PCW_CHG              (1 << 0)

-

-#define MHWSTRAP                            0x7804

-#define TOP_SIG_SR                          0x780c

-#define PAD_DUAL_SGMII_EN                   (1 << 1)

-

-/* RGMII and SGMII PLL clock */

-#define ANA_PLLGP_CR2                       0x78b0

-#define ANA_PLLGP_CR5                       0x78bc

-

-/* Efuse Register Define */

-#define GBE_EFUSE                           0x7bc8

-#define GBE_SEL_EFUSE_EN                    (1 << 0)

-

-/* GPIO_PAD_0 */

-#define GPIO_MODE0                          0x7c0c

-#define GPIO_MODE0_S                        0

-#define GPIO_MODE0_M                        0xf

-#define GPIO_0_INTERRUPT_MODE               0x1

-

-#define SMT0_IOLB                           0x7f04

-#define SMT_IOLB_5_SMI_MDC_EN               (1 << 5)

-

-#endif  /* End of AN8855_REG_H */

+    /* FILE NAME:  an8855_reg.h
+ * PURPOSE:
+ *      It provides AN8855 register definition.
+ * NOTES:
+ *
+ */
+
+#ifndef AN8855_REG_H
+#define AN8855_REG_H
+
+#define PORT_CTRL_BASE                      0x10208000
+#define PORT_CTRL_PORT_OFFSET               0x200
+#define PORT_CTRL_REG(p, r)                 (PORT_CTRL_BASE + (p) * PORT_CTRL_PORT_OFFSET + (r))
+#define PCR(p)                              PORT_CTRL_REG(p, 0x04)
+
+#define PORT_MAC_CTRL_BASE                  0x10210000
+#define PORT_MAC_CTRL_PORT_OFFSET           0x200
+#define PORT_MAC_CTRL_REG(p, r)             (PORT_MAC_CTRL_BASE + (p) * PORT_MAC_CTRL_PORT_OFFSET + (r))
+#define PMCR(p)                             PORT_MAC_CTRL_REG(p, 0x00)
+
+/* Port debug count register */
+#define DBG_CNT_BASE                        0x3018
+#define DBG_CNT_PORT_BASE                   0x100
+#define DBG_CNT(p)                          (DBG_CNT_BASE + (p) * DBG_CNT_PORT_BASE)
+#define DIS_CLR                             (1 << 31)
+
+#define GMACCR                              (PORT_MAC_CTRL_BASE + 0x30e0)
+#define MTCC_LMT_S                          8
+#define MAX_RX_JUMBO_S                      4
+
+/* Values of MAX_RX_PKT_LEN */
+#define RX_PKT_LEN_1518                     0
+#define RX_PKT_LEN_1536                     1
+#define RX_PKT_LEN_1522                     2
+#define RX_PKT_LEN_MAX_JUMBO                3
+
+/* Fields of PMCR */
+#define FORCE_MODE                          (1 << 31)
+#define IPG_CFG_S                           20
+#define IPG_CFG_M                           0x300000
+#define EXT_PHY                             (1 << 19)
+#define MAC_MODE                            (1 << 18)
+#define MAC_TX_EN                           (1 << 16)
+#define MAC_RX_EN                           (1 << 15)
+#define MAC_PRE                             (1 << 14)
+#define BKOFF_EN                            (1 << 12)
+#define BACKPR_EN                           (1 << 11)
+#define FORCE_EEE1G                         (1 << 7)
+#define FORCE_EEE100                        (1 << 6)
+#define FORCE_RX_FC                         (1 << 5)
+#define FORCE_TX_FC                         (1 << 4)
+#define FORCE_SPD_S                         28
+#define FORCE_SPD_M                         0x70000000
+#define FORCE_DPX                           (1 << 25)
+#define FORCE_LINK                          (1 << 24)
+
+/* Fields of PMSR */
+#define EEE1G_STS                           (1 << 7)
+#define EEE100_STS                          (1 << 6)
+#define RX_FC_STS                           (1 << 5)
+#define TX_FC_STS                           (1 << 4)
+#define MAC_SPD_STS_S                       28
+#define MAC_SPD_STS_M                       0x70000000
+#define MAC_DPX_STS                         (1 << 25)
+#define MAC_LNK_STS                         (1 << 24)
+
+/* Values of MAC_SPD_STS */
+#define MAC_SPD_10                          0
+#define MAC_SPD_100                         1
+#define MAC_SPD_1000                        2
+#define MAC_SPD_2500                        3
+
+/* Values of IPG_CFG */
+#define IPG_96BIT                           0
+#define IPG_96BIT_WITH_SHORT_IPG            1
+#define IPG_64BIT                           2
+
+#define SGMII_REG_BASE                      0x5000
+#define SGMII_REG_PORT_BASE                 0x1000
+#define SGMII_REG(p, r)                     (SGMII_REG_BASE + (p) * SGMII_REG_PORT_BASE + (r))
+#define PCS_CONTROL_1(p)                    SGMII_REG(p, 0x00)
+#define SGMII_MODE(p)                       SGMII_REG(p, 0x20)
+#define QPHY_PWR_STATE_CTRL(p)              SGMII_REG(p, 0xe8)
+#define PHYA_CTRL_SIGNAL3(p)                SGMII_REG(p, 0x128)
+
+/* Fields of PCS_CONTROL_1 */
+#define SGMII_LINK_STATUS                   (1 << 18)
+#define SGMII_AN_ENABLE                     (1 << 12)
+#define SGMII_AN_RESTART                    (1 << 9)
+
+/* Fields of SGMII_MODE */
+#define SGMII_REMOTE_FAULT_DIS              (1 << 8)
+#define SGMII_IF_MODE_FORCE_DUPLEX          (1 << 4)
+#define SGMII_IF_MODE_FORCE_SPEED_S         0x2
+#define SGMII_IF_MODE_FORCE_SPEED_M         0x0c
+#define SGMII_IF_MODE_ADVERT_AN             (1 << 1)
+
+/* Values of SGMII_IF_MODE_FORCE_SPEED */
+#define SGMII_IF_MODE_FORCE_SPEED_10        0
+#define SGMII_IF_MODE_FORCE_SPEED_100       1
+#define SGMII_IF_MODE_FORCE_SPEED_1000      2
+
+/* Fields of QPHY_PWR_STATE_CTRL */
+#define PHYA_PWD                            (1 << 4)
+
+/* Fields of PHYA_CTRL_SIGNAL3 */
+#define RG_TPHY_SPEED_S                     2
+#define RG_TPHY_SPEED_M                     0x0c
+
+/* Values of RG_TPHY_SPEED */
+#define RG_TPHY_SPEED_1000                  0
+#define RG_TPHY_SPEED_2500                  1
+
+#define SYS_CTRL                            0x7000
+#define SW_PHY_RST                          (1 << 2)
+#define SW_SYS_RST                          (1 << 1)
+#define SW_REG_RST                          (1 << 0)
+
+#define PHY_IAC                             (0x1000e000)
+#define IAC_MAX_BUSY_TIME                   (1000)
+
+#define CLKGEN_CTRL                         0x7500
+#define CLK_SKEW_OUT_S                      8
+#define CLK_SKEW_OUT_M                      0x300
+#define CLK_SKEW_IN_S                       6
+#define CLK_SKEW_IN_M                       0xc0
+#define RXCLK_NO_DELAY                      (1 << 5)
+#define TXCLK_NO_REVERSE                    (1 << 4)
+#define GP_MODE_S                           1
+#define GP_MODE_M                           0x06
+#define GP_CLK_EN                           (1 << 0)
+
+/* Values of GP_MODE */
+#define GP_MODE_RGMII                       0
+#define GP_MODE_MII                         1
+#define GP_MODE_REV_MII                     2
+
+/* Values of CLK_SKEW_IN */
+#define CLK_SKEW_IN_NO_CHANGE               0
+#define CLK_SKEW_IN_DELAY_100PPS            1
+#define CLK_SKEW_IN_DELAY_200PPS            2
+#define CLK_SKEW_IN_REVERSE                 3
+
+/* Values of CLK_SKEW_OUT */
+#define CLK_SKEW_OUT_NO_CHANGE              0
+#define CLK_SKEW_OUT_DELAY_100PPS           1
+#define CLK_SKEW_OUT_DELAY_200PPS           2
+#define CLK_SKEW_OUT_REVERSE                3
+
+#define HWSTRAP                             0x7800
+#define XTAL_FSEL_S                         7
+#define XTAL_FSEL_M                         (1 << 7)
+
+#define XTAL_40MHZ                          0
+#define XTAL_25MHZ                          1
+
+#define PLLGP_EN                            0x7820
+#define EN_COREPLL                          (1 << 2)
+#define SW_CLKSW                            (1 << 1)
+#define SW_PLLGP                            (1 << 0)
+
+#define PLLGP_CR0                           0x78a8
+#define RG_COREPLL_EN                       (1 << 22)
+#define RG_COREPLL_POSDIV_S                 23
+#define RG_COREPLL_POSDIV_M                 0x3800000
+#define RG_COREPLL_SDM_PCW_S                1
+#define RG_COREPLL_SDM_PCW_M                0x3ffffe
+#define RG_COREPLL_SDM_PCW_CHG              (1 << 0)
+
+#define MHWSTRAP                            0x7804
+#define TOP_SIG_SR                          0x780c
+#define PAD_DUAL_SGMII_EN                   (1 << 1)
+
+/* RGMII and SGMII PLL clock */
+#define ANA_PLLGP_CR2                       0x78b0
+#define ANA_PLLGP_CR5                       0x78bc
+
+/* Efuse Register Define */
+#define GBE_EFUSE                           0x7bc8
+#define GBE_SEL_EFUSE_EN                    (1 << 0)
+
+/* GPIO_PAD_0 */
+#define GPIO_MODE0                          0x7c0c
+#define GPIO_MODE0_S                        0
+#define GPIO_MODE0_M                        0xf
+#define GPIO_0_INTERRUPT_MODE               0x1
+
+#define SMT0_IOLB                           0x7f04
+#define SMT_IOLB_5_SMI_MDC_EN               (1 << 5)
+
+#endif  /* End of AN8855_REG_H */
diff --git a/recipes-devtools/switch/files/src/switch_753x.c b/recipes-devtools/switch/files/src/switch_753x.c
index 6936f6a..03e9778 100644
--- a/recipes-devtools/switch/files/src/switch_753x.c
+++ b/recipes-devtools/switch/files/src/switch_753x.c
@@ -8,17 +8,19 @@
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <linux/if.h>
+#include <errno.h>
 
 #include "switch_netlink.h"
 #include "switch_ioctl.h"
 #include "switch_fun.h"
 #include "switch_fun_an8855.h"
 
-#define SWITCH_APP_VERSION "1.0.1"
+#define SWITCH_APP_VERSION "1.0.7"
 
 struct mt753x_attr *attres;
 int chip_name;
 bool nl_init_flag;
+bool air_skip_check_flag;
 struct switch_func_s *p_switch_func;
 
 static void usage(char *cmd)
@@ -427,27 +429,39 @@
 {
 	unsigned int val;
 	unsigned int off;
+	char *endptr;
 	int i, j;
 
 	if (!strncmp(argv[len - 3], "reg", 4)) {
 		if (argv[len - 2][0] == 'r') {
-			off = strtoul(argv[len - 1], NULL, 16);
+			errno = 0;
+			off = strtoul(argv[len - 1], &endptr, 16);
+			if (errno != 0 || *endptr != '\0')
+				goto error;
 			reg_read(off, &val);
 			printf(" Read reg=%x, value=%x\n", off, val);
 		} else if (argv[len - 2][0] == 'w') {
-			off = strtoul(argv[len - 1], NULL, 16);
+			errno = 0;
+			off = strtoul(argv[len - 1], &endptr, 16);
+			if (errno != 0 || *endptr != '\0')
+				goto error;
 			if (argc != len + 1)
 				usage(argv[0]);
-			val = strtoul(argv[len], NULL, 16);
+			errno = 0;
+			val = strtoul(argv[len], &endptr, 16);
+			if (errno != 0 || *endptr != '\0')
+				goto error;
 			reg_write(off, val);
 			printf(" Write reg=%x, value=%x\n", off, val);
 		} else if (argv[len - 2][0] == 'd') {
-			off = strtoul(argv[len - 1], NULL, 16);
+			errno = 0;
+			off = strtoul(argv[len - 1], &endptr, 16);
+			if (errno != 0 || *endptr != '\0')
+				goto error;
 			for (i = 0; i < 16; i++) {
 				printf("0x%08x: ", off + 0x10 * i);
 				for (j = 0; j < 4; j++) {
-					reg_read(off + i * 0x10 + j * 0x4,
-						 &val);
+					reg_read(off + i * 0x10 + j * 0x4, &val);
 					printf(" 0x%08x", val);
 				}
 				printf("\n");
@@ -456,6 +470,9 @@
 			usage(argv[0]);
 	} else
 		usage(argv[0]);
+	return;
+error:
+	printf("Error: string converting\n");
 }
 
 static int get_chip_name()
@@ -464,6 +481,12 @@
 	FILE *fp = NULL;
 	char buff[255];
 
+	/*judge an8855, must be placed before reg_read*/
+	if (air_skip_check_flag) {
+		temp = 0x8855;
+		return temp;
+	}
+
 	/*judge jaguar embedded switch */
 	fp = fopen("/proc/device-tree/compatible", "r");
 	if (fp != NULL) {
@@ -488,11 +511,6 @@
 	if (temp == 0x7531)
 		return temp;
 
-	/*judge an8855 */
-	reg_read(0x10005000, &temp);
-	if (temp == 0x8855)
-		return temp;
-
 	return -1;
 }
 
@@ -622,7 +640,9 @@
 
 int main(int argc, char *argv[])
 {
-	int err;
+	int err = -EINVAL;
+	FILE *fp = NULL;
+	char buff[255];
 
 	attres = (struct mt753x_attr *)malloc(sizeof(struct mt753x_attr));
 	if (attres == NULL) {
@@ -633,28 +653,35 @@
 	attres->port_num = -1;
 	attres->phy_dev = -1;
 	nl_init_flag = true;
+	air_skip_check_flag = false;
 
-	/* dsa netlink family might not be enabled. Try gsw netlink family. */
-	err = mt753x_netlink_init(MT753X_DSA_GENL_NAME);
-	if (!err)
-		chip_name = get_chip_name();
+	fp = fopen("/proc/air_sw/device", "r");
+	if (fp != NULL) {
+		if (fgets(buff, 255, (FILE *) fp) && strstr(buff, "an8855"))
+			air_skip_check_flag = true;
 
-	if (err < 0) {
-		err = mt753x_netlink_init(MT753X_GENL_NAME);
-		if (!err)
-			chip_name = get_chip_name();
-	}
+		if ((fclose(fp) == 0) && air_skip_check_flag) {
+			err = mt753x_netlink_init(AN8855_DSA_GENL_NAME);
+			if (!err)
+				chip_name = get_chip_name();
 
-	if (err < 0) {
-		err = mt753x_netlink_init(AN8855_DSA_GENL_NAME);
+			if (err < 0) {
+				err = mt753x_netlink_init(AN8855_GENL_NAME);
+				if (!err)
+					chip_name = get_chip_name();
+			}
+		}
+	} else {
+		/* dsa netlink family might not be enabled. Try gsw netlink family. */
+		err = mt753x_netlink_init(MT753X_DSA_GENL_NAME);
 		if (!err)
 			chip_name = get_chip_name();
-	}
 
-	if (err < 0) {
-		err = mt753x_netlink_init(AN8855_GENL_NAME);
-		if (!err)
-			chip_name = get_chip_name();
+		if (err < 0) {
+			err = mt753x_netlink_init(MT753X_GENL_NAME);
+			if (!err)
+				chip_name = get_chip_name();
+		}
 	}
 
 	if (err < 0) {
diff --git a/recipes-devtools/switch/files/src/switch_extend.h b/recipes-devtools/switch/files/src/switch_extend.h
index c352767..a35316e 100644
--- a/recipes-devtools/switch/files/src/switch_extend.h
+++ b/recipes-devtools/switch/files/src/switch_extend.h
@@ -154,7 +154,7 @@
 #define REG_VAWD2_ADDR			(0x0098)
 #define REG_VLAN_ID_BASE		(0x0100)
 
-#define REG_CPGC_ADDR 			(0xB0)
+#define REG_CPGC_ADDR			(0xB0)
 #define REG_CPCG_COL_EN_OFFT		(0)
 #define REG_CPCG_COL_EN_RELMASK		(0x00000001)
 #define REG_CPCG_COL_EN_MASK		(REG_CPCG_COL_EN_RELMASK << REG_CPCG_COL_EN_OFFT)
@@ -336,7 +336,7 @@
 						 "         1: Blocking/Listening/Discarding\n" \
 						 "         2: Learning\n" \
 						 "         3: Forwarding\n"
-#define HELP_COLLISION_POOL_EN	"collision-pool enable [enable 0|1] \n"
-#define HELP_EEE_EN		"eee [enable|disable] ([port|portMap]) \n"
+#define HELP_COLLISION_POOL_EN	"collision-pool enable [enable 0|1]\n"
+#define HELP_EEE_EN		"eee [enable|disable] ([port|portMap])\n"
 
 //#endif //SQA_VERIFY
diff --git a/recipes-devtools/switch/files/src/switch_fun.c b/recipes-devtools/switch/files/src/switch_fun.c
index 4745cf5..4239e1a 100644
--- a/recipes-devtools/switch/files/src/switch_fun.c
+++ b/recipes-devtools/switch/files/src/switch_fun.c
@@ -1,6 +1,6 @@
 /*
-* switch_fun.c: switch function sets
-*/
+ * switch_fun.c: switch function sets
+ */
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -202,7 +202,7 @@
 	int ret;
 
 	if (port_num > 31) {
-		printf("Invalid Port or PHY addr \n");
+		printf("Invalid Port or PHY addr\n");
 		return -1;
 	}
 
@@ -225,7 +225,7 @@
 	int ret;
 
 	if (port_num > 31) {
-		printf("Invalid Port or PHY addr \n");
+		printf("Invalid Port or PHY addr\n");
 		return -1;
 	}
 
@@ -249,7 +249,7 @@
 	int ret;
 
 	if (port_num > 31) {
-		printf("Invalid Port or PHY addr \n");
+		printf("Invalid Port or PHY addr\n");
 		return -1;
 	}
 
@@ -273,7 +273,7 @@
 	int ret;
 
 	if (port_num > 31) {
-		printf("Invalid Port or PHY addr \n");
+		printf("Invalid Port or PHY addr\n");
 		return -1;
 	}
 
@@ -335,8 +335,8 @@
 	}
 
 	printf("mii_mgr_cl45:");
-	printf("Read:  port#=%d, device=0x%x, reg=0x%x, value=0x%x\n", port_num,
-	       0x1E, MT7530_T10_TEST_CONTROL, value);
+	printf("Read:  port#=%d, device=0x%x, reg=0x%x, value=0x%x\n",
+			port_num, 0x1E, MT7530_T10_TEST_CONTROL, value);
 
 	if (!strncmp(argv[3], "auto", 5)) {
 		value &= (~(0x3 << 3));
@@ -349,8 +349,8 @@
 		printf("invaild parameter\n");
 		return;
 	}
-	printf("Write: port#=%d, device=0x%x, reg=0x%x. value=0x%x\n", port_num,
-	       0x1E, MT7530_T10_TEST_CONTROL, value);
+	printf("Write: port#=%d, device=0x%x, reg=0x%x. value=0x%x\n",
+		port_num, 0x1E, MT7530_T10_TEST_CONTROL, value);
 
 	if (nl_init_flag == true)
 		ret =
@@ -408,16 +408,15 @@
 			goto error;
 
 		printf("port = %x, ch_addr = %x, node_addr=%x, data_addr=%x\n",
-		       port_num, ch_addr, node_addr, data_addr);
+				port_num, ch_addr, node_addr, data_addr);
 		tr_reg_control =
 		    (1 << 15) | (1 << 13) | (ch_addr << 11) | (node_addr << 7) |
 		    (data_addr << 1);
 		mii_mgr_write(port_num, 16, tr_reg_control);	// r16 = tr_reg_control
 		mii_mgr_read(port_num, 17, &val_l);
 		mii_mgr_read(port_num, 18, &val_h);
-		printf
-		    ("switch trreg read tr_reg_control=%x, value_H=%x, value_L=%x\n",
-		     tr_reg_control, val_h, val_l);
+		printf("switch trreg read tr_reg_control=%x, value_H=%x, value_L=%x\n",
+				tr_reg_control, val_h, val_l);
 	} else if (argv[2][0] == 'w') {
 		if (argc != 9)
 			return -1;
@@ -456,16 +455,15 @@
 			goto error;
 
 		printf("port = %x, ch_addr = %x, node_addr=%x, data_addr=%x\n",
-		       port_num, ch_addr, node_addr, data_addr);
+				port_num, ch_addr, node_addr, data_addr);
 		tr_reg_control =
 		    (1 << 15) | (0 << 13) | (ch_addr << 11) | (node_addr << 7) |
 		    (data_addr << 1);
 		mii_mgr_write(port_num, 17, val_l);
 		mii_mgr_write(port_num, 18, val_h);
 		mii_mgr_write(port_num, 16, tr_reg_control);	// r16 = tr_reg_control
-		printf
-		    ("switch trreg Write tr_reg_control=%x, value_H=%x, value_L=%x\n",
-		     tr_reg_control, val_h, val_l);
+		printf("switch trreg Write tr_reg_control=%x, value_H=%x, value_L=%x\n",
+				tr_reg_control, val_h, val_l);
 	} else
 		return -1;
 
@@ -497,9 +495,8 @@
 	reg = REG_VTCR_ADDR;
 	while (1) {		// wait until not busy
 		reg_read(reg, &value);
-		if ((value & REG_VTCR_BUSY_MASK) == 0) {
+		if ((value & REG_VTCR_BUSY_MASK) == 0)
 			break;
-		}
 	}
 	reg_write(REG_VAWD1_ADDR, vawd1);
 	printf("write reg: %x, value: %x\n", REG_VAWD1_ADDR, vawd1);
@@ -521,11 +518,17 @@
 {
 	unsigned int vawd1 = 0, vawd2 = 0;
 	unsigned char tbl_idx = 0;
+	unsigned int max_index = 0;
 	char *endptr;
 
+	if (chip_name == 0x7531 || chip_name == 0x7988)
+		max_index = 256;
+	else
+		max_index = 64;
+
 	errno = 0;
 	tbl_idx = strtoul(argv[3], &endptr, 10);
-	if (errno != 0 || *endptr != '\0') {
+	if (errno != 0 || *endptr != '\0' || tbl_idx >= max_index) {
 		printf("Error: wrong ACL rule table index\n");
 		return;
 	}
@@ -589,11 +592,17 @@
 {
 	unsigned int vawd1 = 0, vawd2 = 0;
 	unsigned char tbl_idx = 0;
+	unsigned int max_index = 0;
 	char *endptr;
 
+	if (chip_name == 0x7531 || chip_name == 0x7988)
+		max_index = 128;
+	else
+		max_index = 32;
+
 	errno = 0;
 	tbl_idx = strtoul(argv[3], &endptr, 10);
-	if (errno != 0 || *endptr != '\0') {
+	if (errno != 0 || *endptr != '\0' || tbl_idx >= max_index) {
 		printf("Error: wrong ACL mask table index\n");
 		return;
 	}
@@ -628,7 +637,8 @@
 
 	printf("Rule_control_tbl_idx:%d\n", tbl_idx);
 
-	if (tbl_idx >= max_index) {	/* Check the input parameters is right or not. */
+	if (tbl_idx >= max_index) {
+		/* Check the input parameters is right or not. */
 		printf(HELP_ACL_RULE_TBL_ADD);
 		return;
 	}
@@ -636,9 +646,8 @@
 
 	while (1) {		// wait until not busy
 		reg_read(reg, &value);
-		if ((value & REG_VTCR_BUSY_MASK) == 0) {
+		if ((value & REG_VTCR_BUSY_MASK) == 0)
 			break;
-		}
 	}
 	reg_write(REG_VAWD1_ADDR, vawd1);
 	printf("write reg: %x, value: %x\n", REG_VAWD1_ADDR, vawd1);
@@ -651,9 +660,8 @@
 
 	while (1) {		// wait until not busy
 		reg_read(reg, &value);
-		if ((value & REG_VTCR_BUSY_MASK) == 0) {
+		if ((value & REG_VTCR_BUSY_MASK) == 0)
 			break;
-		}
 	}
 }
 
@@ -661,11 +669,17 @@
 {
 	unsigned int vawd1 = 0, vawd2 = 0;
 	unsigned char tbl_idx = 0;
+	unsigned int max_index = 0;
 	char *endptr;
 
+	if (chip_name == 0x7531 || chip_name == 0x7988)
+		max_index = 128;
+	else
+		max_index = 32;
+
 	errno = 0;
 	tbl_idx = strtoul(argv[3], &endptr, 10);
-	if (errno != 0 || *endptr != '\0') {
+	if (errno != 0 || *endptr != '\0' || tbl_idx >= max_index) {
 		printf("Error: wrong ACL rule control table index\n");
 		return;
 	}
@@ -727,11 +741,12 @@
 {
 	unsigned int vawd1 = 0, vawd2 = 0;
 	unsigned char tbl_idx = 0;
+	unsigned int max_index = 32;
 	char *endptr;
 
 	errno = 0;
 	tbl_idx = strtoul(argv[3], &endptr, 10);
-	if (errno != 0 || *endptr != '\0') {
+	if (errno != 0 || *endptr != '\0' || tbl_idx >= max_index) {
 		printf("Error: wrong ACL rate control table index\n");
 		return;
 	}
@@ -802,9 +817,8 @@
 
 	if (len2 == 12) {
 		if (!argv[4] || strlen(argv[4]) != len2) {
-			printf
-			    ("The [%s] format error, should be of length %d\n",
-			     argv[4], len2);
+			printf("The [%s] format error, should be of length %d\n",
+					argv[4], len2);
 			return -1;
 		}
 	}
@@ -816,8 +830,7 @@
 
 	for (i = 0; i < 7; i++) {
 		if (argv[5][i] != '0' && argv[5][i] != '1') {
-			printf
-			    ("portmap format error, should be of combination of 0 or 1\n");
+			printf("portmap format error, should be of combination of 0 or 1\n");
 			return -1;
 		}
 		*port += (argv[5][i] - '0') * (1 << i);
@@ -890,7 +903,6 @@
 
 error:
 	printf("Error: string converting\n");
-	return;
 }
 
 void acl_dip_meter(int argc, char *argv[])
@@ -1214,8 +1226,7 @@
 		table_size = 0x40;
 		reg_write(REG_ATC_ADDR, 0x811c);	//dip search command
 	}
-	printf
-	    ("hash   port(0:6)   rsp_cnt  flag  timer    dip-address       ATRD\n");
+	printf("hash   port(0:6)   rsp_cnt  flag  timer    dip-address       ATRD\n");
 	for (i = 0; i < table_size; i++) {
 		while (1) {
 			reg_read(REG_ATC_ADDR, &value);
@@ -1292,10 +1303,6 @@
 	reg_write(REG_ATA1_ADDR, value);
 	printf("REG_ATA1_ADDR is 0x%x\n\r", value);
 
-#if 0
-	reg_write(REG_ATA2_ADDR, value);
-	printf("REG_ATA2_ADDR is 0x%x\n\r", value);
-#endif
 	if (!argv[4] || strlen(argv[4]) != 8) {
 		printf("portmap format error, should be of length 7\n");
 		return;
@@ -1303,8 +1310,7 @@
 	j = 0;
 	for (i = 0; i < 7; i++) {
 		if (argv[4][i] != '0' && argv[4][i] != '1') {
-			printf
-			    ("portmap format error, should be of combination of 0 or 1\n");
+			printf("portmap format error, should be of combination of 0 or 1\n");
 			return;
 		}
 		j += (argv[4][i] - '0') * (1 << i);
@@ -1368,7 +1374,6 @@
 
 void dip_clear(int argc, char *argv[])
 {
-
 	unsigned int value = 0;
 
 	reg_write(REG_ATC_ADDR, 0x8102);	//clear all dip
@@ -1481,8 +1486,7 @@
 	j = 0;
 	for (i = 0; i < 7; i++) {
 		if (argv[5][i] != '0' && argv[5][i] != '1') {
-			printf
-			    ("portmap format error, should be of combination of 0 or 1\n");
+			printf("portmap format error, should be of combination of 0 or 1\n");
 			return;
 		}
 		j += (argv[5][i] - '0') * (1 << i);
@@ -1571,8 +1575,7 @@
 		table_end = 0x3F;
 		reg_write(REG_ATC_ADDR, 0x800C);
 	}
-	printf
-	    ("hash  port(0:6)   fid   vid  age(s)   mac-address     filter my_mac\n");
+	printf("hash  port(0:6)   fid   vid  age(s)   mac-address     filter my_mac\n");
 	for (i = 0; i < table_size; i++) {
 		while (1) {
 			reg_read(REG_ATC_ADDR, &value);
@@ -1623,8 +1626,7 @@
 				}
 				break;
 			} else if ((value & 0x4000) && (((value >> 15) & 0x1) == 0) && (((value >> 16) & 0xfff) == table_end)) {	//at_table_end
-				printf("found the last entry %d (not ready)\n",
-				       i);
+				printf("found the last entry %d (not ready)\n", i);
 				return;
 			} else
 				usleep(5);
@@ -1702,8 +1704,7 @@
 	j = 0;
 	for (i = 0; i < 7; i++) {
 		if (argv[3][i] != '0' && argv[3][i] != '1') {
-			printf
-			    ("portmap format error, should be of combination of 0 or 1\n");
+			printf("portmap format error, should be of combination of 0 or 1\n");
 			return;
 		}
 		j += (argv[3][i] - '0') * (1 << i);
@@ -2154,8 +2155,7 @@
 	}
 
 	if (eg_tag)
-		printf
-		    ("  vid  fid  portmap    s-tag\teg_tag(0:untagged 2:tagged)\n");
+		printf("  vid  fid  portmap    s-tag\teg_tag(0:untagged 2:tagged)\n");
 	else
 		printf("  vid  fid  portmap    s-tag\n");
 
@@ -2305,8 +2305,7 @@
 	vlan_mem = 0;
 	for (i = 0; i < 8; i++) {
 		if (argv[5][i] != '0' && argv[5][i] != '1') {
-			printf
-			    ("portmap format error, should be of combination of 0 or 1\n");
+			printf("portmap format error, should be of combination of 0 or 1\n");
 			return;
 		}
 		vlan_mem += (argv[5][i] - '0') * (1 << i);
@@ -2316,8 +2315,7 @@
 	if (argc > 6) {
 		stag = strtoul(argv[6], NULL, 16);
 		if (stag < 0 || 0xfff < stag) {
-			printf
-			    ("wrong stag id range, should be within 0~4095\n");
+			printf("wrong stag id range, should be within 0~4095\n");
 			return;
 		}
 		//printf("STAG is 0x%x\n", stag);
@@ -2338,15 +2336,13 @@
 
 	if (argc > 8 && !eg_con) {
 		if (strlen(argv[8]) != 8) {
-			printf
-			    ("egtag portmap format error, should be of length 7\n");
+			printf("egtag portmap format error, should be of length 7\n");
 			return;
 		}
 
 		for (i = 0; i < 8; i++) {
 			if (argv[8][i] < '0' || argv[8][i] > '3') {
-				printf
-				    ("egtag portmap format error, should be of combination of 0 or 3\n");
+				printf("egtag portmap format error, should be of combination of 0 or 3\n");
 				return;
 			}
 			//eg_tag += (argv[8][i] - '0') * (1 << i * 2);
@@ -2592,13 +2588,13 @@
 	/*Software Register Reset  and Software System Reset */
 	reg_write(0x7000, 0x3);
 	reg_read(0x7000, &value);
-	printf("SYS_CTRL(0x7000) register value =0x%x  \n", value);
+	printf("SYS_CTRL(0x7000) register value =0x%x\n", value);
 	if (chip_name == 0x7531) {
 		reg_write(0x7c0c, 0x11111111);
 		reg_read(0x7c0c, &value);
-		printf("GPIO Mode (0x7c0c) select value =0x%x  \n", value);
+		printf("GPIO Mode (0x7c0c) select value =0x%x\n", value);
 	}
-	printf("Switch Software Reset !!! \n");
+	printf("Switch Software Reset !!!\n");
 }
 
 void phy_set_fc(int argc, char *argv[])
@@ -2633,8 +2629,7 @@
 	}
 	mii_mgr_write(port, 4, phy_value);
 	printf("write phy_value:0x%x\r\n", phy_value);
-	return;
-}				/*end phy_set_fc */
+}
 
 void phy_set_an(int argc, char *argv[])
 {
@@ -2664,7 +2659,7 @@
 	phy_value |= (auto_negotiation_en << 12);
 	mii_mgr_write(port, 0, phy_value);
 	printf("write phy_value:0x%x\r\n", phy_value);
-}				/*end phy_set_an */
+}
 
 void set_mac_pfc(int argc, char *argv[])
 {
@@ -2887,9 +2882,8 @@
 
 	port = atoi(argv[3]);
 
-	for (i = 0; i < 8; i++) {
+	for (i = 0; i < 8; i++)
 		weight[i] = atoi(argv[i + 4]);
-	}
 
 	/* MT7530 total 7 port */
 	if (port < 0 || port > 6) {
@@ -3087,7 +3081,7 @@
 	reg_read(reg, &value);
 
 	printf("SetVid: index:%d active:%d vid:%d portMap:%x tagPortMap:%x\r\n",
-	       index, active, vid, portMap, tagPortMap);
+			index, active, vid, portMap, tagPortMap);
 	return 0;
 
 }				/*end macMT753xVlanSetVid */
@@ -3140,8 +3134,8 @@
 	macMT753xVlanSetPvid(port, pvid);
 
 	printf("port:%d pvid:%d,vlancap: max_port:%d maxvid:%d\r\n",
-	       port, pvid, SWITCH_MAX_PORT, MAX_VID_VALUE);
-}				/*end doVlanSetPvid */
+			port, pvid, SWITCH_MAX_PORT, MAX_VID_VALUE);
+}
 
 void doVlanSetVid(int argc, char *argv[])
 {
@@ -3212,9 +3206,9 @@
 		}
 	}
 	macMT753xVlanSetVid(index, active, vid, portMap, tagPortMap,
-			    ivl_en, fid, stag);
+						ivl_en, fid, stag);
 	printf("index:%d active:%d vid:%d\r\n", index, active, vid);
-}				/*end doVlanSetVid */
+}
 
 void doVlanSetAccFrm(int argc, char *argv[])
 {
@@ -3247,7 +3241,7 @@
 
 	printf("write reg: %x, value: %x\n", reg, value);
 	reg_write(reg, value);
-}				/*end doVlanSetAccFrm */
+}
 
 void doVlanSetPortAttr(int argc, char *argv[])
 {
@@ -3407,9 +3401,8 @@
 	reg = 0xa0;
 	reg_read(reg, &value);
 	value &= (~(1 << 20));
-	if (!aging_en) {
+	if (!aging_en)
 		value |= (1 << 20);
-	}
 
 	aging_unit = (time / 0x100) + 1;
 	aging_cnt = (time / aging_unit);
@@ -3497,9 +3490,8 @@
 	if (errno != 0 || *endptr != '\0' || igmp_mir > 1)
 		goto error;
 
-	printf
-	    ("port:%d, port_tx_mir:%d, port_rx_mir:%d, acl_mir:%d, vlan_mis:%d, igmp_mir:%d\n",
-	     port, port_tx_mir, port_rx_mir, acl_mir, vlan_mis, igmp_mir);
+	printf("port:%d, port_tx_mir:%d, port_rx_mir:%d, acl_mir:%d, vlan_mis:%d, igmp_mir:%d\n",
+			port, port_tx_mir, port_rx_mir, acl_mir, vlan_mis, igmp_mir);
 
 	reg = REG_PCR_P0_ADDR + port * 0x100;
 	reg_read(reg, &value);
@@ -3581,37 +3573,26 @@
 	if (on_off == 1) {
 		if (chip_name == 0x7530) {
 			if (bw > 1000000) {
-				printf
-				    ("\n**Charge rate(%d) is larger than line rate(1000000kbps)**\n",
-				     bw);
+				printf("\n**Charge rate(%d) is larger than line rate(1000000kbps)**\n", bw);
 				return;
 			}
-			value =
-			    ((bw / 32) << 16) + (1 << 15) + (7 << 8) +
-			    (1 << 7) + 0x0f;
+			value = ((bw / 32) << 16) + (1 << 15) + (7 << 8) + (1 << 7) + 0x0f;
 		} else if (chip_name == 0x7531 || chip_name == 0x7988) {
 			if ((chip_name == 0x7531) && (bw > 2500000)) {
-				printf
-				    ("\n**Charge rate(%d) is larger than line rate(2500000kbps)**\n",
-				     bw);
+				printf("\n**Charge rate(%d) is larger than line rate(2500000kbps)**\n", bw);
 				return;
 			}
 
 			if ((chip_name == 0x7988) && (bw > 4000000)) {
-				printf
-				    ("\n**Charge rate(%d) is larger than line rate(4000000kbps)**\n",
-				     bw);
+				printf("\n**Charge rate(%d) is larger than line rate(4000000kbps)**\n", bw);
 				return;
 			}
 
 			if (bw / 32 >= 65536)	//supoort 2.5G case
-				value =
-				    ((bw / 32) << 16) + (1 << 15) + (1 << 14) +
-				    (1 << 12) + (7 << 8) + 0xf;
+				value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (1 << 12) +
+					(7 << 8) + 0xf;
 			else
-				value =
-				    ((bw / 32) << 16) + (1 << 15) + (1 << 14) +
-				    (7 << 8) + 0xf;
+				value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (7 << 8) + 0xf;
 		} else
 			printf("unknow chip\n");
 	}
@@ -3705,36 +3686,25 @@
 	if (on_off == 1) {
 		if (chip_name == 0x7530) {
 			if (bw < 0 || bw > 1000000) {
-				printf
-				    ("\n**Charge rate(%d) is larger than line rate(1000000kbps)**\n",
-				     bw);
+				printf("\n**Charge rate(%d) is larger than line rate(1000000kbps)**\n", bw);
 				return;
 			}
-			value =
-			    ((bw / 32) << 16) + (1 << 15) + (7 << 8) +
-			    (1 << 7) + 0xf;
+			value = ((bw / 32) << 16) + (1 << 15) + (7 << 8) + (1 << 7) + 0xf;
 		} else if (chip_name == 0x7531 || chip_name == 0x7988) {
 			if ((chip_name == 0x7531) && (bw < 0 || bw > 2500000)) {
-				printf
-				    ("\n**Charge rate(%d) is larger than line rate(2500000kbps)**\n",
-				     bw);
+				printf("\n**Charge rate(%d) is larger than line rate(2500000kbps)**\n", bw);
 				return;
 			}
 			if ((chip_name == 0x7988) && (bw < 0 || bw > 4000000)) {
-				printf
-				    ("\n**Charge rate(%d) is larger than line rate(4000000kbps)**\n",
-				     bw);
+				printf("\n**Charge rate(%d) is larger than line rate(4000000kbps)**\n", bw);
 				return;
 			}
 
 			if (bw / 32 >= 65536)	//support 2.5G cases
-				value =
-				    ((bw / 32) << 16) + (1 << 15) + (1 << 14) +
-				    (1 << 12) + (7 << 8) + 0xf;
+				value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (1 << 12) +
+					(7 << 8) + 0xf;
 			else
-				value =
-				    ((bw / 32) << 16) + (1 << 15) + (1 << 14) +
-				    (7 << 8) + 0xf;
+				value = ((bw / 32) << 16) + (1 << 15) + (1 << 14) + (7 << 8) + 0xf;
 		} else
 			printf("unknow chip\n");
 	}
@@ -3834,14 +3804,13 @@
 
 	enable = atoi(argv[3]);
 
-	printf("collision pool enable: %d \n", enable);
-
 	/*Check the input parameters is right or not. */
 	if (enable > 1) {
 		printf(HELP_COLLISION_POOL_EN);
 		return;
 	}
 
+	printf("collision pool enable: %d\n", enable);
 	if (chip_name == 0x7531 || chip_name == 0x7988) {
 		reg = REG_CPGC_ADDR;
 		if (enable == 1) {
@@ -3912,8 +3881,7 @@
 		if (value & REG_CPCG_COL_EN_MASK)
 			table_dump_internal(COLLISION_TABLE);
 		else
-			printf
-			    ("\ncollision pool is disabled, please enable it before use this command.\n");
+			printf("\ncollision pool is disabled, please enable it before use this command.\n");
 	} else {
 		printf("\nCommand not support by this chip.\n");
 	}
@@ -3929,8 +3897,7 @@
 		if (value & REG_CPCG_COL_EN_MASK)
 			dip_dump_internal(COLLISION_TABLE);
 		else
-			printf
-			    ("\ncollision pool is disabled, please enable it before use this command.\n");
+			printf("\ncollision pool is disabled, please enable it before use this command.\n");
 	} else {
 		printf("\nCommand not support by this chip.\n");
 	}
@@ -3946,8 +3913,7 @@
 		if (value & REG_CPCG_COL_EN_MASK)
 			sip_dump_internal(COLLISION_TABLE);
 		else
-			printf
-			    ("\ncollision pool is disabled, please enable it before use this command.\n");
+			printf("\ncollision pool is disabled, please enable it before use this command.\n");
 	} else {
 		printf("\nCommand not support by this chip.\n");
 	}
@@ -4229,15 +4195,13 @@
 			port_map = 0;
 			for (p = 0; p < MAX_PHY_PORT; p++) {
 				if (argv[3][p] != '0' && argv[3][p] != '1') {
-					printf
-					    ("portmap format error, should be combination of 0 or 1\n");
+					printf("portmap format error, should be combination of 0 or 1\n");
 					goto error;
 				}
 				port_map |= ((argv[3][p] - '0') << p);
 			}
 		} else {
-			printf
-			    ("port_no or portmap format error, should be length of 1 or 5\n");
+			printf("port_no or portmap format error, should be length of 1 or 5\n");
 			goto error;
 		}
 	} else {
@@ -4284,7 +4248,6 @@
 	return;
 error:
 	printf(HELP_EEE_EN);
-	return;
 }
 
 void eee_dump(int argc, char *argv[])
@@ -4395,7 +4358,7 @@
 	reg_write(0x4fe0, 0x800000f0);
 }
 
-void exit_free()
+void exit_free(void)
 {
 	free(attres);
 	attres = NULL;
diff --git a/recipes-devtools/switch/files/src/switch_fun.h b/recipes-devtools/switch/files/src/switch_fun.h
index cc16c20..7ca1b0a 100644
--- a/recipes-devtools/switch/files/src/switch_fun.h
+++ b/recipes-devtools/switch/files/src/switch_fun.h
@@ -102,9 +102,9 @@
 int mii_mgr_read(unsigned int port_num, unsigned int reg, unsigned int *value);
 int mii_mgr_write(unsigned int port_num, unsigned int reg, unsigned int value);
 int mii_mgr_c45_read(unsigned int port_num, unsigned int dev, unsigned int reg,
-		     unsigned int *value);
+		unsigned int *value);
 int mii_mgr_c45_write(unsigned int port_num, unsigned int dev, unsigned int reg,
-		      unsigned int value);
+		unsigned int value);
 
 /*phy setting*/
 int phy_dump(int phy_addr);
@@ -222,5 +222,5 @@
 void read_free_page_counters(int argc, char *argv[]);
 
 void phy_crossover(int argc, char *argv[]);
-void exit_free();
+void exit_free(void);
 #endif
diff --git a/recipes-devtools/switch/files/src/switch_fun_an8855.c b/recipes-devtools/switch/files/src/switch_fun_an8855.c
index e5ec490..3f5d9f6 100644
--- a/recipes-devtools/switch/files/src/switch_fun_an8855.c
+++ b/recipes-devtools/switch/files/src/switch_fun_an8855.c
@@ -1,6 +1,6 @@
 /*
-* switch_fun.c: switch function sets
-*/
+ * switch_fun.c: switch function sets
+ */
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -18,9 +18,8 @@
 #include "switch_fun_an8855.h"
 
 #define MAC_STR         "%02X%02X%02X%02X%02X%02X"
-#define MAC2STR(m)      (m)[0],(m)[1],(m)[2],(m)[3],(m)[4],(m)[5]
 
-const static C8_T *mac_address_forward_control_string[] = {
+const static C8_T * mac_address_forward_control_string[] = {
 	"Default",
 	"CPU include",
 	"CPU exclude",
@@ -105,14 +104,13 @@
 };
 
 AIR_ERROR_NO_T
-an8855_reg_read(const UI32_T unit, const UI32_T addr_offset, UI32_T * ptr_data)
+an8855_reg_read(const UI32_T unit, const UI32_T addr_offset, UI32_T *ptr_data)
 {
 	int ret;
 
 	ret = reg_read(addr_offset, ptr_data);
-	if (ret < 0) {
+	if (ret < 0)
 		return AIR_E_OTHERS;
-	}
 
 	return AIR_E_OK;
 }
@@ -123,9 +121,8 @@
 	int ret;
 
 	ret = reg_write(addr_offset, data);
-	if (ret < 0) {
+	if (ret < 0)
 		return AIR_E_OTHERS;
-	}
 
 	return AIR_E_OK;
 }
@@ -133,14 +130,13 @@
 AIR_ERROR_NO_T
 an8855_phy_cl22_read(const UI32_T unit,
 		     const UI32_T port_id,
-		     const UI32_T addr_offset, UI32_T * ptr_data)
+		     const UI32_T addr_offset, UI32_T *ptr_data)
 {
 	int ret;
 
 	ret = mii_mgr_read(port_id, addr_offset, ptr_data);
-	if (ret < 0) {
+	if (ret < 0)
 		return AIR_E_OTHERS;
-	}
 
 	return AIR_E_OK;
 }
@@ -153,9 +149,9 @@
 	int ret;
 
 	ret = mii_mgr_write(port_id, addr_offset, data);
-	if (ret < 0) {
+	if (ret < 0)
 		return AIR_E_OTHERS;
-	}
+
 
 	return AIR_E_OK;
 }
@@ -164,14 +160,14 @@
 an8855_phy_cl45_read(const UI32_T unit,
 		     const UI32_T port_id,
 		     const UI32_T dev_type,
-		     const UI32_T addr_offset, UI32_T * ptr_data)
+		     const UI32_T addr_offset, UI32_T *ptr_data)
 {
 	int ret;
 
 	ret = mii_mgr_c45_read(port_id, dev_type, addr_offset, ptr_data);
-	if (ret < 0) {
+	if (ret < 0)
 		return AIR_E_OTHERS;
-	}
+
 
 	return AIR_E_OK;
 }
@@ -185,9 +181,9 @@
 	int ret;
 
 	ret = mii_mgr_c45_write(port_id, dev_type, addr_offset, data);
-	if (ret < 0) {
+	if (ret < 0)
 		return AIR_E_OTHERS;
-	}
+
 
 	return AIR_E_OK;
 }
@@ -198,12 +194,13 @@
 }
 
 static AIR_ERROR_NO_T
-_printMacEntry(AIR_MAC_ENTRY_T * mt, UI32_T age_unit, UI8_T count, UI8_T title)
+_printMacEntry(AIR_MAC_ENTRY_T *mt, UI32_T age_unit, UI8_T count, UI8_T title)
 {
 	AIR_ERROR_NO_T ret = AIR_E_OK;
 	I32_T i = 0, j = 0;
 	UI8_T first = 0;
 	UI8_T find = 0;
+
 	if (title) {
 		printf("%-6s%-15s%-5s%-5s%-5s%-10s%-10s%-6s\n",
 		       "unit",
@@ -213,7 +210,8 @@
 	}
 	for (i = 0; i < count; i++) {
 		printf("%-6d", age_unit);
-		printf(MAC_STR, MAC2STR(mt[i].mac));
+		printf(MAC_STR, mt[i].mac[0], mt[i].mac[1], mt[i].mac[2],
+			 mt[i].mac[3], mt[i].mac[4], mt[i].mac[5]);
 		printf("...");
 		if (mt[i].flags & AIR_L2_MAC_ENTRY_FLAGS_IVL) {
 			printf("%-3s..", "ivl");
@@ -224,11 +222,11 @@
 			printf("%-5s", ".....");
 			printf("%-5d", mt[i].fid);
 		}
-		if (mt[i].flags & AIR_L2_MAC_ENTRY_FLAGS_STATIC) {
+		if (mt[i].flags & AIR_L2_MAC_ENTRY_FLAGS_STATIC)
 			printf("%-7s.", "static");
-		} else {
+		else
 			printf("%d sec..", mt[i].timer);
-		}
+
 		printf("%-10s",
 		       mac_address_forward_control_string[mt[i].sa_fwd]);
 		first = 0;
@@ -256,7 +254,7 @@
 	return ret;
 }
 
-static AIR_ERROR_NO_T _str2mac(C8_T * str, C8_T * mac)
+static AIR_ERROR_NO_T _str2mac(C8_T *str, C8_T *mac)
 {
 	UI32_T i;
 	C8_T tmpstr[3];
@@ -307,9 +305,9 @@
 	while (1) {
 		memset(ptr_mt, 0, sizeof(AIR_MAC_ENTRY_T) * bucket_size);
 		ret = air_l2_getNextMacAddr(0, &count, ptr_mt);
-		if (AIR_E_OK != ret) {
+		if (ret != AIR_E_OK)
 			break;
-		}
+
 		total_count += count;
 		_printMacEntry(ptr_mt, 0, count, FALSE);
 	}
@@ -328,7 +326,6 @@
 
 DUMP_ERROR:
 	free(ptr_mt);
-	return;
 }
 
 void an8855_table_dump(int argc, char *argv[])
@@ -342,6 +339,7 @@
 	AIR_MAC_ENTRY_T mt;
 	unsigned int i = 0;
 	unsigned int age_time = 0;
+
 	memset(&mt, 0, sizeof(AIR_MAC_ENTRY_T));
 	if (!argv[2] || strlen(argv[2]) != 12) {
 		printf("MAC address format error, should be of length 12\n");
@@ -354,7 +352,7 @@
 	}
 	if (argc > 4) {
 		mt.cvid = strtoul(argv[4], NULL, 0);
-		if (4095 < mt.cvid) {
+		if (mt.cvid > 4095) {
 			printf("wrong vid range, should be within 0~4095\n");
 			return;
 		}
@@ -379,9 +377,9 @@
 			printf("wrong age range, should be within 1~1000000\n");
 			return;
 		}
-	} else {
+	} else
 		mt.flags |= AIR_L2_MAC_ENTRY_FLAGS_STATIC;
-	}
+
 	mt.sa_fwd = AIR_L2_FWD_CTRL_DEFAULT;
 	ret = air_l2_addMacAddr(0, &mt);
 	if (ret == AIR_E_OK) {
@@ -389,16 +387,14 @@
 		usleep(5000);
 		if (!(mt.flags & AIR_L2_MAC_ENTRY_FLAGS_STATIC)) {
 			ret = air_l2_setMacAddrAgeOut(0, age_time);
-			if (ret == AIR_E_OK) {
+			if (ret == AIR_E_OK)
 				printf("set age out time done.\n");
-			} else {
+			else
 				printf("set age out time fail.\n");
-			}
+
 		}
-	} else {
+	} else
 		printf("add mac address fail.\n");
-	}
-	return;
 }
 
 void an8855_table_search_mac_vid(int argc, char *argv[])
@@ -414,7 +410,7 @@
 	}
 
 	ptr_mt = malloc(sizeof(AIR_MAC_ENTRY_T));
-	if (NULL == ptr_mt) {
+	if (ptr_mt == NULL) {
 		printf("Error, malloc fail\n");
 		return;
 	}
@@ -443,7 +439,6 @@
 		printf("\n Not found!\n");
 	}
 	free(ptr_mt);
-	return;
 }
 
 void an8855_table_search_mac_fid(int argc, char *argv[])
@@ -459,7 +454,7 @@
 	}
 
 	ptr_mt = malloc(sizeof(AIR_MAC_ENTRY_T));
-	if (NULL == ptr_mt) {
+	if (ptr_mt == NULL) {
 		printf("Error, malloc fail\n");
 		return;
 	}
@@ -483,11 +478,10 @@
 	if (ret == AIR_E_OK) {
 		_printMacEntry(ptr_mt, 0, 1, TRUE);
 		_printMacEntry(ptr_mt, 0, 1, FALSE);
-	} else {
+	} else
 		printf("\n Not found!\n");
-	}
+
 	free(ptr_mt);
-	return;
 }
 
 void an8855_table_del_fid(int argc, char *argv[])
@@ -516,12 +510,10 @@
 	}
 
 	ret = air_l2_delMacAddr(0, &mt);
-	if (ret == AIR_E_OK) {
+	if (ret == AIR_E_OK)
 		printf("Done.\n");
-	} else {
+	else
 		printf("Fail.\n");
-	}
-	return;
 }
 
 void an8855_table_del_vid(int argc, char *argv[])
@@ -551,12 +543,11 @@
 	}
 
 	ret = air_l2_delMacAddr(0, &mt);
-	if (ret == AIR_E_OK) {
+	if (ret == AIR_E_OK)
 		printf("Done.\n");
-	} else {
+	else
 		printf("Fail.\n");
-	}
-	return;
+
 }
 
 void an8855_table_clear(int argc, char *argv[])
@@ -568,7 +559,7 @@
 		printf("Clear MAC Address Table Done.\n");
 	else
 		printf("Clear MAC Address Table Fail.\n");
-	return;
+
 }
 
 void an8855_set_mirror_to(int argc, char *argv[])
@@ -577,7 +568,7 @@
 	AIR_MIR_SESSION_T session = { 0 };
 
 	idx = strtoul(argv[3], NULL, 0);
-	if (idx < 0 || MAX_PORT < idx) {
+	if (idx < 0 || idx > MAX_PORT) {
 		printf("wrong port member, should be within 0~%d\n", MAX_PORT);
 		return;
 	}
@@ -598,12 +589,12 @@
 	idx = _strtoul(argv[3], NULL, 0);
 	mirror = _strtoul(argv[4], NULL, 0);
 
-	if (idx < 0 || MAX_PORT < idx) {
+	if (idx < 0 || idx > MAX_PORT) {
 		printf("wrong port member, should be within 0~%d\n", MAX_PORT);
 		return;
 	}
 
-	if (mirror < 0 || 3 < mirror) {
+	if (mirror < 0 || mirror > 3) {
 		printf("wrong mirror setting, should be within 0~3\n");
 		return;
 	}
@@ -642,9 +633,9 @@
 
 	if (eg_tag)
 		printf
-		    ("  vid  fid  portmap    s-tag\teg_tag(0:untagged 2:tagged)\n");
+		    ("  vid  fid  portmap   s-tag\teg_tag(0:untagged 2:tagged)\n");
 	else
-		printf("  vid  fid  portmap    s-tag\n");
+		printf("  vid  fid  portmap   s-tag\n");
 
 	for (i = 1; i < 4096; i++) {
 		_air_vlan_readEntry(0, i, &vlan_entry);
@@ -652,73 +643,43 @@
 		if (vlan_entry.valid) {
 			printf(" %4d  ", i);
 			printf(" %2d ", vlan_entry.vlan_entry_format.fid);
-			printf(" %c",
-			       (vlan_entry.
-				vlan_entry_format.port_mem & 0b0000001) ? '1' :
-			       '-');
-			printf("%c",
-			       (vlan_entry.
-				vlan_entry_format.port_mem & 0b0000010) ? '1' :
-			       '-');
-			printf("%c",
-			       (vlan_entry.
-				vlan_entry_format.port_mem & 0b0000100) ? '1' :
-			       '-');
-			printf("%c",
-			       (vlan_entry.
-				vlan_entry_format.port_mem & 0b0001000) ? '1' :
-			       '-');
-			printf("%c",
-			       (vlan_entry.
-				vlan_entry_format.port_mem & 0b0010000) ? '1' :
-			       '-');
-			printf("%c",
-			       (vlan_entry.
-				vlan_entry_format.port_mem & 0b0100000) ? '1' :
-			       '-');
-			printf("%c",
-			       (vlan_entry.
-				vlan_entry_format.port_mem & 0b1000000) ? '1' :
-			       '-');
+			printf(" %c", (vlan_entry.vlan_entry_format.port_mem & 0b0000001)
+				? '1' : '-');
+			printf("%c", (vlan_entry.vlan_entry_format.port_mem & 0b0000010)
+				? '1' : '-');
+			printf("%c", (vlan_entry.vlan_entry_format.port_mem & 0b0000100)
+				? '1' : '-');
+			printf("%c", (vlan_entry.vlan_entry_format.port_mem & 0b0001000)
+				? '1' : '-');
+			printf("%c", (vlan_entry.vlan_entry_format.port_mem & 0b0010000)
+				? '1' : '-');
+			printf("%c", (vlan_entry.vlan_entry_format.port_mem & 0b0100000)
+				? '1' : '-');
+			printf("%c", (vlan_entry.vlan_entry_format.port_mem & 0b1000000)
+				? '1' : '-');
 			printf("    %4d", vlan_entry.vlan_entry_format.eg_ctrl);
 			if (eg_tag) {
 				printf("\t");
 				if (vlan_entry.vlan_entry_format.eg_con
-				    && vlan_entry.
-				    vlan_entry_format.eg_ctrl_en) {
+				    && vlan_entry.vlan_entry_format.eg_ctrl_en) {
 					/* VTAG_EN=1 and EG_CON=1 */
 					printf("CONSISTENT");
-				} else if (vlan_entry.
-					   vlan_entry_format.eg_ctrl_en) {
+				} else if (vlan_entry.vlan_entry_format.eg_ctrl_en) {
 					/* VTAG_EN=1 */
 					printf("%d",
-					       (vlan_entry.
-						vlan_entry_format.eg_ctrl >> 0)
-					       & 0x3);
+						(vlan_entry.vlan_entry_format.eg_ctrl >> 0) & 0x3);
 					printf("%d",
-					       (vlan_entry.
-						vlan_entry_format.eg_ctrl >> 2)
-					       & 0x3);
+						(vlan_entry.vlan_entry_format.eg_ctrl >> 2) & 0x3);
 					printf("%d",
-					       (vlan_entry.
-						vlan_entry_format.eg_ctrl >> 4)
-					       & 0x3);
+						(vlan_entry.vlan_entry_format.eg_ctrl >> 4) & 0x3);
 					printf("%d",
-					       (vlan_entry.
-						vlan_entry_format.eg_ctrl >> 6)
-					       & 0x3);
+						(vlan_entry.vlan_entry_format.eg_ctrl >> 6) & 0x3);
 					printf("%d",
-					       (vlan_entry.
-						vlan_entry_format.eg_ctrl >> 8)
-					       & 0x3);
+						(vlan_entry.vlan_entry_format.eg_ctrl >> 8) & 0x3);
 					printf("%d",
-					       (vlan_entry.
-						vlan_entry_format.eg_ctrl >> 10)
-					       & 0x3);
+						(vlan_entry.vlan_entry_format.eg_ctrl >> 10) & 0x3);
 					printf("%d",
-					       (vlan_entry.
-						vlan_entry_format.eg_ctrl >> 12)
-					       & 0x3);
+						(vlan_entry.vlan_entry_format.eg_ctrl >> 12) & 0x3);
 				} else {
 					/* VTAG_EN=0 */
 					printf("DISABLED");
@@ -802,7 +763,7 @@
 
 	if (argc > 7) {
 		eg_con = strtoul(argv[7], NULL, 2);
-		eg_con = ! !eg_con;
+		eg_con = !!eg_con;
 		vlan_entry.vlan_entry_format.eg_con = eg_con;
 		vlan_entry.vlan_entry_format.eg_ctrl_en = 1;
 	}
@@ -817,8 +778,8 @@
 
 		for (i = 0; i < SWITCH_MAX_PORT; i++) {
 			if (argv[8][i] < '0' || argv[8][i] > '3') {
-				printf
-				    ("egtag portmap format error, should be of combination of 0 or 3\n");
+				printf("egtag portmap format error,");
+				printf("should be of combination of 0 or 3\n");
 				return;
 			}
 			eg_tag |= (argv[8][i] - '0') << (i * 2);
@@ -947,8 +908,8 @@
 		return;
 	}
 
-	printf("\r\nswitch qos base : %d. (port-based:0, tag-based:1,\
-		dscp-based:2, acl-based:3, arl-based:4, stag-based:5)\n", base);
+	printf("\r\nswitch qos base : %d. (port-based:0, tag-based:1,", base);
+	printf("dscp-based:2, acl-based:3, arl-based:4, stag-based:5)\n");
 	reg_read(0x10208030 + 0x200 * port, &value);
 	an8855_get_upw(&value, base);
 	reg_write(0x10208030 + 0x200 * port, value);
@@ -962,9 +923,8 @@
 
 	port = _strtoul(argv[3], NULL, 10);
 
-	for (i = 0; i < 8; i++) {
+	for (i = 0; i < 8; i++)
 		weight[i] = _strtoul(argv[i + 4], NULL, 10);
-	}
 
 	/* MT7530 total 7 port */
 	if (port < 0 || port > 6) {
@@ -978,13 +938,15 @@
 			return;
 		}
 	}
-	printf("port: %x, q0: %x, q1: %x, q2: %x, q3: %x, \
-		q4: %x, q5: %x, q6: %x, q7: %x\n", port, weight[0], weight[1], weight[2], weight[3], weight[4], weight[5], weight[6], weight[7]);
+	printf("port: %x, q0: %x, q1: %x, q2: %x, q3: %x,",
+		port, weight[0], weight[1], weight[2], weight[3]);
+	printf("q4: %x, q5: %x, q6: %x, q7: %x\n",
+		weight[4], weight[5], weight[6], weight[7]);
 
-	for (queue = 0; queue < 8; queue++) {
+	for (queue = 0; queue < 8; queue++)
 		air_qos_setScheduleAlgo(0, port, queue, AIR_QOS_SCH_MODE_WFQ,
 					weight[queue]);
-	}
+
 }
 
 void an8855_qos_set_portpri(int argc, char *argv[])
@@ -1096,17 +1058,19 @@
 		}
 	}
 
-	printf("index: %x, active: %x, vid: %x, portMap: %x, \
-		tagPortMap: %x, ivl_en: %x, fid: %x, stag: %x\n", index, active, vid, portMap, tagPortMap, ivl_en, fid, stag);
+	printf("index: %x, active: %x, vid: %x, portMap: %x,",
+		index, active, vid, portMap);
+	printf("tagPortMap: %x, ivl_en: %x, fid: %x, stag: %x\n",
+		tagPortMap, ivl_en, fid, stag);
 
-	vlan_entry.valid = ! !active;
+	vlan_entry.valid = !!active;
 	vlan_entry.vlan_entry_format.port_mem = portMap;
 	/* Total 6 ports */
 	for (i = 0; i < SWITCH_MAX_PORT; i++) {
 		if (tagPortMap & (1 << i))
 			vlan_entry.vlan_entry_format.eg_ctrl |= 0x2 << (i * 2);
 	}
-	vlan_entry.vlan_entry_format.ivl = ! !ivl_en;
+	vlan_entry.vlan_entry_format.ivl = !!ivl_en;
 	vlan_entry.vlan_entry_format.fid = fid;
 	vlan_entry.vlan_entry_format.stag = stag;
 
@@ -1234,9 +1198,8 @@
 		return;
 	}
 
-	for (port = 0; port < 6; port++) {
+	for (port = 0; port < 6; port++)
 		air_l2_setAgeEnable(0, port, aging_en);
-	}
 
 	air_l2_setMacAddrAgeOut(0, time);
 }
@@ -1264,9 +1227,8 @@
 		session.dst_port = mirror_port;
 		session.flags |= AIR_MIR_SESSION_FLAGS_ENABLE;
 		air_mir_addSession(0, 0, &session);
-	} else {
+	} else
 		air_mir_delSession(0, 0);
-	}
 
 	air_mir_setSessionAdminMode(0, 0, (int)mirror_en);
 }				/*end doMirrorEn */
@@ -1285,13 +1247,14 @@
 	vlan_mis = _strtoul(argv[7], NULL, 10);
 	igmp_mir = _strtoul(argv[8], NULL, 10);
 
-	printf
-	    ("port:%d, port_tx_mir:%d, port_rx_mir:%d, acl_mir:%d, vlan_mis:%d, igmp_mir:%d\n",
-	     port, port_tx_mir, port_rx_mir, acl_mir, vlan_mis, igmp_mir);
+	printf("port:%d, port_tx_mir:%d, port_rx_mir:%d, ",
+		port, port_tx_mir, port_rx_mir);
+	printf("acl_mir:%d, vlan_mis:%d, igmp_mir:%d\n",
+		acl_mir, vlan_mis, igmp_mir);
 
 	/*Check the input parameters is right or not. */
-	//if((port >= vlanCap->max_port_no) || (port_tx_mir > 1) || (port_rx_mir > 1) || (acl_mir > 1) || (vlan_mis > 1)){
-	if ((port >= SWITCH_MAX_PORT) || (port_tx_mir > 1) || (port_rx_mir > 1) || (acl_mir > 1) || (vlan_mis > 1)) {	// also allow CPU port (port6)
+	if ((port >= SWITCH_MAX_PORT) || (port_tx_mir > 1) || (port_rx_mir > 1)
+		|| (acl_mir > 1) || (vlan_mis > 1)) {	// also allow CPU port (port6)
 		printf(HELP_MIRROR_PORTBASED);
 		return;
 	}
@@ -1312,11 +1275,7 @@
 
 	air_mir_setMirrorPort(0, 0, &session);
 
-	/*
-
-	   not support acl/vlan/igmp mismatch
-
-	 */
+	/* not support acl/vlan/igmp mismatch */
 }				/*end doMirrorPortBased */
 
 void an8855_doStp(int argc, char *argv[])
@@ -1346,35 +1305,40 @@
 {
 	AIR_ERROR_NO_T ret = AIR_E_OK;
 	AIR_QOS_RATE_LIMIT_CFG_T rl = { 0 };
+
 	if (on_off) {
 		ret =
 		    air_qos_setRateLimitEnable(0, port,
 					       AIR_QOS_RATE_DIR_INGRESS, TRUE);
-		if (AIR_E_OK != ret) {
+		if (ret != AIR_E_OK) {
 			printf("an8855 set ingress ratelimit eanble fail\n");
 			return;
 		}
+		ret = air_qos_getRateLimit(0, port, &rl);
+		if (ret != AIR_E_OK) {
+			printf("an8855 get port %d ratelimit fail\n",
+				port);
+			return;
+		}
 		rl.ingress_cir = bw;
 		rl.flags |= AIR_QOS_RATE_LIMIT_CFG_FLAGS_ENABLE_INGRESS;
 		ret = air_qos_setRateLimit(0, port, &rl);
-		if (AIR_E_OK != ret) {
+		if (ret != AIR_E_OK) {
 			printf("an8855 set ingress ratelimit value %d fail\n",
 			       bw);
 			return;
-		} else {
-			printf("an8855 set ingress ratelimit value %d ok\n",
-			       bw);
 		}
+		printf("an8855 set ingress ratelimit value %d ok\n", bw);
 	} else {
 		ret =
 		    air_qos_setRateLimitEnable(0, port,
 					       AIR_QOS_RATE_DIR_INGRESS, FALSE);
-		if (AIR_E_OK != ret) {
+		if (ret != AIR_E_OK) {
 			printf("an8855 set ingress ratelimit disable fail\n");
 			return;
-		} else {
-			printf("an8855 set ingress ratelimit disable ok\n");
 		}
+		printf("an8855 set ingress ratelimit disable ok\n");
+
 	}
 }
 
@@ -1382,34 +1346,41 @@
 {
 	AIR_ERROR_NO_T ret = AIR_E_OK;
 	AIR_QOS_RATE_LIMIT_CFG_T rl = { 0 };
+
 	if (on_off) {
 		ret =
 		    air_qos_setRateLimitEnable(0, port, AIR_QOS_RATE_DIR_EGRESS,
 					       TRUE);
-		if (AIR_E_OK != ret) {
+		if (ret != AIR_E_OK) {
 			printf("an8855 set egress ratelimit eanble fail\n");
 			return;
 		}
+		ret = air_qos_getRateLimit(0, port, &rl);
+		if (ret != AIR_E_OK) {
+			printf("an8855 get port %d ratelimit fail\n",
+				port);
+			return;
+		}
 		rl.egress_cir = bw;
 		rl.flags |= AIR_QOS_RATE_LIMIT_CFG_FLAGS_ENABLE_EGRESS;
 		ret = air_qos_setRateLimit(0, port, &rl);
-		if (AIR_E_OK != ret) {
+		if (ret != AIR_E_OK) {
 			printf("an8855 set egress ratelimit value %d fail\n",
 			       bw);
 			return;
-		} else {
-			printf("an8855 set egress ratelimit value %d ok\n", bw);
 		}
+		printf("an8855 set egress ratelimit value %d ok\n", bw);
+
 	} else {
 		ret =
 		    air_qos_setRateLimitEnable(0, port, AIR_QOS_RATE_DIR_EGRESS,
 					       FALSE);
-		if (AIR_E_OK != ret) {
+		if (ret != AIR_E_OK) {
 			printf("an8855 set egress ratelimit disable fail\n");
 			return;
-		} else {
-			printf("an8855 set egress ratelimit disable ok\n");
 		}
+		printf("an8855 set egress ratelimit disable ok\n");
+
 	}
 }
 
@@ -1422,9 +1393,9 @@
 		bw = _strtoul(argv[4], NULL, 0);
 		on_off = 1;
 	} else if (argv[2][1] == 'f') {
-		if (argc != 4) {
+		if (argc != 4)
 			return;
-		}
+
 		on_off = 0;
 	}
 
@@ -1441,9 +1412,9 @@
 		bw = _strtoul(argv[4], NULL, 0);
 		on_off = 1;
 	} else if (argv[2][1] == 'f') {
-		if (argc != 4) {
+		if (argc != 4)
 			return;
-		}
+
 		on_off = 0;
 	}
 
@@ -1554,35 +1525,35 @@
 	queue[6] = (value & 0x3F0000) >> 16;
 	queue[7] = (value & 0x3F000000) >> 24;
 
-	printf("<===Free Page=======Current============Minimal=========> \n ");
-	printf("	                                                 \n ");
-	printf(" page counter      %u                %u               \n ",
+	printf("<===Free Page=======Current============Minimal=========>\n");
+	printf("\n");
+	printf(" page counter      %u                %u\n",
 	       free_page, free_page_min);
-	printf("                                                        \n ");
-	printf("========================================================= \n ");
-	printf("<===Type=======High threshold======Low threshold=========\n ");
-	printf("                                                        \n ");
-	printf("  system:         %u                 %u               \n",
+	printf("\n");
+	printf("=========================================================\n");
+	printf("<===Type=======High threshold======Low threshold=========\n");
+	printf("\n");
+	printf("  system:         %u                 %u\n",
 	       fc_free_blk_hithd * 2, fc_free_blk_lothd * 2);
-	printf("    port:         %u                 %u               \n",
+	printf("    port:         %u                 %u\n",
 	       fc_port_blk_hi_thd * 2, fc_port_blk_thd * 2);
-	printf(" queue 0:         %u                 NA                \n",
+	printf(" queue 0:         %u                 NA\n",
 	       queue[0]);
-	printf(" queue 1:         %u                 NA                \n",
+	printf(" queue 1:         %u                 NA\n",
 	       queue[1]);
-	printf(" queue 2:         %u                 NA                 \n",
+	printf(" queue 2:         %u                 NA\n",
 	       queue[2]);
-	printf(" queue 3:         %u                 NA                \n",
+	printf(" queue 3:         %u                 NA\n",
 	       queue[3]);
-	printf(" queue 4:         %u                 NA                \n",
+	printf(" queue 4:         %u                 NA\n",
 	       queue[4]);
-	printf(" queue 5:         %u                 NA                \n",
+	printf(" queue 5:         %u                 NA\n",
 	       queue[5]);
-	printf(" queue 6:         %u                 NA                \n",
+	printf(" queue 6:         %u                 NA\n",
 	       queue[6]);
-	printf(" queue 7:         %u                 NA                \n",
+	printf(" queue 7:         %u                 NA\n",
 	       queue[7]);
-	printf("=========================================================\n ");
+	printf("=========================================================\n");
 }
 
 void an8855_eee_enable(int argc, char *argv[])
@@ -1618,8 +1589,8 @@
 			port_map = 0;
 			for (p = 0; p < MAX_PHY_PORT; p++) {
 				if (argv[3][p] != '0' && argv[3][p] != '1') {
-					printf
-					    ("portmap format error, should be combination of 0 or 1\n");
+					printf("portmap format error, ");
+					printf("should be combination of 0 or 1\n");
 					goto error;
 				}
 				port_map |= ((argv[3][p] - '0') << p);
@@ -1636,11 +1607,11 @@
 	for (port_num = 0; port_num < MAX_PHY_PORT; port_num++) {
 		if (port_map & (1 << port_num)) {
 			air_port_getPsMode(0, port_num, &mode);
-			if (enable) {
+			if (enable)
 				mode |= AIR_PORT_PS_EEE;
-			} else {
+			else
 				mode &= ~AIR_PORT_PS_EEE;
-			}
+
 			air_port_setPsMode(0, port_num, mode);
 		}
 	}
@@ -1648,7 +1619,6 @@
 
 error:
 	printf(HELP_EEE_EN);
-	return;
 }
 
 void an8855_eee_dump(int argc, char *argv[])
@@ -1694,107 +1664,106 @@
 	AIR_MIB_CNT_RX_T rx_mib[7];
 	AIR_MIB_CNT_TX_T tx_mib[7];
 
-	printf("===================== %8s %8s %8s %8s %8s %8s %8s\n",
+	printf("======================== %8s %8s %8s %8s %8s %8s %8s\n",
 	       "Port0", "Port1", "Port2", "Port3", "Port4", "Port5", "Port6");
 
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		air_mib_get(0, port, &rx_mib[port], &tx_mib[port]);
-	}
 
 	printf("Tx Drop Packet      :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", tx_mib[port].TDPC);
-	}
+
 	printf("\n");
 	printf("Tx CRC Error        :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", tx_mib[port].TCRC);
-	}
+
 	printf("\n");
 	printf("Tx Unicast Packet   :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", tx_mib[port].TUPC);
-	}
+
 	printf("\n");
 	printf("Tx Multicast Packet :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", tx_mib[port].TMPC);
-	}
+
 	printf("\n");
 	printf("Tx Broadcast Packet :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", tx_mib[port].TBPC);
-	}
+
 	printf("\n");
 	printf("Tx Collision Event  :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", tx_mib[port].TCEC);
-	}
+
 	printf("\n");
 	printf("Tx Pause Packet     :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", tx_mib[port].TPPC);
-	}
+
 	printf("\n");
 	printf("Rx Drop Packet      :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].RDPC);
-	}
+
 	printf("\n");
 	printf("Rx Filtering Packet :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].RFPC);
-	}
+
 	printf("\n");
 	printf("Rx Unicast Packet   :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].RUPC);
-	}
+
 	printf("\n");
 	printf("Rx Multicast Packet :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].RMPC);
-	}
+
 	printf("\n");
 	printf("Rx Broadcast Packet :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].RBPC);
-	}
+
 	printf("\n");
 	printf("Rx Alignment Error  :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].RAEPC);
-	}
+
 	printf("\n");
 	printf("Rx CRC Error	    :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].RCEPC);
-	}
+
 	printf("\n");
 	printf("Rx Undersize Error  :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].RUSPC);
-	}
+
 	printf("\n");
 	printf("Rx Fragment Error   :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].RFEPC);
-	}
+
 	printf("\n");
 	printf("Rx Oversize Error   :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].ROSPC);
-	}
+
 	printf("\n");
 	printf("Rx Jabber Error     :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].RJEPC);
-	}
+
 	printf("\n");
 	printf("Rx Pause Packet     :");
-	for (port = 0; port < 7; port++) {
+	for (port = 0; port < 7; port++)
 		printf("%8u ", rx_mib[port].RPPC);
-	}
+
 	printf("\n");
 }
 
diff --git a/recipes-devtools/switch/files/src/switch_fun_an8855.h b/recipes-devtools/switch/files/src/switch_fun_an8855.h
index 1d67080..9be440f 100644
--- a/recipes-devtools/switch/files/src/switch_fun_an8855.h
+++ b/recipes-devtools/switch/files/src/switch_fun_an8855.h
@@ -1,6 +1,6 @@
 /*
-* switch_fun.h: switch function sets
-*/
+ * switch_fun.h: switch function sets
+ */
 #ifndef SWITCH_FUN_AN8855_H
 #define SWITCH_FUN_AN8855_H
 
@@ -16,7 +16,7 @@
 AIR_ERROR_NO_T
 an8855_phy_cl22_read(const UI32_T unit,
 		     const UI32_T port_id,
-		     const UI32_T addr_offset, UI32_T * ptr_data);
+		     const UI32_T addr_offset, UI32_T *ptr_data);
 
 AIR_ERROR_NO_T
 an8855_phy_cl22_write(const UI32_T unit,
@@ -27,7 +27,7 @@
 an8855_phy_cl45_read(const UI32_T unit,
 		     const UI32_T port_id,
 		     const UI32_T dev_type,
-		     const UI32_T addr_offset, UI32_T * ptr_data);
+		     const UI32_T addr_offset, UI32_T *ptr_data);
 
 AIR_ERROR_NO_T
 an8855_phy_cl45_write(const UI32_T unit,
@@ -40,38 +40,6 @@
 
 void an8855_not_supported(int argc, char *argv[]);
 
-#if 0
-/*acl setting*/
-void an8855_acl_mac_add(int argc, char *argv[]);
-void an8855_acl_dip_meter(int argc, char *argv[]);
-void an8855_acl_dip_trtcm(int argc, char *argv[]);
-void an8855_acl_ethertype(int argc, char *argv[]);
-void an8855_acl_ethertype(int argc, char *argv[]);
-void an8855_acl_dip_modify(int argc, char *argv[]);
-void an8855_acl_dip_pppoe(int argc, char *argv[]);
-void an8855_acl_dip_add(int argc, char *argv[]);
-void an8855_acl_l4_add(int argc, char *argv[]);
-void an8855_acl_sp_add(int argc, char *argv[]);
-
-void an8855_acl_port_enable(int argc, char *argv[]);
-void an8855_acl_table_add(int argc, char *argv[]);
-void an8855_acl_mask_table_add(int argc, char *argv[]);
-void an8855_acl_rule_table_add(int argc, char *argv[]);
-void an8855_acl_rate_table_add(int argc, char *argv[]);
-
-/*dip table*/
-void an8855_dip_dump(void);
-void an8855_dip_add(int argc, char *argv[]);
-void an8855_dip_del(int argc, char *argv[]);
-void an8855_dip_clear(void);
-
-/*sip table*/
-void an8855_sip_dump(void);
-void an8855_sip_add(int argc, char *argv[]);
-void an8855_sip_del(int argc, char *argv[]);
-void an8855_sip_clear(void);
-#endif
-
 /*stp*/
 void an8855_doStp(int argc, char *argv[]);
 
diff --git a/recipes-devtools/switch/files/src/switch_ioctl.c b/recipes-devtools/switch/files/src/switch_ioctl.c
index f6b97d4..dd9e621 100644
--- a/recipes-devtools/switch/files/src/switch_ioctl.c
+++ b/recipes-devtools/switch/files/src/switch_ioctl.c
@@ -164,7 +164,7 @@
 			break;
 		}
 	}
-	//printf(" PHY Indirect Access Control(0x701c) register read value =0x%x  \n", reg_value);
+	//printf(" PHY Indirect Access Control(0x701c) register read value =0x%x\n", reg_value);
 	*value = reg_value;
 
 	return 0;
@@ -205,7 +205,7 @@
 		}
 	}
 
-	//printf(" PHY Indirect Access Control(0x701c) register write value =0x%x  \n", reg_value);
+	//printf(" PHY Indirect Access Control(0x701c) register write value =0x%x\n", reg_value);
 
 	return 0;
 }
@@ -332,7 +332,7 @@
 		} else {
 			printf("MDIO cl45 set dev opeartion timeout\n");
 			reg_value = 0;
-			ret = -1; 
+			ret = -1;
 			goto out;
 		}
 	}
@@ -351,12 +351,12 @@
 		} else {
 			printf("MDIO cl45 read reg opeartion timeout\n");
 			reg_value = 0;
-			ret = -1; 
+			ret = -1;
 			break;
 		}
 	}
 out:
-	//printf(" PHY Indirect Access Control(0x701c) register read value =0x%x  \n", reg_value);
+	//printf(" PHY Indirect Access Control(0x701c) register read value =0x%x\n", reg_value);
 	*value = reg_value;
 
 	return ret;
@@ -384,7 +384,7 @@
 			loop_cnt++;
 		else {
 			printf("MDIO cl45 set dev opeartion timeout\n");
-			ret = -1; 
+			ret = -1;
 			goto out;
 		}
 	}
@@ -401,12 +401,12 @@
 			loop_cnt++;
 		else {
 			printf("MDIO cl45 write reg opeartion timeout\n");
-			ret = -1; 
+			ret = -1;
 			break;
 		}
 	}
 out:
-	//printf(" PHY Indirect Access Control(0x701c) register write value =0x%x  \n", reg_value);
+	//printf(" PHY Indirect Access Control(0x701c) register write value =0x%x\n", reg_value);
 	return ret;
 }
 
diff --git a/recipes-devtools/switch/files/src/switch_ioctl.h b/recipes-devtools/switch/files/src/switch_ioctl.h
index dffe9c7..3ee43d7 100644
--- a/recipes-devtools/switch/files/src/switch_ioctl.h
+++ b/recipes-devtools/switch/files/src/switch_ioctl.h
@@ -8,48 +8,43 @@
 #define ETH_DEVNAME "eth0"
 #define BR_DEVNAME "br-lan"
 
-#define RAETH_MII_READ                  0x89F3
-#define RAETH_MII_WRITE                 0x89F4
-#define RAETH_ESW_PHY_DUMP              0x89F7
+#define RAETH_MII_READ			0x89F3
+#define RAETH_MII_WRITE			0x89F4
+#define RAETH_ESW_PHY_DUMP		0x89F7
 
 struct esw_reg {
-        unsigned int off;
-        unsigned int val;
+	unsigned int off;
+	unsigned int val;
 };
 
 struct ra_mii_ioctl_data {
-        __u16 phy_id;
-        __u16 reg_num;
-        __u32 val_in;
-        __u32 val_out;
-/*
-        __u32 port_num;
-        __u32 dev_addr;
-        __u32 reg_addr;
-*/
+	__u16 phy_id;
+	__u16 reg_num;
+	__u32 val_in;
+	__u32 val_out;
 };
 
 struct ra_switch_ioctl_data {
-        unsigned int cmd;
-        unsigned int on_off;
-        unsigned int port;
-        unsigned int bw;
-        unsigned int vid;
-        unsigned int fid;
-        unsigned int port_map;
-        unsigned int rx_port_map;
-        unsigned int tx_port_map;
-        unsigned int igmp_query_interval;
-        unsigned int reg_addr;
-        unsigned int reg_val;
-        unsigned int mode;
-        unsigned int qos_queue_num;
-        unsigned int qos_type;
-        unsigned int qos_pri;
-        unsigned int qos_dscp;
-        unsigned int qos_table_idx;
-        unsigned int qos_weight;
-        unsigned char mac[6];
+	unsigned int cmd;
+	unsigned int on_off;
+	unsigned int port;
+	unsigned int bw;
+	unsigned int vid;
+	unsigned int fid;
+	unsigned int port_map;
+	unsigned int rx_port_map;
+	unsigned int tx_port_map;
+	unsigned int igmp_query_interval;
+	unsigned int reg_addr;
+	unsigned int reg_val;
+	unsigned int mode;
+	unsigned int qos_queue_num;
+	unsigned int qos_type;
+	unsigned int qos_pri;
+	unsigned int qos_dscp;
+	unsigned int qos_table_idx;
+	unsigned int qos_weight;
+	unsigned char mac[6];
 };
 
 extern int chip_name;
@@ -60,11 +55,11 @@
 int reg_write_ioctl(unsigned int offset, unsigned int value);
 int phy_dump_ioctl(unsigned int phy_addr);
 int mii_mgr_cl22_read_ioctl(unsigned int port_num, unsigned int reg,
-			    unsigned int *value);
+			unsigned int *value);
 int mii_mgr_cl22_write_ioctl(unsigned int port_num, unsigned int reg,
-			     unsigned int value);
+			unsigned int value);
 int mii_mgr_cl45_read_ioctl(unsigned int port_num, unsigned int dev,
-			    unsigned int reg, unsigned int *value);
+			unsigned int reg, unsigned int *value);
 int mii_mgr_cl45_write_ioctl(unsigned int port_num, unsigned int dev,
-			     unsigned int reg, unsigned int value);
+			unsigned int reg, unsigned int value);
 #endif
diff --git a/recipes-devtools/switch/files/src/switch_netlink.c b/recipes-devtools/switch/files/src/switch_netlink.c
index 397ebe5..f6f5fb0 100644
--- a/recipes-devtools/switch/files/src/switch_netlink.c
+++ b/recipes-devtools/switch/files/src/switch_netlink.c
@@ -44,7 +44,7 @@
 			    nla_get_string(attrs[MT753X_ATTR_TYPE_MESG]);
 			printf("register switch dev:\n%s", val->dev_info);
 		} else {
-			fprintf(stderr, "ERROR:No switch dev now\n");
+			printf("ERROR:No switch dev now\n");
 			goto done;
 		}
 	} else
@@ -132,7 +132,7 @@
 	/* Allocate an netllink message buffer */
 	msg = nlmsg_alloc();
 	if (!msg) {
-		fprintf(stderr, "Failed to allocate netlink message\n");
+		printf("Failed to allocate netlink message\n");
 		exit(1);
 	}
 	if (!construct) {
@@ -148,7 +148,7 @@
 	if (construct) {
 		err = construct(msg, arg);
 		if (err < 0) {
-			fprintf(stderr, "attributes error\n");
+			printf("attributes error\n");
 			goto nal_put_failure;
 		}
 	}
@@ -156,14 +156,14 @@
 	/* Allocate an new callback handler */
 	callback = nl_cb_alloc(NL_CB_CUSTOM);
 	if (!callback) {
-		fprintf(stderr, "Failed to allocate callback handler\n");
+		printf("Failed to allocate callback handler\n");
 		exit(1);
 	}
 
 	/* Send netlink message */
 	err = nl_send_auto_complete(user_sock, msg);
 	if (err < 0) {
-		fprintf(stderr, "nl_send_auto_complete failied:%d\n", err);
+		printf("nl_send_auto_complete failied:%d\n", err);
 		goto out;
 	}
 	finished = 0;
@@ -218,18 +218,18 @@
 	/* Allocate an new netlink socket */
 	user_sock = nl_socket_alloc();
 	if (!user_sock) {
-		fprintf(stderr, "Failed to create user socket\n");
+		printf("Failed to create user socket\n");
 		goto err;
 	}
 	/* Connetct the genl controller */
 	if (genl_connect(user_sock)) {
-		fprintf(stderr, "Failed to connetct to generic netlink\n");
+		printf("Failed to connetct to generic netlink\n");
 		goto err;
 	}
 	/* Allocate an new nl_cache */
 	ret = genl_ctrl_alloc_cache(user_sock, &cache);
 	if (ret < 0) {
-		fprintf(stderr, "Failed to allocate netlink cache\n");
+		printf("Failed to allocate netlink cache\n");
 		goto err;
 	}
 
@@ -254,7 +254,7 @@
 
 	err = mt753x_request_callback(cmd, list_swdevs, NULL, arg);
 	if (err < 0)
-		fprintf(stderr, "mt753x list dev error\n");
+		printf("mt753x list dev error\n");
 }
 
 static int mt753x_request(struct mt753x_attr *arg, int cmd)
@@ -263,7 +263,7 @@
 
 	err = mt753x_request_callback(cmd, spilt_attrs, construct_attrs, arg);
 	if (err < 0) {
-		fprintf(stderr, "mt753x deal request error\n");
+		printf("mt753x deal request error\n");
 		return err;
 	}
 	return 0;
@@ -279,7 +279,7 @@
 	attr->port_num = port_num;
 	attr->phy_dev = phy_dev;
 	attr->reg = offset;
-	attr->value = -1;
+	attr->value = 0;
 	attr->type = MT753X_ATTR_TYPE_REG;
 
 	switch (op) {
diff --git a/recipes-devtools/switch/files/src/switch_netlink.h b/recipes-devtools/switch/files/src/switch_netlink.h
index cb812d5..94d8389 100644
--- a/recipes-devtools/switch/files/src/switch_netlink.h
+++ b/recipes-devtools/switch/files/src/switch_netlink.h
@@ -1,6 +1,6 @@
 /*
  * switch_netlink.h: switch(netlink) set API
- * 
+ *
  * Author: Sirui Zhao <Sirui.Zhao@mediatek.com>
  */
 #ifndef MT753X_NETLINK_H
@@ -54,20 +54,16 @@
 int mt753x_netlink_init(const char *name);
 void mt753x_netlink_free(void);
 void mt753x_list_swdev(struct mt753x_attr *arg, int cmd);
-int reg_read_netlink(struct mt753x_attr *arg, unsigned int offset,
-		     unsigned int *value);
-int reg_write_netlink(struct mt753x_attr *arg, unsigned int offset,
-		      unsigned int value);
+int reg_read_netlink(struct mt753x_attr *arg, unsigned int offset, unsigned int *value);
+int reg_write_netlink(struct mt753x_attr *arg, unsigned int offset, unsigned int value);
 int phy_cl22_read_netlink(struct mt753x_attr *arg, unsigned int port_num,
-			  unsigned int phy_addr, unsigned int *value);
+			unsigned int phy_addr, unsigned int *value);
 int phy_cl22_write_netlink(struct mt753x_attr *arg, unsigned int port_num,
-			   unsigned int phy_addr, unsigned int value);
+			unsigned int phy_addr, unsigned int value);
 int phy_cl45_read_netlink(struct mt753x_attr *arg, unsigned int port_num,
-			  unsigned int phy_dev, unsigned int phy_addr,
-			  unsigned int *value);
+			unsigned int phy_dev, unsigned int phy_addr, unsigned int *value);
 int phy_cl45_write_netlink(struct mt753x_attr *arg, unsigned int port_num,
-			   unsigned int phy_dev, unsigned int phy_addr,
-			   unsigned int value);
+			unsigned int phy_dev, unsigned int phy_addr, unsigned int value);
 int phy_dump_netlink(struct mt753x_attr *arg, int phy_addr);
 
 #endif
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/generic/pending-5.4/680-NET-skip-GRO-for-foreign-MAC-addresses.patch b/recipes-kernel/linux/linux-mediatek-5.4/generic/pending-5.4/680-NET-skip-GRO-for-foreign-MAC-addresses.patch
index bec6787..987a4f6 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/generic/pending-5.4/680-NET-skip-GRO-for-foreign-MAC-addresses.patch
+++ b/recipes-kernel/linux/linux-mediatek-5.4/generic/pending-5.4/680-NET-skip-GRO-for-foreign-MAC-addresses.patch
@@ -115,35 +115,3 @@
  	call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
  	add_device_randomness(dev->dev_addr, dev->addr_len);
  	return 0;
---- a/net/ethernet/eth.c
-+++ b/net/ethernet/eth.c
-@@ -143,6 +143,18 @@ u32 eth_get_headlen(const struct net_dev
- }
- EXPORT_SYMBOL(eth_get_headlen);
- 
-+static inline bool
-+eth_check_local_mask(const void *addr1, const void *addr2, const void *mask)
-+{
-+	const u16 *a1 = addr1;
-+	const u16 *a2 = addr2;
-+	const u16 *m = mask;
-+
-+	return (((a1[0] ^ a2[0]) & ~m[0]) |
-+		((a1[1] ^ a2[1]) & ~m[1]) |
-+		((a1[2] ^ a2[2]) & ~m[2]));
-+}
-+
- /**
-  * eth_type_trans - determine the packet's protocol ID.
-  * @skb: received socket data
-@@ -174,6 +186,10 @@ __be16 eth_type_trans(struct sk_buff *sk
- 		} else {
- 			skb->pkt_type = PACKET_OTHERHOST;
- 		}
-+
-+		if (eth_check_local_mask(eth->h_dest, dev->dev_addr,
-+					 dev->local_addr_mask))
-+			skb->gro_skip = 1;
- 	}
- 
- 	/*
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855.c
index b0ba4be..78cfbdc 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855.c
@@ -20,12 +20,72 @@
 #include <linux/gpio/consumer.h>
 #include <net/dsa.h>
 #include <linux/of_address.h>
+#include <linux/seq_file.h>
+#include <linux/proc_fs.h>
+#include <linux/version.h>
 
 #include "an8855.h"
 #include "an8855_nl.h"
+#include "an8855_phy.h"
 
 /* AN8855 driver version */
-#define ARHT_AN8855_DSA_DRIVER_VER	"1.0.1-L5.4"
+#define ARHT_AN8855_DSA_DRIVER_VER	"1.0.2"
+
+#define ARHT_CHIP_NAME                  "an8855"
+#define ARHT_PROC_DIR                   "air_sw"
+#define ARHT_PROC_NODE_DEVICE           "device"
+
+struct proc_dir_entry *proc_an8855_dsa_dir;
+
+/* T830 AN8855 Reference Board */
+static const struct an8855_led_cfg led_cfg[] = {
+/*************************************************************************
+ * Enable, LED idx, LED Polarity, LED ON event,  LED Blink event  LED Freq
+ *************************************************************************
+ */
+	/* GPIO0 */
+	{1, P4_LED0, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO1 */
+	{1, P4_LED1, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO2 */
+	{1, P0_LED0, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO3 */
+	{1, P0_LED1, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO4 */
+	{1, P1_LED0, LED_LOW,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO5 */
+	{1, P1_LED1, LED_LOW,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO6 */
+	{0, PHY_LED_MAX, LED_LOW,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO7 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO8 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO9 */
+	{1, P2_LED0, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO10 */
+	{1, P2_LED1, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO11 */
+	{1, P3_LED0, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO12 */
+	{1, P3_LED1, LED_HIGH,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO13 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO14 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO15 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO16 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO17 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO18 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO19 */
+	{0, PHY_LED_MAX, LED_LOW,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO20 */
+	{0, PHY_LED_MAX, LED_LOW,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+};
 
 /* String, offset, and register size in bytes if different from 4 bytes */
 static const struct an8855_mib_desc an8855_mib[] = {
@@ -99,7 +159,6 @@
 	ret = bus->write(bus, priv->phy_base, 0x14, (val & 0xFFFF));
 
 	ret = bus->write(bus, priv->phy_base, 0x1f, 0);
-	ret = bus->write(bus, priv->phy_base, 0x10, 0);
 
 	if (ret < 0) {
 		dev_err(&bus->dev, "failed to write an8855 register\n");
@@ -130,7 +189,6 @@
 	hi = bus->read(bus, priv->phy_base, 0x17);
 
 	ret = bus->write(bus, priv->phy_base, 0x1f, 0);
-	ret = bus->write(bus, priv->phy_base, 0x10, 0);
 	if (ret < 0) {
 		dev_err(&bus->dev, "failed to read an8855 register\n");
 		return ret;
@@ -327,16 +385,22 @@
 static int
 an8855_cl45_read(struct an8855_priv *priv, int port, int devad, int regnum)
 {
-	regnum = MII_ADDR_C45 | (devad << 16) | regnum;
-	return mdiobus_read_nested(priv->bus, port, regnum);
+	an8855_cl22_write(priv, port, 0x0d, devad);
+	an8855_cl22_write(priv, port, 0x0e, regnum);
+	an8855_cl22_write(priv, port, 0x0d, devad | (0x4000));
+	return an8855_cl22_read(priv, port, 0x0e);
 }
 
 static int
 an8855_cl45_write(struct an8855_priv *priv, int port, int devad, int regnum,
 		      u16 val)
 {
-	regnum = MII_ADDR_C45 | (devad << 16) | regnum;
-	return mdiobus_write_nested(priv->bus, port, regnum, val);
+	an8855_cl22_write(priv, port, 0x0d, devad);
+	an8855_cl22_write(priv, port, 0x0e, regnum);
+	an8855_cl22_write(priv, port, 0x0d, devad | (0x4000));
+	an8855_cl22_write(priv, port, 0x0e, val);
+
+	return 0;
 }
 
 int
@@ -457,7 +521,6 @@
 	priv->ports[port].pm |= PORTMATRIX_MATRIX(BIT(AN8855_CPU_PORT));
 	priv->ports[port].enable = true;
 	an8855_write(priv, AN8855_PORTMATRIX_P(port), priv->ports[port].pm);
-	an8855_clear(priv, AN8855_PMCR_P(port), PMCR_LINK_SETTINGS_MASK);
 
 	mutex_unlock(&priv->reg_mutex);
 
@@ -479,7 +542,6 @@
 	 */
 	priv->ports[port].enable = false;
 	an8855_write(priv, AN8855_PORTMATRIX_P(port), PORTMATRIX_CLR);
-	an8855_clear(priv, AN8855_PMCR_P(port), PMCR_LINK_SETTINGS_MASK);
 
 	mutex_unlock(&priv->reg_mutex);
 }
@@ -1085,6 +1147,216 @@
 		dev_dbg(ds->dev, "Add unused port%d to reserved VLAN%d group\n",
 			i, AN8855_RESERVED_VLAN);
 	}
+
+	return 0;
+}
+
+static int an8855_led_set_usr_def(struct dsa_switch *ds, u8 entity,
+		int polar, u16 on_evt, u16 blk_evt, u8 led_freq)
+{
+	struct an8855_priv *priv = ds->priv;
+	u32 cl45_data = 0;
+
+	if (polar == LED_HIGH)
+		on_evt |= LED_ON_POL;
+	else
+		on_evt &= ~LED_ON_POL;
+
+	/* LED on event */
+	an8855_phy_cl45_write(priv, (entity / 4), PHY_DEV1E,
+		PHY_SINGLE_LED_ON_CTRL(entity % 4), on_evt | LED_ON_EN);
+
+	/* LED blink event */
+	an8855_phy_cl45_write(priv, (entity / 4), PHY_DEV1E,
+		PHY_SINGLE_LED_BLK_CTRL(entity % 4), blk_evt);
+
+	/* LED freq */
+	switch (led_freq) {
+	case AIR_LED_BLK_DUR_32M:
+		cl45_data = 0x30e;
+		break;
+	case AIR_LED_BLK_DUR_64M:
+		cl45_data = 0x61a;
+		break;
+	case AIR_LED_BLK_DUR_128M:
+		cl45_data = 0xc35;
+		break;
+	case AIR_LED_BLK_DUR_256M:
+		cl45_data = 0x186a;
+		break;
+	case AIR_LED_BLK_DUR_512M:
+		cl45_data = 0x30d4;
+		break;
+	case AIR_LED_BLK_DUR_1024M:
+		cl45_data = 0x61a8;
+		break;
+	default:
+		break;
+	}
+	an8855_phy_cl45_write(priv, (entity / 4), PHY_DEV1E,
+		PHY_SINGLE_LED_BLK_DUR(entity % 4), cl45_data);
+
+	an8855_phy_cl45_write(priv, (entity / 4), PHY_DEV1E,
+		PHY_SINGLE_LED_ON_DUR(entity % 4), (cl45_data >> 1));
+
+	/* Disable DATA & BAD_SSD for port LED blink behavior */
+	cl45_data = an8855_phy_cl45_read(priv, (entity / 4), PHY_DEV1E,
+		PHY_PMA_CTRL);
+	cl45_data &= ~BIT(0);
+	cl45_data &= ~BIT(15);
+	an8855_phy_cl45_write(priv, (entity / 4), PHY_DEV1E,
+		PHY_PMA_CTRL, cl45_data);
+
+	return 0;
+}
+
+static int an8855_led_set_mode(struct dsa_switch *ds, u8 mode)
+{
+	struct an8855_priv *priv = ds->priv;
+	u16 cl45_data;
+
+	cl45_data = an8855_phy_cl45_read(priv, 0, PHY_DEV1F, PHY_LED_BCR);
+	switch (mode) {
+	case AN8855_LED_MODE_DISABLE:
+		cl45_data &= ~LED_BCR_EXT_CTRL;
+		cl45_data &= ~LED_BCR_MODE_MASK;
+		cl45_data |= LED_BCR_MODE_DISABLE;
+		break;
+	case AN8855_LED_MODE_USER_DEFINE:
+		cl45_data |= LED_BCR_EXT_CTRL;
+		cl45_data |= LED_BCR_CLK_EN;
+		break;
+	default:
+		dev_err(priv->dev, "LED mode%d is not supported!\n", mode);
+		return -EINVAL;
+	}
+	an8855_phy_cl45_write(priv, 0, PHY_DEV1F, PHY_LED_BCR, cl45_data);
+
+	return 0;
+}
+
+static int an8855_led_set_state(struct dsa_switch *ds, u8 entity, u8 state)
+{
+	struct an8855_priv *priv = ds->priv;
+	u16 cl45_data = 0;
+
+	/* Change to per port contorl */
+	cl45_data = an8855_phy_cl45_read(priv, (entity / 4), PHY_DEV1E,
+		PHY_LED_CTRL_SELECT);
+
+	if (state == 1)
+		cl45_data |= (1 << (entity % 4));
+	else
+		cl45_data &= ~(1 << (entity % 4));
+
+	an8855_phy_cl45_write(priv, (entity / 4), PHY_DEV1E,
+		PHY_LED_CTRL_SELECT, cl45_data);
+
+	/* LED enable setting */
+	cl45_data = an8855_phy_cl45_read(priv, (entity / 4),
+		PHY_DEV1E, PHY_SINGLE_LED_ON_CTRL(entity % 4));
+
+	if (state == 1)
+		cl45_data |= LED_ON_EN;
+	else
+		cl45_data &= ~LED_ON_EN;
+
+	an8855_phy_cl45_write(priv, (entity / 4), PHY_DEV1E,
+		PHY_SINGLE_LED_ON_CTRL(entity % 4), cl45_data);
+
+	return 0;
+}
+
+static int an8855_led_init(struct dsa_switch *ds)
+{
+	struct an8855_priv *priv = ds->priv;
+	u32 val, led_count = ARRAY_SIZE(led_cfg);
+	int ret = 0, id;
+	u32 tmp_val = 0;
+	u32 tmp_id = 0;
+
+	ret = an8855_led_set_mode(ds, AN8855_LED_MODE_USER_DEFINE);
+	if (ret != 0) {
+		dev_err(priv->dev, "led_set_mode fail(ret:%d)!\n", ret);
+		return ret;
+	}
+
+	for (id = 0; id < led_count; id++) {
+		ret = an8855_led_set_state(ds,
+			led_cfg[id].phy_led_idx, led_cfg[id].en);
+		if (ret != 0) {
+			dev_err(priv->dev, "led_set_state fail(ret:%d)!\n", ret);
+			return ret;
+		}
+		if (led_cfg[id].en == 1) {
+			ret = an8855_led_set_usr_def(ds,
+				led_cfg[id].phy_led_idx,
+				led_cfg[id].pol, led_cfg[id].on_cfg,
+				led_cfg[id].blk_cfg,
+				led_cfg[id].led_freq);
+			if (ret != 0) {
+				dev_err(priv->dev, "led_set_usr_def fail!\n");
+				return ret;
+			}
+		}
+	}
+
+	/* Setting for System LED & Loop LED */
+	an8855_write(priv, RG_GPIO_OE, 0x0);
+	an8855_write(priv, RG_GPIO_CTRL, 0x0);
+	val = 0;
+	an8855_write(priv, RG_GPIO_L_INV, val);
+
+	val = 0x1001;
+	an8855_write(priv, RG_GPIO_CTRL, val);
+	val = an8855_read(priv, RG_GPIO_DATA);
+	val |= BITS(1, 3);
+	val &= ~(BIT(0));
+	val &= ~(BIT(6));
+
+	an8855_write(priv, RG_GPIO_DATA, val);
+	val = an8855_read(priv, RG_GPIO_OE);
+	val |= 0x41;
+	an8855_write(priv, RG_GPIO_OE, val);
+
+	/* Mapping between GPIO & LED */
+	val = 0;
+	for (id = 0; id < led_count; id++) {
+		/* Skip GPIO6, due to GPIO6 does not support PORT LED */
+		if (id == 6)
+			continue;
+
+		if (led_cfg[id].en == 1) {
+			if (id < 7)
+				val |= led_cfg[id].phy_led_idx << ((id % 4) * 8);
+			else
+				val |= led_cfg[id].phy_led_idx << (((id - 1) % 4) * 8);
+		}
+
+		if (id < 7)
+			tmp_id = id;
+		else
+			tmp_id = id - 1;
+
+		if ((tmp_id % 4) == 0x3) {
+			an8855_write(priv, RG_GPIO_LED_SEL(tmp_id / 4), val);
+			tmp_val = an8855_read(priv, RG_GPIO_LED_SEL(tmp_id / 4));
+			val = 0;
+		}
+	}
+
+	/* Turn on LAN LED mode */
+	val = 0;
+	for (id = 0; id < led_count; id++) {
+		if (led_cfg[id].en == 1)
+			val |= 0x1 << id;
+	}
+	an8855_write(priv, RG_GPIO_LED_MODE, val);
+
+	/* Force clear blink pulse for per port LED */
+	an8855_phy_cl45_write(priv, 0, PHY_DEV1F, PHY_LED_BLINK_DUR_CTRL, 0x1f);
+	usleep_range(1000, 5000);
+	an8855_phy_cl45_write(priv, 0, PHY_DEV1F, PHY_LED_BLINK_DUR_CTRL, 0);
 
 	return 0;
 }
@@ -1095,7 +1367,7 @@
 	struct an8855_priv *priv = ds->priv;
 	struct an8855_dummy_poll p;
 	u32 unused_pm = 0;
-	u32 val, id;
+	u32 val, id, led_count = ARRAY_SIZE(led_cfg);
 	int ret, i;
 
 	/* Reset whole chip through gpio pin or memory-mapped registers for
@@ -1130,6 +1402,63 @@
 		priv->phy_base = priv->phy_base_new;
 	}
 
+	for (i = 0; i < AN8855_NUM_PHYS; i++) {
+		val = an8855_phy_read(ds, i, MII_BMCR);
+		val |= BMCR_ISOLATE;
+		an8855_phy_write(ds, i, MII_BMCR, val);
+	}
+
+	/* AN8855H need to setup before switch init */
+	val = an8855_read(priv, PKG_SEL);
+	if ((val & 0x7) == PAG_SEL_AN8855H) {
+		/* Invert for LED activity change */
+		val = an8855_read(priv, RG_GPIO_L_INV);
+		for (id = 0; id < led_count; id++) {
+			if ((led_cfg[id].pol == LED_HIGH) &&
+				(led_cfg[id].en == 1))
+				val |= 0x1 << id;
+		}
+		an8855_write(priv, RG_GPIO_L_INV, (val | 0x1));
+
+		/* MCU NOP CMD */
+		an8855_write(priv, RG_GDMP_RAM, 0x846);
+		an8855_write(priv, RG_GDMP_RAM + 4, 0x4a);
+
+		/* Enable MCU */
+		val = an8855_read(priv, RG_CLK_CPU_ICG);
+		an8855_write(priv, RG_CLK_CPU_ICG, val | MCU_ENABLE);
+		usleep_range(1000, 5000);
+
+		/* Disable MCU watchdog */
+		val = an8855_read(priv, RG_TIMER_CTL);
+		an8855_write(priv, RG_TIMER_CTL, (val & (~WDOG_ENABLE)));
+
+		/* Configure interrupt */
+		an8855_write(priv, RG_INTB_MODE, (0x1 << priv->intr_pin));
+
+		/* LED settings for T830 reference board */
+		ret = an8855_led_init(ds);
+		if (ret < 0) {
+			dev_err(priv->dev, "an8855_led_init fail. (ret=%d)\n", ret);
+			return ret;
+		}
+	}
+
+	/* Adjust to reduce noise */
+	for (i = 0; i < AN8855_NUM_PHYS; i++) {
+		an8855_phy_cl45_write(priv, i, PHY_DEV1E,
+			PHY_TX_PAIR_DLY_SEL_GBE, 0x4040);
+
+		an8855_phy_cl45_write(priv, i, PHY_DEV1E,
+			PHY_RXADC_CTRL, 0x1010);
+
+		an8855_phy_cl45_write(priv, i, PHY_DEV1E,
+			PHY_RXADC_REV_0, 0x100);
+
+		an8855_phy_cl45_write(priv, i, PHY_DEV1E,
+			PHY_RXADC_REV_1, 0x100);
+	}
+
 	/* Let phylink decide the interface later. */
 	priv->p5_interface = PHY_INTERFACE_MODE_NA;
 
@@ -1139,6 +1468,10 @@
 	an8855_rmw(priv, AN8855_BPC, AN8855_BPDU_PORT_FW_MASK,
 		   AN8855_BPDU_CPU_ONLY);
 
+	val = an8855_read(priv, AN8855_CKGCR);
+	val &= ~(CKG_LNKDN_GLB_STOP | CKG_LNKDN_PORT_STOP);
+	an8855_write(priv, AN8855_CKGCR, val);
+
 	/* Enable and reset MIB counters */
 	an8855_mib_reset(ds);
 
@@ -1157,8 +1490,18 @@
 			   PVC_EG_TAG(AN8855_VLAN_EG_CONSISTENT));
 	}
 
+	for (i = 0; i < AN8855_NUM_PHYS; i++) {
+		val = an8855_phy_read(ds, i, MII_BMCR);
+		val &= ~BMCR_ISOLATE;
+		an8855_phy_write(ds, i, MII_BMCR, val);
+	}
+
 	an8855_phy_setup(ds);
 
+	/* PHY restart AN*/
+	for (i = 0; i < AN8855_NUM_PHYS; i++)
+		an8855_phy_write(ds, i, MII_BMCR, 0x1240);
+
 	/* Group and enable unused ports as a standalone dumb switch. */
 	setup_unused_ports(ds, unused_pm);
 
@@ -1255,6 +1598,28 @@
 {
 	u32 val = 0;
 
+	/* TX FIR - improve TX EYE */
+	val = an8855_read(priv, INTF_CTRL_10);
+	val &= ~(0x3f << 16);
+	val |= BIT(21);
+	val &= ~(0x1f << 24);
+	val |= (0x4 << 24);
+	val |= BIT(29);
+	an8855_write(priv, INTF_CTRL_10, val);
+
+	val = an8855_read(priv, INTF_CTRL_11);
+	val &= ~(0x3f);
+	val |= BIT(6);
+	an8855_write(priv, INTF_CTRL_11, val);
+
+	/* RX CDR - improve RX Jitter Tolerance */
+	val = an8855_read(priv, RG_QP_CDR_LPF_BOT_LIM);
+	val &= ~(0x7 << 24);
+	val |= (0x5 << 24);
+	val &= ~(0x7 << 20);
+	val |= (0x5 << 20);
+	an8855_write(priv, RG_QP_CDR_LPF_BOT_LIM, val);
+
 	/* PLL */
 	val = an8855_read(priv, QP_DIG_MODE_CTRL_1);
 	val &= ~(0x3 << 2);
@@ -1384,7 +1749,7 @@
 	val &= ~(0xf << 25);
 	val |= (0x1 << 25);
 	val &= ~(0x7 << 29);
-	val |= (0x3 << 29);
+	val |= (0x6 << 29);
 	an8855_write(priv, RG_QP_CDR_LPF_SETVALUE, val);
 
 	val = an8855_read(priv, RG_QP_CDR_PR_CKREF_DIV1);
@@ -1415,12 +1780,9 @@
 	val |= (0x4 << 24);
 	an8855_write(priv, RG_QP_CDR_PR_CKREF_DIV1, val);
 
-	val = an8855_read(priv, PLL_CTRL_0);
-	val |= BIT(0);
-	an8855_write(priv, PLL_CTRL_0, val);
-
 	val = an8855_read(priv, RX_CTRL_26);
-	val &= ~BIT(23);
+	val |= BIT(23);
+	val &= ~BIT(24);
 	val |= BIT(26);
 	an8855_write(priv, RX_CTRL_26, val);
 
@@ -1448,8 +1810,8 @@
 	val = an8855_read(priv, RX_CTRL_8);
 	val &= ~(0xfff << 16);
 	val |= (0x200 << 16);
-	val &= ~(0x7fff << 14);
-	val |= (0xfff << 14);
+	val &= ~(0x7fff << 0);
+	val |= (0xfff << 0);
 	an8855_write(priv, RX_CTRL_8, val);
 
 	/* Frequency memter */
@@ -1468,6 +1830,10 @@
 	val |= (0x2710 << 0);
 	an8855_write(priv, RX_CTRL_7, val);
 
+	val = an8855_read(priv, PLL_CTRL_0);
+	val |= BIT(0);
+	an8855_write(priv, PLL_CTRL_0, val);
+
 	/* PCS Init */
 	val = an8855_read(priv, RG_HSGMII_PCS_CTROL_1);
 	val &= ~BIT(30);
@@ -1507,6 +1873,28 @@
 {
 	u32 val = 0;
 
+	/* TX FIR - improve TX EYE */
+	val = an8855_read(priv, INTF_CTRL_10);
+	val &= ~(0x3f << 16);
+	val |= BIT(21);
+	val &= ~(0x1f << 24);
+	val |= BIT(29);
+	an8855_write(priv, INTF_CTRL_10, val);
+
+	val = an8855_read(priv, INTF_CTRL_11);
+	val &= ~(0x3f);
+	val |= (0xd << 0);
+	val |= BIT(6);
+	an8855_write(priv, INTF_CTRL_11, val);
+
+	/* RX CDR - improve RX Jitter Tolerance */
+	val = an8855_read(priv, RG_QP_CDR_LPF_BOT_LIM);
+	val &= ~(0x7 << 24);
+	val |= (0x6 << 24);
+	val &= ~(0x7 << 20);
+	val |= (0x6 << 20);
+	an8855_write(priv, RG_QP_CDR_LPF_BOT_LIM, val);
+
 	/* PMA Init */
 	/* PLL */
 	val = an8855_read(priv, QP_DIG_MODE_CTRL_1);
@@ -1666,15 +2054,10 @@
 	val |= (0x4 << 24);
 	an8855_write(priv, RG_QP_CDR_PR_CKREF_DIV1, val);
 
-	val = an8855_read(priv, PLL_CTRL_0);
-	val |= BIT(0);
-	an8855_write(priv, PLL_CTRL_0, val);
-
 	val = an8855_read(priv, RX_CTRL_26);
-	val &= ~BIT(23);
-	if (mode == SGMII_MODE_AN)
+	val |= BIT(23);
+	val &= ~BIT(24);
 		val |= BIT(26);
-
 	an8855_write(priv, RX_CTRL_26, val);
 
 	val = an8855_read(priv, RX_DLY_0);
@@ -1721,6 +2104,10 @@
 	val |= (0x2710 << 0);
 	an8855_write(priv, RX_CTRL_7, val);
 
+	val = an8855_read(priv, PLL_CTRL_0);
+	val |= BIT(0);
+	an8855_write(priv, PLL_CTRL_0, val);
+
 	if (mode == SGMII_MODE_FORCE) {
 		/* PCS Init */
 		val = an8855_read(priv, QP_DIG_MODE_CTRL_0);
@@ -1805,7 +2192,6 @@
 		/* Restart AN */
 		val = an8855_read(priv, SGMII_REG_AN0);
 		val |= BIT(9);
-		val |= BIT(15);
 		an8855_write(priv, SGMII_REG_AN0, val);
 	}
 
@@ -1923,16 +2309,6 @@
 }
 
 static void
-an8855_phylink_mac_link_down(struct dsa_switch *ds, int port,
-					 unsigned int mode,
-					 phy_interface_t interface)
-{
-	struct an8855_priv *priv = ds->priv;
-
-	an8855_clear(priv, AN8855_PMCR_P(port), PMCR_LINK_SETTINGS_MASK);
-}
-
-static void
 an8855_phylink_mac_link_up(struct dsa_switch *ds, int port,
 				       unsigned int mode,
 				       phy_interface_t interface,
@@ -2194,6 +2570,51 @@
 	return priv->info->phy_write(ds, port, regnum, val);
 }
 
+static int an8855_proc_device_read(struct seq_file *seq, void *v)
+{
+	seq_printf(seq, "%s\n", ARHT_CHIP_NAME);
+
+	return 0;
+}
+
+static int an8855_proc_device_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, an8855_proc_device_read, 0);
+}
+
+#if (KERNEL_VERSION(5, 6, 0) <= LINUX_VERSION_CODE)
+static const struct proc_ops an8855_proc_device_fops = {
+	.proc_open	= an8855_proc_device_open,
+	.proc_read	= seq_read,
+	.proc_lseek	= seq_lseek,
+	.proc_release	= single_release,
+};
+#else
+static const struct file_operations an8855_proc_device_fops = {
+	.owner	= THIS_MODULE,
+	.open	= an8855_proc_device_open,
+	.read	= seq_read,
+	.llseek	= seq_lseek,
+	.release	= single_release,
+};
+#endif
+
+static int an8855_proc_device_init(void)
+{
+	if (!proc_an8855_dsa_dir)
+		proc_an8855_dsa_dir = proc_mkdir(ARHT_PROC_DIR, 0);
+
+	proc_create(ARHT_PROC_NODE_DEVICE, 0400, proc_an8855_dsa_dir,
+			&an8855_proc_device_fops);
+
+	return 0;
+}
+
+static void an8855_proc_device_exit(void)
+{
+	remove_proc_entry(ARHT_PROC_NODE_DEVICE, 0);
+}
+
 static const struct dsa_switch_ops an8855_switch_ops = {
 	.get_tag_protocol = air_get_tag_protocol,
 	.setup = an8855_sw_setup,
@@ -2217,10 +2638,6 @@
 	.port_mirror_add = an8855_port_mirror_add,
 	.port_mirror_del = an8855_port_mirror_del,
 	.phylink_validate = an8855_phylink_validate,
-	.phylink_mac_link_state = an8855_sw_phylink_mac_link_state,
-	.phylink_mac_config = an8855_phylink_mac_config,
-	.phylink_mac_link_down = an8855_phylink_mac_link_down,
-	.phylink_mac_link_up = an8855_phylink_mac_link_up,
 	.get_mac_eee = an8855_get_mac_eee,
 	.set_mac_eee = an8855_set_mac_eee,
 };
@@ -2308,6 +2725,13 @@
 	if ((ret < 0) || (priv->phy_base_new > 0x1f))
 		priv->phy_base_new = -1;
 
+	/* Assign AN8855 interrupt pin */
+	if (of_property_read_u32(dn, "airoha,intr", &priv->intr_pin))
+		priv->intr_pin = AN8855_DFL_INTR_ID;
+
+	if (of_property_read_u32(dn, "airoha,extSurge", &priv->extSurge))
+		priv->extSurge = AN8855_DFL_EXT_SURGE;
+
 	priv->bus = mdiodev->bus;
 	priv->dev = &mdiodev->dev;
 	priv->ds->priv = priv;
@@ -2324,6 +2748,7 @@
 	}
 	an8855_nl_init(&priv);
 
+	an8855_proc_device_init();
 	return 0;
 }
 
@@ -2338,6 +2763,8 @@
 	if (priv->base)
 		iounmap(priv->base);
 
+	an8855_proc_device_exit();
+
 	an8855_nl_exit();
 }
 
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855.h b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855.h
index 531d9be..6c472c2 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855.h
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855.h
@@ -10,10 +10,13 @@
 
 #define AN8855_NUM_PORTS				6
 #define AN8855_CPU_PORT					5
+#define AN8855_WORD_SIZE				4
 #define AN8855_NUM_FDB_RECORDS			2048
 #define AN8855_ALL_MEMBERS				0x3f
 #define AN8855_RESERVED_VLAN			2
 #define AN8855_GPHY_SMI_ADDR_DEFAULT	1
+#define AN8855_DFL_INTR_ID				0xd
+#define AN8855_DFL_EXT_SURGE			0x0
 
 enum an8855_id {
 	ID_AN8855 = 0,
@@ -286,6 +289,8 @@
 #define AN8855_CKGCR			(0x10213e1c)
 #define LPI_TXIDLE_THD			14
 #define LPI_TXIDLE_THD_MASK		BITS(14, 31)
+#define CKG_LNKDN_GLB_STOP	0x01
+#define CKG_LNKDN_PORT_STOP	0x02
 
 /* Register for MIB */
 #define AN8855_PORT_MIB_COUNTER(x)	(0x10214000 + (x) * 0x200)
@@ -303,18 +308,14 @@
 					 CCR_RX_OCT_CNT_BAD | \
 					 CCR_TX_OCT_CNT_GOOD | \
 					 CCR_TX_OCT_CNT_BAD | \
-					 CCR_RX_OCT_CNT_GOOD_2 | \
 					 CCR_RX_OCT_CNT_BAD_2 | \
-					 CCR_TX_OCT_CNT_GOOD_2 | \
 					 CCR_TX_OCT_CNT_BAD_2)
 #define	 CCR_MIB_ACTIVATE		(CCR_MIB_ENABLE | \
 					 CCR_RX_OCT_CNT_GOOD | \
 					 CCR_RX_OCT_CNT_BAD | \
 					 CCR_TX_OCT_CNT_GOOD | \
 					 CCR_TX_OCT_CNT_BAD | \
-					 CCR_RX_OCT_CNT_GOOD_2 | \
 					 CCR_RX_OCT_CNT_BAD_2 | \
-					 CCR_TX_OCT_CNT_GOOD_2 | \
 					 CCR_TX_OCT_CNT_BAD_2)
 
 /* AN8855 SGMII register group */
@@ -331,6 +332,22 @@
 #define AN8855_RST_CTRL			0x100050c0
 #define	 SYS_CTRL_SYS_RST		BIT(31)
 
+#define INT_MASK			0x100050F0
+#define INT_SYS_BIT			BIT(15)
+
+#define RG_CLK_CPU_ICG		0x10005034
+#define MCU_ENABLE			BIT(3)
+
+#define RG_TIMER_CTL		0x1000a100
+#define WDOG_ENABLE			BIT(25)
+
+#define CKGCR				0x10213E1C
+#define CKG_LNKDN_GLB_STOP	0x01
+#define CKG_LNKDN_PORT_STOP	0x02
+
+#define PKG_SEL				0x10000094
+#define PAG_SEL_AN8855H		0x2
+
 /* Register for hw trap status */
 #define AN8855_HWTRAP			0x1000009c
 
@@ -339,6 +356,15 @@
 
 #define SCU_BASE				0x10000000
 #define RG_RGMII_TXCK_C			(SCU_BASE + 0x1d0)
+#define RG_GPIO_LED_MODE		(SCU_BASE + 0x0054)
+#define RG_GPIO_LED_SEL(i)	(SCU_BASE + (0x0058 + ((i) * 4)))
+#define RG_INTB_MODE			(SCU_BASE + 0x0080)
+#define RG_GDMP_RAM				(SCU_BASE + 0x10000)
+
+#define RG_GPIO_L_INV			(SCU_BASE + 0x0010)
+#define RG_GPIO_CTRL			(SCU_BASE + 0xa300)
+#define RG_GPIO_DATA			(SCU_BASE + 0xa304)
+#define RG_GPIO_OE			(SCU_BASE + 0xa314)
 
 #define HSGMII_AN_CSR_BASE		0x10220000
 #define SGMII_REG_AN0			(HSGMII_AN_CSR_BASE + 0x000)
@@ -382,6 +408,8 @@
 #define SS_LCPLL_TDC_PCW_1			(QP_PMA_TOP_BASE + 0x248)
 #define INTF_CTRL_8			(QP_PMA_TOP_BASE + 0x320)
 #define INTF_CTRL_9			(QP_PMA_TOP_BASE + 0x324)
+#define INTF_CTRL_10		(QP_PMA_TOP_BASE + 0x328)
+#define INTF_CTRL_11		(QP_PMA_TOP_BASE + 0x32c)
 #define PLL_CTRL_0			(QP_PMA_TOP_BASE + 0x400)
 #define PLL_CTRL_2			(QP_PMA_TOP_BASE + 0x408)
 #define PLL_CTRL_3			(QP_PMA_TOP_BASE + 0x40c)
@@ -399,6 +427,7 @@
 #define QP_ANA_CSR_BASE				0x1022f000
 #define RG_QP_RX_DAC_EN				(QP_ANA_CSR_BASE + 0x00)
 #define RG_QP_RXAFE_RESERVE			(QP_ANA_CSR_BASE + 0x04)
+#define RG_QP_CDR_LPF_BOT_LIM		(QP_ANA_CSR_BASE + 0x08)
 #define RG_QP_CDR_LPF_MJV_LIM		(QP_ANA_CSR_BASE + 0x0c)
 #define RG_QP_CDR_LPF_SETVALUE		(QP_ANA_CSR_BASE + 0x14)
 #define RG_QP_CDR_PR_CKREF_DIV1		(QP_ANA_CSR_BASE + 0x18)
@@ -437,6 +466,74 @@
 	u8 ivl;
 };
 
+/* Definition of LED */
+#define LED_ON_EVENT	(LED_ON_EVT_LINK_1000M | \
+			LED_ON_EVT_LINK_100M | LED_ON_EVT_LINK_10M |\
+			LED_ON_EVT_LINK_HD | LED_ON_EVT_LINK_FD)
+
+#define LED_BLK_EVENT	(LED_BLK_EVT_1000M_TX_ACT | \
+			LED_BLK_EVT_1000M_RX_ACT | \
+			LED_BLK_EVT_100M_TX_ACT | \
+			LED_BLK_EVT_100M_RX_ACT | \
+			LED_BLK_EVT_10M_TX_ACT | \
+			LED_BLK_EVT_10M_RX_ACT)
+
+#define LED_FREQ	AIR_LED_BLK_DUR_64M
+
+enum phy_led_idx {
+	P0_LED0,
+	P0_LED1,
+	P0_LED2,
+	P0_LED3,
+	P1_LED0,
+	P1_LED1,
+	P1_LED2,
+	P1_LED3,
+	P2_LED0,
+	P2_LED1,
+	P2_LED2,
+	P2_LED3,
+	P3_LED0,
+	P3_LED1,
+	P3_LED2,
+	P3_LED3,
+	P4_LED0,
+	P4_LED1,
+	P4_LED2,
+	P4_LED3,
+	PHY_LED_MAX
+};
+
+/* TBD */
+enum an8855_led_blk_dur {
+	AIR_LED_BLK_DUR_32M,
+	AIR_LED_BLK_DUR_64M,
+	AIR_LED_BLK_DUR_128M,
+	AIR_LED_BLK_DUR_256M,
+	AIR_LED_BLK_DUR_512M,
+	AIR_LED_BLK_DUR_1024M,
+	AIR_LED_BLK_DUR_LAST
+};
+
+enum an8855_led_polarity {
+	LED_LOW,
+	LED_HIGH,
+};
+enum an8855_led_mode {
+	AN8855_LED_MODE_DISABLE,
+	AN8855_LED_MODE_USER_DEFINE,
+	AN8855_LED_MODE_LAST
+};
+
+struct an8855_led_cfg {
+	u16 en;
+	u8  phy_led_idx;
+	u16 pol;
+	u16 on_cfg;
+	u16 blk_cfg;
+	u8 led_freq;
+};
+
 /* struct an8855_port -	This is the main data structure for holding the state
  *			of the port.
  * @enable:	The status used for show port is enabled or not.
@@ -522,11 +619,13 @@
 	unsigned int phy_base;
 	int phy_base_new;
 	unsigned int id;
+	u32 intr_pin;
 	phy_interface_t p5_interface;
 	unsigned int p5_intf_sel;
 	u8 mirror_rx;
 	u8 mirror_tx;
 	u8 eee_enable;
+	u32 extSurge;
 
 	struct an8855_port ports[AN8855_NUM_PORTS];
 	/* protect among processes for registers access */
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_nl.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_nl.c
index b80ce6f..45099d8 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_nl.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_nl.c
@@ -45,8 +45,8 @@
 static const struct nla_policy an8855_nl_cmd_policy[] = {
 	[AN8855_ATTR_TYPE_MESG] = {.type = NLA_STRING},
 	[AN8855_ATTR_TYPE_PHY] = {.type = NLA_S32},
-	[AN8855_ATTR_TYPE_REG] = {.type = NLA_S32},
-	[AN8855_ATTR_TYPE_VAL] = {.type = NLA_S32},
+	[AN8855_ATTR_TYPE_REG] = {.type = NLA_U32},
+	[AN8855_ATTR_TYPE_VAL] = {.type = NLA_U32},
 	[AN8855_ATTR_TYPE_DEV_NAME] = {.type = NLA_S32},
 	[AN8855_ATTR_TYPE_DEV_ID] = {.type = NLA_S32},
 	[AN8855_ATTR_TYPE_DEVAD] = {.type = NLA_S32},
@@ -150,15 +150,15 @@
 an8855_nl_reply_read(struct genl_info *info)
 {
 	struct sk_buff *rep_skb = NULL;
-	s32 phy, devad, reg;
-	int value;
+	s32 phy, devad;
+	u32 reg = 0;
+	int value = 0;
 	int ret = 0;
 
 	phy = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_PHY, -1);
 	devad = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_DEVAD, -1);
-	reg = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_REG, -1);
 
-	if (reg < 0)
+	if (an8855_nl_get_u32(info, AN8855_ATTR_TYPE_REG, &reg))
 		goto err;
 
 	ret = an8855_nl_prepare_reply(info, AN8855_CMD_READ, &rep_skb);
@@ -172,11 +172,11 @@
 						devad, reg);
 	} else
 		value = an8855_read(an8855_sw_priv, reg);
-	ret = nla_put_s32(rep_skb, AN8855_ATTR_TYPE_REG, reg);
+	ret = nla_put_u32(rep_skb, AN8855_ATTR_TYPE_REG, reg);
 	if (ret < 0)
 		goto err;
 
-	ret = nla_put_s32(rep_skb, AN8855_ATTR_TYPE_VAL, value);
+	ret = nla_put_u32(rep_skb, AN8855_ATTR_TYPE_VAL, value);
 	if (ret < 0)
 		goto err;
 
@@ -193,18 +193,16 @@
 an8855_nl_reply_write(struct genl_info *info)
 {
 	struct sk_buff *rep_skb = NULL;
-	s32 phy, devad, reg;
-	u32 value;
+	s32 phy, devad;
+	u32 value = 0, reg = 0;
 	int ret = 0;
 
 	phy = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_PHY, -1);
 	devad = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_DEVAD, -1);
-	reg = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_REG, -1);
-
-	if (an8855_nl_get_u32(info, AN8855_ATTR_TYPE_VAL, &value))
+	if (an8855_nl_get_u32(info, AN8855_ATTR_TYPE_REG, &reg))
 		goto err;
 
-	if (reg < 0)
+	if (an8855_nl_get_u32(info, AN8855_ATTR_TYPE_VAL, &value))
 		goto err;
 
 	ret = an8855_nl_prepare_reply(info, AN8855_CMD_WRITE, &rep_skb);
@@ -218,11 +216,11 @@
 					  value);
 	} else
 		an8855_write(an8855_sw_priv, reg, value);
-	ret = nla_put_s32(rep_skb, AN8855_ATTR_TYPE_REG, reg);
+	ret = nla_put_u32(rep_skb, AN8855_ATTR_TYPE_REG, reg);
 	if (ret < 0)
 		goto err;
 
-	ret = nla_put_s32(rep_skb, AN8855_ATTR_TYPE_VAL, value);
+	ret = nla_put_u32(rep_skb, AN8855_ATTR_TYPE_VAL, value);
 	if (ret < 0)
 		goto err;
 
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_phy.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_phy.c
index 5499312..9df0834 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_phy.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_phy.c
@@ -14,32 +14,36 @@
 #include "an8855.h"
 #include "an8855_phy.h"
 
-#define AN8855_NUM_PHYS 5
+#define AN8855_EFUSE_DATA0	0x1000a500
 
-static u32
-an8855_phy_read_dev_reg(struct dsa_switch *ds, u32 port_num,
-				   u32 dev_addr, u32 reg_addr)
+const u8 dsa_r50ohm_table[] = {
+	127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
+	127, 127, 127, 127, 127, 127, 127, 126, 122, 117,
+	112, 109, 104, 101,  97,  94,  90,  88,  84,  80,
+	78,  74,  72,  68,  66,  64,  61,  58,  56,  53,
+	51,  48,  47,  44,  42,  40,  38,  36,  34,  32,
+	31,  28,  27,  24,  24,  22,  20,  18,  16,  16,
+	14,  12,  11,   9
+};
+
+static u8 shift_check(u8 base)
 {
-	struct an8855_priv *priv = ds->priv;
-	u32 phy_val;
-	u32 addr;
+	u8 i;
+	u32 sz = sizeof(dsa_r50ohm_table)/sizeof(u8);
 
-	addr = MII_ADDR_C45 | (dev_addr << 16) | (reg_addr & 0xffff);
-	phy_val = priv->info->phy_read(ds, port_num, addr);
+	for (i = 0; i < sz; ++i)
+		if (dsa_r50ohm_table[i] == base)
+			break;
 
-	return phy_val;
+	if (i < 8 || i >= sz)
+		return 25; /* index of 94 */
+
+	return (i - 8);
 }
 
-static void
-an8855_phy_write_dev_reg(struct dsa_switch *ds, u32 port_num,
-				     u32 dev_addr, u32 reg_addr, u32 write_data)
+static u8 get_shift_val(u8 idx)
 {
-	struct an8855_priv *priv = ds->priv;
-	u32 addr;
-
-	addr = MII_ADDR_C45 | (dev_addr << 16) | (reg_addr & 0xffff);
-
-	priv->info->phy_write(ds, port_num, addr, write_data);
+	return dsa_r50ohm_table[idx];
 }
 
 static void
@@ -64,7 +68,10 @@
 an8855_phy_setting(struct dsa_switch *ds)
 {
 	struct an8855_priv *priv = ds->priv;
-	int i;
+	int i, j;
+	u8 shift_sel = 0, rsel_tx_a = 0, rsel_tx_b = 0;
+	u8 rsel_tx_c = 0, rsel_tx_d = 0;
+	u16 cl45_data = 0;
 	u32 val;
 
 	/* Release power down */
@@ -82,48 +89,89 @@
 		val |= ADVERTISE_PAUSE_ASYM;
 		an8855_switch_phy_write(ds, i, MII_ADVERTISE, val);
 	}
+
+	if (priv->extSurge) {
+		for (i = 0; i < AN8855_NUM_PHYS; i++) {
+			/* Read data */
+			for (j = 0; j < AN8855_WORD_SIZE; j++) {
+				val = an8855_read(priv, AN8855_EFUSE_DATA0 +
+					(AN8855_WORD_SIZE * (3 + j + (4 * i))));
+
+				shift_sel = shift_check((val & 0x7f000000) >> 24);
+				switch (j) {
+				case 0:
+					rsel_tx_a = get_shift_val(shift_sel);
+					break;
+				case 1:
+					rsel_tx_b = get_shift_val(shift_sel);
+					break;
+				case 2:
+					rsel_tx_c = get_shift_val(shift_sel);
+					break;
+				case 3:
+					rsel_tx_d = get_shift_val(shift_sel);
+					break;
+				default:
+					continue;
+				}
+			}
+			cl45_data = an8855_phy_cl45_read(priv, i, PHY_DEV1E, 0x174);
+			cl45_data &= ~(0x7f7f);
+			cl45_data |= (rsel_tx_a << 8);
+			cl45_data |= rsel_tx_b;
+			an8855_phy_cl45_write(priv, i, PHY_DEV1E, 0x174, cl45_data);
+			cl45_data = an8855_phy_cl45_read(priv, i, PHY_DEV1E, 0x175);
+			cl45_data &= ~(0x7f7f);
+			cl45_data |= (rsel_tx_c << 8);
+			cl45_data |= rsel_tx_d;
+			an8855_phy_cl45_write(priv, i, PHY_DEV1E, 0x175, cl45_data);
+		}
+	}
 }
 
 static void
 an8855_low_power_setting(struct dsa_switch *ds)
 {
 	int port, addr;
+	struct an8855_priv *priv = ds->priv;
 
 	for (port = 0; port < AN8855_NUM_PHYS; port++) {
-		an8855_phy_write_dev_reg(ds, port, 0x1e, 0x11, 0x0f00);
-		an8855_phy_write_dev_reg(ds, port, 0x1e, 0x3c, 0x0000);
-		an8855_phy_write_dev_reg(ds, port, 0x1e, 0x3d, 0x0000);
-		an8855_phy_write_dev_reg(ds, port, 0x1e, 0x3e, 0x0000);
-		an8855_phy_write_dev_reg(ds, port, 0x1e, 0xc6, 0x53aa);
+		an8855_phy_cl45_write(priv, port, 0x1e, 0x11, 0x0f00);
+		an8855_phy_cl45_write(priv, port, 0x1e, 0x3c, 0x0000);
+		an8855_phy_cl45_write(priv, port, 0x1e, 0x3d, 0x0000);
+		an8855_phy_cl45_write(priv, port, 0x1e, 0x3e, 0x0000);
+		an8855_phy_cl45_write(priv, port, 0x1e, 0xc6, 0x53aa);
 	}
 
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x268, 0x07f1);
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x269, 0x2111);
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x26a, 0x0000);
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x26b, 0x0074);
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x26e, 0x00f6);
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x26f, 0x6666);
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x271, 0x2c02);
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x272, 0x0c22);
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x700, 0x0001);
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x701, 0x0803);
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x702, 0x01b6);
-	an8855_phy_write_dev_reg(ds, 0, 0x1f, 0x703, 0x2111);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x268, 0x07f1);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x269, 0x2111);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x26a, 0x0000);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x26b, 0x0074);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x26e, 0x00f6);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x26f, 0x6666);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x271, 0x2c02);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x272, 0x0c22);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x700, 0x0001);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x701, 0x0803);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x702, 0x01b6);
+	an8855_phy_cl45_write(priv, 0, 0x1f, 0x703, 0x2111);
 
-	an8855_phy_write_dev_reg(ds, 1, 0x1f, 0x700, 0x0001);
+	an8855_phy_cl45_write(priv, 1, 0x1f, 0x700, 0x0001);
 
 	for (addr = 0x200; addr <= 0x230; addr += 2)
-		an8855_phy_write_dev_reg(ds, 0, 0x1f, addr, 0x2020);
+		an8855_phy_cl45_write(priv, 0, 0x1f, addr, 0x2020);
 
 	for (addr = 0x201; addr <= 0x231; addr += 2)
-		an8855_phy_write_dev_reg(ds, 0, 0x1f, addr, 0x0020);
+		an8855_phy_cl45_write(priv, 0, 0x1f, addr, 0x0020);
 }
 
 static void
 an8855_eee_setting(struct dsa_switch *ds, u32 port)
 {
+	struct an8855_priv *priv = ds->priv;
+
 	/* Disable EEE */
-	an8855_phy_write_dev_reg(ds, port, PHY_DEV07, PHY_DEV07_REG_03C, 0);
+	an8855_phy_cl45_write(priv, port, PHY_DEV07, PHY_DEV07_REG_03C, 0);
 }
 
 int
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_phy.h b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_phy.h
index 63a03bb..1193e67 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_phy.h
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/dsa/airoha/an8855/an8855_phy.h
@@ -12,6 +12,8 @@
 
 #include <linux/bitops.h>
 
+#define AN8855_NUM_PHYS	5
+
 /*phy calibration use*/
 #define DEV_1E				0x1E
 /*global device 0x1f, always set P0*/
@@ -169,11 +171,69 @@
 /* PHY EEE Register bitmap of define */
 #define PHY_DEV07			0x07
 #define PHY_DEV07_REG_03C		0x3c
+#define ADV_EEE_100			0x2
+#define ADV_EEE_1000		0x4
 
 /* PHY DEV 0x1e Register bitmap of define */
 #define PHY_DEV1E			0x1e
+/* PHY TX PAIR DELAY SELECT Register */
+#define PHY_TX_PAIR_DLY_SEL_GBE		0x013
+/* PHY ADC Register */
+#define PHY_RXADC_CTRL				0x0d8
+#define PHY_RXADC_REV_0				0x0d9
+#define PHY_RXADC_REV_1				0x0da
+
+/* PHY LED Register bitmap of define */
+#define PHY_LED_CTRL_SELECT		0x3e8
+#define PHY_SINGLE_LED_ON_CTRL(i)	(0x3e0 + ((i) * 2))
+#define PHY_SINGLE_LED_BLK_CTRL(i)	(0x3e1 + ((i) * 2))
+#define PHY_SINGLE_LED_ON_DUR(i)	(0x3e9 + ((i) * 2))
+#define PHY_SINGLE_LED_BLK_DUR(i)	(0x3ea + ((i) * 2))
+
+#define PHY_PMA_CTRL	(0x340)
+
 #define PHY_DEV1F			0x1f
 
+#define PHY_LED_ON_CTRL(i)		(0x24 + ((i) * 2))
+#define LED_ON_EN				(1 << 15)
+#define LED_ON_POL				(1 << 14)
+#define LED_ON_EVT_MASK			(0x7f)
+
+/* LED ON Event */
+#define LED_ON_EVT_FORCE		(1 << 6)
+#define LED_ON_EVT_LINK_HD		(1 << 5)
+#define LED_ON_EVT_LINK_FD		(1 << 4)
+#define LED_ON_EVT_LINK_DOWN	(1 << 3)
+#define LED_ON_EVT_LINK_10M		(1 << 2)
+#define LED_ON_EVT_LINK_100M	(1 << 1)
+#define LED_ON_EVT_LINK_1000M	(1 << 0)
+
+#define PHY_LED_BLK_CTRL(i)		(0x25 + ((i) * 2))
+#define LED_BLK_EVT_MASK		(0x3ff)
+/* LED Blinking Event */
+#define LED_BLK_EVT_FORCE			(1 << 9)
+#define LED_BLK_EVT_10M_RX_ACT		(1 << 5)
+#define LED_BLK_EVT_10M_TX_ACT		(1 << 4)
+#define LED_BLK_EVT_100M_RX_ACT		(1 << 3)
+#define LED_BLK_EVT_100M_TX_ACT		(1 << 2)
+#define LED_BLK_EVT_1000M_RX_ACT	(1 << 1)
+#define LED_BLK_EVT_1000M_TX_ACT	(1 << 0)
+
+#define PHY_LED_BCR				(0x21)
+#define LED_BCR_EXT_CTRL		(1 << 15)
+#define LED_BCR_CLK_EN			(1 << 3)
+#define LED_BCR_TIME_TEST		(1 << 2)
+#define LED_BCR_MODE_MASK		(3)
+#define LED_BCR_MODE_DISABLE	(0)
+
+#define PHY_LED_ON_DUR			(0x22)
+#define LED_ON_DUR_MASK			(0xffff)
+
+#define PHY_LED_BLK_DUR			(0x23)
+#define LED_BLK_DUR_MASK		(0xffff)
+
+#define PHY_LED_BLINK_DUR_CTRL	(0x720)
+
 /* Proprietory Control Register of Internal Phy device 0x1e */
 #define PHY_TX_MLT3_BASE		0x0
 #define PHY_DEV1E_REG_13		0x13
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_dbg.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_dbg.c
index fca5e3e..1916266 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_dbg.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_dbg.c
@@ -609,7 +609,6 @@
 	case PSE_EIP197_PORT:
 		pse_info_get_cdm(eth, port, 6, options);
 		break;
-		break;
 	default:
 		pr_info("Not supported\n");
 		break;
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_reset.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_reset.c
index df23ae3..19cd4e3 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_reset.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_reset.c
@@ -42,6 +42,41 @@
 	reset_event->count[id]++;
 }
 
+static void mtk_dump_reg(void *_eth, char *name, u32 offset, u32 range)
+{
+	struct mtk_eth *eth = _eth;
+	u32 cur = offset;
+
+	pr_info("\n============ %s ============\n", name);
+	while (cur < offset + range) {
+		pr_info("0x%x: %08x %08x %08x %08x\n",
+			cur, mtk_r32(eth, cur), mtk_r32(eth, cur + 0x4),
+			mtk_r32(eth, cur + 0x8), mtk_r32(eth, cur + 0xc));
+		cur += 0x10;
+	}
+}
+
+static void mtk_dump_regmap(struct regmap *pmap, char *name,
+			    u32 offset, u32 range)
+{
+	unsigned int cur = offset;
+	unsigned int val1 = 0, val2 = 0, val3 = 0, val4 = 0;
+
+	if (!pmap)
+		return;
+
+	pr_info("\n============ %s ============\n", name);
+	while (cur < offset + range) {
+		regmap_read(pmap, cur, &val1);
+		regmap_read(pmap, cur + 0x4, &val2);
+		regmap_read(pmap, cur + 0x8, &val3);
+		regmap_read(pmap, cur + 0xc, &val4);
+		pr_info("0x%x: %08x %08x %08x %08x\n",
+			cur, val1, val2, val3, val4);
+		cur += 0x10;
+	}
+}
+
 int mtk_eth_cold_reset(struct mtk_eth *eth)
 {
 	u32 reset_bits = 0;
@@ -55,16 +90,15 @@
 #if defined(CONFIG_MEDIATEK_NETSYS_V3)
 	if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE2))
 		reset_bits |= RSTCTRL_PPE2;
-	if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
+	if (mtk_reset_flag == MTK_FE_START_RESET)
 		reset_bits |= RSTCTRL_WDMA0 | RSTCTRL_WDMA1 | RSTCTRL_WDMA2;
 #endif
 	ethsys_reset(eth, reset_bits);
 
-	if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
-		regmap_write(eth->ethsys, ETHSYS_FE_RST_CHK_IDLE_EN, 0x3ffffff);
-
 	if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
-		regmap_write(eth->ethsys, ETHSYS_FE_RST_CHK_IDLE_EN, 0x6F8FF);
+		regmap_write(eth->ethsys, ETHSYS_FE_RST_CHK_IDLE_EN, 0x6f8ff);
+	else if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2))
+		regmap_write(eth->ethsys, ETHSYS_FE_RST_CHK_IDLE_EN, 0x3ffffff);
 
 	return 0;
 }
@@ -89,6 +123,7 @@
 	}
 
 	if (i < 1000) {
+		done = 1;
 		reset_bits = RSTCTRL_ETH | RSTCTRL_PPE0;
 		if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
 			reset_bits |= RSTCTRL_PPE1;
@@ -96,8 +131,7 @@
 		if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE2))
 			reset_bits |= RSTCTRL_PPE2;
 		if (mtk_reset_flag == MTK_FE_START_RESET)
-			reset_bits |= RSTCTRL_WDMA0 |
-			RSTCTRL_WDMA1 | RSTCTRL_WDMA2;
+			reset_bits |= RSTCTRL_WDMA0 | RSTCTRL_WDMA1 | RSTCTRL_WDMA2;
 #endif
 
 		regmap_update_bits(eth->ethsys, ETHSYS_RSTCTRL,
@@ -105,27 +139,51 @@
 
 		udelay(1);
 		regmap_read(eth->ethsys, ETHSYS_RSTCTRL, &val2);
-		if (!(val2 & reset_bits))
+		if (!(val2 & reset_bits)) {
 			pr_info("[%s] error val2=0x%x reset_bits=0x%x !\n",
 				__func__, val2, reset_bits);
+			done = 0;
+		}
 		reset_bits |= RSTCTRL_FE;
 		regmap_update_bits(eth->ethsys, ETHSYS_RSTCTRL,
 				   reset_bits, ~reset_bits);
-
 		udelay(1);
 		regmap_read(eth->ethsys, ETHSYS_RSTCTRL, &val3);
-		if (val3 & reset_bits)
+		if (val3 & reset_bits) {
 			pr_info("[%s] error val3=0x%x reset_bits=0x%x !\n",
 				__func__, val3, reset_bits);
-		done = 1;
+			done = 0;
+		}
 		mtk_reset_event_update(eth, MTK_EVENT_WARM_CNT);
 	}
 
 	pr_info("[%s] reset record val1=0x%x, val2=0x%x, val3=0x%x i:%d done:%d\n",
 		__func__, val1, val2, val3, i, done);
 
-	if (!done)
+	if (!done) {
+		mtk_dump_reg(eth, "FE", 0x0, 0x300);
+		mtk_dump_reg(eth, "ADMA", PDMA_BASE + 0x200, 0x10);
+		mtk_dump_reg(eth, "QDMA", QDMA_BASE + 0x200, 0x10);
+		mtk_dump_reg(eth, "WDMA0", WDMA_BASE(0) + 0x200, 0x10);
+		mtk_dump_reg(eth, "WDMA1", WDMA_BASE(1) + 0x200, 0x10);
+		mtk_dump_reg(eth, "PPE0", PPE_BASE(0), 0x10);
+		mtk_dump_reg(eth, "PPE0", PPE_BASE(0) + 0x180, 0x20);
+		if (!MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V1)) {
+			mtk_dump_reg(eth, "PPE1", PPE_BASE(1), 0x10);
+			mtk_dump_reg(eth, "PPE1", PPE_BASE(1) + 0x180, 0x20);
+		}
+		if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
+			mtk_dump_reg(eth, "PPE2", PPE_BASE(2), 0x10);
+			mtk_dump_reg(eth, "PPE2", PPE_BASE(2) + 0x180, 0x20);
+			regmap_write(eth->ethsys, ETHSYS_LP_NONE_IDLE_LAT0, 0xffffffff);
+			regmap_write(eth->ethsys, ETHSYS_LP_NONE_IDLE_LAT1, 0xffffffff);
+			regmap_read(eth->ethsys, ETHSYS_LP_NONE_IDLE_LAT0, &val1);
+			regmap_read(eth->ethsys, ETHSYS_LP_NONE_IDLE_LAT1, &val2);
+			pr_info("ETHSYS_LP_NONE_IDLE_LAT0:%x\n", val1);
+			pr_info("ETHSYS_LP_NONE_IDLE_LAT1:%x\n", val2);
+		}
 		mtk_eth_cold_reset(eth);
+	}
 
 	return 0;
 }
@@ -187,41 +245,6 @@
 	return IRQ_HANDLED;
 }
 
-static void mtk_dump_reg(void *_eth, char *name, u32 offset, u32 range)
-{
-	struct mtk_eth *eth = _eth;
-	u32 cur = offset;
-
-	pr_info("\n============ %s ============\n", name);
-	while(cur < offset + range) {
-		pr_info("0x%x: %08x %08x %08x %08x\n",
-			cur, mtk_r32(eth, cur), mtk_r32(eth, cur + 0x4),
-			mtk_r32(eth, cur + 0x8), mtk_r32(eth, cur + 0xc));
-		cur += 0x10;
-	}
-}
-
-static void mtk_dump_regmap(struct regmap *pmap, char *name,
-			    u32 offset, u32 range)
-{
-	unsigned int cur = offset;
-	unsigned int val1 = 0, val2 = 0, val3 = 0, val4 = 0;
-
-	if (!pmap)
-		return;
-
-	pr_info("\n============ %s ============\n", name);
-	while (cur < offset + range) {
-		regmap_read(pmap, cur, &val1);
-		regmap_read(pmap, cur + 0x4, &val2);
-		regmap_read(pmap, cur + 0x8, &val3);
-		regmap_read(pmap, cur + 0xc, &val4);
-		pr_info("0x%x: %08x %08x %08x %08x\n",
-			cur, val1, val2, val3, val4);
-		cur += 0x10;
-	}
-}
-
 void mtk_dump_netsys_info(void *_eth)
 {
 	struct mtk_eth *eth = _eth;
@@ -266,7 +289,7 @@
 
 	cur_opq = (mtk_r32(eth, MTK_PSE_OQ_STA(id)) & mask);
 	if ((cur_opq != 0) && (cur_opq == *pre_opq))
-		*err_opq++;
+		(*err_opq)++;
 	else
 		*err_opq = 0;
 
@@ -279,7 +302,7 @@
 	static u32 err_cnt[MTK_WDMA_CNT];
 	static u32 err_opq1, err_opq2, err_opq8;
 	static u32 err_opq9, err_opq13, err_opq15;
-	u32 opq1, opq2, opq8, opq9, opq13, opq15;
+	static u32 opq1, opq2, opq8, opq9, opq13, opq15;
 	u32 cur_dtx, tx_busy, fsm_ts;
 	u32 i, err_opq = 0, err_flag = 0;
 
@@ -342,26 +365,42 @@
 u32 mtk_monitor_wdma_rx(struct mtk_eth *eth)
 {
 	static u32 pre_drx[MTK_WDMA_CNT];
+	static u32 pre_crx[MTK_WDMA_CNT];
 	static u32 pre_opq[MTK_WDMA_CNT];
 	static u32 err_cnt[MTK_WDMA_CNT];
-	u32 cur_crx = 0, cur_drx = 0, cur_opq = 0, fsm_fs;
+	bool connsys_busy, netsys_busy;
+	u32 cur_crx = 0, cur_drx = 0, cur_opq = 0, fsm_fs, max_cnt;
 	u32 i, err_flag = 0;
+	int rx_cnt;
 
 	for (i = 0; i < MTK_WDMA_CNT; i++) {
+		connsys_busy = netsys_busy = false;
+		max_cnt = mtk_r32(eth, MTK_WDMA_RX_MAX_CNT(i));
 		cur_crx = mtk_r32(eth, MTK_WDMA_CRX_PTR(i));
 		cur_drx = mtk_r32(eth, MTK_WDMA_DRX_PTR(i));
+		rx_cnt = (cur_drx > cur_crx) ? (cur_drx - 1 - cur_crx) :
+					       (cur_drx - 1 - cur_crx + max_cnt);
 		cur_opq = MTK_FE_WDMA_OQ(i);
 		fsm_fs = mtk_r32(eth, MTK_FE_CDM_FSM(i)) &
 			(MTK_CDM_FS_FSM_MASK | MTK_CDM_FS_PARSER_FSM_MASK);
-		/*drx unchange && ring not full && output && fsm_fs*/
-		if (cur_drx == pre_drx[i] && (cur_crx != cur_drx) &&
-		    (cur_opq != 0 && cur_opq == pre_opq[i]) && fsm_fs) {
+		/* drx and crx remain unchanged && rx_cnt is not zero */
+		if ((cur_drx == pre_drx[i]) && (cur_crx == pre_crx[i]) && (rx_cnt > 0))
+			connsys_busy = true;
+		/* drx and crx remain unchanged && pse_opq is not empty */
+		else if ((cur_drx == pre_drx[i]) && (cur_crx == pre_crx[i]) &&
+			 (cur_opq != 0 && cur_opq == pre_opq[i]) && fsm_fs)
+			netsys_busy = true;
+		if (connsys_busy || netsys_busy) {
 			err_cnt[i]++;
 			if (err_cnt[i] >= 3) {
-				pr_info("WDMA %d Rx Info\n", i);
+				pr_info("WDMA %d Rx Info (%s)\n", i,
+					connsys_busy ? "CONNSYS busy" : "NETSYS busy");
 				pr_info("err_cnt = %d", err_cnt[i]);
 				pr_info("prev_drx = 0x%x	| cur_drx = 0x%x\n",
 					pre_drx[i], cur_drx);
+				pr_info("prev_crx = 0x%x	| cur_crx = 0x%x\n",
+					pre_crx[i], cur_crx);
+				pr_info("rx cnt = %d\n", rx_cnt);
 				pr_info("WDMA_CRX_PTR = 0x%x\n",
 					mtk_r32(eth, MTK_WDMA_CRX_PTR(i)));
 				pr_info("WDMA_DRX_PTR = 0x%x\n",
@@ -375,6 +414,7 @@
 			}
 		} else
 			err_cnt[i] = 0;
+		pre_crx[i] = cur_crx;
 		pre_drx[i] = cur_drx;
 		pre_opq[i] = cur_opq;
 	}
@@ -387,15 +427,21 @@
 
 u32 mtk_monitor_rx_fc(struct mtk_eth *eth)
 {
-	u32 i = 0, mib_base = 0, gdm_fc = 0;
+	struct mtk_hw_stats *hw_stats;
+	static u32 gdm_rx_fc[MTK_MAX_DEVS];
+	u32 i = 0, is_rx_fc = 0;
 
 	for (i = 0; i < MTK_MAC_COUNT; i++) {
-		mib_base = MTK_GDM1_TX_GBCNT + MTK_STAT_OFFSET*i + MTK_GDM_RX_FC;
-		gdm_fc =  mtk_r32(eth, mib_base);
-		if (gdm_fc < 1)
-			return 1;
+		if (!eth->mac[i] || !netif_running(eth->netdev[i]))
+			continue;
+
+		hw_stats = eth->mac[i]->hw_stats;
+		if (hw_stats->rx_flow_control_packets - gdm_rx_fc[i])
+			is_rx_fc = 1;
+
+		gdm_rx_fc[i] = hw_stats->rx_flow_control_packets;
 	}
-	return 0;
+	return is_rx_fc;
 }
 
 u32 mtk_monitor_qdma_tx(struct mtk_eth *eth)
@@ -408,7 +454,7 @@
 	u32 is_qfwd_hang = mtk_r32(eth, MTK_QDMA_FWD_CNT) == 0;
 
 	is_rx_fc = mtk_monitor_rx_fc(eth);
-	if (is_qfsm_hang && is_qfwd_hang && is_rx_fc) {
+	if (is_qfsm_hang && is_qfwd_hang && !is_rx_fc) {
 		err_cnt_qtx++;
 		if (err_cnt_qtx >= 3) {
 			pr_info("QDMA Tx Info\n");
@@ -604,6 +650,9 @@
 	u32 cur_fsm, pse_ipq, err_flag = 0, i;
 
 	for (i = 0; i < MTK_MAX_DEVS; i++) {
+		if (!eth->mac[i] || !netif_running(eth->netdev[i]))
+			continue;
+
 		struct mtk_hw_stats *hw_stats = eth->mac[i]->hw_stats;
 
 		is_gmac_rx[i] = (mtk_r32(eth, MTK_MAC_FSM(i)) & 0xFF0000) != 0x10000;
@@ -623,6 +672,9 @@
 
 	if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
 		for (i = 0; i < MTK_MAX_DEVS; i++) {
+			if (!eth->mac[i] || !netif_running(eth->netdev[i]))
+				continue;
+
 			if (i == 0) {
 				pse_ipq = (mtk_r32(eth, MTK_PSE_IQ_STA(0)) >> 16) & 0xFFF;
 				cur_fsm = mtk_r32(eth, MTK_FE_GDM1_FSM) & 0xFF;
@@ -672,6 +724,9 @@
 	u32 err_flag = 0, i, pse_opq;
 
 	for (i = 0; i < MTK_MAX_DEVS; i++) {
+		if (!eth->mac[i] || !netif_running(eth->netdev[i]))
+			continue;
+
 		struct mtk_hw_stats *hw_stats = eth->mac[i]->hw_stats;
 
 		if (i == 0)
@@ -697,6 +752,9 @@
 	}
 
 	for (i = 0; i < MTK_MAX_DEVS; i++) {
+		if (!eth->mac[i] || !netif_running(eth->netdev[i]))
+			continue;
+
 		gdm_fsm = mtk_r32(eth, MTK_FE_GDM_FSM(i)) & 0x1FFF0000;
 		pse_opq = MTK_FE_GDM_OQ(i);
 		if ((pre_gdm[i] == gdm_fsm) && (gdm_fsm == 0x10330000) &&
@@ -811,6 +869,9 @@
 	u32 mcr, sts, i;
 
 	for (i = 0; i < MTK_MAX_DEVS; i++) {
+		if (!eth->mac[i])
+			continue;
+
 		mac = eth->mac[i];
 		if (mac->type == MTK_GDM_TYPE) {
 			mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
@@ -829,18 +890,21 @@
 	}
 }
 
-void mtk_pse_port_linkdown(struct mtk_eth *eth, int port)
+void mtk_pse_set_port_link(struct mtk_eth *eth, u32 port, bool enable)
 {
-	u32 fe_glo_cfg;
+	u32 val;
 
-	fe_glo_cfg = mtk_r32(eth, MTK_FE_GLO_CFG(port));
-	fe_glo_cfg |= MTK_FE_LINK_DOWN_PORT(port);
-	mtk_w32(eth, fe_glo_cfg, MTK_FE_GLO_CFG(port));
+	val = mtk_r32(eth, MTK_FE_GLO_CFG(port));
+	if (enable)
+		val &= ~MTK_FE_LINK_DOWN_P(port);
+	else
+		val |= MTK_FE_LINK_DOWN_P(port);
+	mtk_w32(eth, val, MTK_FE_GLO_CFG(port));
 }
 
 void mtk_prepare_reset_fe(struct mtk_eth *eth)
 {
-	u32 i = 0, val = 0, mcr = 0;
+	u32 i = 0, val = 0;
 
 	/* Disable NETSYS Interrupt */
 	mtk_w32(eth, 0, MTK_FE_INT_ENABLE);
@@ -851,6 +915,9 @@
 	for (i = 0; i < MTK_MAC_COUNT; i++) {
 		if (!eth->netdev[i])
 			continue;
+
+		/* call carrier off first to avoid false dev_watchdog timeouts */
+		netif_carrier_off(eth->netdev[i]);
 		netif_tx_disable(eth->netdev[i]);
 	}
 
@@ -861,14 +928,14 @@
 	/* Force mac link down */
 	mtk_mac_linkdown(eth);
 
-	/* Force pse port link down */
-	mtk_pse_port_linkdown(eth, 0);
-	mtk_pse_port_linkdown(eth, 1);
-	mtk_pse_port_linkdown(eth, 2);
-	mtk_pse_port_linkdown(eth, 8);
-	mtk_pse_port_linkdown(eth, 9);
+	/* Force PSE port link down */
+	mtk_pse_set_port_link(eth, 0, false);
+	mtk_pse_set_port_link(eth, 1, false);
+	mtk_pse_set_port_link(eth, 2, false);
+	mtk_pse_set_port_link(eth, 8, false);
+	mtk_pse_set_port_link(eth, 9, false);
 	if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3))
-		mtk_pse_port_linkdown(eth, 15);
+		mtk_pse_set_port_link(eth, 15, false);
 
 	/* Enable GDM drop */
 	for (i = 0; i < MTK_MAC_COUNT; i++)
@@ -911,9 +978,9 @@
 	}
 
 	if (i >= poll_time) {
-		pr_info("[%s] PPE keeps busy !\n", __func__);
+		pr_warn("[%s] PPE%d keeps busy !\n", __func__, ppe_id);
 		mtk_dump_reg(eth, "FE", 0x0, 0x500);
-		mtk_dump_reg(eth, "PPE", 0x2200, 0x200);
+		mtk_dump_reg(eth, "PPE", PPE_BASE(ppe_id), 0x200);
 	}
 }
 
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_reset.h b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_reset.h
index dd8206a..facb645 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_reset.h
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_reset.h
@@ -92,4 +92,5 @@
 void mtk_prepare_reset_fe(struct mtk_eth *eth);
 void mtk_prepare_reset_ppe(struct mtk_eth *eth, u32 ppe_id);
 
+void mtk_pse_set_port_link(struct mtk_eth *eth, u32 port, bool enable);
 #endif		/* MTK_ETH_RESET_H */
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 8971a7f..82f87b5 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -623,9 +623,11 @@
 {
 	struct mtk_mac *mac = container_of(config, struct mtk_mac,
 					   phylink_config);
+	struct mtk_eth *eth = mac->hw;
 	u32 val;
 
-	if (mac->type == MTK_XGDM_TYPE && mac->id != MTK_GMAC1_ID) {
+	if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3) &&
+	    mac->id != MTK_GMAC1_ID) {
 		val = mtk_r32(mac->hw, MTK_XMAC_MCR(mac->id));
 		val &= 0xfffffff0;
 		val |= XMAC_MCR_TRX_DISABLE;
@@ -970,10 +972,10 @@
 			__func__, gdm_fsm, mac_fsm);
 }
 
-static void mtk_pse_port_link_set(struct mtk_mac *mac, bool up,
-				  phy_interface_t interface)
+static void mtk_pse_set_mac_port_link(struct mtk_mac *mac, bool up,
+				      phy_interface_t interface)
 {
-	u32 fe_glo_cfg, val = 0, port = 0;
+	u32 port = 0;
 
 	if (!up && interface == PHY_INTERFACE_MODE_XGMII) {
 		void __iomem *base;
@@ -995,26 +997,18 @@
 	switch (mac->id) {
 	case MTK_GMAC1_ID:
 		port = PSE_GDM1_PORT;
-		val = MTK_FE_LINK_DOWN_PORT(port);
 		break;
 	case MTK_GMAC2_ID:
 		port = PSE_GDM2_PORT;
-		val = MTK_FE_LINK_DOWN_PORT(port);
 		break;
 	case MTK_GMAC3_ID:
 		port = PSE_GDM3_PORT;
-		val = MTK_FE_LINK_DOWN_PORT(port);
 		break;
+	default:
+		return;
 	}
 
-	fe_glo_cfg = mtk_r32(mac->hw, MTK_FE_GLO_CFG(port));
-
-	if (!up)
-		fe_glo_cfg |= val;
-	else
-		fe_glo_cfg &= ~val;
-
-	mtk_w32(mac->hw, fe_glo_cfg, MTK_FE_GLO_CFG(port));
+	mtk_pse_set_port_link(mac->hw, port, up);
 	mtk_gdm_fsm_poll(mac);
 }
 
@@ -1027,7 +1021,7 @@
 	unsigned int id;
 	u32 mcr, sts;
 
-	mtk_pse_port_link_set(mac, false, interface);
+	mtk_pse_set_mac_port_link(mac, false, interface);
 	if (mac->type == MTK_GDM_TYPE) {
 		mcr = mtk_r32(mac->hw, MTK_MAC_MCR(mac->id));
 		mcr &= ~(MAC_MCR_TX_EN | MAC_MCR_RX_EN | MAC_MCR_FORCE_LINK);
@@ -1209,7 +1203,7 @@
 		mcr &= ~(XMAC_MCR_TRX_DISABLE);
 		mtk_w32(mac->hw, mcr, MTK_XMAC_MCR(mac->id));
 	}
-	mtk_pse_port_link_set(mac, true, interface);
+	mtk_pse_set_mac_port_link(mac, true, interface);
 }
 
 static void mtk_validate(struct phylink_config *config,
@@ -2162,7 +2156,8 @@
 			}
 
 			memset(&txd_info, 0, sizeof(struct mtk_tx_dma_desc_info));
-			txd_info.size = min(frag_size, eth->soc->txrx.dma_max_len);
+			txd_info.size = min_t(unsigned int, frag_size,
+					      eth->soc->txrx.dma_max_len);
 			txd_info.qid = queue;
 			txd_info.last = i == skb_shinfo(skb)->nr_frags - 1 &&
 					!(frag_size - txd_info.size);
@@ -2322,7 +2317,6 @@
 	struct netdev_queue *txq;
 	bool gso = false;
 	int tx_num;
-	int i = 0;
 	int qid = skb_get_queue_mapping(skb);
 
 	/* normally we can rely on the stack not calling this more than once,
@@ -3254,8 +3248,11 @@
 	}
 
 	/* invalidate lro rings */
-	for (i = 0; i < MTK_HW_LRO_RING_NUM; i++)
-		mtk_w32(eth, 0, reg_map->pdma.lro_rx_ctrl_dw0 + 0x8 + (i * 0x40));
+	for (i = 0; i < MTK_HW_LRO_RING_NUM; i++) {
+		int idx = MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_RX_V2) ? i : i + 1;
+
+		mtk_w32(eth, 0, reg_map->pdma.lro_rx_ctrl_dw0 + 0x8 + (idx * 0x40));
+	}
 
 	/* disable HW LRO */
 	mtk_w32(eth, 0, reg_map->pdma.lro_ctrl_dw0);
@@ -3763,11 +3760,21 @@
 static void mtk_dma_free(struct mtk_eth *eth)
 {
 	const struct mtk_soc_data *soc = eth->soc;
-	int i;
+	int i, j, txqs;
 
-	for (i = 0; i < MTK_MAC_COUNT; i++)
-		if (eth->netdev[i])
-			netdev_reset_queue(eth->netdev[i]);
+	if (MTK_HAS_CAPS(eth->soc->caps, MTK_QDMA))
+		txqs = MTK_QDMA_TX_NUM;
+	else
+		txqs = MTK_PDMA_TX_NUM;
+
+	for (i = 0; i < MTK_MAC_COUNT; i++) {
+		if (!eth->netdev[i])
+			continue;
+
+		for (j = 0; j < txqs; j++)
+			netdev_tx_reset_queue(netdev_get_tx_queue(eth->netdev[i], j));
+	}
+
 	if ( !eth->soc->has_sram && eth->scratch_ring) {
 		dma_free_coherent(eth->dma_dev,
 				  soc->txrx.fq_dma_size * soc->txrx.txd_size,
@@ -3859,8 +3866,8 @@
 	const struct mtk_reg_map *reg_map = eth->soc->reg_map;
 
 	if (tx_ring) {
-		if (unlikely(!(mtk_r32(eth, eth->soc->reg_map->pdma.irq_status) &
-			       mtk_r32(eth, eth->soc->reg_map->pdma.irq_mask) &
+		if (unlikely(!(mtk_r32(eth, reg_map->pdma.irq_status) &
+			       mtk_r32(eth, reg_map->pdma.irq_mask) &
 			       MTK_TX_DONE_INT(tx_ring->ring_no))))
 			return IRQ_NONE;
 
@@ -3869,8 +3876,8 @@
 			__napi_schedule(&txrx_napi->napi);
 		}
 	} else {
-		if (unlikely(!(mtk_r32(eth, eth->soc->reg_map->pdma.irq_status) &
-			       mtk_r32(eth, eth->soc->reg_map->pdma.irq_mask) &
+		if (unlikely(!(mtk_r32(eth, reg_map->pdma.irq_status) &
+			       mtk_r32(eth, reg_map->pdma.irq_mask) &
 			       MTK_RX_DONE_INT(rx_ring->ring_no))))
 			return IRQ_NONE;
 
@@ -4739,6 +4746,8 @@
 	mtk_prepare_reset_ppe(eth, 0);
 	if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE1))
 		mtk_prepare_reset_ppe(eth, 1);
+	if (MTK_HAS_CAPS(eth->soc->caps, MTK_RSTCTRL_PPE2))
+		mtk_prepare_reset_ppe(eth, 2);
 
 	/* Adjust FE configurations to prepare for reset */
 	mtk_prepare_reset_fe(eth);
@@ -4757,7 +4766,7 @@
 				eth->netdev[i]);
 		}
 		rtnl_unlock();
-		if (wait_for_completion_timeout(&wait_ser_done, 3000)) {
+		if (wait_for_completion_timeout(&wait_ser_done, msecs_to_jiffies(3000))) {
 			if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3) &&
 			    (mtk_stop_fail)) {
 				pr_info("send MTK_FE_START_RESET stop\n");
@@ -4766,8 +4775,9 @@
 							 eth->netdev[i]);
 				rtnl_unlock();
 				if (!wait_for_completion_timeout(&wait_ser_done,
-								 3000))
+								 msecs_to_jiffies(3000)))
 					pr_warn("wait for MTK_FE_START_RESET\n");
+				mtk_stop_fail = 0;
 			}
 			pr_warn("wait for MTK_FE_START_RESET\n");
 		}
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.h b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.h
index 198cd0e..08f5988 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.h
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_eth_soc.h
@@ -71,8 +71,10 @@
 #define MTK_RSS_MAX_INDIRECTION_TABLE	128
 
 /* Frame Engine Global Configuration */
-#define MTK_FE_GLO_CFG(port)	((port < 8) ? 0x0 : 0x24)
-#define MTK_FE_LINK_DOWN_PORT(x)	((x < 8) ? (1 << (8 + x)) : (1 << (x - 8)))
+#define MTK_FE_GLO_CFG(x)	((x < 8) ? 0x0 : 0x24)
+#define MTK_FE_LINK_DOWN_P(x)	((x < 8) ? FIELD_PREP(GENMASK(15, 8), BIT(x)) :	\
+					   FIELD_PREP(GENMASK(7, 0), BIT(x - 8)))
+
 /* Frame Engine Global Reset Register */
 #define MTK_RST_GL		0x04
 #define RST_GL_PSE		BIT(0)
@@ -539,6 +541,7 @@
 #define MTK_WDMA_GLO_CFG(x)	(WDMA_BASE(x) + 0x204)
 #define MTK_WDMA_TX_DBG_MON0(x)	(WDMA_BASE(x) + 0x230)
 #define MTK_WDMA_RX_DBG_MON1(x)	(WDMA_BASE(x) + 0x3c4)
+#define MTK_WDMA_RX_MAX_CNT(x)	(WDMA_BASE(x) + 0x104)
 #define MTK_WDMA_CRX_PTR(x)	(WDMA_BASE(x) + 0x108)
 #define MTK_WDMA_DRX_PTR(x)	(WDMA_BASE(x) + 0x10C)
 #define MTK_CDM_FS_PARSER_FSM_MASK	GENMASK(27, 24)
@@ -892,6 +895,10 @@
 /* ethernet reset check idle register */
 #define ETHSYS_FE_RST_CHK_IDLE_EN 	0x28
 
+/* ethernet non-idle check register */
+#define ETHSYS_LP_NONE_IDLE_LAT0 (0x144)
+#define ETHSYS_LP_NONE_IDLE_LAT1 (0x148)
+
 /* ethernet dma channel agent map */
 #define ETHSYS_DMA_AG_MAP	0x408
 #define ETHSYS_DMA_AG_MAP_PDMA	BIT(0)
@@ -1006,6 +1013,12 @@
 #define USXGMII_LPA_LINK	BIT(15)
 #define USXGMII_LPA_LATCH	BIT(31)
 
+/* Register to QPHY wrapper control */
+#define RG_PHY_TOP_CTRL0	0x82C
+#define USXGMII_PN_SWAP_MASK	GENMASK(1, 0)
+#define USXGMII_PN_SWAP_RX	BIT(1)
+#define USXGMII_PN_SWAP_TX	BIT(0)
+
 /* Register to read PCS Link status */
 #define RG_PCS_RX_STATUS0	0x904
 #define RG_PCS_RX_STATUS_UPDATE	BIT(16)
@@ -1775,16 +1788,18 @@
 	struct mtk_eth		*eth;
 	struct regmap		*regmap;
 	struct regmap		*regmap_pextp;
-	spinlock_t		regmap_lock;
+	struct mutex		regmap_lock;
+	struct mutex		reset_lock;
 	phy_interface_t		interface;
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(advertising);
-	unsigned long		link_poll_inband;
+	unsigned long		link_poll_expire;
 	unsigned int		mode;
 	u32			flags;
 	u32			ana_rgc3;
 	u32			polarity;
 	u8			id;
-	struct timer_list	link_poll_outband;
+	struct phylink_link_state	state;
+	struct delayed_work	link_poll;
 	struct phylink_pcs	pcs;
 };
 
@@ -1812,12 +1827,15 @@
 	struct mtk_eth		*eth;
 	struct regmap		*regmap;
 	struct regmap		*regmap_pextp;
-	spinlock_t		regmap_lock;
+	struct mutex		regmap_lock;
+	struct mutex		reset_lock;
 	phy_interface_t		interface;
-	unsigned long		link_poll_inband;
+	unsigned long		link_poll_expire;
 	unsigned int		mode;
+	u32			polarity;
 	u8			id;
-	struct timer_list	link_poll_outband;
+	struct phylink_link_state	state;
+	struct delayed_work	link_poll;
 	struct phylink_pcs	pcs;
 };
 
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.c
index 011421c..d4f74c1 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.c
@@ -36,20 +36,24 @@
 void (*ra_sw_nat_clear_bind_entries)(void) = NULL;
 EXPORT_SYMBOL(ra_sw_nat_clear_bind_entries);
 
-int (*hnat_get_wdma_tx_port)(int wdma_idx) = NULL;
+int (*hnat_get_wdma_tx_port)(u32 wdma_idx) = NULL;
 EXPORT_SYMBOL(hnat_get_wdma_tx_port);
-int (*hnat_get_wdma_rx_port)(int wdma_idx) = NULL;
+int (*hnat_get_wdma_rx_port)(u32 wdma_idx) = NULL;
 EXPORT_SYMBOL(hnat_get_wdma_rx_port);
 
 int (*ppe_del_entry_by_mac)(unsigned char *mac) = NULL;
 EXPORT_SYMBOL(ppe_del_entry_by_mac);
+int (*ppe_del_entry_by_ip)(bool is_ipv4, void *addr) = NULL;
+EXPORT_SYMBOL(ppe_del_entry_by_ip);
+int (*ppe_del_entry_by_bssid_wcid)(u32 wdma_idx, u16 bssid, u16 wcid) = NULL;
+EXPORT_SYMBOL(ppe_del_entry_by_bssid_wcid);
 
 void (*ppe_dev_register_hook)(struct net_device *dev) = NULL;
 EXPORT_SYMBOL(ppe_dev_register_hook);
 void (*ppe_dev_unregister_hook)(struct net_device *dev) = NULL;
 EXPORT_SYMBOL(ppe_dev_unregister_hook);
 
-int (*hnat_set_wdma_pse_port_state)(int wdma_idx, int up) = NULL;
+int (*hnat_set_wdma_pse_port_state)(u32 wdma_idx, bool up) = NULL;
 EXPORT_SYMBOL(hnat_set_wdma_pse_port_state);
 
 static void hnat_sma_build_entry(struct timer_list *t)
@@ -144,7 +148,7 @@
 	}
 }
 
-static int mtk_get_wdma_tx_port(int wdma_idx)
+static int mtk_get_wdma_tx_port(u32 wdma_idx)
 {
 	if (wdma_idx == 0 || wdma_idx == 1 || wdma_idx == 2)
 		return NR_PPE0_PORT;
@@ -152,7 +156,7 @@
 	return -EINVAL;
 }
 
-static int mtk_get_wdma_rx_port(int wdma_idx)
+static int mtk_get_wdma_rx_port(u32 wdma_idx)
 {
 	if (wdma_idx == 2)
 		return NR_WDMA2_PORT;
@@ -164,20 +168,39 @@
 	return -EINVAL;
 }
 
-static int mtk_set_wdma_pse_port_state(int wdma_idx, int up)
+static int mtk_set_wdma_pse_port_state(u32 wdma_idx, bool up)
 {
-	u32 port = 0, link_dwn = 0;
+	int port;
 
 	port = mtk_get_wdma_rx_port(wdma_idx);
 	if (port < 0)
 		return -EINVAL;
 
-	link_dwn = 0x1 << (port - NR_WDMA0_PORT);
-	cr_set_field(hnat_priv->fe_base + MTK_FE_GLO_CFG(port), link_dwn, !up);
+	cr_set_field(hnat_priv->fe_base + MTK_FE_GLO_CFG(port),
+		     MTK_FE_LINK_DOWN_P((u32)port), !up);
 
 	return 0;
 }
 
+static int mtk_set_ppe_pse_port_state(u32 ppe_id, bool up)
+{
+	u32 port;
+
+	if (ppe_id == 0)
+		port = NR_PPE0_PORT;
+	else if (ppe_id == 1)
+		port = NR_PPE1_PORT;
+	else if (ppe_id == 2)
+		port = NR_PPE2_PORT;
+	else
+		return -EINVAL;
+
+	cr_set_field(hnat_priv->fe_base + MTK_FE_GLO_CFG(port),
+		     MTK_FE_LINK_DOWN_P(port), !up);
+
+	return 0;
+}
+
 void set_gmac_ppe_fwd(int id, int enable)
 {
 	void __iomem *reg;
@@ -241,6 +264,85 @@
 	return ret;
 }
 
+static int entry_ip_cmp(struct foe_entry *entry, bool is_ipv4, void *addr)
+{
+	struct in6_addr *tmp_ipv6;
+	struct in6_addr ipv6 = {0};
+	struct in6_addr foe_sipv6 = {0};
+	struct in6_addr foe_dipv6 = {0};
+	u32 *tmp_ipv4, ipv4;
+	u32 *sipv6_0 = NULL;
+	u32 *dipv6_0 = NULL;
+	int ret = 0;
+
+	if (is_ipv4) {
+		tmp_ipv4 = (u32 *)addr;
+		ipv4 = ntohl(*tmp_ipv4);
+
+		switch ((int)entry->bfib1.pkt_type) {
+		case IPV4_HNAPT:
+		case IPV4_HNAT:
+			if (entry->ipv4_hnapt.sip == ipv4 ||
+			    entry->ipv4_hnapt.new_dip == ipv4)
+				ret = 1;
+			break;
+		case IPV4_DSLITE:
+		case IPV4_MAP_E:
+			if (entry->ipv4_dslite.sip == ipv4 ||
+			    entry->ipv4_dslite.dip == ipv4)
+				ret = 1;
+			break;
+		default:
+			break;
+		}
+	} else {
+		memset(&foe_sipv6, 0, sizeof(struct in6_addr));
+		memset(&foe_dipv6, 0, sizeof(struct in6_addr));
+		memset(&ipv6, 0, sizeof(struct in6_addr));
+
+		tmp_ipv6 = (struct in6_addr *)addr;
+		ipv6.s6_addr32[0] = ntohl(tmp_ipv6->s6_addr32[0]);
+		ipv6.s6_addr32[1] = ntohl(tmp_ipv6->s6_addr32[1]);
+		ipv6.s6_addr32[2] = ntohl(tmp_ipv6->s6_addr32[2]);
+		ipv6.s6_addr32[3] = ntohl(tmp_ipv6->s6_addr32[3]);
+
+		switch ((int)entry->bfib1.pkt_type) {
+		case IPV6_3T_ROUTE:
+		case IPV6_5T_ROUTE:
+		case IPV6_6RD:
+			sipv6_0 = &(entry->ipv6_3t_route.ipv6_sip0);
+			dipv6_0 = &(entry->ipv6_3t_route.ipv6_dip0);
+			break;
+#if defined(CONFIG_MEDIATEK_NETSYS_V3)
+		case IPV6_HNAT:
+		case IPV6_HNAPT:
+			sipv6_0 = &(entry->ipv6_hnapt.ipv6_sip0);
+			dipv6_0 = &(entry->ipv6_hnapt.new_ipv6_ip0);
+			break;
+#endif
+		default:
+			break;
+		}
+
+		if (sipv6_0 && dipv6_0) {
+			memcpy(&foe_sipv6, sipv6_0, sizeof(struct in6_addr));
+			memcpy(&foe_dipv6, dipv6_0, sizeof(struct in6_addr));
+			if (!memcmp(&foe_sipv6, &ipv6, sizeof(struct in6_addr)) ||
+			    !memcmp(&foe_dipv6, &ipv6, sizeof(struct in6_addr)))
+				ret = 1;
+		}
+	}
+
+	if (ret && debug_level >= 2) {
+		if (is_ipv4)
+			pr_info("ipv4=%pI4\n", tmp_ipv4);
+		else
+			pr_info("ipv6=%pI6\n", tmp_ipv6);
+	}
+
+	return ret;
+}
+
 int entry_delete_by_mac(u8 *mac)
 {
 	struct foe_entry *entry = NULL;
@@ -265,6 +367,70 @@
 	return ret;
 }
 
+int entry_delete_by_ip(bool is_ipv4, void *addr)
+{
+	struct foe_entry *entry = NULL;
+	int index, i, ret = 0;
+
+	for (i = 0; i < CFG_PPE_NUM; i++) {
+		entry = hnat_priv->foe_table_cpu[i];
+		for (index = 0; index < DEF_ETRY_NUM; entry++, index++) {
+			if (entry->bfib1.state == BIND && entry_ip_cmp(entry, is_ipv4, addr)) {
+				memset(entry, 0, sizeof(*entry));
+				hnat_cache_ebl(1);
+				if (debug_level >= 2)
+					pr_info("delete entry idx = %d\n", index);
+				ret++;
+			}
+		}
+	}
+
+	if (!ret && debug_level >= 2)
+		pr_info("entry not found\n");
+
+	return ret;
+}
+
+static int entry_delete_by_bssid_wcid(u32 wdma_idx, u16 bssid, u16 wcid)
+{
+	struct foe_entry *entry = NULL;
+	int index, i;
+	int ret = 0;
+	int port;
+
+	port = mtk_get_wdma_rx_port(wdma_idx);
+
+	if (port < 0)
+		return -EINVAL;
+
+	for (i = 0; i < CFG_PPE_NUM; i++) {
+		entry = hnat_priv->foe_table_cpu[i];
+		for (index = 0; index < DEF_ETRY_NUM; entry++, index++) {
+			if (entry->bfib1.state != BIND)
+				continue;
+
+			if (IS_IPV4_GRP(entry)) {
+				if (entry->ipv4_hnapt.winfo.bssid != bssid ||
+				    entry->ipv4_hnapt.winfo.wcid != wcid ||
+				    entry->ipv4_hnapt.iblk2.dp != port)
+					continue;
+			} else {
+				if (entry->ipv6_5t_route.winfo.bssid != bssid ||
+				    entry->ipv6_5t_route.winfo.wcid != wcid ||
+				    entry->ipv6_5t_route.iblk2.dp != port)
+					continue;
+			}
+
+			memset(entry, 0, sizeof(*entry));
+			hnat_cache_ebl(1);
+			if (debug_level >= 2)
+				pr_info("delete entry idx = %d\n", index);
+			ret++;
+		}
+	}
+	return ret;
+}
+
 static void hnat_roam_handler(struct work_struct *work)
 {
 	struct kvec iov;
@@ -442,6 +608,8 @@
 	if (hnat_priv->data->version == MTK_HNAT_V3) {
 		cr_set_field(hnat_priv->ppe_base[ppe_id] + PPE_SB_FIFO_DBG,
 			     SB_MED_FULL_DRP_EN, 1);
+		cr_set_bits(hnat_priv->ppe_base[ppe_id] + PPE_GLO_CFG,
+			    NEW_IPV4_ID_INC_EN | TSID_EN);
 	}
 
 	/*enable ppe mib counter*/
@@ -668,6 +836,8 @@
 		return -1;
 
 	ppe_del_entry_by_mac = entry_delete_by_mac;
+	ppe_del_entry_by_ip = entry_delete_by_ip;
+	ppe_del_entry_by_bssid_wcid = entry_delete_by_bssid_wcid;
 	hook_toggle = 1;
 
 	return 0;
@@ -705,6 +875,8 @@
 
 	mod_timer(&hnat_priv->hnat_sma_build_entry_timer, jiffies + 3 * HZ);
 	ppe_del_entry_by_mac = NULL;
+	ppe_del_entry_by_ip = NULL;
+	ppe_del_entry_by_bssid_wcid = NULL;
 	hook_toggle = 0;
 
 	return 0;
@@ -713,6 +885,7 @@
 int hnat_warm_init(void)
 {
 	u32 foe_table_sz, foe_mib_tb_sz, ppe_id = 0;
+	int i;
 
 	unregister_netevent_notifier(&nf_hnat_netevent_nb);
 
@@ -738,6 +911,14 @@
 		hnat_hw_init(ppe_id);
 	}
 
+	/* The SER will enable all the PPE ports again,
+	 * so we have to manually disable the unused ports one more.
+	 */
+	for (i = 0; i < MAX_PPE_NUM; i++) {
+		if (i >= CFG_PPE_NUM)
+			mtk_set_ppe_pse_port_state(i, false);
+	}
+
 	set_gmac_ppe_fwd(NR_GMAC1_PORT, 1);
 	set_gmac_ppe_fwd(NR_GMAC2_PORT, 1);
 	set_gmac_ppe_fwd(NR_GMAC3_PORT, 1);
@@ -765,14 +946,18 @@
 	const struct of_device_id *match;
 
 	hnat_priv = devm_kzalloc(&pdev->dev, sizeof(struct mtk_hnat), GFP_KERNEL);
-	if (!hnat_priv)
-		return -ENOMEM;
+	if (!hnat_priv) {
+		err = -ENOMEM;
+		goto err_out2;
+	}
 
 	hnat_priv->foe_etry_num = DEF_ETRY_NUM;
 
 	match = of_match_device(of_hnat_match, &pdev->dev);
-	if (unlikely(!match))
-		return -EINVAL;
+	if (unlikely(!match)) {
+		err = -EINVAL;
+		goto err_out2;
+	}
 
 	hnat_priv->data = (struct mtk_hnat_data *)match->data;
 
@@ -780,8 +965,10 @@
 	np = hnat_priv->dev->of_node;
 
 	err = of_property_read_string(np, "mtketh-wan", &name);
-	if (err < 0)
-		return -EINVAL;
+	if (err < 0) {
+		err = -EINVAL;
+		goto err_out2;
+	}
 
 	strncpy(hnat_priv->wan, (char *)name, IFNAMSIZ - 1);
 	dev_info(&pdev->dev, "wan = %s\n", hnat_priv->wan);
@@ -810,8 +997,10 @@
 	/*get total gmac num in hnat*/
 	err = of_property_read_u32_index(np, "mtketh-max-gmac", 0, &val);
 
-	if (err < 0)
-		return -EINVAL;
+	if (err < 0) {
+		err = -EINVAL;
+		goto err_out2;
+	}
 
 	hnat_priv->gmac_num = val;
 
@@ -836,13 +1025,17 @@
 	dev_info(&pdev->dev, "ppe num = %d\n", hnat_priv->ppe_num);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	if (!res)
-		return -ENOENT;
+	if (!res) {
+		err = -ENOENT;
+		goto err_out2;
+	}
 
 	hnat_priv->fe_base = devm_ioremap_nocache(&pdev->dev, res->start,
 					     res->end - res->start + 1);
-	if (!hnat_priv->fe_base)
-		return -EADDRNOTAVAIL;
+	if (!hnat_priv->fe_base) {
+		err = -EADDRNOTAVAIL;
+		goto err_out2;
+	}
 
 #if defined(CONFIG_MEDIATEK_NETSYS_V2) || defined(CONFIG_MEDIATEK_NETSYS_V3)
 	hnat_priv->ppe_base[0] = hnat_priv->fe_base + 0x2200;
@@ -858,7 +1051,7 @@
 
 	err = hnat_init_debugfs(hnat_priv);
 	if (err)
-		return err;
+		goto err_out2;
 
 	prop = of_find_property(np, "ext-devices", NULL);
 	for (name = of_prop_next_string(prop, NULL); name;
@@ -886,6 +1079,16 @@
 			goto err_out;
 	}
 
+	/* The PSE default enables all the PPE ports,
+	 * so we need to manually disable the unused ports.
+	 */
+	for (i = 0; i < MAX_PPE_NUM; i++) {
+		if (i >= CFG_PPE_NUM)
+			mtk_set_ppe_pse_port_state(i, false);
+		else
+			mtk_set_ppe_pse_port_state(i, true);
+	}
+
 	if (hnat_priv->data->whnat) {
 		err = whnat_adjust_nf_hooks();
 		if (err)
@@ -932,6 +1135,9 @@
 		ext_if_del(ext_entry);
 		kfree(ext_entry);
 	}
+err_out2:
+	for (i = 0; i < MAX_PPE_NUM; i++)
+		mtk_set_ppe_pse_port_state(i, false);
 	return err;
 }
 
@@ -950,6 +1156,9 @@
 	for (i = 0; i < CFG_PPE_NUM; i++)
 		hnat_stop(i);
 
+	for (i = 0; i < MAX_PPE_NUM; i++)
+		mtk_set_ppe_pse_port_state(i, false);
+
 	hnat_deinit_debugfs(hnat_priv);
 	hnat_release_netdev();
 	del_timer_sync(&hnat_priv->hnat_sma_build_entry_timer);
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
index f7ca61c..c59e97e 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat.h
@@ -17,6 +17,7 @@
 #include <linux/string.h>
 #include <linux/if.h>
 #include <linux/if_ether.h>
+#include <net/dsa.h>
 #include <net/netevent.h>
 #include <net/netfilter/nf_conntrack_zones.h>
 #include <linux/mod_devicetable.h>
@@ -192,6 +193,7 @@
 #define TTL0_DRP (0x1 << 4) /* RW */
 #define MCAST_TB_EN (0x1 << 7) /* RW */
 #define MCAST_HASH (0x3 << 12) /* RW */
+#define NEW_IPV4_ID_INC_EN (0x1 << 20) /* RW */
 #define SP_CMP_EN (0x1 << 25) /* RW */
 
 #define MC_P3_PPSE (0xf << 12) /* RW */
@@ -1286,30 +1288,19 @@
 		hnat_set_entry_lock(entry, false);
 }
 
-#if defined(CONFIG_NET_DSA_MT7530)
-u32 hnat_dsa_fill_stag(const struct net_device *netdev,
+int hnat_dsa_fill_stag(const struct net_device *netdev,
 		       struct foe_entry *entry,
 		       struct flow_offload_hw_path *hw_path,
 		       u16 eth_proto, int mape);
-
+int hnat_dsa_get_port(struct net_device **dev);
 static inline bool hnat_dsa_is_enable(struct mtk_hnat *priv)
 {
+#if defined(CONFIG_NET_DSA)
 	return (priv->wan_dsa_port != NONE_DSA_PORT);
-}
 #else
-static inline u32 hnat_dsa_fill_stag(const struct net_device *netdev,
-				     struct foe_entry *entry,
-				     struct flow_offload_hw_path *hw_path,
-				     u16 eth_proto, int mape)
-{
-	return 0;
-}
-
-static inline bool hnat_dsa_is_enable(struct mtk_hnat *priv)
-{
 	return false;
-}
 #endif
+}
 
 void hnat_deinit_debugfs(struct mtk_hnat *h);
 int hnat_init_debugfs(struct mtk_hnat *h);
@@ -1350,6 +1341,7 @@
 void set_gmac_ppe_fwd(int gmac_no, int enable);
 int entry_detail(u32 ppe_id, int index);
 int entry_delete_by_mac(u8 *mac);
+int entry_delete_by_ip(bool is_ipv4, void *addr);
 int entry_delete(u32 ppe_id, int index);
 int hnat_warm_init(void);
 u32 hnat_get_ppe_hash(struct foe_entry *entry);
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c
index 3e0d540..53f4d10 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_debugfs.c
@@ -324,6 +324,9 @@
 	pr_info("              6   <entry_idx>  Show PPE2 specific foe entry info. of assigned <entry_idx>\n");
 	pr_info("              7   <entry_idx>  Delete PPE2 specific foe entry of assigned <entry_idx>\n");
 	pr_info("                               When entry_idx is -1, clear all entries\n");
+	pr_info("              8   <mac>        Delete all PPEs foe entry of assinged smac and dmac\n");
+	pr_info("              9   <ip>         Delete all PPEs foe entry of assinged IP(DL and UL)\n");
+	pr_info("              10  <ipV6>       Delete all PPEs foe entry of assinged IPv6(DL and UL)\n");
 
 	return 0;
 }
@@ -743,6 +746,66 @@
 }
 EXPORT_SYMBOL(entry_delete);
 
+static u32 hnat_char2hex(const char c)
+{
+	switch (c) {
+	case '0'...'9':
+		return 0x0 + (c - '0');
+	case 'a'...'f':
+		return 0xa + (c - 'a');
+	case 'A'...'F':
+		return 0xa + (c - 'A');
+	default:
+		pr_info("MAC format error\n");
+		return 0;
+	}
+}
+
+static void hnat_parse_mac(char *str, char *mac)
+{
+	int i;
+
+	for (i = 0; i < ETH_ALEN; i++) {
+		mac[i] = (hnat_char2hex(str[i * 3]) << 4) +
+			 (hnat_char2hex(str[i * 3 + 1]));
+	}
+}
+
+int delete_entry_by_mac(char *mac_str)
+{
+	char mac[6];
+
+	hnat_parse_mac(mac_str, mac);
+	entry_delete_by_mac(mac);
+
+	return 0;
+}
+
+int delete_entry_by_ip(bool is_ipv4, char *str)
+{
+	struct in6_addr ipv6;
+	void *addr = NULL;
+	u32 ipv4;
+
+	if (is_ipv4) {
+		if (!in4_pton(str, -1, (u8 *)&ipv4, -1, NULL)) {
+			pr_info("Invalid IPv4 address.\n");
+			return -EINVAL;
+		}
+		addr = (void *)(&ipv4);
+	} else {
+		if (!in6_pton(str, -1, (u8 *)&ipv6, -1, NULL)) {
+			pr_info("Invalid IPv6 address.\n");
+			return -EINVAL;
+		}
+		addr = (void *)(&ipv6);
+	}
+
+	entry_delete_by_ip(is_ipv4, addr);
+
+	return 0;
+}
+
 int cr_set_usage(int level)
 {
 	debug_level = level;
@@ -1893,6 +1956,7 @@
 	char *p_token = NULL;
 	char *p_delimiter = " \t";
 	int ret;
+	bool is_ipv4 = true;
 
 	if (len >= sizeof(buf)) {
 		pr_info("input handling fail!\n");
@@ -1925,16 +1989,32 @@
 			arg1 = 0;
 		else
 			ret = kstrtol(p_token, 10, &arg1);
+
+		(*entry_set_func[arg0])(arg1);
+		break;
+	case 8:
+		p_token = strsep(&p_buf, p_delimiter);
+		if (!p_token)
+			break;
+
+		delete_entry_by_mac(p_token);
+		break;
+	case 9:
+	case 10:
+		p_token = strsep(&p_buf, p_delimiter);
+		if (!p_token)
+			break;
+
+		if (arg0 == 10)
+			is_ipv4 = false;
+		delete_entry_by_ip(is_ipv4, p_token);
 		break;
 	default:
 		pr_info("no handler defined for command id(0x%08lx)\n\r", arg0);
-		arg0 = 0;
-		arg1 = 0;
+		entry_set_usage(debug_level);
 		break;
 	}
 
-	(*entry_set_func[arg0])(arg1);
-
 	return len;
 }
 
@@ -3049,31 +3129,6 @@
 	return hash;
 }
 
-static u32 hnat_char2hex(const char c)
-{
-	switch (c) {
-	case '0'...'9':
-		return 0x0 + (c - '0');
-	case 'a'...'f':
-		return 0xa + (c - 'a');
-	case 'A'...'F':
-		return 0xa + (c - 'A');
-	default:
-		pr_info("MAC format error\n");
-		return 0;
-	}
-}
-
-static void hnat_parse_mac(char *str, char *mac)
-{
-	int i;
-
-	for (i = 0; i < ETH_ALEN; i++) {
-		mac[i] = (hnat_char2hex(str[i * 3]) << 4) +
-			 (hnat_char2hex(str[i * 3 + 1]));
-	}
-}
-
 static void hnat_static_entry_help(void)
 {
 	pr_info("-------------------- Usage --------------------\n");
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
index cbebcd4..6960462 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_nf_hook.c
@@ -843,7 +843,7 @@
 mtk_hnat_ipv4_nf_pre_routing(void *priv, struct sk_buff *skb,
 			     const struct nf_hook_state *state)
 {
-	struct flow_offload_hw_path hw_path;
+	struct flow_offload_hw_path hw_path = { 0 };
 
 	if (!skb)
 		goto drop;
@@ -998,7 +998,7 @@
 	return NF_DROP;
 }
 
-static unsigned int hnat_ipv6_get_nexthop(struct sk_buff *skb,
+static int hnat_ipv6_get_nexthop(struct sk_buff *skb,
 					  const struct net_device *out,
 					  struct flow_offload_hw_path *hw_path)
 {
@@ -1056,7 +1056,7 @@
 	return 0;
 }
 
-static unsigned int hnat_ipv4_get_nexthop(struct sk_buff *skb,
+static int hnat_ipv4_get_nexthop(struct sk_buff *skb,
 					  const struct net_device *out,
 					  struct flow_offload_hw_path *hw_path)
 {
@@ -1065,10 +1065,13 @@
 	struct dst_entry *dst = skb_dst(skb);
 	struct rtable *rt = (struct rtable *)dst;
 	struct net_device *dev = (__force struct net_device *)out;
+	struct ethhdr *eth;
 
 	if (hw_path->flags & FLOW_OFFLOAD_PATH_PPPOE) {
+		rcu_read_lock_bh();
 		memcpy(eth_hdr(skb)->h_source, hw_path->eth_src, ETH_ALEN);
 		memcpy(eth_hdr(skb)->h_dest, hw_path->eth_dest, ETH_ALEN);
+		rcu_read_unlock_bh();
 		return 0;
 	}
 
@@ -1088,8 +1091,15 @@
 		return -1;
 	}
 
+	if (ip_hdr(skb)->protocol == IPPROTO_IPV6)
+		/* 6RD LAN->WAN(6to4) */
+		eth = (struct ethhdr *)(skb->data - ETH_HLEN);
+	else
+		eth = eth_hdr(skb);
+
-	memcpy(eth_hdr(skb)->h_dest, neigh->ha, ETH_ALEN);
-	memcpy(eth_hdr(skb)->h_source, out->dev_addr, ETH_ALEN);
+	memcpy(eth->h_dest, neigh->ha, ETH_ALEN);
+	memcpy(eth->h_source, out->dev_addr, ETH_ALEN);
+	eth->h_proto = htons(ETH_P_IP);
 
 	rcu_read_unlock_bh();
 
@@ -1224,8 +1234,10 @@
 				     struct foe_entry *foe,
 				     struct flow_offload_hw_path *hw_path)
 {
+	struct net_device *master_dev = (struct net_device *)dev;
 	struct foe_entry entry = { 0 };
 	int whnat = IS_WHNAT(dev);
+	struct mtk_mac *mac;
 	struct ethhdr *eth;
 	struct iphdr *iph;
 	struct ipv6hdr *ip6h;
@@ -1235,15 +1247,17 @@
 	enum ip_conntrack_info ctinfo;
 	int gmac = NR_DISCARD;
 	int udp = 0;
+	int port_id = 0;
 	u32 qid = 0;
-	u32 port_id = 0;
 	u32 payload_len = 0;
 	int mape = 0;
-	struct mtk_mac *mac = netdev_priv(dev);
 
 	if (ipv6_hdr(skb)->nexthdr == NEXTHDR_IPIP)
 		/* point to ethernet header for DS-Lite and MapE */
 		eth = get_ipv6_ipip_ethhdr(skb, hw_path);
+	else if (ip_hdr(skb)->protocol == IPPROTO_IPV6)
+		/* 6RD LAN->WAN(6to4) */
+		eth = (struct ethhdr *)(skb->data - ETH_HLEN);
 	else
 		eth = eth_hdr(skb);
 
@@ -1381,6 +1395,44 @@
 			entry.ipv4_hnapt.bfib1.udp = udp;
 			break;
 
+		case IPPROTO_IPV6:
+			/* 6RD LAN->WAN(6to4) */
+			if (entry.bfib1.pkt_type == IPV6_6RD) {
+				entry.ipv6_6rd.ipv6_sip0 = foe->ipv6_6rd.ipv6_sip0;
+				entry.ipv6_6rd.ipv6_sip1 = foe->ipv6_6rd.ipv6_sip1;
+				entry.ipv6_6rd.ipv6_sip2 = foe->ipv6_6rd.ipv6_sip2;
+				entry.ipv6_6rd.ipv6_sip3 = foe->ipv6_6rd.ipv6_sip3;
+
+				entry.ipv6_6rd.ipv6_dip0 = foe->ipv6_6rd.ipv6_dip0;
+				entry.ipv6_6rd.ipv6_dip1 = foe->ipv6_6rd.ipv6_dip1;
+				entry.ipv6_6rd.ipv6_dip2 = foe->ipv6_6rd.ipv6_dip2;
+				entry.ipv6_6rd.ipv6_dip3 = foe->ipv6_6rd.ipv6_dip3;
+
+				entry.ipv6_6rd.sport = foe->ipv6_6rd.sport;
+				entry.ipv6_6rd.dport = foe->ipv6_6rd.dport;
+				entry.ipv6_6rd.tunnel_sipv4 = ntohl(iph->saddr);
+				entry.ipv6_6rd.tunnel_dipv4 = ntohl(iph->daddr);
+				entry.ipv6_6rd.hdr_chksum = ppe_get_chkbase(iph);
+				entry.ipv6_6rd.flag = (ntohs(iph->frag_off) >> 13);
+				entry.ipv6_6rd.ttl = iph->ttl;
+				entry.ipv6_6rd.dscp = iph->tos;
+				entry.ipv6_6rd.per_flow_6rd_id = 1;
+				entry.ipv6_6rd.vlan1 = hw_path->vlan_id;
+				if (hnat_priv->data->per_flow_accounting)
+					entry.ipv6_6rd.iblk2.mibf = 1;
+
+				ip6h = (struct ipv6hdr *)skb_inner_network_header(skb);
+				if (ip6h->nexthdr == NEXTHDR_UDP)
+					entry.ipv6_6rd.bfib1.udp = 1;
+
+#if defined(CONFIG_MEDIATEK_NETSYS_V3)
+				entry.ipv6_6rd.eg_keep_ecn = 1;
+				entry.ipv6_6rd.eg_keep_cls = 1;
+#endif
+				break;
+			}
+
+			return -1;
 		default:
 			return -1;
 		}
@@ -1640,41 +1692,7 @@
 		break;
 
 	default:
-		iph = ip_hdr(skb);
-		switch (entry.bfib1.pkt_type) {
-		case IPV6_6RD: /* 6RD LAN->WAN */
-			entry.ipv6_6rd.ipv6_sip0 = foe->ipv6_6rd.ipv6_sip0;
-			entry.ipv6_6rd.ipv6_sip1 = foe->ipv6_6rd.ipv6_sip1;
-			entry.ipv6_6rd.ipv6_sip2 = foe->ipv6_6rd.ipv6_sip2;
-			entry.ipv6_6rd.ipv6_sip3 = foe->ipv6_6rd.ipv6_sip3;
-
-			entry.ipv6_6rd.ipv6_dip0 = foe->ipv6_6rd.ipv6_dip0;
-			entry.ipv6_6rd.ipv6_dip1 = foe->ipv6_6rd.ipv6_dip1;
-			entry.ipv6_6rd.ipv6_dip2 = foe->ipv6_6rd.ipv6_dip2;
-			entry.ipv6_6rd.ipv6_dip3 = foe->ipv6_6rd.ipv6_dip3;
-
-			entry.ipv6_6rd.sport = foe->ipv6_6rd.sport;
-			entry.ipv6_6rd.dport = foe->ipv6_6rd.dport;
-			entry.ipv6_6rd.tunnel_sipv4 = ntohl(iph->saddr);
-			entry.ipv6_6rd.tunnel_dipv4 = ntohl(iph->daddr);
-			entry.ipv6_6rd.hdr_chksum = ppe_get_chkbase(iph);
-			entry.ipv6_6rd.flag = (ntohs(iph->frag_off) >> 13);
-			entry.ipv6_6rd.ttl = iph->ttl;
-			entry.ipv6_6rd.dscp = iph->tos;
-			entry.ipv6_6rd.per_flow_6rd_id = 1;
-			entry.ipv6_6rd.vlan1 = hw_path->vlan_id;
-			if (hnat_priv->data->per_flow_accounting)
-				entry.ipv6_6rd.iblk2.mibf = 1;
-
-#if defined(CONFIG_MEDIATEK_NETSYS_V3)
-			entry.ipv6_6rd.eg_keep_ecn = 1;
-			entry.ipv6_6rd.eg_keep_cls = 1;
-#endif
-			break;
-
-		default:
-			return -1;
-		}
+		return -1;
 	}
 
 	/* Fill Layer2 Info.*/
@@ -1683,33 +1701,25 @@
 	/* Fill Info Blk*/
 	entry = ppe_fill_info_blk(eth, entry, hw_path);
 
-	if (IS_LAN(dev)) {
-		if (IS_BOND_MODE) {
-			gmac = ((skb_hnat_entry(skb) >> 1) % hnat_priv->gmac_num) ?
-				 NR_GMAC2_PORT : NR_GMAC1_PORT;
-		} else if (IS_DSA_LAN(dev)) {
-			port_id = hnat_dsa_fill_stag(dev, &entry, hw_path,
-						     ntohs(eth->h_proto),
-						     mape);
-			gmac = NR_GMAC1_PORT;
-		} else {
-			gmac = HNAT_GMAC_FP(mac->id);
+	if (IS_LAN_GRP(dev) || IS_WAN(dev)) { /* Forward to GMAC Ports */
+		port_id = hnat_dsa_get_port(&master_dev);
+		if (port_id >= 0) {
+			if (hnat_dsa_fill_stag(dev, &entry, hw_path,
+					       ntohs(eth->h_proto), mape) < 0)
+				return 0;
 		}
-	} else if (IS_LAN2(dev)) {
+
+		mac = netdev_priv(master_dev);
 		gmac = HNAT_GMAC_FP(mac->id);
-	} else if (IS_WAN(dev)) {
-		if (mape_toggle && mape == 1) {
+
+		if (IS_LAN(dev) && IS_BOND_MODE) {
+			gmac = ((skb_hnat_entry(skb) >> 1) % hnat_priv->gmac_num) ?
+				 NR_GMAC2_PORT : NR_GMAC1_PORT;
+		} else if (IS_WAN(dev) && mape_toggle && mape == 1) {
 			gmac = NR_PDMA_PORT;
 			/* Set act_dp = wan_dev */
 			entry.ipv4_hnapt.act_dp &= ~UDF_PINGPONG_IFIDX;
 			entry.ipv4_hnapt.act_dp |= dev->ifindex & UDF_PINGPONG_IFIDX;
-		} else if (IS_DSA_WAN(dev)) {
-			port_id = hnat_dsa_fill_stag(dev, &entry, hw_path,
-						     ntohs(eth->h_proto),
-						     mape);
-			gmac = NR_GMAC1_PORT;
-		} else {
-			gmac = HNAT_GMAC_FP(mac->id);
 		}
 	} else if (IS_EXT(dev) && (FROM_GE_PPD(skb) || FROM_GE_LAN_GRP(skb) ||
 		   FROM_GE_WAN(skb) || FROM_GE_VIRTUAL(skb) || FROM_WED(skb))) {
@@ -1931,7 +1941,7 @@
 		/* We must ensure all info has been updated before set to hw */
 		wmb();
 		/* After other fields have been written, write info1 to BIND the entry */
-		foe->bfib1 = entry.bfib1;
+		memcpy(&foe->bfib1, &entry.bfib1, sizeof(entry.bfib1));
 
 		/* reset statistic for this entry */
 		if (hnat_priv->data->per_flow_accounting &&
@@ -2240,7 +2250,7 @@
 	/* We must ensure all info has been updated before set to hw */
 	wmb();
 	/* After other fields have been written, write info1 to BIND the entry */
-	hw_entry->bfib1 = entry.bfib1;
+	memcpy(&hw_entry->bfib1, &entry.bfib1, sizeof(entry.bfib1));
 
 	hnat_set_entry_lock(hw_entry, false);
 
@@ -2748,8 +2758,8 @@
 
 static unsigned int mtk_hnat_nf_post_routing(
 	struct sk_buff *skb, const struct net_device *out,
-	unsigned int (*fn)(struct sk_buff *, const struct net_device *,
-			   struct flow_offload_hw_path *),
+	int (*fn)(struct sk_buff *, const struct net_device *,
+		  struct flow_offload_hw_path *),
 	const char *func)
 {
 	struct foe_entry *entry;
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_stag.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_stag.c
index 75c3a75..d8e5709 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_stag.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_hnat/hnat_stag.c
@@ -6,58 +6,77 @@
 
 #include <linux/of_device.h>
 #include <net/netfilter/nf_flow_table.h>
+
 #include "hnat.h"
 
+int hnat_dsa_get_port(struct net_device **dev)
+{
+#if defined(CONFIG_NET_DSA)
+	struct dsa_port *dp;
+
+	dp = dsa_port_from_netdev(*dev);
+	if (IS_ERR(dp))
+		return -ENODEV;
+
+	*dev = dp->cpu_dp->master;
+
+	return dp->index;
+#else
+	return -ENODEV;
+#endif
+}
+
-u32 hnat_dsa_fill_stag(const struct net_device *netdev,
+int hnat_dsa_fill_stag(const struct net_device *netdev,
 		       struct foe_entry *entry,
 		       struct flow_offload_hw_path *hw_path,
 		       u16 eth_proto,
 		       int mape)
 {
-	const struct net_device *ndev;
+#if defined(CONFIG_NET_DSA)
 	const unsigned int *port_reg;
+	const struct dsa_port *dp;
+	struct net_device *ndev;
 	int port_index;
-	u16 sp_tag;
+	u16 dsa_tag;
 
 	if (hw_path->flags & FLOW_OFFLOAD_PATH_VLAN)
 		ndev = hw_path->dev;
 	else
-		ndev = netdev;
+		ndev = (struct net_device *)netdev;
 
 	port_reg = of_get_property(ndev->dev.of_node, "reg", NULL);
 	if (unlikely(!port_reg))
 		return -EINVAL;
 
 	port_index = be32_to_cpup(port_reg);
-	sp_tag = BIT(port_index);
+
+	/* In the case MAPE LAN --> WAN, binding entry is to CPU.
+	 * Do not add special tag.
+	 */
+	if (IS_WAN(ndev) && mape)
+		return port_index;
+
+	dp = dsa_port_from_netdev(ndev);
+	if (IS_ERR(dp))
+		return -ENODEV;
+
+	dsa_tag = BIT(port_index);
 
 	if (!entry->bfib1.vlan_layer)
 		entry->bfib1.vlan_layer = 1;
 	else
 		/* VLAN existence indicator */
-		sp_tag |= BIT(8);
-	entry->bfib1.vpm = 0;
+		dsa_tag |= BIT(8);
 
-	switch (eth_proto) {
-	case ETH_P_IP:
-		if (entry->ipv4_hnapt.bfib1.pkt_type == IPV4_DSLITE
-			|| (entry->ipv4_hnapt.bfib1.pkt_type == IPV4_MAP_E))
-			entry->ipv4_dslite.etype = sp_tag;
-		else
-			entry->ipv4_hnapt.etype = sp_tag;
-		break;
-	case ETH_P_IPV6:
-		/* In the case MAPE LAN --> WAN, binding entry is to CPU.
-		 * Do not add special tag.
-		 */
-		if (!mape)
-			/* etype offset of ipv6 entries are the same. */
-			entry->ipv6_5t_route.etype = sp_tag;
+	if (IS_IPV4_GRP(entry))
+		entry->ipv4_hnapt.etype = dsa_tag;
+	else
+		entry->ipv6_5t_route.etype = dsa_tag;
 
-		break;
-	default:
-		pr_info("DSA + HNAT unsupport protocol\n");
-	}
+	entry->bfib1.vpm = 0;
 
 	return port_index;
+#else
+	return -EINVAL;
+#endif
 }
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_sgmii.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_sgmii.c
index 8ae7608..51a9b1f 100755
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_sgmii.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_sgmii.c
@@ -77,18 +77,70 @@
 {
 	unsigned int val;
 
+	mutex_lock(&mpcs->reset_lock);
+
 	regmap_read(mpcs->regmap, SGMSYS_PCS_CONTROL_1, &val);
 
+	mutex_unlock(&mpcs->reset_lock);
+
 	return FIELD_GET(SGMII_LINK_STATYS, val);
 }
 
+static void mtk_sgmii_get_state(struct mtk_sgmii_pcs *mpcs)
+{
+	struct phylink_link_state *state = &mpcs->state;
+	unsigned int bm, adv, rgc3, sgm_mode;
+
+	mutex_lock(&mpcs->reset_lock);
+
+	state->interface = mpcs->interface;
+
+	regmap_read(mpcs->regmap, SGMSYS_PCS_CONTROL_1, &bm);
+	if (bm & SGMII_AN_ENABLE) {
+		regmap_read(mpcs->regmap, SGMSYS_PCS_ADVERTISE, &adv);
+
+		phylink_mii_c22_pcs_decode_state(state,
+						 FIELD_GET(SGMII_BMSR, bm),
+						 FIELD_GET(SGMII_LPA, adv));
+	} else {
+		state->link = !!(bm & SGMII_LINK_STATYS);
+
+		regmap_read(mpcs->regmap, SGMSYS_SGMII_MODE, &sgm_mode);
+
+		switch (sgm_mode & SGMII_SPEED_MASK) {
+		case SGMII_SPEED_10:
+			state->speed = SPEED_10;
+			break;
+		case SGMII_SPEED_100:
+			state->speed = SPEED_100;
+			break;
+		case SGMII_SPEED_1000:
+			regmap_read(mpcs->regmap, mpcs->ana_rgc3, &rgc3);
+			rgc3 = FIELD_GET(RG_PHY_SPEED_3_125G, rgc3);
+			state->speed = rgc3 ? SPEED_2500 : SPEED_1000;
+			break;
+		}
+
+		if (sgm_mode & SGMII_DUPLEX_HALF)
+			state->duplex = DUPLEX_HALF;
+		else
+			state->duplex = DUPLEX_FULL;
+	}
+
+	mutex_unlock(&mpcs->reset_lock);
+}
+
-void mtk_sgmii_reset(struct mtk_eth *eth, int id)
+void mtk_sgmii_reset(struct mtk_sgmii_pcs *mpcs)
 {
+	struct mtk_eth *eth = mpcs->eth;
+	int id = mpcs->id;
 	u32 val = 0;
 
-	if (!eth->toprgu)
+	if (id >= MTK_MAX_DEVS || !eth->toprgu)
 		return;
 
+	mutex_lock(&mpcs->reset_lock);
+
 	switch (id) {
 	case 0:
 		/* Enable software reset */
@@ -104,7 +156,7 @@
 		       SWSYSRST_SGMII0_GRST;
 		regmap_write(eth->toprgu, TOPRGU_SWSYSRST, val);
 
-		udelay(100);
+		usleep_range(100, 500);
 
 		/* De-assert SGMII reset */
 		regmap_read(eth->toprgu, TOPRGU_SWSYSRST, &val);
@@ -133,7 +185,7 @@
 		       SWSYSRST_SGMII1_GRST;
 		regmap_write(eth->toprgu, TOPRGU_SWSYSRST, val);
 
-		udelay(100);
+		usleep_range(100, 500);
 
 		/* De-assert SGMII reset */
 		regmap_read(eth->toprgu, TOPRGU_SWSYSRST, &val);
@@ -150,7 +202,9 @@
 		break;
 	}
 
+	mutex_unlock(&mpcs->reset_lock);
+
-	mdelay(1);
+	usleep_range(10000, 11000);
 }
 
 void mtk_sgmii_setup_phya_gen1(struct mtk_sgmii_pcs *mpcs)
@@ -210,7 +264,7 @@
 	/* Force AEQ on */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x02002800);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x3040, GENMASK(31, 0),
 			   0x20000000);
 	/* Setup DA default value */
@@ -241,28 +295,28 @@
 	/* Release reset */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200E800);
-	udelay(150);
+	usleep_range(150, 500);
 	/* Switch to P0 */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200C111);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200C101);
-	udelay(15);
+	usleep_range(15, 50);
 	/* Switch to Gen2 */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0201C111);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0201C101);
-	udelay(100);
+	usleep_range(100, 500);
 	regmap_update_bits(mpcs->regmap_pextp, 0x30B0, GENMASK(31, 0),
 			   0x00000030);
 	regmap_update_bits(mpcs->regmap_pextp, 0x00F4, GENMASK(31, 0),
 			   0x80201F01);
 	regmap_update_bits(mpcs->regmap_pextp, 0x3040, GENMASK(31, 0),
 			   0x30000000);
-	udelay(400);
+	usleep_range(400, 1000);
 }
 
 void mtk_sgmii_setup_phya_gen2(struct mtk_sgmii_pcs *mpcs)
@@ -322,7 +376,7 @@
 	/* Force AEQ on */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x02002800);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x3040, GENMASK(31, 0),
 			   0x20000000);
 	/* Setup DA default value */
@@ -351,28 +405,28 @@
 	/* Release reset */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200E800);
-	udelay(150);
+	usleep_range(150, 500);
 	/* Switch to P0 */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200C111);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200C101);
-	udelay(15);
+	usleep_range(15, 50);
 	/* Switch to Gen2 */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0201C111);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0201C101);
-	udelay(100);
+	usleep_range(100, 500);
 	regmap_update_bits(mpcs->regmap_pextp, 0x30B0, GENMASK(31, 0),
 			   0x00000030);
 	regmap_update_bits(mpcs->regmap_pextp, 0x00F4, GENMASK(31, 0),
 			   0x80201F01);
 	regmap_update_bits(mpcs->regmap_pextp, 0x3040, GENMASK(31, 0),
 			   0x30000000);
-	udelay(400);
+	usleep_range(400, 1000);
 }
 
 static int mtk_sgmii_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
@@ -391,8 +445,6 @@
 	if (advertise < 0)
 		return advertise;
 
-	spin_lock(&mpcs->regmap_lock);
-
 	/* Clearing IF_MODE_BIT0 switches the PCS to BASE-X mode, and
 	 * we assume that fixes it's speed at bitrate = line rate (in
 	 * other words, 1000Mbps or 2500Mbps).
@@ -416,22 +468,22 @@
 			speed = SGMII_SPEED_1000;
 	}
 
-	if (mpcs->interface != interface) {
-		mpcs->interface = interface;
-		mpcs->mode = mode;
-		linkmode_copy(mpcs->advertising, advertising);
-		mode_changed = true;
-	}
-
 	link_timer = phylink_get_link_timer_ns(interface);
-	if (link_timer < 0) {
-		spin_unlock(&mpcs->regmap_lock);
+	if (link_timer < 0)
 		return link_timer;
-	}
 
 	if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
 		mtk_sgmii_xfi_pll_enable(eth->sgmii);
-		mtk_sgmii_reset(eth, mpcs->id);
+		mtk_sgmii_reset(mpcs);
+	}
+
+	mutex_lock(&mpcs->regmap_lock);
+
+	if (mode >= 0 && mpcs->interface != interface) {
+		mpcs->interface = interface;
+		mpcs->mode = mode;
+		linkmode_copy(mpcs->advertising, advertising);
+		mode_changed = true;
 	}
 
 	/* PHYA power down */
@@ -474,7 +526,7 @@
 			   SGMII_AN_ENABLE, bmcr);
 
 	/* Release PHYA power down state */
-	udelay(100);
+	usleep_range(50, 100);
 	regmap_write(mpcs->regmap, SGMSYS_QPHY_PWR_STATE_CTRL, 0);
 
 	if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V3)) {
@@ -484,32 +536,38 @@
 			mtk_sgmii_setup_phya_gen1(mpcs);
 	}
 
-	spin_unlock(&mpcs->regmap_lock);
+	mutex_unlock(&mpcs->regmap_lock);
 
 	return changed || mode_changed;
 }
 
-static void mtk_sgmii_pcs_link_poll(struct timer_list *t)
+static void mtk_sgmii_pcs_link_poll(struct work_struct *work)
 {
-	struct mtk_sgmii_pcs *mpcs = from_timer(mpcs, t, link_poll_outband);
+	struct mtk_sgmii_pcs *mpcs = container_of(work, struct mtk_sgmii_pcs,
+						  link_poll.work);
 
-	if (mpcs->interface == PHY_INTERFACE_MODE_NA)
+	if (mpcs->interface != PHY_INTERFACE_MODE_SGMII &&
+	    mpcs->interface != PHY_INTERFACE_MODE_1000BASEX &&
+	    mpcs->interface != PHY_INTERFACE_MODE_2500BASEX)
 		goto exit;
 
 	if (!mtk_sgmii_link_status(mpcs))
-		mtk_sgmii_pcs_config(&mpcs->pcs, mpcs->mode, mpcs->interface,
+		mtk_sgmii_pcs_config(&mpcs->pcs, -1, mpcs->interface,
 				     mpcs->advertising, false);
 
 exit:
-	if (mpcs->mode != MLO_AN_INBAND)
-		mod_timer(&mpcs->link_poll_outband, jiffies + HZ);
+	if (mpcs->mode == MLO_AN_INBAND)
+		mtk_sgmii_get_state(mpcs);
+	else if (!delayed_work_pending(&mpcs->link_poll))
+		schedule_delayed_work(&mpcs->link_poll, msecs_to_jiffies(1000));
 }
 
 static int mtk_sgmii_pcs_enable(struct phylink_pcs *pcs)
 {
 	struct mtk_sgmii_pcs *mpcs = pcs_to_mtk_sgmii_pcs(pcs);
 
-	mod_timer(&mpcs->link_poll_outband, jiffies + HZ);
+	if (!delayed_work_pending(&mpcs->link_poll))
+		schedule_delayed_work(&mpcs->link_poll, msecs_to_jiffies(1000));
 
 	return 0;
 }
@@ -518,58 +576,34 @@
 {
 	struct mtk_sgmii_pcs *mpcs = pcs_to_mtk_sgmii_pcs(pcs);
 
-	del_timer_sync(&mpcs->link_poll_outband);
+	cancel_delayed_work_sync(&mpcs->link_poll);
 
-	mpcs->interface = PHY_INTERFACE_MODE_NA;
+	if (mpcs->mode == MLO_AN_INBAND)
+		mtk_sgmii_get_state(mpcs);
 }
 
 static void mtk_sgmii_pcs_get_state(struct phylink_pcs *pcs,
 				    struct phylink_link_state *state)
 {
 	struct mtk_sgmii_pcs *mpcs = pcs_to_mtk_sgmii_pcs(pcs);
-	unsigned int bm, adv, rgc3, sgm_mode;
-
-	state->interface = mpcs->interface;
-
-	regmap_read(mpcs->regmap, SGMSYS_PCS_CONTROL_1, &bm);
-	if (bm & SGMII_AN_ENABLE) {
-		regmap_read(mpcs->regmap, SGMSYS_PCS_ADVERTISE, &adv);
-
-		phylink_mii_c22_pcs_decode_state(state,
-						 FIELD_GET(SGMII_BMSR, bm),
-						 FIELD_GET(SGMII_LPA, adv));
-	} else {
-		state->link = !!(bm & SGMII_LINK_STATYS);
-
-		regmap_read(mpcs->regmap, SGMSYS_SGMII_MODE, &sgm_mode);
-
-		switch (sgm_mode & SGMII_SPEED_MASK) {
-		case SGMII_SPEED_10:
-			state->speed = SPEED_10;
-			break;
-		case SGMII_SPEED_100:
-			state->speed = SPEED_100;
-			break;
-		case SGMII_SPEED_1000:
-			regmap_read(mpcs->regmap, mpcs->ana_rgc3, &rgc3);
-			rgc3 = FIELD_GET(RG_PHY_SPEED_3_125G, rgc3);
-			state->speed = rgc3 ? SPEED_2500 : SPEED_1000;
-			break;
-		}
 
-		if (sgm_mode & SGMII_DUPLEX_HALF)
-			state->duplex = DUPLEX_HALF;
-		else
-			state->duplex = DUPLEX_FULL;
-	}
+	/* When the interface of the mpcs is not initialized,
+	 * we should avoid overriding the state interface.
+	 */
+	if (mpcs->state.interface != PHY_INTERFACE_MODE_NA)
+		state->interface = mpcs->state.interface;
+	state->speed = mpcs->state.speed;
+	state->duplex = mpcs->state.duplex;
+	state->link = mpcs->state.link;
 
 	/* Reconfiguring SGMII every second to ensure that PCS can
 	 * link up with the Link Partner when a module is inserted.
 	 */
-	if (state->link == 0 && time_after(jiffies, mpcs->link_poll_inband + HZ)) {
-		mpcs->link_poll_inband = jiffies;
-		mtk_sgmii_pcs_config(pcs, MLO_AN_INBAND,
-				     state->interface, mpcs->advertising, false);
+	if (time_after(jiffies, mpcs->link_poll_expire) &&
+	    !delayed_work_pending(&mpcs->link_poll)) {
+		mpcs->link_poll_expire = jiffies + HZ;
+		mpcs->state.an_enabled = state->an_enabled;
+		schedule_delayed_work(&mpcs->link_poll, 0);
 	}
 }
 
@@ -591,6 +625,7 @@
 				  int speed, int duplex)
 {
 	struct mtk_sgmii_pcs *mpcs = pcs_to_mtk_sgmii_pcs(pcs);
+	struct device *dev = mpcs->eth->dev;
 	unsigned int sgm_mode, val;
 	unsigned long t_start = jiffies;
 
@@ -602,7 +637,7 @@
 
 	} while (time_before(jiffies, t_start + msecs_to_jiffies(3000)));
 
-	pr_warn("%s wait link up timeout!\n", __func__);
+	dev_warn(dev, "sgmii%d: wait link up timeout!\n", mpcs->id);
 	return;
 
 exit:
@@ -669,9 +704,14 @@
 		ss->pcs[i].pcs.poll = true;
 		ss->pcs[i].interface = PHY_INTERFACE_MODE_NA;
 
-		timer_setup(&ss->pcs[i].link_poll_outband, mtk_sgmii_pcs_link_poll, 0);
+		ss->pcs[i].state.link = 0;
+		ss->pcs[i].state.duplex = DUPLEX_FULL;
+		ss->pcs[i].state.speed = SPEED_1000;
+
+		INIT_DELAYED_WORK(&ss->pcs[i].link_poll, mtk_sgmii_pcs_link_poll);
 
-		spin_lock_init(&ss->pcs[i].regmap_lock);
+		mutex_init(&ss->pcs[i].regmap_lock);
+		mutex_init(&ss->pcs[i].reset_lock);
 
 		of_node_put(np);
 	}
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_usxgmii.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_usxgmii.c
index 16ae838..85aae88 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_usxgmii.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/ethernet/mediatek/mtk_usxgmii.c
@@ -186,7 +186,7 @@
 	/* Force AEQ on */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x02002800);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x3040, GENMASK(31, 0),
 			   0x20000000);
 	/* Setup DA default value */
@@ -219,28 +219,28 @@
 	/* Release reset */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200E800);
-	udelay(150);
+	usleep_range(150, 500);
 	/* Switch to P0 */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200C111);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200C101);
-	udelay(15);
+	usleep_range(15, 50);
 	/* Switch to Gen3 */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0202C111);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0202C101);
-	udelay(100);
+	usleep_range(100, 500);
 	regmap_update_bits(mpcs->regmap_pextp, 0x30B0, GENMASK(31, 0),
 			   0x00000030);
 	regmap_update_bits(mpcs->regmap_pextp, 0x00F4, GENMASK(31, 0),
 			   0x80201F00);
 	regmap_update_bits(mpcs->regmap_pextp, 0x3040, GENMASK(31, 0),
 			   0x30000000);
-	udelay(400);
+	usleep_range(400, 1000);
 }
 
 void mtk_usxgmii_setup_phya_5gbaser(struct mtk_usxgmii_pcs *mpcs)
@@ -300,7 +300,7 @@
 	/* Force AEQ on */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x02002800);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x3040, GENMASK(31, 0),
 			   0x20000000);
 	/* Setup DA default value */
@@ -333,28 +333,28 @@
 	/* Release reset */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200E800);
-	udelay(150);
+	usleep_range(150, 500);
 	/* Switch to P0 */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200C111);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200C101);
-	udelay(15);
+	usleep_range(15, 50);
 	/* Switch to Gen3 */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0202C111);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0202C101);
-	udelay(100);
+	usleep_range(100, 500);
 	regmap_update_bits(mpcs->regmap_pextp, 0x30B0, GENMASK(31, 0),
 			   0x00000030);
 	regmap_update_bits(mpcs->regmap_pextp, 0x00F4, GENMASK(31, 0),
 			   0x80201F00);
 	regmap_update_bits(mpcs->regmap_pextp, 0x3040, GENMASK(31, 0),
 			   0x30000000);
-	udelay(400);
+	usleep_range(400, 1000);
 }
 
 void mtk_usxgmii_setup_phya_10gbaser(struct mtk_usxgmii_pcs *mpcs)
@@ -414,7 +414,7 @@
 	/* Force AEQ on */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x02002800);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x3040, GENMASK(31, 0),
 			   0x20000000);
 	/* Setup DA default value */
@@ -450,34 +450,36 @@
 	/* Release reset */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200E800);
-	udelay(150);
+	usleep_range(150, 500);
 	/* Switch to P0 */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200C111);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0200C101);
-	udelay(15);
+	usleep_range(15, 50);
 	/* Switch to Gen3 */
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0202C111);
-	ndelay(1020);
+	usleep_range(1, 5);
 	regmap_update_bits(mpcs->regmap_pextp, 0x0070, GENMASK(31, 0),
 			   0x0202C101);
-	udelay(100);
+	usleep_range(100, 500);
 	regmap_update_bits(mpcs->regmap_pextp, 0x30B0, GENMASK(31, 0),
 			   0x00000030);
 	regmap_update_bits(mpcs->regmap_pextp, 0x00F4, GENMASK(31, 0),
 			   0x80201F00);
 	regmap_update_bits(mpcs->regmap_pextp, 0x3040, GENMASK(31, 0),
 			   0x30000000);
-	udelay(400);
+	usleep_range(400, 1000);
 }
 
 int mtk_usxgmii_link_status(struct mtk_usxgmii_pcs *mpcs)
 {
 	unsigned int val;
 
+	mutex_lock(&mpcs->reset_lock);
+
 	/* Refresh USXGMII link status by toggling RG_PCS_RX_STATUS_UPDATE */
 	regmap_read(mpcs->regmap, RG_PCS_RX_STATUS0, &val);
 	val |= RG_PCS_RX_STATUS_UPDATE;
@@ -490,16 +492,113 @@
 	/* Read USXGMII link status */
 	regmap_read(mpcs->regmap, RG_PCS_RX_STATUS0, &val);
 
+	mutex_unlock(&mpcs->reset_lock);
+
 	return FIELD_GET(RG_PCS_RX_LINK_STATUS, val);
 }
 
+bool mtk_usxgmii_is_valid_ctle(struct mtk_usxgmii_pcs *mpcs)
+{
+	unsigned int val, ctle;
+
+	mutex_lock(&mpcs->reset_lock);
+
+	regmap_write(mpcs->regmap_pextp, 0x00, 0x00000404);
+	regmap_write(mpcs->regmap_pextp, 0x10, 0x00d600d5);
+	regmap_read(mpcs->regmap_pextp, 0xd0, &val);
+
+	mutex_unlock(&mpcs->reset_lock);
+
+	ctle = FIELD_GET(GENMASK(12, 8), val);
+	if (ctle > 10)
+		return false;
+
+	return true;
+}
+
+static void mtk_usxgmii_get_state(struct mtk_usxgmii_pcs *mpcs)
+{
+	struct phylink_link_state *state = &mpcs->state;
+	struct mtk_eth *eth = mpcs->eth;
+	struct mtk_mac *mac = eth->mac[mtk_xgmii2mac_id(eth, mpcs->id)];
+	u32 val = 0;
+
+	mutex_lock(&mpcs->reset_lock);
+
+	regmap_read(mpcs->regmap, RG_PCS_AN_CTRL0, &val);
+	if (FIELD_GET(USXGMII_AN_ENABLE, val)) {
+		/* Refresh LPA by inverting LPA_LATCH */
+		regmap_read(mpcs->regmap, RG_PCS_AN_STS0, &val);
+		regmap_update_bits(mpcs->regmap, RG_PCS_AN_STS0,
+				   USXGMII_LPA_LATCH,
+				   !(val & USXGMII_LPA_LATCH));
+
+		regmap_read(mpcs->regmap, RG_PCS_AN_STS0, &val);
+
+		state->interface = mpcs->interface;
+		state->link = FIELD_GET(USXGMII_LPA_LINK, val);
+		state->duplex = FIELD_GET(USXGMII_LPA_DUPLEX, val);
+
+		switch (FIELD_GET(USXGMII_LPA_SPEED_MASK, val)) {
+		case USXGMII_LPA_SPEED_10:
+			state->speed = SPEED_10;
+			break;
+		case USXGMII_LPA_SPEED_100:
+			state->speed = SPEED_100;
+			break;
+		case USXGMII_LPA_SPEED_1000:
+			state->speed = SPEED_1000;
+			break;
+		case USXGMII_LPA_SPEED_2500:
+			state->speed = SPEED_2500;
+			break;
+		case USXGMII_LPA_SPEED_5000:
+			state->speed = SPEED_5000;
+			break;
+		case USXGMII_LPA_SPEED_10000:
+			state->speed = SPEED_10000;
+			break;
+		}
+	} else {
+		val = mtk_r32(mac->hw, MTK_XGMAC_STS(mac->id));
+
+		if (mac->id == MTK_GMAC2_ID)
+			val = val >> 16;
+
+		switch (FIELD_GET(MTK_USXGMII_PCS_MODE, val)) {
+		case 0:
+			state->speed = SPEED_10000;
+			break;
+		case 1:
+			state->speed = SPEED_5000;
+			break;
+		case 2:
+			state->speed = SPEED_2500;
+			break;
+		case 3:
+			state->speed = SPEED_1000;
+			break;
+		}
+
+		state->interface = mpcs->interface;
+		state->link = FIELD_GET(MTK_USXGMII_PCS_LINK, val);
+		state->duplex = DUPLEX_FULL;
+	}
+
+	mutex_unlock(&mpcs->reset_lock);
+}
+
-void mtk_usxgmii_reset(struct mtk_eth *eth, int id)
+void mtk_usxgmii_reset(struct mtk_usxgmii_pcs *mpcs)
 {
+	struct mtk_eth *eth = mpcs->eth;
+	int id = mpcs->id;
 	u32 val = 0;
 
 	if (id >= MTK_MAX_DEVS || !eth->toprgu)
 		return;
 
+	mutex_lock(&mpcs->reset_lock);
+
 	switch (id) {
 	case 0:
 		/* Enable software reset */
@@ -515,7 +614,7 @@
 		       SWSYSRST_XFI0_GRST;
 		regmap_write(eth->toprgu, TOPRGU_SWSYSRST, val);
 
-		udelay(100);
+		usleep_range(100, 500);
 
 		/* De-assert USXGMII reset */
 		regmap_read(eth->toprgu, TOPRGU_SWSYSRST, &val);
@@ -544,7 +643,7 @@
 		       SWSYSRST_XFI1_GRST;
 		regmap_write(eth->toprgu, TOPRGU_SWSYSRST, val);
 
-		udelay(100);
+		usleep_range(100, 500);
 
 		/* De-assert USXGMII reset */
 		regmap_read(eth->toprgu, TOPRGU_SWSYSRST, &val);
@@ -561,7 +660,9 @@
 		break;
 	}
 
+	mutex_unlock(&mpcs->reset_lock);
+
-	mdelay(10);
+	usleep_range(10000, 11000);
 }
 
 static int mtk_usxgmii_pcs_config(struct phylink_pcs *pcs, unsigned int mode,
@@ -571,12 +672,9 @@
 {
 	struct mtk_usxgmii_pcs *mpcs = pcs_to_mtk_usxgmii_pcs(pcs);
 	struct mtk_eth *eth = mpcs->eth;
-	unsigned long flags;
 	unsigned int an_ctrl = 0, link_timer = 0, xfi_mode = 0, adapt_mode = 0;
 	bool mode_changed = false;
 
-	spin_lock_irqsave(&mpcs->regmap_lock, flags);
-
 	if (interface == PHY_INTERFACE_MODE_USXGMII) {
 		an_ctrl = FIELD_PREP(USXGMII_AN_SYNC_CNT, 0x1FF) |
 			  USXGMII_AN_ENABLE;
@@ -602,20 +700,25 @@
 			   FIELD_PREP(USXGMII_XFI_TX_MODE, USXGMII_XFI_TX_MODE_5G);
 		adapt_mode = USXGMII_RATE_UPDATE_MODE;
 	} else {
-		spin_unlock_irqrestore(&mpcs->regmap_lock, flags);
 		return -EINVAL;
 	}
 
 	adapt_mode |= FIELD_PREP(USXGMII_RATE_ADAPT_MODE, USXGMII_RATE_ADAPT_MODE_X1);
 
+	mtk_usxgmii_xfi_pll_enable(eth->usxgmii);
+	mtk_usxgmii_reset(mpcs);
+
-	if (mpcs->interface != interface) {
+	mutex_lock(&mpcs->regmap_lock);
+
+	if (mode >= 0 && mpcs->interface != interface) {
 		mpcs->interface = interface;
 		mpcs->mode = mode;
 		mode_changed = true;
 	}
 
-	mtk_usxgmii_xfi_pll_enable(eth->usxgmii);
-	mtk_usxgmii_reset(eth, mpcs->id);
+	/* Configure the interface polarity */
+	regmap_update_bits(mpcs->regmap, RG_PHY_TOP_CTRL0,
+			   USXGMII_PN_SWAP_MASK, mpcs->polarity);
 
 	/* Setup USXGMII AN ctrl */
 	regmap_update_bits(mpcs->regmap, RG_PCS_AN_CTRL0,
@@ -646,13 +749,13 @@
 			   USXGMII_XFI_RX_MODE | USXGMII_XFI_TX_MODE,
 			   xfi_mode);
 
-	udelay(1);
+	usleep_range(1, 5);
 
 	/* Un-gated MAC CK */
 	regmap_update_bits(mpcs->regmap, RG_PHY_TOP_SPEED_CTRL1,
 			   USXGMII_MAC_CK_GATED, 0);
 
-	udelay(1);
+	usleep_range(1, 5);
 
 	/* Disable interface force mode for the AN mode */
 	if (an_ctrl & USXGMII_AN_ENABLE)
@@ -667,32 +770,38 @@
 	else if (interface == PHY_INTERFACE_MODE_5GBASER)
 		mtk_usxgmii_setup_phya_5gbaser(mpcs);
 
-	spin_unlock_irqrestore(&mpcs->regmap_lock, flags);
+	mutex_unlock(&mpcs->regmap_lock);
 
 	return mode_changed;
 }
 
-static void mtk_usxgmii_pcs_link_poll(struct timer_list *t)
+static void mtk_usxgmii_pcs_link_poll(struct work_struct *work)
 {
-	struct mtk_usxgmii_pcs *mpcs = from_timer(mpcs, t, link_poll_outband);
+	struct mtk_usxgmii_pcs *mpcs = container_of(work, struct mtk_usxgmii_pcs,
+						    link_poll.work);
 
-	if (mpcs->interface == PHY_INTERFACE_MODE_NA)
+	if (mpcs->interface != PHY_INTERFACE_MODE_5GBASER &&
+	    mpcs->interface != PHY_INTERFACE_MODE_10GKR &&
+	    mpcs->interface != PHY_INTERFACE_MODE_USXGMII)
 		goto exit;
 
-	if (!mtk_usxgmii_link_status(mpcs))
-		mtk_usxgmii_pcs_config(&mpcs->pcs, mpcs->mode,
+	if (!mtk_usxgmii_link_status(mpcs) || !mtk_usxgmii_is_valid_ctle(mpcs))
+		mtk_usxgmii_pcs_config(&mpcs->pcs, -1,
 				       mpcs->interface, NULL, false);
 
 exit:
-	if (mpcs->mode != MLO_AN_INBAND)
-		mod_timer(&mpcs->link_poll_outband, jiffies + HZ);
+	if (mpcs->mode == MLO_AN_INBAND)
+		mtk_usxgmii_get_state(mpcs);
+	else if (!delayed_work_pending(&mpcs->link_poll))
+		schedule_delayed_work(&mpcs->link_poll, msecs_to_jiffies(1000));
 }
 
 static int mtk_usxgmii_pcs_enable(struct phylink_pcs *pcs)
 {
 	struct mtk_usxgmii_pcs *mpcs = pcs_to_mtk_usxgmii_pcs(pcs);
 
-	mod_timer(&mpcs->link_poll_outband, jiffies + HZ);
+	if (!delayed_work_pending(&mpcs->link_poll))
+		schedule_delayed_work(&mpcs->link_poll, msecs_to_jiffies(1000));
 
 	return 0;
 }
@@ -701,86 +810,31 @@
 {
 	struct mtk_usxgmii_pcs *mpcs = pcs_to_mtk_usxgmii_pcs(pcs);
 
-	del_timer_sync(&mpcs->link_poll_outband);
+	cancel_delayed_work_sync(&mpcs->link_poll);
 
-	mpcs->interface = PHY_INTERFACE_MODE_NA;
+	if (mpcs->mode == MLO_AN_INBAND)
+		mtk_usxgmii_get_state(mpcs);
 }
 
 static void mtk_usxgmii_pcs_get_state(struct phylink_pcs *pcs,
 				    struct phylink_link_state *state)
 {
 	struct mtk_usxgmii_pcs *mpcs = pcs_to_mtk_usxgmii_pcs(pcs);
-	struct mtk_eth *eth = mpcs->eth;
-	struct mtk_mac *mac = eth->mac[mtk_xgmii2mac_id(eth, mpcs->id)];
-	u32 val = 0;
-
-	regmap_read(mpcs->regmap, RG_PCS_AN_CTRL0, &val);
-	if (FIELD_GET(USXGMII_AN_ENABLE, val)) {
-		/* Refresh LPA by inverting LPA_LATCH */
-		regmap_read(mpcs->regmap, RG_PCS_AN_STS0, &val);
-		regmap_update_bits(mpcs->regmap, RG_PCS_AN_STS0,
-				   USXGMII_LPA_LATCH,
-				   !(val & USXGMII_LPA_LATCH));
-
-		regmap_read(mpcs->regmap, RG_PCS_AN_STS0, &val);
-
-		state->interface = mpcs->interface;
-		state->link = FIELD_GET(USXGMII_LPA_LINK, val);
-		state->duplex = FIELD_GET(USXGMII_LPA_DUPLEX, val);
-
-		switch (FIELD_GET(USXGMII_LPA_SPEED_MASK, val)) {
-		case USXGMII_LPA_SPEED_10:
-			state->speed = SPEED_10;
-			break;
-		case USXGMII_LPA_SPEED_100:
-			state->speed = SPEED_100;
-			break;
-		case USXGMII_LPA_SPEED_1000:
-			state->speed = SPEED_1000;
-			break;
-		case USXGMII_LPA_SPEED_2500:
-			state->speed = SPEED_2500;
-			break;
-		case USXGMII_LPA_SPEED_5000:
-			state->speed = SPEED_5000;
-			break;
-		case USXGMII_LPA_SPEED_10000:
-			state->speed = SPEED_10000;
-			break;
-		}
-	} else {
-		val = mtk_r32(mac->hw, MTK_XGMAC_STS(mac->id));
-
-		if (mac->id == MTK_GMAC2_ID)
-			val = val >> 16;
-
-		switch (FIELD_GET(MTK_USXGMII_PCS_MODE, val)) {
-		case 0:
-			state->speed = SPEED_10000;
-			break;
-		case 1:
-			state->speed = SPEED_5000;
-			break;
-		case 2:
-			state->speed = SPEED_2500;
-			break;
-		case 3:
-			state->speed = SPEED_1000;
-			break;
-		}
 
-		state->interface = mpcs->interface;
-		state->link = FIELD_GET(MTK_USXGMII_PCS_LINK, val);
-		state->duplex = DUPLEX_FULL;
-	}
+	if (mpcs->state.interface != PHY_INTERFACE_MODE_NA)
+		state->interface = mpcs->state.interface;
+	state->speed = mpcs->state.speed;
+	state->duplex = mpcs->state.duplex;
+	state->link = mpcs->state.link;
 
 	/* Reconfiguring USXGMII every second to ensure that PCS can
 	 * link up with the Link Partner when a module is inserted.
 	 */
-	if (state->link == 0 && time_after(jiffies, mpcs->link_poll_inband + HZ)) {
-		mpcs->link_poll_inband = jiffies;
-		mtk_usxgmii_pcs_config(pcs, MLO_AN_INBAND,
-				       state->interface, NULL, false);
+	if (time_after(jiffies, mpcs->link_poll_expire) &&
+	    !delayed_work_pending(&mpcs->link_poll)) {
+		mpcs->link_poll_expire = jiffies + HZ;
+		mpcs->state.an_enabled = state->an_enabled;
+		schedule_delayed_work(&mpcs->link_poll, 0);
 	}
 }
 
@@ -802,14 +856,9 @@
 				    int speed, int duplex)
 {
 	struct mtk_usxgmii_pcs *mpcs = pcs_to_mtk_usxgmii_pcs(pcs);
+	struct device *dev = mpcs->eth->dev;
 	unsigned long t_start = jiffies;
 
-	/* Reconfiguring USXGMII to ensure the quality of the RX signal
-	 * after the line side link up.
-	 */
-	mtk_usxgmii_pcs_config(pcs, mode,
-			       interface, NULL, false);
-
 	do {
 		msleep(100);
 
@@ -818,7 +867,7 @@
 
 	} while (time_before(jiffies, t_start + msecs_to_jiffies(3000)));
 
-	pr_warn("%s wait link up timeout!\n", __func__);
+	dev_warn(dev, "usxgmii%d: wait link up timeout!\n", mpcs->id);
 }
 
 static const struct phylink_pcs_ops mtk_usxgmii_pcs_ops = {
@@ -848,13 +897,26 @@
 		if (IS_ERR(ss->pcs[i].regmap))
 			return PTR_ERR(ss->pcs[i].regmap);
 
+		ss->pcs[i].polarity = 0;
+		if (of_property_read_bool(np, "pn_swap"))
+			ss->pcs[i].polarity |= USXGMII_PN_SWAP_TX | USXGMII_PN_SWAP_RX;
+		else if (of_property_read_bool(np, "pn_swap_tx"))
+			ss->pcs[i].polarity |= USXGMII_PN_SWAP_TX;
+		else if (of_property_read_bool(np, "pn_swap_rx"))
+			ss->pcs[i].polarity |= USXGMII_PN_SWAP_RX;
+
 		ss->pcs[i].pcs.ops = &mtk_usxgmii_pcs_ops;
 		ss->pcs[i].pcs.poll = true;
 		ss->pcs[i].interface = PHY_INTERFACE_MODE_NA;
 
-		timer_setup(&ss->pcs[i].link_poll_outband, mtk_usxgmii_pcs_link_poll, 0);
+		ss->pcs[i].state.link = 0;
+		ss->pcs[i].state.duplex = DUPLEX_FULL;
+		ss->pcs[i].state.speed = SPEED_10000;
+
+		INIT_DELAYED_WORK(&ss->pcs[i].link_poll, mtk_usxgmii_pcs_link_poll);
 
-		spin_lock_init(&ss->pcs[i].regmap_lock);
+		mutex_init(&ss->pcs[i].regmap_lock);
+		mutex_init(&ss->pcs[i].reset_lock);
 
 		of_node_put(np);
 	}
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855.c
index f3db8b8..79d6d1a 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855.c
@@ -18,6 +18,16 @@
 /* AN8855 registers */
 #define SCU_BASE					0x10000000
 #define RG_RGMII_TXCK_C				(SCU_BASE + 0x1d0)
+#define RG_GPIO_LED_MODE			(SCU_BASE + 0x0054)
+#define RG_GPIO_LED_SEL(i)	(SCU_BASE + (0x0058 + ((i) * 4)))
+#define RG_INTB_MODE				(SCU_BASE + 0x0080)
+#define RG_GDMP_RAM				(SCU_BASE + 0x10000)
+
+#define RG_GPIO_L_INV			(SCU_BASE + 0x0010)
+#define RG_GPIO_CTRL			(SCU_BASE + 0xa300)
+#define RG_GPIO_DATA			(SCU_BASE + 0xa304)
+#define RG_GPIO_OE			(SCU_BASE + 0xa314)
+
 
 #define HSGMII_AN_CSR_BASE			0x10220000
 #define SGMII_REG_AN0				(HSGMII_AN_CSR_BASE + 0x000)
@@ -61,6 +71,8 @@
 #define SS_LCPLL_TDC_PCW_1			(QP_PMA_TOP_BASE + 0x248)
 #define INTF_CTRL_8		(QP_PMA_TOP_BASE + 0x320)
 #define INTF_CTRL_9		(QP_PMA_TOP_BASE + 0x324)
+#define INTF_CTRL_10	(QP_PMA_TOP_BASE + 0x328)
+#define INTF_CTRL_11	(QP_PMA_TOP_BASE + 0x32c)
 #define PLL_CTRL_0		(QP_PMA_TOP_BASE + 0x400)
 #define PLL_CTRL_2		(QP_PMA_TOP_BASE + 0x408)
 #define PLL_CTRL_3		(QP_PMA_TOP_BASE + 0x40c)
@@ -78,6 +90,7 @@
 #define QP_ANA_CSR_BASE				0x1022f000
 #define RG_QP_RX_DAC_EN				(QP_ANA_CSR_BASE + 0x00)
 #define RG_QP_RXAFE_RESERVE			(QP_ANA_CSR_BASE + 0x04)
+#define RG_QP_CDR_LPF_BOT_LIM		(QP_ANA_CSR_BASE + 0x08)
 #define RG_QP_CDR_LPF_MJV_LIM		(QP_ANA_CSR_BASE + 0x0c)
 #define RG_QP_CDR_LPF_SETVALUE		(QP_ANA_CSR_BASE + 0x14)
 #define RG_QP_CDR_PR_CKREF_DIV1		(QP_ANA_CSR_BASE + 0x18)
@@ -106,6 +119,66 @@
 /* Fields of PHY_EXT_REG_14 */
 #define PHY_EN_DOWN_SHFIT		BIT(4)
 
+/* PHY dev address 0x1E */
+#define PHY_DEV1E				0x1e
+
+/* PHY TX PAIR DELAY SELECT Register */
+#define PHY_TX_PAIR_DLY_SEL_GBE		0x013
+/* PHY ADC Register */
+#define PHY_RXADC_CTRL				0x0d8
+#define PHY_RXADC_REV_0				0x0d9
+#define PHY_RXADC_REV_1				0x0da
+
+/* PHY LED Register bitmap of define */
+#define PHY_LED_CTRL_SELECT		0x3e8
+#define PHY_SINGLE_LED_ON_CTRL(i)	(0x3e0 + ((i) * 2))
+#define PHY_SINGLE_LED_BLK_CTRL(i)	(0x3e1 + ((i) * 2))
+#define PHY_SINGLE_LED_ON_DUR(i)	(0x3e9 + ((i) * 2))
+#define PHY_SINGLE_LED_BLK_DUR(i)	(0x3ea + ((i) * 2))
+
+#define PHY_PMA_CTRL	(0x340)
+
+/* PHY dev address 0x1F */
+#define PHY_DEV1F				0x1f
+#define PHY_LED_ON_CTRL(i)		(0x24 + ((i) * 2))
+#define LED_ON_EN				(1 << 15)
+#define LED_ON_POL				(1 << 14)
+#define LED_ON_EVT_MASK			(0x7f)
+/* LED ON Event */
+#define LED_ON_EVT_FORCE		(1 << 6)
+#define LED_ON_EVT_LINK_HD		(1 << 5)
+#define LED_ON_EVT_LINK_FD		(1 << 4)
+#define LED_ON_EVT_LINK_DOWN	(1 << 3)
+#define LED_ON_EVT_LINK_10M		(1 << 2)
+#define LED_ON_EVT_LINK_100M	(1 << 1)
+#define LED_ON_EVT_LINK_1000M	(1 << 0)
+
+#define PHY_LED_BLK_CTRL(i)		(0x25 + ((i) * 2))
+#define LED_BLK_EVT_MASK		(0x3ff)
+/* LED Blinking Event */
+#define LED_BLK_EVT_FORCE			(1 << 9)
+#define LED_BLK_EVT_10M_RX_ACT		(1 << 5)
+#define LED_BLK_EVT_10M_TX_ACT		(1 << 4)
+#define LED_BLK_EVT_100M_RX_ACT		(1 << 3)
+#define LED_BLK_EVT_100M_TX_ACT		(1 << 2)
+#define LED_BLK_EVT_1000M_RX_ACT	(1 << 1)
+#define LED_BLK_EVT_1000M_TX_ACT	(1 << 0)
+
+#define PHY_LED_BCR				(0x21)
+#define LED_BCR_EXT_CTRL		(1 << 15)
+#define LED_BCR_CLK_EN			(1 << 3)
+#define LED_BCR_TIME_TEST		(1 << 2)
+#define LED_BCR_MODE_MASK		(3)
+#define LED_BCR_MODE_DISABLE	(0)
+
+#define PHY_LED_ON_DUR			(0x22)
+#define LED_ON_DUR_MASK			(0xffff)
+
+#define PHY_LED_BLK_DUR			(0x23)
+#define LED_BLK_DUR_MASK		(0xffff)
+
+#define PHY_LED_BLINK_DUR_CTRL	(0x720)
+
 /* Unique fields of PMCR for AN8855 */
 #define FORCE_TX_FC		BIT(4)
 #define FORCE_RX_FC		BIT(5)
@@ -117,10 +190,114 @@
 #define CHIP_ID			0x10005000
 #define CHIP_REV		0x10005004
 
+#define AN8855_EFUSE_DATA0	0x1000a500
+
+const u8 r50ohm_table[] = {
+	127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
+	127, 127, 127, 127, 127, 127, 127, 126, 122, 117,
+	112, 109, 104, 101,  97,  94,  90,  88,  84,  80,
+	78,  74,  72,  68,  66,  64,  61,  58,  56,  53,
+	51,  48,  47,  44,  42,  40,  38,  36,  34,  32,
+	31,  28,  27,  24,  24,  22,  20,  18,  16,  16,
+	14,  12,  11,   9
+};
+
+static u8 shift_check(u8 base)
+{
+	u8 i;
+	u32 sz = sizeof(r50ohm_table)/sizeof(u8);
+
+	for (i = 0; i < sz; ++i)
+		if (r50ohm_table[i] == base)
+			break;
+
+	if (i < 8 || i >= sz)
+		return 25; /* index of 94 */
+
+	return (i - 8);
+}
+
+static u8 get_shift_val(u8 idx)
+{
+	return r50ohm_table[idx];
+}
+
+/* T830 AN8855 Reference Board */
+static const struct an8855_led_cfg led_cfg[] = {
+/*************************************************************************
+ * Enable, LED idx, LED Polarity, LED ON event,  LED Blink event  LED Freq
+ *************************************************************************
+ */
+	/* GPIO0 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO1 */
+	{1, P0_LED1, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO2 */
+	{1, P1_LED1, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO3 */
+	{1, P2_LED1, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO4 */
+	{1, P3_LED1, LED_LOW,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO5 */
+	{1, P4_LED1, LED_LOW,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO6 */
+	{0, PHY_LED_MAX, LED_LOW,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO7 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO8 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO9 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO10 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO11 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO12 */
+	{0, PHY_LED_MAX, LED_LOW,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO13 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO14 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO15 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO16 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO17 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO18 */
+	{0, PHY_LED_MAX, LED_HIGH, LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO19 */
+	{0, PHY_LED_MAX, LED_LOW,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+	/* GPIO20 */
+	{0, PHY_LED_MAX, LED_LOW,  LED_ON_EVENT, LED_BLK_EVENT, LED_FREQ},
+};
+
 static int an8855_set_hsgmii_mode(struct gsw_an8855 *gsw)
 {
 	u32 val = 0;
 
+	/* TX FIR - improve TX EYE */
+	val = an8855_reg_read(gsw, INTF_CTRL_10);
+	val &= ~(0x3f << 16);
+	val |= BIT(21);
+	val &= ~(0x1f << 24);
+	val |= (0x4 << 24);
+	val |= BIT(29);
+	an8855_reg_write(gsw, INTF_CTRL_10, val);
+
+	val = an8855_reg_read(gsw, INTF_CTRL_11);
+	val &= ~(0x3f);
+	val |= BIT(6);
+	an8855_reg_write(gsw, INTF_CTRL_11, val);
+
+	/* RX CDR - improve RX Jitter Tolerance */
+	val = an8855_reg_read(gsw, RG_QP_CDR_LPF_BOT_LIM);
+	val &= ~(0x7 << 24);
+	val |= (0x5 << 24);
+	val &= ~(0x7 << 20);
+	val |= (0x5 << 20);
+	an8855_reg_write(gsw, RG_QP_CDR_LPF_BOT_LIM, val);
+
 	/* PLL */
 	val = an8855_reg_read(gsw, QP_DIG_MODE_CTRL_1);
 	val &= ~(0x3 << 2);
@@ -250,7 +427,7 @@
 	val &= ~(0xf << 25);
 	val |= (0x1 << 25);
 	val &= ~(0x7 << 29);
-	val |= (0x3 << 29);
+	val |= (0x6 << 29);
 	an8855_reg_write(gsw, RG_QP_CDR_LPF_SETVALUE, val);
 
 	val = an8855_reg_read(gsw, RG_QP_CDR_PR_CKREF_DIV1);
@@ -281,12 +458,10 @@
 	val |= (0x4 << 24);
 	an8855_reg_write(gsw, RG_QP_CDR_PR_CKREF_DIV1, val);
 
-	val = an8855_reg_read(gsw, PLL_CTRL_0);
-	val |= BIT(0);
-	an8855_reg_write(gsw, PLL_CTRL_0, val);
-
+	/* PMA (For HW Mode) */
 	val = an8855_reg_read(gsw, RX_CTRL_26);
-	val &= ~BIT(23);
+	val |= BIT(23);
+	val &= ~BIT(24);
 	val |= BIT(26);
 	an8855_reg_write(gsw, RX_CTRL_26, val);
 
@@ -314,8 +489,8 @@
 	val = an8855_reg_read(gsw, RX_CTRL_8);
 	val &= ~(0xfff << 16);
 	val |= (0x200 << 16);
-	val &= ~(0x7fff << 14);
-	val |= (0xfff << 14);
+	val &= ~(0x7fff << 0);
+	val |= (0xfff << 0);
 	an8855_reg_write(gsw, RX_CTRL_8, val);
 
 	/* Frequency memter */
@@ -334,6 +509,10 @@
 	val |= (0x2710 << 0);
 	an8855_reg_write(gsw, RX_CTRL_7, val);
 
+	val = an8855_reg_read(gsw, PLL_CTRL_0);
+	val |= BIT(0);
+	an8855_reg_write(gsw, PLL_CTRL_0, val);
+
 	/* PCS Init */
 	val = an8855_reg_read(gsw, RG_HSGMII_PCS_CTROL_1);
 	val &= ~BIT(30);
@@ -372,6 +551,28 @@
 {
 	u32 val = 0;
 
+	/* TX FIR - improve TX EYE */
+	val = an8855_reg_read(gsw, INTF_CTRL_10);
+	val &= ~(0x3f << 16);
+	val |= BIT(21);
+	val &= ~(0x1f << 24);
+	val |= BIT(29);
+	an8855_reg_write(gsw, INTF_CTRL_10, val);
+
+	val = an8855_reg_read(gsw, INTF_CTRL_11);
+	val &= ~(0x3f);
+	val |= (0xd << 0);
+	val |= BIT(6);
+	an8855_reg_write(gsw, INTF_CTRL_11, val);
+
+	/* RX CDR - improve RX Jitter Tolerance */
+	val = an8855_reg_read(gsw, RG_QP_CDR_LPF_BOT_LIM);
+	val &= ~(0x7 << 24);
+	val |= (0x6 << 24);
+	val &= ~(0x7 << 20);
+	val |= (0x6 << 20);
+	an8855_reg_write(gsw, RG_QP_CDR_LPF_BOT_LIM, val);
+
 	/* PMA Init */
 	/* PLL */
 	val = an8855_reg_read(gsw, QP_DIG_MODE_CTRL_1);
@@ -531,13 +732,10 @@
 	val |= (0x4 << 24);
 	an8855_reg_write(gsw, RG_QP_CDR_PR_CKREF_DIV1, val);
 
-	val = an8855_reg_read(gsw, PLL_CTRL_0);
-	val |= BIT(0);
-	an8855_reg_write(gsw, PLL_CTRL_0, val);
-
+	/* PMA (For HW Mode) */
 	val = an8855_reg_read(gsw, RX_CTRL_26);
-	val &= ~BIT(23);
-	if (mode == SGMII_MODE_AN)
+	val |= BIT(23);
+	val &= ~BIT(24);
 		val |= BIT(26);
 
 	an8855_reg_write(gsw, RX_CTRL_26, val);
@@ -586,6 +784,10 @@
 	val |= (0x2710 << 0);
 	an8855_reg_write(gsw, RX_CTRL_7, val);
 
+	val = an8855_reg_read(gsw, PLL_CTRL_0);
+	val |= BIT(0);
+	an8855_reg_write(gsw, PLL_CTRL_0, val);
+
 	if (mode == SGMII_MODE_FORCE) {
 		/* PCS Init */
 		val = an8855_reg_read(gsw, QP_DIG_MODE_CTRL_0);
@@ -670,7 +872,6 @@
 		/* Restart AN */
 		val = an8855_reg_read(gsw, SGMII_REG_AN0);
 		val |= BIT(9);
-		val |= BIT(15);
 		an8855_reg_write(gsw, SGMII_REG_AN0, val);
 	}
 
@@ -772,7 +973,10 @@
 
 static void an8855_phy_setting(struct gsw_an8855 *gsw)
 {
-	int i;
+	int i, j;
+	u8 shift_sel = 0, rsel_tx_a = 0, rsel_tx_b = 0;
+	u8 rsel_tx_c = 0, rsel_tx_d = 0;
+	u16 cl45_data = 0;
 	u32 val;
 
 	/* Release power down */
@@ -791,52 +995,262 @@
 		val |= ADVERTISE_PAUSE_ASYM;
 		gsw->mii_write(gsw, i, MII_ADVERTISE, val);
 	}
+
+	if (gsw->extSurge) {
+		for (i = 0; i < AN8855_NUM_PHYS; i++) {
+			/* Read data */
+			for (j = 0; j < AN8855_WORD_SIZE; j++) {
+				val = an8855_reg_read(gsw, AN8855_EFUSE_DATA0 +
+					(AN8855_WORD_SIZE * (3 + j + (4 * i))));
+
+				shift_sel = shift_check((val & 0x7f000000) >> 24);
+				switch (j) {
+				case 0:
+					rsel_tx_a = get_shift_val(shift_sel);
+					break;
+				case 1:
+					rsel_tx_b = get_shift_val(shift_sel);
+					break;
+				case 2:
+					rsel_tx_c = get_shift_val(shift_sel);
+					break;
+				case 3:
+					rsel_tx_d = get_shift_val(shift_sel);
+					break;
+				default:
+					continue;
+				}
+			}
+			cl45_data = gsw->mmd_read(gsw, i, PHY_DEV1E, 0x174);
+			cl45_data &= ~(0x7f7f);
+			cl45_data |= (rsel_tx_a << 8);
+			cl45_data |= rsel_tx_b;
+			gsw->mmd_write(gsw, i, PHY_DEV1E, 0x174, cl45_data);
+			cl45_data = gsw->mmd_read(gsw, i, PHY_DEV1E, 0x175);
+			cl45_data &= ~(0x7f7f);
+			cl45_data |= (rsel_tx_c << 8);
+			cl45_data |= rsel_tx_d;
+			gsw->mmd_write(gsw, i, PHY_DEV1E, 0x175, cl45_data);
+		}
+	}
+}
+
+static void an8855_eee_setting(struct gsw_an8855 *gsw, u32 port)
+{
+	/* Disable EEE */
+	gsw->mmd_write(gsw, port, PHY_DEV07, PHY_DEV07_REG_03C, 0);
+}
+
+static int an8855_led_set_usr_def(struct gsw_an8855 *gsw, u8 entity,
+		int polar, u16 on_evt, u16 blk_evt, u8 led_freq)
+{
+	u32 cl45_data = 0;
+
+	if (polar == LED_HIGH)
+		on_evt |= LED_ON_POL;
+	else
+		on_evt &= ~LED_ON_POL;
+
+	/* LED on event */
+	gsw->mmd_write(gsw, (entity / 4), PHY_DEV1E,
+		PHY_SINGLE_LED_ON_CTRL(entity % 4), on_evt | LED_ON_EN);
+
+	/* LED blink event */
+	gsw->mmd_write(gsw, (entity / 4), PHY_DEV1E,
+		PHY_SINGLE_LED_BLK_CTRL(entity % 4), blk_evt);
+
+	/* LED freq */
+	switch (led_freq) {
+	case AIR_LED_BLK_DUR_32M:
+		cl45_data = 0x30e;
+		break;
+	case AIR_LED_BLK_DUR_64M:
+		cl45_data = 0x61a;
+		break;
+	case AIR_LED_BLK_DUR_128M:
+		cl45_data = 0xc35;
+		break;
+	case AIR_LED_BLK_DUR_256M:
+		cl45_data = 0x186a;
+		break;
+	case AIR_LED_BLK_DUR_512M:
+		cl45_data = 0x30d4;
+		break;
+	case AIR_LED_BLK_DUR_1024M:
+		cl45_data = 0x61a8;
+		break;
+	default:
+		break;
+	}
+	gsw->mmd_write(gsw, (entity / 4), PHY_DEV1E,
+		PHY_SINGLE_LED_BLK_DUR(entity % 4), cl45_data);
+
+	gsw->mmd_write(gsw, (entity / 4), PHY_DEV1E,
+		PHY_SINGLE_LED_ON_DUR(entity % 4), (cl45_data >> 1));
+
+	/* Disable DATA & BAD_SSD for port LED blink behavior */
+	cl45_data = gsw->mmd_read(gsw, (entity / 4), PHY_DEV1E,
+		PHY_PMA_CTRL);
+	cl45_data &= ~BIT(0);
+	cl45_data &= ~BIT(15);
+	gsw->mmd_write(gsw, (entity / 4), PHY_DEV1E,
+		PHY_PMA_CTRL, cl45_data);
+
+	return 0;
 }
 
-static void an8855_low_power_setting(struct gsw_an8855 *gsw)
+static int an8855_led_set_mode(struct gsw_an8855 *gsw, u8 mode)
 {
-	int port, addr;
+	u16 cl45_data;
 
-	for (port = 0; port < AN8855_NUM_PHYS; port++) {
-		gsw->mmd_write(gsw, port, 0x1e, 0x11, 0x0f00);
-		gsw->mmd_write(gsw, port, 0x1e, 0x3c, 0x0000);
-		gsw->mmd_write(gsw, port, 0x1e, 0x3d, 0x0000);
-		gsw->mmd_write(gsw, port, 0x1e, 0x3e, 0x0000);
-		gsw->mmd_write(gsw, port, 0x1e, 0xc6, 0x53aa);
+	cl45_data = gsw->mmd_read(gsw, 0, PHY_DEV1F, PHY_LED_BCR);
+	switch (mode) {
+	case AN8855_LED_MODE_DISABLE:
+		cl45_data &= ~LED_BCR_EXT_CTRL;
+		cl45_data &= ~LED_BCR_MODE_MASK;
+		cl45_data |= LED_BCR_MODE_DISABLE;
+		break;
+	case AN8855_LED_MODE_USER_DEFINE:
+		cl45_data |= LED_BCR_EXT_CTRL;
+		cl45_data |= LED_BCR_CLK_EN;
+		break;
+	default:
+		dev_info(gsw->dev, "LED mode%d is not supported!\n", mode);
+		return -EINVAL;
 	}
+	gsw->mmd_write(gsw, 0, PHY_DEV1F, PHY_LED_BCR, cl45_data);
 
-	gsw->mmd_write(gsw, 0, 0x1f, 0x268, 0x07f1);
-	gsw->mmd_write(gsw, 0, 0x1f, 0x269, 0x2111);
-	gsw->mmd_write(gsw, 0, 0x1f, 0x26a, 0x0000);
-	gsw->mmd_write(gsw, 0, 0x1f, 0x26b, 0x0074);
-	gsw->mmd_write(gsw, 0, 0x1f, 0x26e, 0x00f6);
-	gsw->mmd_write(gsw, 0, 0x1f, 0x26f, 0x6666);
-	gsw->mmd_write(gsw, 0, 0x1f, 0x271, 0x2c02);
-	gsw->mmd_write(gsw, 0, 0x1f, 0x272, 0x0c22);
-	gsw->mmd_write(gsw, 0, 0x1f, 0x700, 0x0001);
-	gsw->mmd_write(gsw, 0, 0x1f, 0x701, 0x0803);
-	gsw->mmd_write(gsw, 0, 0x1f, 0x702, 0x01b6);
-	gsw->mmd_write(gsw, 0, 0x1f, 0x703, 0x2111);
+	return 0;
+}
 
-	gsw->mmd_write(gsw, 1, 0x1f, 0x700, 0x0001);
+static int an8855_led_set_state(struct gsw_an8855 *gsw, u8 entity, u8 state)
+{
+	u16 cl45_data = 0;
+
+	/* Change to per port contorl */
+	cl45_data = gsw->mmd_read(gsw, (entity / 4), PHY_DEV1E,
+		PHY_LED_CTRL_SELECT);
+
+	if (state == 1)
+		cl45_data |= (1 << (entity % 4));
+	else
+		cl45_data &= ~(1 << (entity % 4));
+	gsw->mmd_write(gsw, (entity / 4), PHY_DEV1E,
+		PHY_LED_CTRL_SELECT, cl45_data);
+
+	/* LED enable setting */
+	cl45_data = gsw->mmd_read(gsw, (entity / 4),
+		PHY_DEV1E, PHY_SINGLE_LED_ON_CTRL(entity % 4));
 
-	for (addr = 0x200; addr <= 0x230; addr += 2)
-		gsw->mmd_write(gsw, 0, 0x1f, addr, 0x2020);
+	if (state == 1)
+		cl45_data |= LED_ON_EN;
+	else
+		cl45_data &= ~LED_ON_EN;
 
-	for (addr = 0x201; addr <= 0x231; addr += 2)
-		gsw->mmd_write(gsw, 0, 0x1f, addr, 0x0020);
+	gsw->mmd_write(gsw, (entity / 4), PHY_DEV1E,
+		PHY_SINGLE_LED_ON_CTRL(entity % 4), cl45_data);
+
+	return 0;
 }
 
-static void an8855_eee_setting(struct gsw_an8855 *gsw, u32 port)
+static int an8855_led_init(struct gsw_an8855 *gsw)
 {
-	/* Disable EEE */
-	gsw->mmd_write(gsw, port, PHY_DEV07, PHY_DEV07_REG_03C, 0);
+	u32 val, led_count = ARRAY_SIZE(led_cfg);
+	int ret = 0, id;
+	u32 tmp_val = 0;
+	u32 tmp_id = 0;
+
+	ret = an8855_led_set_mode(gsw, AN8855_LED_MODE_USER_DEFINE);
+	if (ret != 0) {
+		dev_info(gsw->dev, "led_set_mode fail(ret:%d)!\n", ret);
+		return ret;
+	}
+
+	for (id = 0; id < led_count; id++) {
+		ret = an8855_led_set_state(gsw,
+			led_cfg[id].phy_led_idx, led_cfg[id].en);
+		if (ret != 0) {
+			dev_info(gsw->dev, "led_set_state fail(ret:%d)!\n", ret);
+			return ret;
+		}
+		if (led_cfg[id].en == 1) {
+			ret = an8855_led_set_usr_def(gsw,
+				led_cfg[id].phy_led_idx,
+				led_cfg[id].pol, led_cfg[id].on_cfg,
+				led_cfg[id].blk_cfg,
+				led_cfg[id].led_freq);
+			if (ret != 0) {
+				dev_info(gsw->dev, "led_set_usr_def fail!\n");
+				return ret;
+			}
+		}
+	}
+
+	/* Setting for System LED & Loop LED */
+	an8855_reg_write(gsw, RG_GPIO_OE, 0x0);
+	an8855_reg_write(gsw, RG_GPIO_CTRL, 0x0);
+	val = 0;
+	an8855_reg_write(gsw, RG_GPIO_L_INV, val);
+
+	val = 0x1001;
+	an8855_reg_write(gsw, RG_GPIO_CTRL, val);
+	val = an8855_reg_read(gsw, RG_GPIO_DATA);
+	val |= BITS(1, 3);
+	val &= ~(BIT(0));
+	val &= ~(BIT(6));
+
+	an8855_reg_write(gsw, RG_GPIO_DATA, val);
+	val = an8855_reg_read(gsw, RG_GPIO_OE);
+	val |= 0x41;
+	an8855_reg_write(gsw, RG_GPIO_OE, val);
+
+	/* Mapping between GPIO & LED */
+	val = 0;
+	for (id = 0; id < led_count; id++) {
+		/* Skip GPIO6, due to GPIO6 does not support PORT LED */
+		if (id == 6)
+			continue;
+
+		if (led_cfg[id].en == 1) {
+			if (id < 7)
+				val |= led_cfg[id].phy_led_idx << ((id % 4) * 8);
+			else
+				val |= led_cfg[id].phy_led_idx << (((id - 1) % 4) * 8);
+		}
+
+		if (id < 7)
+			tmp_id = id;
+		else
+			tmp_id = id - 1;
+
+		if ((tmp_id % 4) == 0x3) {
+			an8855_reg_write(gsw, RG_GPIO_LED_SEL(tmp_id / 4), val);
+			tmp_val = an8855_reg_read(gsw, RG_GPIO_LED_SEL(tmp_id / 4));
+			val = 0;
+		}
+	}
+
+	/* Turn on LAN LED mode */
+	val = 0;
+	for (id = 0; id < led_count; id++) {
+		if (led_cfg[id].en == 1)
+			val |= 0x1 << id;
+	}
+	an8855_reg_write(gsw, RG_GPIO_LED_MODE, val);
+
+	/* Force clear blink pulse for per port LED */
+	gsw->mmd_write(gsw, 0, PHY_DEV1F, PHY_LED_BLINK_DUR_CTRL, 0x1f);
+	usleep_range(1000, 5000);
+	gsw->mmd_write(gsw, 0, PHY_DEV1F, PHY_LED_BLINK_DUR_CTRL, 0);
+
+	return 0;
 }
 
 static int an8855_sw_init(struct gsw_an8855 *gsw)
 {
-	int i;
-	u32 val;
+	int i, ret = 0;
+	u32 val, led_count = ARRAY_SIZE(led_cfg);
+	int id;
 
 	gsw->phy_base = gsw->smi_addr & AN8855_SMI_ADDR_MASK;
 
@@ -852,7 +1266,7 @@
 	an8855_reg_write(gsw, SYS_CTRL, SW_SYS_RST);
 	usleep_range(100000, 110000);
 
-	/* change gphy smi address */
+	/* Change gphy smi address */
 	if (gsw->new_smi_addr != gsw->smi_addr) {
 		an8855_reg_write(gsw, RG_GPHY_SMI_ADDR, gsw->new_smi_addr);
 		gsw->smi_addr = gsw->new_smi_addr;
@@ -865,6 +1279,59 @@
 		gsw->mii_write(gsw, i, MII_BMCR, val);
 	}
 
+	/* AN8855H need to setup before switch init */
+	val = an8855_reg_read(gsw, PKG_SEL);
+	if ((val & 0x7) == PAG_SEL_AN8855H) {
+
+		/* Invert for LED activity change */
+		val = an8855_reg_read(gsw, RG_GPIO_L_INV);
+		for (id = 0; id < led_count; id++) {
+			if ((led_cfg[id].pol == LED_HIGH) &&
+				(led_cfg[id].en == 1))
+				val |= 0x1 << id;
+		}
+		an8855_reg_write(gsw, RG_GPIO_L_INV, (val | 0x1));
+
+		/* MCU NOP CMD */
+		an8855_reg_write(gsw, RG_GDMP_RAM, 0x846);
+		an8855_reg_write(gsw, RG_GDMP_RAM + 4, 0x4a);
+
+		/* Enable MCU */
+		val = an8855_reg_read(gsw, RG_CLK_CPU_ICG);
+		an8855_reg_write(gsw, RG_CLK_CPU_ICG, val | MCU_ENABLE);
+		usleep_range(1000, 5000);
+
+		/* Disable MCU watchdog */
+		val = an8855_reg_read(gsw, RG_TIMER_CTL);
+		an8855_reg_write(gsw, RG_TIMER_CTL, (val & (~WDOG_ENABLE)));
+
+		/* Configure interrupt */
+		an8855_reg_write(gsw, RG_INTB_MODE, (0x1 << gsw->intr_pin));
+
+		/* LED settings for T830 reference board */
+		ret = an8855_led_init(gsw);
+		if (ret < 0) {
+			dev_info(gsw->dev, "an8855_led_init fail. (ret=%d)\n", ret);
+			return ret;
+		}
+	}
+
+	/* Adjust to reduce noise */
+	for (i = 0; i < AN8855_NUM_PHYS; i++) {
+		gsw->mmd_write(gsw, i, PHY_DEV1E,
+			PHY_TX_PAIR_DLY_SEL_GBE, 0x4040);
+
+		gsw->mmd_write(gsw, i, PHY_DEV1E,
+			PHY_RXADC_CTRL, 0x1010);
+
+		gsw->mmd_write(gsw, i, PHY_DEV1E,
+			PHY_RXADC_REV_0, 0x100);
+
+		gsw->mmd_write(gsw, i, PHY_DEV1E,
+			PHY_RXADC_REV_1, 0x100);
+	}
+
+	/* Setup SERDES port 5 */
 	an8855_mac_port_setup(gsw, 5, &gsw->port5_cfg);
 
 	/* Global mac control settings */
@@ -875,6 +1342,7 @@
 	val = an8855_reg_read(gsw, CKGCR);
 	val &= ~(CKG_LNKDN_GLB_STOP | CKG_LNKDN_PORT_STOP);
 	an8855_reg_write(gsw, CKGCR, val);
+
 	return 0;
 }
 
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855.h b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855.h
index 883ba6e..5f84ee5 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855.h
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855.h
@@ -23,8 +23,24 @@
 
 #define AN8855_DFL_CPU_PORT		5
 #define AN8855_NUM_PHYS			5
+#define AN8855_WORD_SIZE		4
 #define AN8855_DFL_SMI_ADDR		0x1
 #define AN8855_SMI_ADDR_MASK	0x1f
+#define AN8855_DFL_INTR_ID		0xd
+#define AN8855_DFL_EXT_SURGE	0x0
+
+#define LED_ON_EVENT	(LED_ON_EVT_LINK_1000M | \
+			LED_ON_EVT_LINK_100M | LED_ON_EVT_LINK_10M |\
+			LED_ON_EVT_LINK_HD | LED_ON_EVT_LINK_FD)
+
+#define LED_BLK_EVENT	(LED_BLK_EVT_1000M_TX_ACT | \
+			LED_BLK_EVT_1000M_RX_ACT | \
+			LED_BLK_EVT_100M_TX_ACT | \
+			LED_BLK_EVT_100M_RX_ACT | \
+			LED_BLK_EVT_10M_TX_ACT | \
+			LED_BLK_EVT_10M_RX_ACT)
+
+#define LED_FREQ	AIR_LED_BLK_DUR_64M
 
 struct gsw_an8855;
 
@@ -37,6 +53,60 @@
 	SGMII_MODE_FORCE,
 };
 
+enum phy_led_idx {
+	P0_LED0,
+	P0_LED1,
+	P0_LED2,
+	P0_LED3,
+	P1_LED0,
+	P1_LED1,
+	P1_LED2,
+	P1_LED3,
+	P2_LED0,
+	P2_LED1,
+	P2_LED2,
+	P2_LED3,
+	P3_LED0,
+	P3_LED1,
+	P3_LED2,
+	P3_LED3,
+	P4_LED0,
+	P4_LED1,
+	P4_LED2,
+	P4_LED3,
+	PHY_LED_MAX
+};
+
+/* TBD */
+enum an8855_led_blk_dur {
+	AIR_LED_BLK_DUR_32M,
+	AIR_LED_BLK_DUR_64M,
+	AIR_LED_BLK_DUR_128M,
+	AIR_LED_BLK_DUR_256M,
+	AIR_LED_BLK_DUR_512M,
+	AIR_LED_BLK_DUR_1024M,
+	AIR_LED_BLK_DUR_LAST
+};
+
+enum an8855_led_polarity {
+	LED_LOW,
+	LED_HIGH,
+};
+enum an8855_led_mode {
+	AN8855_LED_MODE_DISABLE,
+	AN8855_LED_MODE_USER_DEFINE,
+	AN8855_LED_MODE_LAST
+};
+
+struct an8855_led_cfg {
+	u16 en;
+	u8  phy_led_idx;
+	u16 pol;
+	u16 on_cfg;
+	u16 blk_cfg;
+	u8 led_freq;
+};
+
 struct an8855_port_cfg {
 	struct device_node *np;
 	phy_interface_t phy_mode;
@@ -55,6 +125,8 @@
 	u32 smi_addr;
 	u32 new_smi_addr;
 	u32 phy_base;
+	u32 intr_pin;
+	u32 extSurge;
 
 	enum an8855_model model;
 	const char *name;
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_mdio.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_mdio.c
index 920240d..a4eb389 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_mdio.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_mdio.c
@@ -1,4 +1,4 @@
-// SPDX-License-Identifian8855_gsw_ider: GPL-2.0
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2023 Airoha Inc.
  * Author: Min Yao <min.yao@airoha.com>
@@ -18,6 +18,9 @@
 #include <linux/of_net.h>
 #include <linux/of_irq.h>
 #include <linux/phy.h>
+#include <linux/version.h>
+#include <linux/seq_file.h>
+#include <linux/proc_fs.h>
 
 #include "an8855.h"
 #include "an8855_swconfig.h"
@@ -25,11 +28,15 @@
 #include "an8855_nl.h"
 
 /* AN8855 driver version */
-#define ARHT_AN8855_SWCFG_DRIVER_VER	"1.0.1-L5.4"
+#define ARHT_AN8855_SWCFG_DRIVER_VER	"1.0.6"
+#define ARHT_CHIP_NAME                  "an8855"
+#define ARHT_PROC_DIR                   "air_sw"
+#define ARHT_PROC_NODE_DEVICE           "device"
 
 static u32 an8855_gsw_id;
 struct list_head an8855_devs;
 static DEFINE_MUTEX(an8855_devs_lock);
+struct proc_dir_entry *proc_an8855_gsw_dir;
 
 static struct an8855_sw_id *an8855_sw_ids[] = {
 	&an8855_id,
@@ -53,7 +60,6 @@
 	high = gsw->host_bus->read(gsw->host_bus, gsw->smi_addr, 0x17);
 
 	gsw->host_bus->write(gsw->host_bus, gsw->smi_addr, 0x1f, 0x0);
-	gsw->host_bus->write(gsw->host_bus, gsw->smi_addr, 0x10, 0x0);
 
 	mutex_unlock(&gsw->host_bus->mdio_lock);
 
@@ -78,7 +84,6 @@
 			     (val & 0xFFFF));
 
 	gsw->host_bus->write(gsw->host_bus, gsw->smi_addr, 0x1f, 0x0);
-	gsw->host_bus->write(gsw->host_bus, gsw->smi_addr, 0x10, 0x0);
 
 	mutex_unlock(&gsw->host_bus->mdio_lock);
 }
@@ -110,13 +115,17 @@
 int an8855_mmd_read(struct gsw_an8855 *gsw, int addr, int devad, u16 reg)
 {
 	int val;
-	u32 regnum = MII_ADDR_C45 | (devad << 16) | reg;
 
 	if (addr < AN8855_NUM_PHYS)
 		addr = (gsw->phy_base + addr) & AN8855_SMI_ADDR_MASK;
 
 	mutex_lock(&gsw->host_bus->mdio_lock);
-	val = gsw->host_bus->read(gsw->host_bus, addr, regnum);
+
+	gsw->host_bus->write(gsw->host_bus, addr, 0x0d, devad);
+	gsw->host_bus->write(gsw->host_bus, addr, 0x0e, reg);
+	gsw->host_bus->write(gsw->host_bus, addr, 0x0d, devad | (0x4000));
+	val = gsw->host_bus->read(gsw->host_bus, addr, 0xe);
+
 	mutex_unlock(&gsw->host_bus->mdio_lock);
 
 	return val;
@@ -125,13 +134,16 @@
 void an8855_mmd_write(struct gsw_an8855 *gsw, int addr, int devad, u16 reg,
 		      u16 val)
 {
-	u32 regnum = MII_ADDR_C45 | (devad << 16) | reg;
-
 	if (addr < AN8855_NUM_PHYS)
 		addr = (gsw->phy_base + addr) & AN8855_SMI_ADDR_MASK;
 
 	mutex_lock(&gsw->host_bus->mdio_lock);
-	gsw->host_bus->write(gsw->host_bus, addr, regnum, val);
+
+	gsw->host_bus->write(gsw->host_bus, addr, 0x0d, devad);
+	gsw->host_bus->write(gsw->host_bus, addr, 0x0e, reg);
+	gsw->host_bus->write(gsw->host_bus, addr, 0x0d, devad | (0x4000));
+	gsw->host_bus->write(gsw->host_bus, addr, 0x0e, val);
+
 	mutex_unlock(&gsw->host_bus->mdio_lock);
 }
 
@@ -146,6 +158,10 @@
 	struct device_node *fixed_link_node;
 	struct an8855_port_cfg *port_cfg;
 	u32 port;
+#if (KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE)
+	int ret;
+
+#endif
 
 	for_each_child_of_node(gsw->dev->of_node, port_np) {
 		if (!of_device_is_compatible(port_np, "airoha,an8855-port"))
@@ -172,9 +188,13 @@
 		}
 
 		port_cfg->np = port_np;
-
+#if (KERNEL_VERSION(5, 5, 0) <= LINUX_VERSION_CODE)
+		ret = of_get_phy_mode(port_np, &port_cfg->phy_mode);
+		if (ret < 0) {
+#else
 		port_cfg->phy_mode = of_get_phy_mode(port_np);
 		if (port_cfg->phy_mode < 0) {
+#endif
 			dev_info(gsw->dev, "incorrect phy-mode %d\n", port);
 			continue;
 		}
@@ -296,6 +316,7 @@
 	}
 
 	gpio_direction_output(gsw->reset_pin, 0);
+	gpio_set_value(gsw->reset_pin, 0);
 	usleep_range(100000, 150000);
 	gpio_set_value(gsw->reset_pin, 1);
 	usleep_range(100000, 150000);
@@ -314,6 +335,51 @@
 	return IRQ_HANDLED;
 }
 
+static int an8855_proc_device_read(struct seq_file *seq, void *v)
+{
+	seq_printf(seq, "%s\n", ARHT_CHIP_NAME);
+
+	return 0;
+}
+
+static int an8855_proc_device_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, an8855_proc_device_read, 0);
+}
+
+#if (KERNEL_VERSION(5, 6, 0) <= LINUX_VERSION_CODE)
+static const struct proc_ops an8855_proc_device_fops = {
+	.proc_open	= an8855_proc_device_open,
+	.proc_read	= seq_read,
+	.proc_lseek	= seq_lseek,
+	.proc_release	= single_release,
+};
+#else
+static const struct file_operations an8855_proc_device_fops = {
+	.owner	= THIS_MODULE,
+	.open	= an8855_proc_device_open,
+	.read	= seq_read,
+	.llseek	= seq_lseek,
+	.release	= single_release,
+};
+#endif
+
+static int an8855_proc_device_init(struct gsw_an8855 *gsw)
+{
+	if (!proc_an8855_gsw_dir)
+		proc_an8855_gsw_dir = proc_mkdir(ARHT_PROC_DIR, 0);
+
+	proc_create(ARHT_PROC_NODE_DEVICE, 0400, proc_an8855_gsw_dir,
+			&an8855_proc_device_fops);
+
+	return 0;
+}
+
+static void an8855_proc_device_exit(void)
+{
+	remove_proc_entry(ARHT_PROC_NODE_DEVICE, 0);
+}
+
 static int an8855_probe(struct platform_device *pdev)
 {
 	struct gsw_an8855 *gsw;
@@ -355,6 +421,14 @@
 	if (of_property_read_u32(np, "airoha,smi-addr", &gsw->new_smi_addr))
 		gsw->new_smi_addr = AN8855_DFL_SMI_ADDR;
 
+	/* Assign AN8855 interrupt pin */
+	if (of_property_read_u32(np, "airoha,intr", &gsw->intr_pin))
+		gsw->intr_pin = AN8855_DFL_INTR_ID;
+
+	/* AN8855 surge enhancement */
+	if (of_property_read_u32(np, "airoha,extSurge", &gsw->extSurge))
+		gsw->extSurge = AN8855_DFL_EXT_SURGE;
+
 	/* Get LAN/WAN port mapping */
 	map = an8855_find_mapping(np);
 	if (map) {
@@ -411,6 +485,8 @@
 
 	an8855_gsw_nl_init();
 
+	an8855_proc_device_init(gsw);
+
 	an8855_swconfig_init(gsw);
 
 	if (sw->post_init)
@@ -441,6 +517,8 @@
 	an8855_swconfig_destroy(gsw);
 #endif
 
+	an8855_proc_device_exit();
+
 	an8855_gsw_nl_exit();
 
 	an8855_remove_gsw(gsw);
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_nl.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_nl.c
index 37e3dad..f5af6d3 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_nl.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_nl.c
@@ -26,8 +26,8 @@
 static const struct nla_policy an8855_nl_cmd_policy[] = {
 	[AN8855_ATTR_TYPE_MESG] = { .type = NLA_STRING },
 	[AN8855_ATTR_TYPE_PHY] = { .type = NLA_S32 },
-	[AN8855_ATTR_TYPE_REG] = { .type = NLA_S32 },
-	[AN8855_ATTR_TYPE_VAL] = { .type = NLA_S32 },
+	[AN8855_ATTR_TYPE_REG] = { .type = NLA_U32 },
+	[AN8855_ATTR_TYPE_VAL] = { .type = NLA_U32 },
 	[AN8855_ATTR_TYPE_DEV_NAME] = { .type = NLA_S32 },
 	[AN8855_ATTR_TYPE_DEV_ID] = { .type = NLA_S32 },
 	[AN8855_ATTR_TYPE_DEVAD] = { .type = NLA_S32 },
@@ -202,15 +202,15 @@
 static int an8855_nl_reply_read(struct genl_info *info, struct gsw_an8855 *gsw)
 {
 	struct sk_buff *rep_skb = NULL;
-	s32 phy, devad, reg;
-	int value;
+	s32 phy, devad;
+	u32 reg = 0;
+	int value = 0;
 	int ret = 0;
 
 	phy = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_PHY, -1);
 	devad = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_DEVAD, -1);
-	reg = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_REG, -1);
 
-	if (reg < 0)
+	if (an8855_nl_get_u32(info, AN8855_ATTR_TYPE_REG, &reg))
 		goto err;
 
 	ret = an8855_nl_prepare_reply(info, AN8855_CMD_READ, &rep_skb);
@@ -226,11 +226,11 @@
 		value = an8855_reg_read(gsw, reg);
 	}
 
-	ret = nla_put_s32(rep_skb, AN8855_ATTR_TYPE_REG, reg);
+	ret = nla_put_u32(rep_skb, AN8855_ATTR_TYPE_REG, reg);
 	if (ret < 0)
 		goto err;
 
-	ret = nla_put_s32(rep_skb, AN8855_ATTR_TYPE_VAL, value);
+	ret = nla_put_u32(rep_skb, AN8855_ATTR_TYPE_VAL, value);
 	if (ret < 0)
 		goto err;
 
@@ -246,18 +246,16 @@
 static int an8855_nl_reply_write(struct genl_info *info, struct gsw_an8855 *gsw)
 {
 	struct sk_buff *rep_skb = NULL;
-	s32 phy, devad, reg;
-	u32 value;
+	s32 phy, devad;
+	u32 value = 0, reg = 0;
 	int ret = 0;
 
 	phy = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_PHY, -1);
 	devad = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_DEVAD, -1);
-	reg = an8855_nl_get_s32(info, AN8855_ATTR_TYPE_REG, -1);
-
-	if (an8855_nl_get_u32(info, AN8855_ATTR_TYPE_VAL, &value))
+	if (an8855_nl_get_u32(info, AN8855_ATTR_TYPE_REG, &reg))
 		goto err;
 
-	if (reg < 0)
+	if (an8855_nl_get_u32(info, AN8855_ATTR_TYPE_VAL, &value))
 		goto err;
 
 	ret = an8855_nl_prepare_reply(info, AN8855_CMD_WRITE, &rep_skb);
@@ -273,11 +271,11 @@
 		an8855_reg_write(gsw, reg, value);
 	}
 
-	ret = nla_put_s32(rep_skb, AN8855_ATTR_TYPE_REG, reg);
+	ret = nla_put_u32(rep_skb, AN8855_ATTR_TYPE_REG, reg);
 	if (ret < 0)
 		goto err;
 
-	ret = nla_put_s32(rep_skb, AN8855_ATTR_TYPE_VAL, value);
+	ret = nla_put_u32(rep_skb, AN8855_ATTR_TYPE_VAL, value);
 	if (ret < 0)
 		goto err;
 
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_regs.h b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_regs.h
index 9dbfaeb..32790a1 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_regs.h
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_regs.h
@@ -85,10 +85,10 @@
 #define PMCR(p)					PORT_MAC_CTRL_REG(p, 0x00)
 #define PMSR(p)					PORT_MAC_CTRL_REG(p, 0x10)
 
-#define GMACCR					(PORT_MAC_CTRL_BASE + 0x30e0)
+#define GMACCR					(PORT_MAC_CTRL_BASE + 0x3e00)
 
-#define MAX_RX_JUMBO_S			2
-#define MAX_RX_JUMBO_M			0x3c
+#define MAX_RX_JUMBO_S			4
+#define MAX_RX_JUMBO_M			0xf0
 #define MAX_RX_PKT_LEN_S		0
 #define MAX_RX_PKT_LEN_M		0x3
 
@@ -172,6 +172,12 @@
 #define STATS_RSFTPC		0xF8
 #define STATS_RXCDPC		0xFC
 
+#define RG_CLK_CPU_ICG		0x10005034
+#define MCU_ENABLE			BIT(3)
+
+#define RG_TIMER_CTL		0x1000a100
+#define WDOG_ENABLE			BIT(25)
+
 #define SYS_CTRL			0x100050C0
 #define SW_SYS_RST			BIT(31)
 
@@ -182,7 +188,10 @@
 #define SYS_INT_STS			0x1021C014
 #define PHY_LC_INT(p)		BIT(p)
 
-#define CKGCR				(0x10213E1C)
-#define CKG_LNKDN_GLB_STOP	(0x01)
-#define CKG_LNKDN_PORT_STOP	(0x02)
+#define CKGCR				0x10213E1C
+#define CKG_LNKDN_GLB_STOP	0x01
+#define CKG_LNKDN_PORT_STOP	0x02
+
+#define PKG_SEL				0x10000094
+#define PAG_SEL_AN8855H		0x2
 #endif /* _AN8855_REGS_H_ */
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_swconfig.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_swconfig.c
index e796582..2dd2ffd 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_swconfig.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_swconfig.c
@@ -125,7 +125,7 @@
 {
 	struct gsw_an8855 *gsw = container_of(dev, struct gsw_an8855, swdev);
 
-	if (port >= AN8855_NUM_PORTS)
+	if (port < 0 || port >= AN8855_NUM_PORTS)
 		return -EINVAL;
 
 	*val = an8855_reg_read(gsw, PVID(port));
@@ -138,7 +138,7 @@
 {
 	struct gsw_an8855 *gsw = container_of(dev, struct gsw_an8855, swdev);
 
-	if (port >= AN8855_NUM_PORTS)
+	if (port < 0 || port >= AN8855_NUM_PORTS)
 		return -EINVAL;
 
 	if (pvid < AN8855_MIN_VID || pvid > AN8855_MAX_VID)
@@ -300,18 +300,20 @@
 static u64 get_mib_counter(struct gsw_an8855 *gsw, int i, int port)
 {
 	unsigned int offset;
-	u64 lo, hi, hi2;
+	u64 lo = 0, hi = 0, hi2 = 0;
 
-	offset = an8855_mibs[i].offset;
+	if (i >= 0) {
+		offset = an8855_mibs[i].offset;
 
-	if (an8855_mibs[i].size == 1)
-		return an8855_reg_read(gsw, MIB_COUNTER_REG(port, offset));
+		if (an8855_mibs[i].size == 1)
+			return an8855_reg_read(gsw, MIB_COUNTER_REG(port, offset));
 
-	do {
-		hi = an8855_reg_read(gsw, MIB_COUNTER_REG(port, offset + 4));
-		lo = an8855_reg_read(gsw, MIB_COUNTER_REG(port, offset));
-		hi2 = an8855_reg_read(gsw, MIB_COUNTER_REG(port, offset + 4));
-	} while (hi2 != hi);
+		do {
+			hi = an8855_reg_read(gsw, MIB_COUNTER_REG(port, offset + 4));
+			lo = an8855_reg_read(gsw, MIB_COUNTER_REG(port, offset));
+			hi2 = an8855_reg_read(gsw, MIB_COUNTER_REG(port, offset + 4));
+		} while (hi2 != hi);
+	}
 
 	return (hi << 32) | lo;
 }
@@ -370,7 +372,7 @@
 	an8855_reg_write(gsw, PORTMATRIX(gsw->cpu_port), PORT_MATRIX_M);
 
 	for (i = 0; i < AN8855_NUM_PORTS; i++) {
-		u32 pvc_mode = 0x8100 << STAG_VPID_S;
+		u32 pvc_mode = 0x9100 << STAG_VPID_S;
 
 		if (gsw->port5_cfg.stag_on && i == 5)
 			pvc_mode |= PVC_PORT_STAG | PVC_STAG_REPLACE;
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_vlan.c b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_vlan.c
index 6ef8c99..1a1d751 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_vlan.c
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/files-5.4/drivers/net/phy/airoha/an8855/an8855_vlan.c
@@ -11,19 +11,19 @@
 		.name = "llllw",
 		.pvids = { 1, 1, 1, 1, 2, 1 },
 		.members = { 0, 0x2f, 0x30 },
-		.etags = { 0, 0, 0x20 },
+		.etags = { 0, 0, 0 },
 		.vids = { 0, 1, 2 },
 	}, {
 		.name = "wllll",
 		.pvids = { 2, 1, 1, 1, 1, 1 },
 		.members = { 0, 0x3e, 0x21 },
-		.etags = { 0, 0, 0x20 },
+		.etags = { 0, 0, 0 },
 		.vids = { 0, 1, 2 },
 	}, {
 		.name = "lwlll",
 		.pvids = { 1, 2, 1, 1, 1, 1 },
 		.members = { 0, 0x3d, 0x22 },
-		.etags = { 0, 0, 0x20 },
+		.etags = { 0, 0, 0 },
 		.vids = { 0, 1, 2 },
 	}, {
 		.name = "lllll",
@@ -124,14 +124,14 @@
 
 	/* set all untag-only ports as transparent and the rest as user port */
 	for (i = 0; i < AN8855_NUM_PORTS; i++) {
-		u32 pvc_mode = 0x8100 << STAG_VPID_S;
+		u32 pvc_mode = 0x9100 << STAG_VPID_S;
 
 		if (untag_ports & BIT(i) && !(tag_ports & BIT(i)))
-			pvc_mode = (0x8100 << STAG_VPID_S) |
+			pvc_mode = (0x9100 << STAG_VPID_S) |
 				(VA_TRANSPARENT_PORT << VLAN_ATTR_S);
 
 		if (gsw->port5_cfg.stag_on && i == 5)
-			pvc_mode = (u32)((0x8100 << STAG_VPID_S) | PVC_PORT_STAG
+			pvc_mode = (u32)((0x9100 << STAG_VPID_S) | PVC_PORT_STAG
 						| PVC_STAG_REPLACE);
 
 		an8855_reg_write(gsw, PVC(i), pvc_mode);
@@ -159,7 +159,8 @@
 		u16 pvid = 0;
 		u32 val;
 
-		if (vlan < AN8855_NUM_VLANS && gsw->vlan_entries[vlan].member)
+		if ((vlan >= 0) && (vlan < AN8855_NUM_VLANS)
+			&& (gsw->vlan_entries[vlan].member))
 			pvid = gsw->vlan_entries[vlan].vid;
 
 		val = an8855_reg_read(gsw, PVID(i));
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/flow_patch/999-3001-mt7622-backport-nf-hw-offload-framework-and-upstream.patch b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/flow_patch/999-3001-mt7622-backport-nf-hw-offload-framework-and-upstream.patch
index b0eb98b..ec39c96 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/flow_patch/999-3001-mt7622-backport-nf-hw-offload-framework-and-upstream.patch
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/flow_patch/999-3001-mt7622-backport-nf-hw-offload-framework-and-upstream.patch
@@ -3101,10 +3101,10 @@
  static struct dst_entry	*ip6_dst_check(struct dst_entry *dst, u32 cookie);
  static unsigned int	 ip6_default_advmss(const struct dst_entry *dst);
 -static unsigned int	 ip6_mtu(const struct dst_entry *dst);
-+static unsigned int	ip6_mtu(const struct dst_entry *dst);
- static struct dst_entry *ip6_negative_advice(struct dst_entry *);
++static unsigned int    ip6_mtu(const struct dst_entry *dst);
+ static void		ip6_negative_advice(struct sock *sk,
+ 					    struct dst_entry *dst);
  static void		ip6_dst_destroy(struct dst_entry *);
- static void		ip6_dst_ifdown(struct dst_entry *,
 @@ -3125,25 +3125,7 @@ static unsigned int ip6_default_advmss(const struct dst_entry *dst)
  
  static unsigned int ip6_mtu(const struct dst_entry *dst)
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/0005-dts-mt7622-add-gsw.patch b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/0005-dts-mt7622-add-gsw.patch
index fb959ce..73aba88 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/0005-dts-mt7622-add-gsw.patch
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/0005-dts-mt7622-add-gsw.patch
@@ -1,3 +1,5 @@
+diff --git a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts
+index eec9ec1..84df1ca 100644
 --- a/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts
 +++ b/arch/arm64/boot/dts/mediatek/mt7622-bananapi-bpi-r64.dts
 @@ -53,6 +53,13 @@
@@ -14,7 +16,7 @@
  	leds {
  		compatible = "gpio-leds";
  
-@@ -146,6 +153,36 @@
+@@ -147,6 +154,36 @@
  	};
  };
  
@@ -51,6 +53,8 @@
  &i2c1 {
  	pinctrl-names = "default";
  	pinctrl-0 = <&i2c1_pins>;
+diff --git a/arch/arm64/boot/dts/mediatek/mt7622-rfb1.dts b/arch/arm64/boot/dts/mediatek/mt7622-rfb1.dts
+index ee57fcc..0fc2dcb 100644
 --- a/arch/arm64/boot/dts/mediatek/mt7622-rfb1.dts
 +++ b/arch/arm64/boot/dts/mediatek/mt7622-rfb1.dts
 @@ -1,7 +1,6 @@
@@ -81,7 +85,7 @@
  	};
  
  	cpus {
-@@ -39,23 +39,36 @@
+@@ -40,23 +39,36 @@
  
  	gpio-keys {
  		compatible = "gpio-keys";
@@ -115,14 +119,14 @@
 +			gpios = <&pio 88 GPIO_ACTIVE_HIGH>;
 + 		};
 + 	};
-+	
++
  	memory@40000000 {
 -		reg = <0 0x40000000 0 0x20000000>;
 +		reg = <0 0x40000000 0 0x40000000>;
+ 		device_type = "memory";
  	};
  
- 	reg_1p8v: regulator-1p8v {
-@@ -101,23 +113,82 @@
+@@ -102,24 +114,83 @@
  };
  
  &eth {
@@ -162,6 +166,7 @@
 -		phy5: ethernet-phy@5 {
 -			reg = <5>;
 -			phy-mode = "sgmii";
+-		};
 +		switch@0 {
 +			compatible = "mediatek,mt7531";
 +			reg = <0>;
@@ -209,24 +214,11 @@
 +					};
 +				};
 +			};
- 		};
++ 		};
  	};
  };
-@@ -185,15 +256,28 @@
  
- &pcie {
- 	pinctrl-names = "default";
--	pinctrl-0 = <&pcie0_pins>;
-+	pinctrl-0 = <&pcie0_pins>, <&pcie1_pins>;
- 	status = "okay";
- 
- 	pcie@0,0 {
- 		status = "okay";
- 	};
-+
-+	pcie@1,0 {
-+		status = "okay";
-+	};
+@@ -195,6 +266,15 @@
  };
  
  &pio {
@@ -242,7 +234,7 @@
  	/* eMMC is shared pin with parallel NAND */
  	emmc_pins_default: emmc-pins-default {
  		mux {
-@@ -460,11 +544,11 @@
+@@ -461,11 +541,11 @@
  };
  
  &sata {
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/0993-arm64-dts-mediatek-Split-PCIe-node-for-MT2712-MT7622.patch b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/0993-arm64-dts-mediatek-Split-PCIe-node-for-MT2712-MT7622.patch
index 4fe0e0f..14999a5 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/0993-arm64-dts-mediatek-Split-PCIe-node-for-MT2712-MT7622.patch
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/0993-arm64-dts-mediatek-Split-PCIe-node-for-MT2712-MT7622.patch
@@ -389,25 +389,20 @@
  					<0 0 0 2 &pcie_intc1 1>,
 --- a/arch/arm64/boot/dts/mediatek/mt7622-rfb1.dts
 +++ b/arch/arm64/boot/dts/mediatek/mt7622-rfb1.dts
-@@ -254,18 +254,16 @@
+@@ -184,14 +184,16 @@
  	};
  };
  
 -&pcie {
 +&pcie0 {
  	pinctrl-names = "default";
--	pinctrl-0 = <&pcie0_pins>, <&pcie1_pins>;
-+	pinctrl-0 = <&pcie0_pins>;
+ 	pinctrl-0 = <&pcie0_pins>;
  	status = "okay";
 +};
  
 -	pcie@0,0 {
 -		status = "okay";
 -	};
--
--	pcie@1,0 {
--		status = "okay";
--	};
 +&pcie1 {
 +	pinctrl-names = "default";
 +	pinctrl-0 = <&pcie1_pins>;
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1402-v6.4-mtd-spinand-backport-series-flash.patch b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1402-v6.4-mtd-spinand-backport-series-flash.patch
index d3434eb..e0c59d5 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1402-v6.4-mtd-spinand-backport-series-flash.patch
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1402-v6.4-mtd-spinand-backport-series-flash.patch
@@ -442,7 +442,7 @@
  		     NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 2, 1, 1),
  		     NAND_ECCREQ(4, 512),
  		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-@@ -116,51 +118,194 @@ static const struct spinand_info macroni
+@@ -116,23 +118,76 @@ static const struct spinand_info macroni
  					      &update_cache_variants),
  		     SPINAND_HAS_QE_BIT,
  		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
@@ -455,16 +455,18 @@
  					      &write_cache_variants,
  					      &update_cache_variants),
  		     SPINAND_HAS_QE_BIT,
+-		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
+-	SPINAND_INFO("MX35LF4GE4AD", 0x37,
 +		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
 +				     mx35lf1ge4ab_ecc_get_status)),
 +	SPINAND_INFO("MX35LF4GE4AD",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x37),
-+		     NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1),
-+		     NAND_ECCREQ(8, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
+ 		     NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1),
+ 		     NAND_ECCREQ(8, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+ 					      &write_cache_variants,
+ 					      &update_cache_variants),
+ 		     SPINAND_HAS_QE_BIT,
 +		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
 +				     mx35lf1ge4ab_ecc_get_status)),
 +	SPINAND_INFO("MX35LF1G24AD",
@@ -476,30 +478,16 @@
 +					      &update_cache_variants),
 +		     SPINAND_HAS_QE_BIT,
  		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
--	SPINAND_INFO("MX35LF4GE4AD", 0x37,
--		     NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1),
+-	SPINAND_INFO("MX35LF2G14AC", 0x20,
 +	SPINAND_INFO("MX35LF2G24AD",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x24),
 +		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 2, 1, 1),
- 		     NAND_ECCREQ(8, 512),
- 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
- 					      &write_cache_variants,
- 					      &update_cache_variants),
- 		     SPINAND_HAS_QE_BIT,
- 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
--};
--
--static int macronix_spinand_detect(struct spinand_device *spinand)
--{
--	u8 *id = spinand->id.data;
--	int ret;
--
--	/*
--	 * Macronix SPI NAND read ID needs a dummy byte, so the first byte in
--	 * raw_id is garbage.
--	 */
--	if (id[1] != SPINAND_MFR_MACRONIX)
--		return 0;
++		     NAND_ECCREQ(8, 512),
++		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
++					      &write_cache_variants,
++					      &update_cache_variants),
++		     SPINAND_HAS_QE_BIT,
++		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)),
 +	SPINAND_INFO("MX35LF4G24AD",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x35),
 +		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 2, 1, 1),
@@ -529,131 +517,133 @@
 +		     SPINAND_HAS_QE_BIT,
 +		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
 +				     mx35lf1ge4ab_ecc_get_status)),
- 
--	ret = spinand_match_and_init(spinand, macronix_spinand_table,
--				     ARRAY_SIZE(macronix_spinand_table),
--				     id[2]);
--	if (ret)
--		return ret;
++
 +	SPINAND_INFO("MX35LF2G14AC",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x20),
-+		     NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 2, 1, 1),
-+		     NAND_ECCREQ(4, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
-+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
-+				     mx35lf1ge4ab_ecc_get_status)),
+ 		     NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 2, 1, 1),
+ 		     NAND_ECCREQ(4, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+@@ -141,7 +196,8 @@ static const struct spinand_info macroni
+ 		     SPINAND_HAS_QE_BIT,
+ 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
+ 				     mx35lf1ge4ab_ecc_get_status)),
+-	SPINAND_INFO("MX35UF4G24AD", 0xb5,
 +	SPINAND_INFO("MX35UF4G24AD",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xb5),
-+		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 2, 1, 1),
-+		     NAND_ECCREQ(8, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
-+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
-+				     mx35lf1ge4ab_ecc_get_status)),
+ 		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 2, 1, 1),
+ 		     NAND_ECCREQ(8, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+@@ -150,7 +206,8 @@ static const struct spinand_info macroni
+ 		     SPINAND_HAS_QE_BIT,
+ 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
+ 				     mx35lf1ge4ab_ecc_get_status)),
+-	SPINAND_INFO("MX35UF4GE4AD", 0xb7,
 +	SPINAND_INFO("MX35UF4GE4AD",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xb7),
-+		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
-+		     NAND_ECCREQ(8, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
-+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
-+				     mx35lf1ge4ab_ecc_get_status)),
+ 		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
+ 		     NAND_ECCREQ(8, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+@@ -159,7 +216,8 @@ static const struct spinand_info macroni
+ 		     SPINAND_HAS_QE_BIT,
+ 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
+ 				     mx35lf1ge4ab_ecc_get_status)),
+-	SPINAND_INFO("MX35UF2G14AC", 0xa0,
 +	SPINAND_INFO("MX35UF2G14AC",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa0),
-+		     NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 2, 1, 1),
-+		     NAND_ECCREQ(4, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
-+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
-+				     mx35lf1ge4ab_ecc_get_status)),
+ 		     NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 2, 1, 1),
+ 		     NAND_ECCREQ(4, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+@@ -168,7 +226,8 @@ static const struct spinand_info macroni
+ 		     SPINAND_HAS_QE_BIT,
+ 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
+ 				     mx35lf1ge4ab_ecc_get_status)),
+-	SPINAND_INFO("MX35UF2G24AD", 0xa4,
 +	SPINAND_INFO("MX35UF2G24AD",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa4),
-+		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 2, 1, 1),
-+		     NAND_ECCREQ(8, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
-+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
-+				     mx35lf1ge4ab_ecc_get_status)),
+ 		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 2, 1, 1),
+ 		     NAND_ECCREQ(8, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+@@ -177,7 +236,8 @@ static const struct spinand_info macroni
+ 		     SPINAND_HAS_QE_BIT,
+ 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
+ 				     mx35lf1ge4ab_ecc_get_status)),
+-	SPINAND_INFO("MX35UF2GE4AD", 0xa6,
 +	SPINAND_INFO("MX35UF2GE4AD",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa6),
-+		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
-+		     NAND_ECCREQ(8, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
-+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
-+				     mx35lf1ge4ab_ecc_get_status)),
+ 		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
+ 		     NAND_ECCREQ(8, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+@@ -186,7 +246,8 @@ static const struct spinand_info macroni
+ 		     SPINAND_HAS_QE_BIT,
+ 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
+ 				     mx35lf1ge4ab_ecc_get_status)),
+-	SPINAND_INFO("MX35UF2GE4AC", 0xa2,
 +	SPINAND_INFO("MX35UF2GE4AC",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xa2),
-+		     NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
-+		     NAND_ECCREQ(4, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
-+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
-+				     mx35lf1ge4ab_ecc_get_status)),
+ 		     NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
+ 		     NAND_ECCREQ(4, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+@@ -195,7 +256,8 @@ static const struct spinand_info macroni
+ 		     SPINAND_HAS_QE_BIT,
+ 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
+ 				     mx35lf1ge4ab_ecc_get_status)),
+-	SPINAND_INFO("MX35UF1G14AC", 0x90,
 +	SPINAND_INFO("MX35UF1G14AC",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x90),
-+		     NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
-+		     NAND_ECCREQ(4, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
-+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
-+				     mx35lf1ge4ab_ecc_get_status)),
+ 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
+ 		     NAND_ECCREQ(4, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+@@ -204,7 +266,8 @@ static const struct spinand_info macroni
+ 		     SPINAND_HAS_QE_BIT,
+ 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
+ 				     mx35lf1ge4ab_ecc_get_status)),
+-	SPINAND_INFO("MX35UF1G24AD", 0x94,
 +	SPINAND_INFO("MX35UF1G24AD",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x94),
-+		     NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
-+		     NAND_ECCREQ(8, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
-+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
-+				     mx35lf1ge4ab_ecc_get_status)),
+ 		     NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
+ 		     NAND_ECCREQ(8, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+@@ -213,7 +276,8 @@ static const struct spinand_info macroni
+ 		     SPINAND_HAS_QE_BIT,
+ 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
+ 				     mx35lf1ge4ab_ecc_get_status)),
+-	SPINAND_INFO("MX35UF1GE4AD", 0x96,
 +	SPINAND_INFO("MX35UF1GE4AD",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x96),
-+		     NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
-+		     NAND_ECCREQ(8, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
-+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
-+				     mx35lf1ge4ab_ecc_get_status)),
+ 		     NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
+ 		     NAND_ECCREQ(8, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+@@ -222,7 +286,8 @@ static const struct spinand_info macroni
+ 		     SPINAND_HAS_QE_BIT,
+ 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
+ 				     mx35lf1ge4ab_ecc_get_status)),
+-	SPINAND_INFO("MX35UF1GE4AC", 0x92,
 +	SPINAND_INFO("MX35UF1GE4AC",
 +		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x92),
-+		     NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
-+		     NAND_ECCREQ(4, 512),
-+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
-+					      &write_cache_variants,
-+					      &update_cache_variants),
-+		     SPINAND_HAS_QE_BIT,
-+		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
-+				     mx35lf1ge4ab_ecc_get_status)),
+ 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
+ 		     NAND_ECCREQ(4, 512),
+ 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+@@ -231,6 +296,7 @@ static const struct spinand_info macroni
+ 		     SPINAND_HAS_QE_BIT,
+ 		     SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout,
+ 				     mx35lf1ge4ab_ecc_get_status)),
++
+ };
  
--	return 1;
--}
-+};
+ static int macronix_spinand_detect(struct spinand_device *spinand)
+--- a/drivers/mtd/nand/spi/macronix.c
++++ b/drivers/mtd/nand/spi/macronix.c
+@@ -255,7 +255,6 @@ static int macronix_spinand_detect(struc
+ }
  
  static const struct spinand_manufacturer_ops macronix_spinand_manuf_ops = {
 -	.detect = macronix_spinand_detect,
  };
+ const struct spinand_manufacturer macronix_spinand_manufacturer = {
  
+--- a/drivers/mtd/nand/spi/macronix.c
++++ b/drivers/mtd/nand/spi/macronix.c
+@@ -326,5 +326,7 @@ static const struct spinand_manufacturer
  const struct spinand_manufacturer macronix_spinand_manufacturer = {
  	.id = SPINAND_MFR_MACRONIX,
  	.name = "Macronix",
@@ -661,6 +651,7 @@
 +	.nchips = ARRAY_SIZE(macronix_spinand_table),
  	.ops = &macronix_spinand_manuf_ops,
  };
+ 
 Index: linux-5.4.260/drivers/mtd/nand/spi/micron.c
 ===================================================================
 --- linux-5.4.260.orig/drivers/mtd/nand/spi/micron.c
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1716-v6.6-net-phy-add-phylink-pcs_enable-and-pcs_disable.patch b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1716-v6.6-net-phy-add-phylink-pcs_enable-and-pcs_disable.patch
index 29306fd..a3f7134 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1716-v6.6-net-phy-add-phylink-pcs_enable-and-pcs_disable.patch
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1716-v6.6-net-phy-add-phylink-pcs_enable-and-pcs_disable.patch
@@ -38,7 +38,7 @@
 -	if (pcs_changed)
 +	if (pcs_changed) {
 +		if (pl->pcs && pl->pcs->ops->pcs_disable)
-+			pcs->ops->pcs_disable(pl->pcs);
++			pl->pcs->ops->pcs_disable(pl->pcs);
 +
  		pl->pcs = pcs;
 +	}
@@ -47,7 +47,7 @@
  
 +	if (pl->pcs_state == PCS_STATE_STARTING || pcs_changed) {
 +		if (pl->pcs && pl->pcs->ops->pcs_enable)
-+			err = pcs->ops->pcs_enable(pl->pcs);
++			err = pl->pcs->ops->pcs_enable(pl->pcs);
 +	}
 +
  	if (pl->pcs) {
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1802-v6.4-backport-pinctrl-pinconf-setting-combo.patch b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1802-v6.4-backport-pinctrl-pinconf-setting-combo.patch
index 43ca0c5..cea4fe8 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1802-v6.4-backport-pinctrl-pinconf-setting-combo.patch
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-1802-v6.4-backport-pinctrl-pinconf-setting-combo.patch
@@ -109,109 +109,82 @@
  					return err;
 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
 +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.c
-@@ -506,6 +506,404 @@ int mtk_pinconf_bias_get_rev1(struct mtk
- 	return 0;
+@@ -6,7 +6,6 @@
+  *
+  */
+ 
+-#include <dt-bindings/pinctrl/mt65xx.h>
+ #include <linux/device.h>
+ #include <linux/err.h>
+ #include <linux/gpio/driver.h>
+@@ -67,44 +66,34 @@ static int mtk_hw_pin_field_lookup(struc
+ 				   const struct mtk_pin_desc *desc,
+ 				   int field, struct mtk_pin_field *pfd)
+ {
+-	const struct mtk_pin_field_calc *c;
++	const struct mtk_pin_field_calc *c, *e;
+ 	const struct mtk_pin_reg_calc *rc;
+-	int start = 0, end, check;
+-	bool found = false;
+ 	u32 bits;
+ 
+ 	if (hw->soc->reg_cal && hw->soc->reg_cal[field].range) {
+ 		rc = &hw->soc->reg_cal[field];
+ 	} else {
+ 		dev_dbg(hw->dev,
+-			"Not support field %d for this soc\n", field);
++			"Not support field %d for pin %d (%s)\n",
++			field, desc->number, desc->name);
+ 		return -ENOTSUPP;
+ 	}
+ 
+-	end = rc->nranges - 1;
++	c = rc->range;
++	e = c + rc->nranges;
+ 
+-	while (start <= end) {
+-		check = (start + end) >> 1;
+-		if (desc->number >= rc->range[check].s_pin
+-		 && desc->number <= rc->range[check].e_pin) {
+-			found = true;
+-			break;
+-		} else if (start == end)
++	while (c < e) {
++		if (desc->number >= c->s_pin && desc->number <= c->e_pin)
+ 			break;
+-		else if (desc->number < rc->range[check].s_pin)
+-			end = check - 1;
+-		else
+-			start = check + 1;
++		c++;
+ 	}
+ 
+-	if (!found) {
++	if (c >= e) {
+ 		dev_dbg(hw->dev, "Not support field %d for pin = %d (%s)\n",
+ 			field, desc->number, desc->name);
+ 		return -ENOTSUPP;
+ 	}
+ 
+-	c = rc->range + check;
+-
+ 	if (c->i_base > hw->nbase - 1) {
+ 		dev_err(hw->dev,
+ 			"Invalid base for field %d for pin = %d (%s)\n",
+@@ -193,9 +182,6 @@ int mtk_hw_set_value(struct mtk_pinctrl
+ 	if (err)
+ 		return err;
+ 
+-	if (value < 0 || value > pf.mask)
+-		return -EINVAL;
+-
+ 	if (!pf.next)
+ 		mtk_rmw(hw, pf.index, pf.offset, pf.mask << pf.bitpos,
+ 			(value & pf.mask) << pf.bitpos);
+@@ -619,6 +605,186 @@ out:
+ 	return err;
  }
  
-+/* Combo for the following pull register type:
-+ * 1. PU + PD
-+ * 2. PULLSEL + PULLEN
-+ * 3. PUPD + R0 + R1
-+ */
-+static int mtk_pinconf_bias_set_pu_pd(struct mtk_pinctrl *hw,
-+				const struct mtk_pin_desc *desc,
-+				u32 pullup, u32 arg)
-+{
-+	int err, pu, pd;
-+
-+	if (arg == MTK_DISABLE) {
-+		pu = 0;
-+		pd = 0;
-+	} else if ((arg == MTK_ENABLE) && pullup) {
-+		pu = 1;
-+		pd = 0;
-+	} else if ((arg == MTK_ENABLE) && !pullup) {
-+		pu = 0;
-+		pd = 1;
-+	} else {
-+		err = -EINVAL;
-+		goto out;
-+	}
-+
-+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PU, pu);
-+	if (err)
-+		goto out;
-+
-+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PD, pd);
-+
-+out:
-+	return err;
-+}
-+
-+static int mtk_pinconf_bias_set_pullsel_pullen(struct mtk_pinctrl *hw,
-+				const struct mtk_pin_desc *desc,
-+				u32 pullup, u32 arg)
-+{
-+	int err, enable;
-+
-+	if (arg == MTK_DISABLE)
-+		enable = 0;
-+	else if (arg == MTK_ENABLE)
-+		enable = 1;
-+	else {
-+		err = -EINVAL;
-+		goto out;
-+	}
-+
-+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLEN, enable);
-+	if (err)
-+		goto out;
-+
-+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup);
-+
-+out:
-+	return err;
-+}
-+
-+static int mtk_pinconf_bias_set_pupd_r1_r0(struct mtk_pinctrl *hw,
-+				const struct mtk_pin_desc *desc,
-+				u32 pullup, u32 arg)
-+{
-+	int err, r0, r1;
-+
-+	if ((arg == MTK_DISABLE) || (arg == MTK_PUPD_SET_R1R0_00)) {
-+		pullup = 0;
-+		r0 = 0;
-+		r1 = 0;
-+	} else if (arg == MTK_PUPD_SET_R1R0_01) {
-+		r0 = 1;
-+		r1 = 0;
-+	} else if (arg == MTK_PUPD_SET_R1R0_10) {
-+		r0 = 0;
-+		r1 = 1;
-+	} else if (arg == MTK_PUPD_SET_R1R0_11) {
-+		r0 = 1;
-+		r1 = 1;
-+	} else {
-+		err = -EINVAL;
-+		goto out;
-+	}
-+
-+	/* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */
-+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_PUPD, !pullup);
-+	if (err)
-+		goto out;
-+
-+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R0, r0);
-+	if (err)
-+		goto out;
-+
-+	err = mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_R1, r1);
-+
-+out:
-+	return err;
-+}
-+
 +static int mtk_hw_pin_rsel_lookup(struct mtk_pinctrl *hw,
 +				  const struct mtk_pin_desc *desc,
 +				  u32 pullup, u32 arg, u32 *rsel_val)
@@ -392,105 +365,59 @@
 +	return err;
 +}
 +
-+static int mtk_pinconf_bias_get_pu_pd(struct mtk_pinctrl *hw,
-+				const struct mtk_pin_desc *desc,
-+				u32 *pullup, u32 *enable)
-+{
-+	int err, pu, pd;
-+
-+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PU, &pu);
-+	if (err)
-+		goto out;
-+
-+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PD, &pd);
-+	if (err)
-+		goto out;
-+
-+	if (pu == 0 && pd == 0) {
-+		*pullup = 0;
-+		*enable = MTK_DISABLE;
-+	} else if (pu == 1 && pd == 0) {
-+		*pullup = 1;
-+		*enable = MTK_ENABLE;
-+	} else if (pu == 0 && pd == 1) {
-+		*pullup = 0;
-+		*enable = MTK_ENABLE;
-+	} else
-+		err = -EINVAL;
-+
-+out:
-+	return err;
-+}
-+
-+static int mtk_pinconf_bias_get_pullsel_pullen(struct mtk_pinctrl *hw,
-+				const struct mtk_pin_desc *desc,
-+				u32 *pullup, u32 *enable)
-+{
-+	int err;
-+
-+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLSEL, pullup);
-+	if (err)
-+		goto out;
-+
-+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PULLEN, enable);
-+
-+out:
-+	return err;
-+}
-+
-+static int mtk_pinconf_bias_get_pupd_r1_r0(struct mtk_pinctrl *hw,
-+				const struct mtk_pin_desc *desc,
-+				u32 *pullup, u32 *enable)
-+{
-+	int err, r0, r1;
-+
-+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_PUPD, pullup);
-+	if (err)
-+		goto out;
-+	/* MTK HW PUPD bit: 1 for pull-down, 0 for pull-up */
-+	*pullup = !(*pullup);
-+
-+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R0, &r0);
-+	if (err)
-+		goto out;
-+
-+	err = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_R1, &r1);
-+	if (err)
-+		goto out;
-+
-+	if ((r1 == 0) && (r0 == 0))
-+		*enable = MTK_PUPD_SET_R1R0_00;
-+	else if ((r1 == 0) && (r0 == 1))
-+		*enable = MTK_PUPD_SET_R1R0_01;
-+	else if ((r1 == 1) && (r0 == 0))
-+		*enable = MTK_PUPD_SET_R1R0_10;
-+	else if ((r1 == 1) && (r0 == 1))
-+		*enable = MTK_PUPD_SET_R1R0_11;
-+	else
-+		err = -EINVAL;
-+
-+out:
-+	return err;
-+}
-+
-+int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
-+			      const struct mtk_pin_desc *desc,
-+			      u32 *pullup, u32 *enable)
-+{
+ static int mtk_pinconf_bias_get_pu_pd(struct mtk_pinctrl *hw,
+ 				const struct mtk_pin_desc *desc,
+ 				u32 *pullup, u32 *enable)
+@@ -700,45 +866,43 @@ out:
+ 	return err;
+ }
+ 
+-int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
+-				const struct mtk_pin_desc *desc,
+-				u32 pullup, u32 arg)
+-{
+-	int err;
+-
+-	err = mtk_pinconf_bias_set_pu_pd(hw, desc, pullup, arg);
+-	if (!err)
+-		goto out;
+-
+-	err = mtk_pinconf_bias_set_pullsel_pullen(hw, desc, pullup, arg);
+-	if (!err)
+-		goto out;
+-
+-	err = mtk_pinconf_bias_set_pupd_r1_r0(hw, desc, pullup, arg);
+-
+-out:
+-	return err;
+-}
+-
+ int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
+ 			      const struct mtk_pin_desc *desc,
+ 			      u32 *pullup, u32 *enable)
+ {
+-	int err;
 +	int err = -ENOTSUPP;
 +	u32 try_all_type;
-+
+ 
+-	err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable);
+-	if (!err)
+-		goto out;
 +	if (hw->soc->pull_type)
 +		try_all_type = hw->soc->pull_type[desc->number];
 +	else
 +		try_all_type = MTK_PULL_TYPE_MASK;
-+
+ 
+-	err = mtk_pinconf_bias_get_pullsel_pullen(hw, desc, pullup, enable);
+-	if (!err)
+-		goto out;
 +	if (try_all_type & MTK_PULL_RSEL_TYPE) {
 +		err = mtk_pinconf_bias_get_rsel(hw, desc, pullup, enable);
 +		if (!err)
 +			return err;
 +	}
-+
+ 
+-	err = mtk_pinconf_bias_get_pupd_r1_r0(hw, desc, pullup, enable);
 +	if (try_all_type & MTK_PULL_PU_PD_TYPE) {
 +		err = mtk_pinconf_bias_get_pu_pd(hw, desc, pullup, enable);
 +		if (!err)
@@ -506,14 +433,44 @@
 +
 +	if (try_all_type & MTK_PULL_PUPD_R1R0_TYPE)
 +		err = mtk_pinconf_bias_get_pupd_r1_r0(hw, desc, pullup, enable);
-+
-+	return err;
-+}
+ 
+-out:
+ 	return err;
+ }
 +EXPORT_SYMBOL_GPL(mtk_pinconf_bias_get_combo);
-+
+ 
  /* Revision 0 */
  int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
- 			  const struct mtk_pin_desc *desc, u32 arg)
+@@ -831,18 +995,6 @@ int mtk_pinconf_drive_get_rev1(struct mt
+ 	return 0;
+ }
+ 
+-int mtk_pinconf_drive_set_raw(struct mtk_pinctrl *hw,
+-			       const struct mtk_pin_desc *desc, u32 arg)
+-{
+-	return mtk_hw_set_value(hw, desc, PINCTRL_PIN_REG_DRV, arg);
+-}
+-
+-int mtk_pinconf_drive_get_raw(struct mtk_pinctrl *hw,
+-			       const struct mtk_pin_desc *desc, int *val)
+-{
+-	return mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DRV, val);
+-}
+-
+ int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
+ 			     const struct mtk_pin_desc *desc, bool pullup,
+ 			     u32 arg)
+@@ -876,9 +1028,7 @@ int mtk_pinconf_adv_pull_set(struct mtk_
+ 			if (err)
+ 				return err;
+ 		} else {
+-			err = mtk_pinconf_bias_set_rev1(hw, desc, pullup);
+-			if (err)
+-				err = mtk_pinconf_bias_set(hw, desc, pullup);
++			return -ENOTSUPP;
+ 		}
+ 	}
+ 
 --- a/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
 +++ b/drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
 @@ -17,6 +17,34 @@
@@ -593,19 +550,22 @@
  
  	/* Specific pinconfig operations */
  	int (*bias_disable_set)(struct mtk_pinctrl *hw,
-@@ -215,7 +264,10 @@ struct mtk_pin_soc {
+@@ -215,12 +264,10 @@ struct mtk_pin_soc {
  			const struct mtk_pin_desc *desc, bool pullup);
  	int (*bias_get)(struct mtk_pinctrl *hw,
  			const struct mtk_pin_desc *desc, bool pullup, int *res);
 -
-+	int (*bias_set_combo)(struct mtk_pinctrl *hw,
+ 	int (*bias_set_combo)(struct mtk_pinctrl *hw,
+-			const struct mtk_pin_desc *desc, u32 pullup, u32 arg);
 +			      const struct mtk_pin_desc *desc, u32 pullup, u32 arg);
-+	int (*bias_get_combo)(struct mtk_pinctrl *hw,
+ 	int (*bias_get_combo)(struct mtk_pinctrl *hw,
+-			const struct mtk_pin_desc *desc, u32 *pullup, u32 *arg);
+-
 +			      const struct mtk_pin_desc *desc, u32 *pullup, u32 *arg);
  	int (*drive_set)(struct mtk_pinctrl *hw,
  			 const struct mtk_pin_desc *desc, u32 arg);
  	int (*drive_get)(struct mtk_pinctrl *hw,
-@@ -246,6 +298,10 @@ struct mtk_pinctrl {
+@@ -251,6 +298,10 @@ struct mtk_pinctrl {
  	struct mtk_eint			*eint;
  	struct mtk_pinctrl_group	*groups;
  	const char          **grp_names;
@@ -616,7 +576,18 @@
  };
  
  void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set);
-@@ -282,7 +338,12 @@ int mtk_pinconf_drive_set(struct mtk_pin
+@@ -282,28 +333,22 @@ int mtk_pinconf_bias_set_rev1(struct mtk
+ int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
+ 			      const struct mtk_pin_desc *desc, bool pullup,
+ 			      int *res);
+-int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
+-				const struct mtk_pin_desc *desc,
+-				u32 pullup, u32 enable);
+-int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
+-			      const struct mtk_pin_desc *desc,
+-			      u32 *pullup, u32 *enable);
+ 
+ int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
  			  const struct mtk_pin_desc *desc, u32 arg);
  int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
  			  const struct mtk_pin_desc *desc, int *val);
@@ -630,3 +601,13 @@
  int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
  			       const struct mtk_pin_desc *desc, u32 arg);
  int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
+ 			       const struct mtk_pin_desc *desc, int *val);
+ 
+-int mtk_pinconf_drive_set_raw(struct mtk_pinctrl *hw,
+-			       const struct mtk_pin_desc *desc, u32 arg);
+-int mtk_pinconf_drive_get_raw(struct mtk_pinctrl *hw,
+-			       const struct mtk_pin_desc *desc, int *val);
+-
+ int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
+ 			     const struct mtk_pin_desc *desc, bool pullup,
+ 			     u32 arg);
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-2377-integrate-ONFI-and-CASN-manipulation.patch b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-2377-integrate-ONFI-and-CASN-manipulation.patch
new file mode 100644
index 0000000..c2b76f9
--- /dev/null
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-2377-integrate-ONFI-and-CASN-manipulation.patch
@@ -0,0 +1,162 @@
+--- a/drivers/mtd/nand/raw/nand_onfi.c
++++ b/drivers/mtd/nand/raw/nand_onfi.c
+@@ -12,20 +12,14 @@
+  * This file contains all ONFI helpers.
+  */
+ 
++#include <linux/mtd/param.h>
+ #include <linux/slab.h>
+ 
+ #include "internals.h"
+ 
+ u16 onfi_crc16(u16 crc, u8 const *p, size_t len)
+ {
+-	int i;
+-	while (len--) {
+-		crc ^= *p++ << 8;
+-		for (i = 0; i < 8; i++)
+-			crc = (crc << 1) ^ ((crc & 0x8000) ? 0x8005 : 0);
+-	}
+-
+-	return crc;
++	return nanddev_crc16(crc, p, len);
+ }
+ 
+ /* Parse the Extended Parameter Page. */
+@@ -104,37 +98,6 @@ ext_out:
+ }
+ 
+ /*
+- * Recover data with bit-wise majority
+- */
+-static void nand_bit_wise_majority(const void **srcbufs,
+-				   unsigned int nsrcbufs,
+-				   void *dstbuf,
+-				   unsigned int bufsize)
+-{
+-	int i, j, k;
+-
+-	for (i = 0; i < bufsize; i++) {
+-		u8 val = 0;
+-
+-		for (j = 0; j < 8; j++) {
+-			unsigned int cnt = 0;
+-
+-			for (k = 0; k < nsrcbufs; k++) {
+-				const u8 *srcbuf = srcbufs[k];
+-
+-				if (srcbuf[i] & BIT(j))
+-					cnt++;
+-			}
+-
+-			if (cnt > nsrcbufs / 2)
+-				val |= BIT(j);
+-		}
+-
+-		((u8 *)dstbuf)[i] = val;
+-	}
+-}
+-
+-/*
+  * Check if the NAND chip is ONFI compliant, returns 1 if it is, 0 otherwise.
+  */
+ int nand_onfi_detect(struct nand_chip *chip)
+@@ -184,7 +147,7 @@ int nand_onfi_detect(struct nand_chip *c
+ 		const void *srcbufs[3] = {p, p + 1, p + 2};
+ 
+ 		pr_warn("Could not find a valid ONFI parameter page, trying bit-wise majority to recover it\n");
+-		nand_bit_wise_majority(srcbufs, ARRAY_SIZE(srcbufs), p,
++		nanddev_bit_wise_majority(srcbufs, ARRAY_SIZE(srcbufs), p,
+ 				       sizeof(*p));
+ 
+ 		if (onfi_crc16(ONFI_CRC_BASE, (u8 *)p, 254) !=
+--- /dev/null
++++ b/drivers/mtd/nand/param.c
+@@ -0,0 +1,52 @@
++/* SPDX-License-Identifier: GPL-2.0 */
++/*
++ * Copyright (c) 2023 - Mediatek
++ *
++ * Author: SkyLake <SkyLake.Huang@mediatek.com>
++ */
++
++#include <linux/mtd/param.h>
++
++u16 nanddev_crc16(u16 crc, u8 const *p, size_t len)
++{
++	int i;
++
++	while (len--) {
++		crc ^= *p++ << 8;
++		for (i = 0; i < 8; i++)
++			crc = (crc << 1) ^ ((crc & 0x8000) ? 0x8005 : 0);
++	}
++
++	return crc;
++}
++
++/*
++ * Recover data with bit-wise majority
++ */
++void nanddev_bit_wise_majority(const void **srcbufs,
++				   unsigned int nsrcbufs,
++				   void *dstbuf,
++				   unsigned int bufsize)
++{
++	int i, j, k;
++
++	for (i = 0; i < bufsize; i++) {
++		u8 val = 0;
++
++		for (j = 0; j < 8; j++) {
++			unsigned int cnt = 0;
++
++			for (k = 0; k < nsrcbufs; k++) {
++				const u8 *srcbuf = srcbufs[k];
++
++				if (srcbuf[i] & BIT(j))
++					cnt++;
++			}
++
++			if (cnt > nsrcbufs / 2)
++				val |= BIT(j);
++		}
++
++		((u8 *)dstbuf)[i] = val;
++	}
++}
+--- /dev/null
++++ b/include/linux/mtd/param.h
+@@ -0,0 +1,22 @@
++/* SPDX-License-Identifier: GPL-2.0 */
++/*
++ * Copyright (c) 2023 - Mediatek
++ *
++ * Author: SkyLake <SkyLake.Huang@mediatek.com>
++ */
++
++#ifndef __LINUX_NAND_PARAM
++#define __LINUX_NAND_PARAM
++
++#include <linux/bitops.h>
++#include <linux/types.h>
++#include <stddef.h>
++
++u16 nanddev_crc16(u16 crc, u8 const *p, size_t len);
++void nanddev_bit_wise_majority(const void **srcbufs,
++				   unsigned int nsrcbufs,
++				   void *dstbuf,
++				   unsigned int bufsize);
++
++#endif /* __LINUX_NAND_PARAM */
++
+--- a/drivers/mtd/nand/Makefile
++++ b/drivers/mtd/nand/Makefile
+@@ -1,6 +1,6 @@
+ # SPDX-License-Identifier: GPL-2.0
+ 
+-nandcore-objs := core.o bbt.o
++nandcore-objs := core.o bbt.o param.o
+ obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
+ 
+ obj-y	+= onenand/
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-2378-Add-CASN-support-for-SPI-NAND.patch b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-2378-Add-CASN-support-for-SPI-NAND.patch
new file mode 100644
index 0000000..fbf328f
--- /dev/null
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/999-2378-Add-CASN-support-for-SPI-NAND.patch
@@ -0,0 +1,1196 @@
+From f588443bf5be9b8fda24fbdc80187ce8f015dcf1 Mon Sep 17 00:00:00 2001
+From: "SkyLake.Huang" <skylake.huang@mediatek.com>
+Date: Mon, 31 Jul 2023 10:40:09 +0800
+Subject: [PATCH] Add CASN support for SPI-NAND
+
+Signed-off-by: SkyLake.Huang <skylake.huang@mediatek.com>
+---
+ drivers/mtd/nand/spi/core.c | 569 +++++++++++++++++++++++++++++++++++-
+ include/linux/mtd/onfi.h    | 153 +++++++++-
+ include/linux/mtd/spinand.h |  59 +++-
+ 3 files changed, 772 insertions(+), 9 deletions(-)
+
+--- a/drivers/mtd/nand/spi/core.c
++++ b/drivers/mtd/nand/spi/core.c
+@@ -9,10 +9,13 @@
+ 
+ #define pr_fmt(fmt)	"spi-nand: " fmt
+ 
++#include <linux/bitfield.h>
+ #include <linux/device.h>
+ #include <linux/jiffies.h>
+ #include <linux/kernel.h>
+ #include <linux/module.h>
++#include <linux/mtd/casn.h>
++#include <linux/mtd/param.h>
+ #include <linux/mtd/spinand.h>
+ #include <linux/of.h>
+ #include <linux/slab.h>
+@@ -20,12 +23,15 @@
+ #include <linux/spi/spi.h>
+ #include <linux/spi/spi-mem.h>
+ 
++extern void sanitize_string(uint8_t *s, size_t len);
++
+ static int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val)
+ {
+-	struct spi_mem_op op = SPINAND_GET_FEATURE_OP(reg,
+-						      spinand->scratchbuf);
++	struct spi_mem_op op;
+ 	int ret;
+ 
++	op = (struct spi_mem_op) SPINAND_GET_FEATURE_OP(reg,
++							spinand->scratchbuf);
+ 	ret = spi_mem_exec_op(spinand->spimem, &op);
+ 	if (ret)
+ 		return ret;
+@@ -36,8 +42,10 @@ static int spinand_read_reg_op(struct sp
+ 
+ static int spinand_write_reg_op(struct spinand_device *spinand, u8 reg, u8 val)
+ {
+-	struct spi_mem_op op = SPINAND_SET_FEATURE_OP(reg,
+-						      spinand->scratchbuf);
++	struct spi_mem_op op;
++
++	op = (struct spi_mem_op) SPINAND_SET_FEATURE_OP(reg,
++							spinand->scratchbuf);
+ 
+ 	*spinand->scratchbuf = val;
+ 	return spi_mem_exec_op(spinand->spimem, &op);
+@@ -402,6 +410,62 @@ static int spinand_lock_block(struct spi
+ 	return spinand_write_reg_op(spinand, REG_BLOCK_LOCK, lock);
+ }
+ 
++static size_t eccsr_none_op(size_t val, size_t mask) { return val; }
++static size_t eccsr_and_op(size_t val, size_t mask) { return val & mask; }
++static size_t eccsr_add_op(size_t val, size_t mask) { return val + mask; }
++static size_t eccsr_minus_op(size_t val, size_t mask) { return val - mask; }
++static size_t eccsr_mul_op(size_t val, size_t mask) { return val * mask; }
++
++static void spinand_read_adv_ecc(struct spinand_device *spinand,
++				 struct spi_mem_op *ops, u16 *eccsr,
++				 u16 mask, u8 shift,
++				 u8 pre_op, u8 pre_mask)
++{
++	u8 *p = spinand->scratchbuf;
++
++	spi_mem_exec_op(spinand->spimem, ops);
++
++	if (likely(mask <= 0xff))
++		*eccsr += (*p & mask) >> shift;
++	else
++		*eccsr += (((*p << 8) | (*p+1)) & mask) >> shift;
++
++	*eccsr = spinand->eccsr_math_op[pre_op](*eccsr, pre_mask);
++}
++
++static int spinand_casn_get_ecc_status(struct spinand_device *spinand, u8 status)
++{
++	struct mtd_info *mtd = spinand_to_mtd(spinand);
++	struct CASN_ADVECC *ah = spinand->advecc_high;
++	struct CASN_ADVECC *al = spinand->advecc_low;
++	u16 eccsr_high = 0;
++	u16 eccsr_low = 0;
++	u32 eccsr = 0;
++
++	if (al->cmd) {
++		spinand_read_adv_ecc(spinand,
++				     spinand->advecc_low_ops, &eccsr_low,
++				     al->mask, al->shift,
++				     al->pre_op, al->pre_mask);
++		eccsr += eccsr_low;
++	}
++	if (ah->cmd) {
++		spinand_read_adv_ecc(spinand,
++				     spinand->advecc_high_ops, &eccsr_high,
++				     ah->mask, ah->shift,
++				     ah->pre_op, ah->pre_mask);
++		eccsr += eccsr_high << spinand->advecc_low_bitcnt;
++	}
++
++	if (eccsr == spinand->advecc_noerr_status)
++		return 0;
++	else if (eccsr == spinand->advecc_uncor_status)
++		return -EBADMSG;
++	eccsr = spinand->eccsr_math_op[spinand->advecc_post_op](eccsr, spinand->advecc_post_mask);
++
++	return eccsr > mtd->ecc_strength ? mtd->ecc_strength : eccsr;
++}
++
+ static int spinand_check_ecc_status(struct spinand_device *spinand, u8 status)
+ {
+ 	struct nand_device *nand = spinand_to_nand(spinand);
+@@ -792,10 +856,11 @@ static int spinand_manufacturer_match(st
+ }
+ 
+ int spinand_cal_read(void *priv, u32 *addr, int addrlen, u8 *buf, int readlen) {
+-	int ret;
+-	u8 status;
+ 	struct spinand_device *spinand = (struct spinand_device *)priv;
+ 	struct device *dev = &spinand->spimem->spi->dev;
++	struct spi_mem_op op;
++	u8 status;
++	int ret;
+ 
+ 	typedef struct nand_pos my_pos;
+ 	my_pos pos;
+@@ -838,13 +903,246 @@ int spinand_cal_read(void *priv, u32 *ad
+ 	if (ret < 0)
+ 		return ret;
+ 
+-	struct spi_mem_op op = SPINAND_PAGE_READ_FROM_CACHE_OP(
++	op = (struct spi_mem_op) SPINAND_PAGE_READ_FROM_CACHE_OP(
+ 		false, 0, 1, buf, readlen);
+ 	ret = spi_mem_exec_op(spinand->spimem, &op);
+ 
+ 	return 0;
+ }
+ 
++static int spinand_check_casn_validity(struct spinand_device *spinand,
++				       struct nand_casn *casn)
++{
++	struct device *dev = &spinand->spimem->spi->dev;
++
++	if (be32_to_cpu(casn->bits_per_cell) != 1) {
++		dev_err(dev, "[CASN] bits-per-cell must be 1\n");
++		return -EINVAL;
++	}
++
++	switch (be32_to_cpu(casn->bytes_per_page)) {
++	case 2048:
++	case 4096:
++		break;
++	default:
++		dev_err(dev, "[CASN] page size must be 2048/4096\n");
++		return -EINVAL;
++	}
++
++	switch (be32_to_cpu(casn->spare_bytes_per_page)) {
++	case 64:
++	case 96:
++	case 128:
++	case 256:
++		break;
++	default:
++		dev_err(dev, "[CASN] spare size must be 64/128/256\n");
++		return -EINVAL;
++	}
++
++	switch (be32_to_cpu(casn->pages_per_block)) {
++	case 64:
++	case 128:
++		break;
++	default:
++		dev_err(dev, "[CASN] pages_per_block must be 64/128\n");
++		return -EINVAL;
++	}
++
++	switch (be32_to_cpu(casn->blocks_per_lun)) {
++	case 1024:
++		if (be32_to_cpu(casn->max_bb_per_lun) != 20) {
++			dev_err(dev, "[CASN] max_bb_per_lun must be 20 when blocks_per_lun is 1024\n");
++			return -EINVAL;
++		}
++		break;
++	case 2048:
++		if (be32_to_cpu(casn->max_bb_per_lun) != 40) {
++			dev_err(dev, "[CASN] max_bb_per_lun must be 40 when blocks_per_lun is 2048\n");
++			return -EINVAL;
++		}
++		break;
++	case 4096:
++		if (be32_to_cpu(casn->max_bb_per_lun) != 80) {
++			dev_err(dev, "[CASN] max_bb_per_lun must be 80 when blocks_per_lun is 4096\n");
++			return -EINVAL;
++		}
++		break;
++	default:
++		dev_err(dev, "[CASN] blocks_per_lun must be 1024/2048/4096\n");
++		return -EINVAL;
++	}
++
++	switch (be32_to_cpu(casn->planes_per_lun)) {
++	case 1:
++	case 2:
++		break;
++	default:
++		dev_err(dev, "[CASN] planes_per_lun must be 1/2\n");
++		return -EINVAL;
++	}
++
++	switch (be32_to_cpu(casn->luns_per_target)) {
++	case 1:
++	case 2:
++		break;
++	default:
++		dev_err(dev, "[CASN] luns_per_target must be 1/2\n");
++		return -EINVAL;
++	}
++
++	switch (be32_to_cpu(casn->total_target)) {
++	case 1:
++	case 2:
++		break;
++	default:
++		dev_err(dev, "[CASN] ntargets must be 1/2\n");
++		return -EINVAL;
++	}
++
++	if (casn->casn_oob.layout_type != OOB_CONTINUOUS &&
++	    casn->casn_oob.layout_type != OOB_DISCRETE) {
++		dev_err(dev, "[CASN] OOB layout type isn't correct.\n");
++		return -EINVAL;
++	}
++
++	if (casn->ecc_status_high.status_nbytes > 2 ||
++	    casn->ecc_status_low.status_nbytes > 2) {
++		dev_err(dev, "[CASN] ADVECC status nbytes must be no more than 2\n");
++		return -EINVAL;
++	}
++
++	return 0;
++}
++
++static int spinand_check_casn(struct spinand_device *spinand,
++			struct nand_casn *casn, unsigned int *sel)
++{
++	struct device *dev = &spinand->spimem->spi->dev;
++	uint16_t crc = be16_to_cpu(casn->crc);
++	uint16_t crc_compute;
++	int ret = 0;
++	int i;
++
++	/* There are 3 copies of CASN Pages V1. Choose one avabilable copy
++	 * first. If none of the copies is available, try to recover.
++	 */
++	for (i = 0; i < CASN_PAGE_V1_COPIES; i++) {
++		if (be32_to_cpu(casn[i].signature) != CASN_SIGNATURE) {
++			ret = -EINVAL;
++			continue;
++		}
++		crc_compute = nanddev_crc16(CASN_CRC_BASE, (u8 *)(casn + i),
++					    SPINAND_CASN_V1_CRC_OFS);
++		dev_dbg(dev, "CASN COPY %d CRC read: 0x%x, compute: 0x%x\n",
++			i, crc, crc_compute);
++		if (crc != crc_compute) {
++			ret = -EBADMSG;
++			continue;
++		}
++		ret = spinand_check_casn_validity(spinand, casn + i);
++		if (ret < 0)
++			continue;
++		*sel = i;
++		break;
++	}
++
++	if (i == CASN_PAGE_V1_COPIES && ret == -EBADMSG) {
++		const void *srcbufs[CASN_PAGE_V1_COPIES];
++		int j;
++
++		for (j = 0; j < CASN_PAGE_V1_COPIES; j++)
++			srcbufs[j] = casn + j;
++		dev_info(dev, "Couldn't find a valid CASN page, try bitwise majority to recover it\n");
++		nanddev_bit_wise_majority(srcbufs, CASN_PAGE_V1_COPIES, casn,
++					  sizeof(*casn));
++		crc_compute = nanddev_crc16(CASN_CRC_BASE, (uint8_t *)casn,
++					    SPINAND_CASN_V1_CRC_OFS);
++		if (crc_compute != crc) {
++			dev_err(dev, "CASN page recovery failed, aborting\n");
++			return -EBADMSG;
++		}
++		ret = spinand_check_casn_validity(spinand, casn + i);
++		if (ret < 0)
++			return ret;
++		dev_info(dev, "CASN page recovery succeeded\n");
++		*sel = 0;
++	}
++
++	return ret;
++}
++
++static int spinand_casn_detect(struct spinand_device *spinand,
++			       struct nand_casn *casn, unsigned int *sel)
++{
++	struct device *dev = &spinand->spimem->spi->dev;
++	uint8_t casn_offset[3] = {0x0, 0x1, 0x4};
++	struct nand_page_io_req req;
++	struct spi_mem_op op;
++	struct nand_pos pos;
++	int check_ret = 0;
++	uint8_t status;
++	int final_ret;
++	int ret = 0;
++	u8 cfg_reg;
++	int i;
++
++	ret = spinand_read_reg_op(spinand, REG_CFG, &cfg_reg);
++	if (ret)
++		return ret;
++
++	ret = spinand_write_reg_op(spinand, REG_CFG, cfg_reg | BIT(6));
++	if (ret)
++		return ret;
++
++	memset(&pos, 0, sizeof(pos));
++
++	req = (struct nand_page_io_req){
++		.pos = pos,
++		.dataoffs = 0,
++		.datalen = 256 * CASN_PAGE_V1_COPIES,
++		.databuf.in = (u8 *)casn,
++		.mode = MTD_OPS_AUTO_OOB,
++	};
++
++	for (i = 0; i < sizeof(casn_offset)/sizeof(uint8_t); i++) {
++		req.pos.page = casn_offset[i];
++		ret = spinand_load_page_op(spinand, &req);
++		if (ret)
++			goto finish;
++
++		ret = spinand_wait(spinand, &status);
++		if (ret < 0)
++			goto finish;
++
++		op = (struct spi_mem_op) SPINAND_PAGE_READ_FROM_CACHE_OP(
++			false, 768, 1, (u8 *)casn, 256 * CASN_PAGE_V1_COPIES);
++		ret = spi_mem_exec_op(spinand->spimem, &op);
++		if (ret < 0)
++			goto finish;
++
++		check_ret = spinand_check_casn(spinand, casn, sel);
++		if (!check_ret)
++			break;
++	}
++
++finish:
++	/* We need to restore configuration register. */
++	final_ret = spinand_write_reg_op(spinand, REG_CFG, cfg_reg);
++	if (final_ret)
++		return final_ret;
++
++	if (check_ret) {
++		dev_err(dev, "CASN page check failed\n");
++		return check_ret;
++	}
++
++	if (ret)
++		dev_err(dev, "CASN page read failed\n");
++
++	return ret;
++}
++
+ static int spinand_id_detect(struct spinand_device *spinand)
+ {
+ 	u8 *id = spinand->id.data;
+@@ -876,7 +1174,7 @@ static int spinand_id_detect(struct spin
+ 
+ static int spinand_manufacturer_init(struct spinand_device *spinand)
+ {
+-	if (spinand->manufacturer->ops->init)
++	if (!spinand->use_casn && spinand->manufacturer->ops->init)
+ 		return spinand->manufacturer->ops->init(spinand);
+ 
+ 	return 0;
+@@ -885,7 +1183,7 @@ static int spinand_manufacturer_init(str
+ static void spinand_manufacturer_cleanup(struct spinand_device *spinand)
+ {
+ 	/* Release manufacturer private data */
+-	if (spinand->manufacturer->ops->cleanup)
++	if (!spinand->use_casn && spinand->manufacturer->ops->cleanup)
+ 		return spinand->manufacturer->ops->cleanup(spinand);
+ }
+ 
+@@ -988,37 +1286,456 @@ int spinand_match_and_init(struct spinan
+ 	return -ENOTSUPP;
+ }
+ 
++static int spinand_casn_ooblayout_ecc(struct mtd_info *mtd, int section,
++				       struct mtd_oob_region *region)
++{
++	struct spinand_device *spinand = mtd_to_spinand(mtd);
++	int sectionp;
++	struct CASN_OOB *co = spinand->casn_oob;
++
++	sectionp = spinand->base.memorg.pagesize/mtd->ecc_step_size;
++	if (section >= sectionp)
++		return -ERANGE;
++
++	if (co->layout_type == OOB_DISCRETE) {
++		region->offset = co->ecc_parity_start +
++				 (co->free_length + co->ecc_parity_space)
++				 * section;
++	} else if (co->layout_type == OOB_CONTINUOUS) {
++		region->offset = co->ecc_parity_start + co->ecc_parity_space * section;
++	}
++	region->length = co->ecc_parity_real_length;
++
++	return 0;
++}
++
++static int spinand_casn_ooblayout_free(struct mtd_info *mtd, int section,
++					struct mtd_oob_region *region)
++{
++	struct spinand_device *spinand = mtd_to_spinand(mtd);
++	int sectionp;
++	struct CASN_OOB *co = spinand->casn_oob;
++
++	sectionp = spinand->base.memorg.pagesize/mtd->ecc_step_size;
++	if (section >= sectionp)
++		return -ERANGE;
++
++	if (!section) {
++		region->offset = co->free_start + co->bbm_length;
++		region->length = co->free_length - co->bbm_length;
++	} else {
++		if (co->layout_type == OOB_DISCRETE) {
++			region->offset = co->free_start +
++					 (co->free_length +
++					  co->ecc_parity_space) * section;
++		} else if (co->layout_type == OOB_CONTINUOUS) {
++			region->offset = co->free_start +
++					 co->free_length * section;
++		}
++		region->length = co->free_length;
++	}
++
++	return 0;
++}
++
++static const struct mtd_ooblayout_ops spinand_casn_ooblayout = {
++	.ecc = spinand_casn_ooblayout_ecc,
++	.free = spinand_casn_ooblayout_free,
++};
++
++static int spinand_set_read_op_variants(struct spinand_device *spinand,
++					struct nand_casn *casn)
++{
++	struct spinand_op_variants casn_read_cache_variants;
++	u16 sdr_read_cap = be16_to_cpu(casn->sdr_read_cap);
++	struct spi_mem_op *read_ops;
++	const struct spi_mem_op *op;
++	int i = 0;
++
++	read_ops = devm_kzalloc(&spinand->spimem->spi->dev,
++				sizeof(struct spi_mem_op) *
++				hweight16(sdr_read_cap),
++				GFP_KERNEL);
++	if (!read_ops)
++		return -ENOMEM;
++
++	if (FIELD_GET(SDR_READ_1_4_4, sdr_read_cap)) {
++		read_ops[i] = (struct spi_mem_op)
++			SPINAND_CASN_PAGE_READ_FROM_CACHE_QUADIO_OP(
++				casn->sdr_read_1_4_4.addr_nbytes, 0,
++				casn->sdr_read_1_4_4.dummy_nbytes, NULL, 0
++			);
++		i++;
++	}
++	if (FIELD_GET(SDR_READ_1_1_4, sdr_read_cap)) {
++		read_ops[i] = (struct spi_mem_op)
++			SPINAND_CASN_PAGE_READ_FROM_CACHE_X4_OP(
++				casn->sdr_read_1_1_4.addr_nbytes, 0,
++				casn->sdr_read_1_1_4.dummy_nbytes, NULL, 0
++			);
++		i++;
++	}
++	if (FIELD_GET(SDR_READ_1_2_2, sdr_read_cap)) {
++		read_ops[i] = (struct spi_mem_op)
++			SPINAND_CASN_PAGE_READ_FROM_CACHE_DUALIO_OP(
++				casn->sdr_read_1_2_2.addr_nbytes, 0,
++				casn->sdr_read_1_2_2.dummy_nbytes, NULL, 0
++			);
++		i++;
++	}
++	if (FIELD_GET(SDR_READ_1_1_2, sdr_read_cap)) {
++		read_ops[i] = (struct spi_mem_op)
++			SPINAND_CASN_PAGE_READ_FROM_CACHE_X2_OP(
++				casn->sdr_read_1_1_2.addr_nbytes, 0,
++				casn->sdr_read_1_1_2.dummy_nbytes, NULL, 0
++			);
++		i++;
++	}
++	if (FIELD_GET(SDR_READ_1_1_1_FAST, sdr_read_cap)) {
++		read_ops[i] = (struct spi_mem_op)
++			SPINAND_CASN_PAGE_READ_FROM_CACHE_OP(
++				true, casn->sdr_read_1_1_1_fast.addr_nbytes, 0,
++				casn->sdr_read_1_1_1_fast.dummy_nbytes, NULL, 0
++			);
++		i++;
++	}
++	if (FIELD_GET(SDR_READ_1_1_1, sdr_read_cap)) {
++		read_ops[i] = (struct spi_mem_op)
++			SPINAND_CASN_PAGE_READ_FROM_CACHE_OP(
++				false, casn->sdr_read_1_1_1.addr_nbytes, 0,
++				casn->sdr_read_1_1_1.dummy_nbytes, NULL, 0
++			);
++		i++;
++	}
++
++	casn_read_cache_variants = (struct spinand_op_variants){
++		.ops = read_ops,
++		.nops = hweight16(sdr_read_cap),
++	};
++
++	op = spinand_select_op_variant(spinand, &casn_read_cache_variants);
++	if (!op) {
++		devm_kfree(&spinand->spimem->spi->dev, read_ops);
++		return -ENOTSUPP;
++	}
++	spinand->op_templates.read_cache = op;
++
++	return 0;
++}
++
++static int spinand_set_write_op_variants(struct spinand_device *spinand,
++					 struct nand_casn *casn)
++{
++	struct spinand_op_variants casn_write_cache_variants;
++	struct spi_mem_op *write_ops;
++	const struct spi_mem_op *op;
++	int i = 0;
++
++	write_ops = devm_kzalloc(&spinand->spimem->spi->dev,
++				 sizeof(struct spi_mem_op) *
++				 hweight8(casn->sdr_write_cap),
++				 GFP_KERNEL);
++	if (!write_ops)
++		return -ENOMEM;
++
++	if (FIELD_GET(SDR_WRITE_1_1_4, casn->sdr_write_cap)) {
++		write_ops[i] = (struct spi_mem_op)
++			SPINAND_CASN_PROG_LOAD_X4(
++				true, casn->sdr_write_1_1_4.addr_nbytes, 0,
++				NULL, 0);
++		i++;
++	}
++	if (FIELD_GET(SDR_WRITE_1_1_1, casn->sdr_write_cap)) {
++		write_ops[i] = (struct spi_mem_op)
++			SPINAND_CASN_PROG_LOAD(
++				true, casn->sdr_write_1_1_1.addr_nbytes, 0,
++				NULL, 0);
++		i++;
++	}
++
++	casn_write_cache_variants = (struct spinand_op_variants){
++		.ops = write_ops,
++		.nops = hweight8(casn->sdr_write_cap),
++	};
++
++	op = spinand_select_op_variant(spinand, &casn_write_cache_variants);
++	if (!op) {
++		devm_kfree(&spinand->spimem->spi->dev, write_ops);
++		return -ENOTSUPP;
++	}
++	spinand->op_templates.write_cache = op;
++
++	return 0;
++}
++
++static int spinand_set_update_op_variants(struct spinand_device *spinand,
++					  struct nand_casn *casn)
++{
++	struct spinand_op_variants casn_update_cache_variants;
++	struct spi_mem_op *update_ops;
++	const struct spi_mem_op *op;
++	int i = 0;
++
++	update_ops = devm_kzalloc(&spinand->spimem->spi->dev,
++				  sizeof(struct spi_mem_op) *
++				  hweight8(casn->sdr_update_cap),
++				  GFP_KERNEL);
++	if (!update_ops)
++		return -ENOMEM;
++
++	if (FIELD_GET(SDR_UPDATE_1_1_4, casn->sdr_update_cap)) {
++		update_ops[i] = (struct spi_mem_op)
++			SPINAND_CASN_PROG_LOAD_X4(
++				false, casn->sdr_update_1_1_4.addr_nbytes, 0,
++				NULL, 0);
++		i++;
++	}
++	if (FIELD_GET(SDR_UPDATE_1_1_1, casn->sdr_update_cap)) {
++		update_ops[i] = (struct spi_mem_op)
++			SPINAND_CASN_PROG_LOAD(
++				false, casn->sdr_update_1_1_1.addr_nbytes, 0,
++				NULL, 0);
++		i++;
++	}
++
++	casn_update_cache_variants = (struct spinand_op_variants){
++		.ops = update_ops,
++		.nops = hweight8(casn->sdr_update_cap),
++	};
++
++	op = spinand_select_op_variant(spinand, &casn_update_cache_variants);
++	if (!op) {
++		devm_kfree(&spinand->spimem->spi->dev, update_ops);
++		return -ENOTSUPP;
++	}
++	spinand->op_templates.update_cache = op;
++
++	return 0;
++}
++
++static int spinand_init_via_casn(struct spinand_device *spinand,
++				 struct nand_casn *casn)
++{
++	struct nand_device *nand = spinand_to_nand(spinand);
++	u32 val;
++	int ret;
++	int i;
++
++	/* Set members of nand->memorg via CASN. */
++	for (i = 0; i < 9; i++) {
++		val = be32_to_cpu(*(&casn->bits_per_cell + i));
++		memcpy((u32 *)&nand->memorg.bits_per_cell + i, &val, sizeof(u32));
++	}
++	nand->eccreq.strength = be32_to_cpu(casn->ecc_strength);
++	nand->eccreq.step_size = be32_to_cpu(casn->ecc_step_size);
++	spinand->flags = casn->flags;
++
++	if (spinand->flags & SPINAND_SUP_ADV_ECC_STATUS) {
++		spinand->eccinfo = (struct spinand_ecc_info) {
++			&spinand_casn_get_ecc_status, &spinand_casn_ooblayout};
++	} else {
++		spinand->eccinfo = (struct spinand_ecc_info) {
++			NULL, &spinand_casn_ooblayout };
++	}
++
++	spinand->advecc_high_ops = devm_kzalloc(&spinand->spimem->spi->dev,
++						sizeof(struct spi_mem_op),
++						GFP_KERNEL);
++	if (!spinand->advecc_high_ops)
++		return -ENOMEM;
++	spinand->advecc_low_ops = devm_kzalloc(&spinand->spimem->spi->dev,
++					       sizeof(struct spi_mem_op),
++					       GFP_KERNEL);
++	if (!spinand->advecc_low_ops)
++		return -ENOMEM;
++	spinand->casn_oob = devm_kzalloc(&spinand->spimem->spi->dev,
++					 sizeof(struct CASN_OOB),
++					 GFP_KERNEL);
++	if (!spinand->casn_oob)
++		return -ENOMEM;
++	spinand->advecc_high = devm_kzalloc(&spinand->spimem->spi->dev,
++					    sizeof(struct CASN_ADVECC),
++					    GFP_KERNEL);
++	if (!spinand->advecc_high)
++		return -ENOMEM;
++	spinand->advecc_low = devm_kzalloc(&spinand->spimem->spi->dev,
++					   sizeof(struct CASN_ADVECC),
++					   GFP_KERNEL);
++	if (!spinand->advecc_low)
++		return -ENOMEM;
++
++	*spinand->advecc_high_ops = (struct spi_mem_op)
++		SPINAND_CASN_ADVECC_OP(casn->ecc_status_high, spinand->scratchbuf);
++	*spinand->advecc_low_ops = (struct spi_mem_op)
++		SPINAND_CASN_ADVECC_OP(casn->ecc_status_low, spinand->scratchbuf);
++
++	memcpy(spinand->casn_oob, &casn->casn_oob, sizeof(struct CASN_OOB));
++
++	spinand->advecc_high->cmd = casn->ecc_status_high.cmd;
++	spinand->advecc_high->mask = be16_to_cpu(casn->ecc_status_high.status_mask);
++	spinand->advecc_high->shift = spinand->advecc_high->mask ?
++				      ffs(spinand->advecc_high->mask)-1 : 0;
++	spinand->advecc_high->pre_op = casn->ecc_status_high.pre_op;
++	spinand->advecc_high->pre_mask = casn->ecc_status_high.pre_mask;
++
++	spinand->advecc_low->cmd = casn->ecc_status_low.cmd;
++	spinand->advecc_low->mask = be16_to_cpu(casn->ecc_status_low.status_mask);
++	spinand->advecc_low->shift = spinand->advecc_low->mask ?
++				     ffs(spinand->advecc_low->mask)-1 : 0;
++	spinand->advecc_low->pre_op = casn->ecc_status_low.pre_op;
++	spinand->advecc_low->pre_mask = casn->ecc_status_low.pre_mask;
++
++	spinand->advecc_low_bitcnt = hweight16(spinand->advecc_low->mask);
++
++	spinand->advecc_noerr_status = casn->advecc_noerr_status;
++	spinand->advecc_uncor_status = casn->advecc_uncor_status;
++	spinand->advecc_post_op = casn->advecc_post_op;
++	spinand->advecc_post_mask = casn->advecc_post_mask;
++	spinand->eccsr_math_op[0] = eccsr_none_op;
++	spinand->eccsr_math_op[1] = eccsr_and_op;
++	spinand->eccsr_math_op[2] = eccsr_add_op;
++	spinand->eccsr_math_op[3] = eccsr_minus_op;
++	spinand->eccsr_math_op[4] = eccsr_mul_op;
++
++	ret = spinand_set_read_op_variants(spinand, casn);
++	if (ret < 0)
++		return ret;
++	ret = spinand_set_write_op_variants(spinand, casn);
++	if (ret < 0)
++		return ret;
++	ret = spinand_set_update_op_variants(spinand, casn);
++	if (ret < 0)
++		return ret;
++
++	return 0;
++}
++
++static void spinand_dump_casn(struct spinand_device *spinand, struct nand_casn *casn)
++{
++	int i;
++
++	dev_dbg(&spinand->spimem->spi->dev,
++		"---Start dumping full CASN page---\n");
++	for (i = 0; i < 64; i++)
++		pr_debug("0x%08x", *((u32 *)casn + i));
++
++	pr_debug("** Dump critical fields **\n");
++	pr_debug("signature: 0x%04x\n", be32_to_cpu(casn->signature));
++	pr_debug("version: v%u.%u\n", casn->version >> 4, casn->version & 0xf);
++	pr_debug("[Memory Organization]\n");
++	pr_debug("  bits_per_cell: %d\n", be32_to_cpu(casn->bits_per_cell));
++	pr_debug("  bytes_per_page: %d\n", be32_to_cpu(casn->bytes_per_page));
++	pr_debug("  spare_bytes_per_page: %d\n",
++		 be32_to_cpu(casn->spare_bytes_per_page));
++	pr_debug("  pages_per_block: %d\n",
++		 be32_to_cpu(casn->pages_per_block));
++	pr_debug("  blocks_per_lun: %d\n", be32_to_cpu(casn->blocks_per_lun));
++	pr_debug("  max_bb_per_lun: %d\n", be32_to_cpu(casn->max_bb_per_lun));
++	pr_debug("  planes_per_lun: %d\n", be32_to_cpu(casn->planes_per_lun));
++	pr_debug("  luns_per_target: %d\n",
++		 be32_to_cpu(casn->luns_per_target));
++	pr_debug("  total_target: %d\n", be32_to_cpu(casn->total_target));
++	pr_debug("[flags]\n");
++	pr_debug("  0. Have QE bit? %s\n",
++		casn->flags & SPINAND_HAS_QE_BIT ? "Yes" : "No");
++	pr_debug("  1. Have continuous read feature bit? %s\n",
++		casn->flags & SPINAND_HAS_CR_FEAT_BIT ? "Yes" : "No");
++	pr_debug("  2. Support continuous read? %s\n",
++		casn->flags & SPINAND_SUP_CR ? "Yes" : "No");
++	pr_debug("  3. Support on-die ECC? %s\n",
++		casn->flags & SPINAND_SUP_ON_DIE_ECC ? "Yes" : "No");
++	pr_debug("  4. Support legacy ECC status? %s\n",
++		casn->flags & SPINAND_SUP_LEGACY_ECC_STATUS ? "Yes" : "No");
++	pr_debug("  5. Support advanced ECC status? %s\n",
++		casn->flags & SPINAND_SUP_ADV_ECC_STATUS ? "Yes" : "No");
++	pr_debug("  6. ECC parity readable? %s\n",
++		casn->flags & SPINAND_ECC_PARITY_READABLE ? "Yes" : "No");
++	pr_debug("[R/W ability]\n");
++	pr_debug("  read ability: %x\n", be16_to_cpu(casn->sdr_read_cap));
++	pr_debug("  write ability: %x\n", casn->sdr_write_cap);
++	pr_debug("  update ability: %x\n", casn->sdr_update_cap);
++	pr_debug("advanced ECC no error state: %x\n",
++		 casn->advecc_noerr_status);
++	pr_debug("advecced ECC uncorrectable state: %x\n",
++		 casn->advecc_uncor_status);
++	pr_debug("CRC: 0x%04x\n", be16_to_cpu(casn->crc));
++
++	dev_dbg(&spinand->spimem->spi->dev,
++		"---Dumping full CASN page ends here.---\n");
++}
++
+ static int spinand_detect(struct spinand_device *spinand)
+ {
+-	struct device *dev = &spinand->spimem->spi->dev;
+ 	struct nand_device *nand = spinand_to_nand(spinand);
++	struct device *dev = &spinand->spimem->spi->dev;
++	struct nand_casn *casn;
++	char manufacturer[14];
++	unsigned int sel = 0;
++	char model[17];
+ 	int ret;
+ 
+ 	ret = spinand_reset_op(spinand);
+ 	if (ret)
+ 		return ret;
+ 
+-	ret = spinand_id_detect(spinand);
+-	if (ret) {
+-		dev_err(dev, "unknown raw ID %*phN\n", SPINAND_MAX_ID_LEN,
+-			spinand->id.data);
+-		return ret;
++	spinand->use_casn = false;
++	casn = kzalloc((sizeof(struct nand_casn) * CASN_PAGE_V1_COPIES), GFP_KERNEL);
++	if (!casn)
++		return -ENOMEM;
++
++	ret = spinand_casn_detect(spinand, casn, &sel);
++	if (!ret) {
++		spinand->use_casn = true;
++		strncpy(manufacturer, casn[sel].manufacturer, sizeof(manufacturer)-1);
++		sanitize_string(manufacturer, sizeof(manufacturer));
++		strncpy(model, casn[sel].model, sizeof(model)-1);
++		sanitize_string(model, sizeof(model));
++
++		spinand_dump_casn(spinand, casn + sel);
++
++		ret = spinand_init_via_casn(spinand, casn + sel);
++		if (ret)
++			dev_err(dev, "Initilize spinand via CASN failed: %d\n", ret);
++	}
++
++	if (ret < 0) {
++		dev_warn(dev, "Fallback to read ID\n");
++
++		ret = spinand_reset_op(spinand);
++		if (ret)
++			goto free_casn;
++		ret = spinand_id_detect(spinand);
++		if (ret) {
++			dev_err(dev, "unknown raw ID %*phN\n", SPINAND_MAX_ID_LEN,
++				spinand->id.data);
++			goto free_casn;
++		}
+ 	}
+ 
+ 	if (nand->memorg.ntargets > 1 && !spinand->select_target) {
+ 		dev_err(dev,
+ 			"SPI NANDs with more than one die must implement ->select_target()\n");
+-		return -EINVAL;
++		ret = -EINVAL;
++		goto free_casn;
++	}
++
++	if (spinand->use_casn) {
++		dev_info(&spinand->spimem->spi->dev,
++			 "%s %s SPI NAND was found.\n", manufacturer, model);
++	} else {
++		dev_info(&spinand->spimem->spi->dev,
++			 "%s SPI NAND was found.\n", spinand->manufacturer->name);
+ 	}
+ 
+-	dev_info(&spinand->spimem->spi->dev,
+-		 "%s SPI NAND was found.\n", spinand->manufacturer->name);
+ 	dev_info(&spinand->spimem->spi->dev,
+ 		 "%llu MiB, block size: %zu KiB, page size: %zu, OOB size: %u\n",
+ 		 nanddev_size(nand) >> 20, nanddev_eraseblock_size(nand) >> 10,
+ 		 nanddev_page_size(nand), nanddev_per_page_oobsize(nand));
+ 
+-	return 0;
++free_casn:
++	kfree(casn);
++
++	return ret;
+ }
+ 
+ static int spinand_noecc_ooblayout_ecc(struct mtd_info *mtd, int section,
+--- a/include/linux/mtd/spinand.h
++++ b/include/linux/mtd/spinand.h
+@@ -62,6 +62,59 @@
+ 		   SPI_MEM_OP_NO_DUMMY,					\
+ 		   SPI_MEM_OP_NO_DATA)
+ 
++/* Macros for CASN */
++#define SPINAND_CASN_PAGE_READ_FROM_CACHE_OP(fast, naddr, addr, ndummy, buf, len) \
++	SPI_MEM_OP(SPI_MEM_OP_CMD(fast ? 0x0b : 0x03, 1),		\
++		   SPI_MEM_OP_ADDR(naddr, addr, 1),			\
++		   SPI_MEM_OP_DUMMY(ndummy, 1),			\
++		   SPI_MEM_OP_DATA_IN(len, buf, 1))
++
++#define SPINAND_CASN_PAGE_READ_FROM_CACHE_X2_OP(naddr, addr, ndummy, buf, len)	\
++	SPI_MEM_OP(SPI_MEM_OP_CMD(0x3b, 1),			\
++		   SPI_MEM_OP_ADDR(naddr, addr, 1),			\
++		   SPI_MEM_OP_DUMMY(ndummy, 1),			\
++		   SPI_MEM_OP_DATA_IN(len, buf, 2))
++
++#define SPINAND_CASN_PAGE_READ_FROM_CACHE_DUALIO_OP(naddr, addr, ndummy, buf, len)	\
++		SPI_MEM_OP(SPI_MEM_OP_CMD(0xbb, 1),			\
++			   SPI_MEM_OP_ADDR(naddr, addr, 2),			\
++			   SPI_MEM_OP_DUMMY(ndummy, 2),			\
++			   SPI_MEM_OP_DATA_IN(len, buf, 2))
++
++#define SPINAND_CASN_PAGE_READ_FROM_CACHE_X4_OP(naddr, addr, ndummy, buf, len)	\
++	SPI_MEM_OP(SPI_MEM_OP_CMD(0x6b, 1),				\
++		   SPI_MEM_OP_ADDR(naddr, addr, 1),				\
++		   SPI_MEM_OP_DUMMY(ndummy, 1),				\
++		   SPI_MEM_OP_DATA_IN(len, buf, 4))
++
++#define SPINAND_CASN_PAGE_READ_FROM_CACHE_QUADIO_OP(naddr, addr, ndummy, buf, len)	\
++	SPI_MEM_OP(SPI_MEM_OP_CMD(0xeb, 1),				\
++		   SPI_MEM_OP_ADDR(naddr, addr, 4),				\
++		   SPI_MEM_OP_DUMMY(ndummy, 4),				\
++		   SPI_MEM_OP_DATA_IN(len, buf, 4))
++
++#define SPINAND_CASN_PROG_LOAD(reset, naddr, addr, buf, len)			\
++	SPI_MEM_OP(SPI_MEM_OP_CMD(reset ? 0x02 : 0x84, 1),		\
++		   SPI_MEM_OP_ADDR(naddr, addr, 1),				\
++		   SPI_MEM_OP_NO_DUMMY,					\
++		   SPI_MEM_OP_DATA_OUT(len, buf, 1))
++
++#define SPINAND_CASN_PROG_LOAD_X4(reset, naddr, addr, buf, len)			\
++	SPI_MEM_OP(SPI_MEM_OP_CMD(reset ? 0x32 : 0x34, 1),		\
++		   SPI_MEM_OP_ADDR(naddr, addr, 1),				\
++		   SPI_MEM_OP_NO_DUMMY,					\
++		   SPI_MEM_OP_DATA_OUT(len, buf, 4))
++
++#define SPINAND_CASN_ADVECC_OP(casn_adv_ecc_status, buf)			\
++	SPI_MEM_OP(SPI_MEM_OP_CMD(casn_adv_ecc_status.cmd, 1),			\
++		   SPI_MEM_OP_ADDR(casn_adv_ecc_status.addr_nbytes,		\
++				   casn_adv_ecc_status.addr,			\
++				   casn_adv_ecc_status.addr_buswidth),		\
++		   SPI_MEM_OP_DUMMY(casn_adv_ecc_status.dummy_nbytes,		\
++				    casn_adv_ecc_status.dummy_buswidth),	\
++		   SPI_MEM_OP_DATA_IN(casn_adv_ecc_status.status_nbytes, buf, 1))
++/* Macros for CASN end */
++
+ #define SPINAND_PAGE_READ_FROM_CACHE_OP(fast, addr, ndummy, buf, len)	\
+ 	SPI_MEM_OP(SPI_MEM_OP_CMD(fast ? 0x0b : 0x03, 1),		\
+ 		   SPI_MEM_OP_ADDR(2, addr, 1),				\
+@@ -287,6 +340,12 @@ struct spinand_ecc_info {
+ 
+ #define SPINAND_HAS_QE_BIT		BIT(0)
+ #define SPINAND_HAS_CR_FEAT_BIT		BIT(1)
++#define SPINAND_SUP_CR			BIT(2)
++#define SPINAND_SUP_ON_DIE_ECC		BIT(3)
++#define SPINAND_SUP_LEGACY_ECC_STATUS	BIT(4)
++#define SPINAND_SUP_ADV_ECC_STATUS	BIT(5)
++#define SPINAND_ECC_PARITY_READABLE	BIT(6)
++
+ 
+ /**
+  * struct spinand_info - Structure used to describe SPI NAND chips
+@@ -363,6 +422,28 @@ struct spinand_dirmap {
+ };
+ 
+ /**
++ * struct CASN_ADVECC - CASN's advanced ECC description
++ * @cmd: Command to access SPI-NAND on-chip ECC status registers
++ * @mask: Mask to access SPI-NAND on-chip ECC status registers.
++ *	  ADV_ECC_STATUS->status_nbytes | CASN_ADVECC->mask
++ *			1		|      0 to 0xff
++ *			2		|     0 to 0xffff
++ * @shift: How many bits to shift to get on-chip ECC status
++ * @pre_op: This comes from CASN page's ADV_ECC_STATUS's pre_op.
++ *	    After reading on-chip ECC status, we need to do some math
++ *	    operations if this is specified.
++ * @pre_mask: This comes from CASN page's ADV_ECC_STATUS's pre_mask.
++ *	      This is used in companion with pre_op above.
++ */
++struct CASN_ADVECC {
++	u8 cmd;
++	u16 mask;
++	u8 shift;
++	u8 pre_op;
++	u8 pre_mask;
++};
++
++/**
+  * struct spinand_device - SPI NAND device instance
+  * @base: NAND device instance
+  * @spimem: pointer to the SPI mem object
+@@ -414,6 +495,23 @@ struct spinand_device {
+ 	u8 *oobbuf;
+ 	u8 *scratchbuf;
+ 	const struct spinand_manufacturer *manufacturer;
++
++	bool use_casn;
++	struct nand_casn *casn;
++	struct spi_mem_op *advecc_high_ops; /* ops to read higher part of advanced ECC status*/
++	struct spi_mem_op *advecc_low_ops;
++	struct CASN_OOB *casn_oob;
++	struct CASN_ADVECC *advecc_high;
++	struct CASN_ADVECC *advecc_low;
++
++	u8 advecc_low_bitcnt;
++	u8 advecc_noerr_status;
++	u8 advecc_uncor_status;
++	u8 advecc_post_op;
++	u8 advecc_post_mask;
++
++	size_t (*eccsr_math_op[4])(size_t, size_t);
++
+ 	void *priv;
+ };
+ 
+@@ -484,3 +582,4 @@ int spinand_upd_cfg(struct spinand_devic
+ int spinand_select_target(struct spinand_device *spinand, unsigned int target);
+ 
+ #endif /* __LINUX_MTD_SPINAND_H */
++
+--- /dev/null
++++ b/include/linux/mtd/casn.h
+@@ -0,0 +1,191 @@
++/* SPDX-License-Identifier: GPL-2.0 */
++/*
++ * Copyright (c) 2023 - Mediatek
++ *
++ * Author: SkyLake <SkyLake.Huang@mediatek.com>
++ */
++
++#ifndef __LINUX_MTD_CASN_H
++#define __LINUX_MTD_CASN_H
++
++#define CASN_CRC_BASE	0x4341
++#define CASN_SIGNATURE	0x4341534EU
++#define SPINAND_CASN_V1_CRC_OFS (254)
++#define CASN_PAGE_V1_COPIES     (3)
++
++#define SDR_READ_1_1_1		BIT(0)
++#define SDR_READ_1_1_1_FAST	BIT(1)
++#define SDR_READ_1_1_2		BIT(2)
++#define SDR_READ_1_2_2		BIT(3)
++#define SDR_READ_1_1_4		BIT(4)
++#define SDR_READ_1_4_4		BIT(5)
++#define SDR_READ_1_1_8		BIT(6)
++#define SDR_READ_1_8_8		BIT(7)
++
++#define SDR_WRITE_1_1_1		BIT(0)
++#define SDR_WRITE_1_1_4		BIT(1)
++
++#define SDR_UPDATE_1_1_1	BIT(0)
++#define SDR_UPDATE_1_1_4	BIT(1)
++
++struct op_slice {
++	u8 cmd_opcode;
++#if defined(__LITTLE_ENDIAN_BITFIELD)
++	u8 dummy_nbytes : 4;
++	u8 addr_nbytes : 4;
++#elif defined(__BIG_ENDIAN_BITFIELD)
++	u8 addr_nbytes : 4;
++	u8 dummy_nbytes : 4;
++#endif
++};
++
++struct SPINAND_FLAGS {
++#if defined(__LITTLE_ENDIAN_BITFIELD)
++	u8 has_qe_bit : 1;
++	u8 has_cr_feat_bit : 1;
++	u8 conti_read_cap : 1;
++	u8 on_die_ecc : 1;
++	u8 legacy_ecc_status : 1;
++	u8 adv_ecc_status : 1;
++	u8 ecc_parity_readable : 1;
++	u8 ecc_alg : 1; /* ECC algorithm */
++#elif defined(__BIG_ENDIAN_BITFIELD)
++	u8 ecc_alg : 1; /* ECC algorithm */
++	u8 ecc_parity_readable : 1;
++	u8 adv_ecc_status : 1;
++	u8 legacy_ecc_status : 1;
++	u8 on_die_ecc : 1;
++	u8 conti_read_cap : 1;
++	u8 has_cr_feat_bit : 1;
++	u8 has_qe_bit : 1;
++#endif
++};
++
++struct ADV_ECC_STATUS {
++	u8 cmd;
++	u8 addr;
++	u8 addr_nbytes;
++	u8 addr_buswidth;
++	u8 dummy_nbytes;
++	u8 dummy_buswidth;
++	u8 status_nbytes;
++	u16 status_mask;
++	u8 pre_op; /* pre-process operator */
++	u8 pre_mask; /* pre-process mask */
++} __packed;
++
++struct CASN_OOB {
++	u8 layout_type;
++
++	/* OOB free layout */
++	u8 free_start;
++	u8 free_length;
++	u8 bbm_length;
++
++	/* ECC parity layout */
++	u8 ecc_parity_start;
++	u8 ecc_parity_space;
++	u8 ecc_parity_real_length;
++};
++
++enum oob_overall {
++	OOB_DISCRETE = 0,
++	OOB_CONTINUOUS,
++};
++
++struct nand_casn {
++	/* CASN signature must be 4 chars: 'C','A','S','N'  */
++	union {
++		u8 sig[4];
++		u32 signature;
++	};
++
++	u8 version;
++	char manufacturer[13];
++	char model[16];
++
++	__be32 bits_per_cell;
++	__be32 bytes_per_page;
++	__be32 spare_bytes_per_page;
++	__be32 pages_per_block;
++	__be32 blocks_per_lun;
++	__be32 max_bb_per_lun;
++	__be32 planes_per_lun;
++	__be32 luns_per_target;
++	__be32 total_target;
++
++	__be32 ecc_strength;
++	__be32 ecc_step_size;
++
++	u8 flags;
++	u8 reserved1;
++
++	__be16 sdr_read_cap;
++	struct op_slice sdr_read_1_1_1;
++	struct op_slice sdr_read_1_1_1_fast;
++	struct op_slice sdr_read_1_1_2;
++	struct op_slice sdr_read_1_2_2;
++	struct op_slice sdr_read_1_1_4;
++	struct op_slice sdr_read_1_4_4;
++	struct op_slice sdr_read_1_1_8;
++	struct op_slice sdr_read_1_8_8;
++
++	struct op_slice sdr_cont_read_1_1_1;
++	struct op_slice sdr_cont_read_1_1_1_fast;
++	struct op_slice sdr_cont_read_1_1_2;
++	struct op_slice sdr_cont_read_1_2_2;
++	struct op_slice sdr_cont_read_1_1_4;
++	struct op_slice sdr_cont_read_1_4_4;
++	struct op_slice sdr_cont_read_1_1_8;
++	struct op_slice sdr_cont_read_1_8_8;
++
++	__be16 ddr_read_cap;
++	struct op_slice ddr_read_1_1_1;
++	struct op_slice ddr_read_1_1_1_fast;
++	struct op_slice ddr_read_1_1_2;
++	struct op_slice ddr_read_1_2_2;
++	struct op_slice ddr_read_1_1_4;
++	struct op_slice ddr_read_1_4_4;
++	struct op_slice ddr_read_1_1_8;
++	struct op_slice ddr_read_1_8_8;
++
++	struct op_slice ddr_cont_read_1_1_1;
++	struct op_slice ddr_cont_read_1_1_1_fast;
++	struct op_slice ddr_cont_read_1_1_2;
++	struct op_slice ddr_cont_read_1_2_2;
++	struct op_slice ddr_cont_read_1_1_4;
++	struct op_slice ddr_cont_read_1_4_4;
++	struct op_slice ddr_cont_read_1_1_8;
++	struct op_slice ddr_cont_read_1_8_8;
++
++	u8 sdr_write_cap;
++	struct op_slice sdr_write_1_1_1;
++	struct op_slice sdr_write_1_1_4;
++	struct op_slice reserved2[6];
++	u8 ddr_write_cap;
++	struct op_slice reserved3[8];
++
++	u8 sdr_update_cap;
++	struct op_slice sdr_update_1_1_1;
++	struct op_slice sdr_update_1_1_4;
++	struct op_slice reserved4[6];
++	u8 ddr_update_cap;
++	struct op_slice reserved5[8];
++
++	struct CASN_OOB casn_oob;
++
++	/* Advanced ECC status CMD0 (higher bits) */
++	struct ADV_ECC_STATUS ecc_status_high;
++	/* Advanced ECC status CMD1 (lower bits) */
++	struct ADV_ECC_STATUS ecc_status_low;
++
++	u8 advecc_noerr_status;
++	u8 advecc_uncor_status;
++	u8 advecc_post_op;
++	u8 advecc_post_mask;
++
++	u8 reserved6[5];
++	__be16 crc;
++} __packed;
++
++#endif /* __LINUX_MTD_CASN_H */
diff --git a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/patches-5.4.inc b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/patches-5.4.inc
index 81a4054..6ab5265 100644
--- a/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/patches-5.4.inc
+++ b/recipes-kernel/linux/linux-mediatek-5.4/mediatek/patches-5.4/patches-5.4.inc
@@ -162,6 +162,8 @@
     file://999-2374-drivers-spi-mt65xx-Add-controller-calibration-parameter.patch \
     file://999-2375-spi-update-driver.patch \
     file://999-2376-drivers-spi-mt65xx-add-dts-buswidth-flow.patch \
+    file://999-2377-integrate-ONFI-and-CASN-manipulation.patch \
+    file://999-2378-Add-CASN-support-for-SPI-NAND.patch \
     file://999-2380-fix-dirty-race-between-do_tmpfile.patch \
     file://999-2500-cpufreq-add-the-missing-platform-driver-unregister.patch \
     file://999-2501-cpufreq-Enable-clocks-and-regulators.patch \
diff --git a/recipes-kernel/linux/linux-mediatek_5.4.bb b/recipes-kernel/linux/linux-mediatek_5.4.bb
index fcfe567..643bab7 100644
--- a/recipes-kernel/linux/linux-mediatek_5.4.bb
+++ b/recipes-kernel/linux/linux-mediatek_5.4.bb
@@ -9,8 +9,8 @@
 
 KBRANCH ?= "linux-5.4.y"
 
-LINUX_VERSION ?= "5.4.271"
-SRCREV_machine ?= "3fec063b052e395f4920fbc59a8d0bb3c9666d76"
+LINUX_VERSION ?= "5.4.281"
+SRCREV_machine ?= "84d75fd864979b0228cfe7170a359c0a60f04a98"
 KMETA = "kernel-meta"
 SRCREV_meta ?= "feeb59687bc0f054af837a5061f8d413ec7c93e9"