162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* Copyright Sunplus Technology Co., Ltd. 362306a36Sopenharmony_ci * All rights reserved. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef __SPL2SW_DEFINE_H__ 762306a36Sopenharmony_ci#define __SPL2SW_DEFINE_H__ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#define MAX_NETDEV_NUM 2 /* Maximum # of net-device */ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci/* Interrupt status */ 1262306a36Sopenharmony_ci#define MAC_INT_DAISY_MODE_CHG BIT(31) /* Daisy Mode Change */ 1362306a36Sopenharmony_ci#define MAC_INT_IP_CHKSUM_ERR BIT(23) /* IP Checksum Append Error */ 1462306a36Sopenharmony_ci#define MAC_INT_WDOG_TIMER1_EXP BIT(22) /* Watchdog Timer1 Expired */ 1562306a36Sopenharmony_ci#define MAC_INT_WDOG_TIMER0_EXP BIT(21) /* Watchdog Timer0 Expired */ 1662306a36Sopenharmony_ci#define MAC_INT_INTRUDER_ALERT BIT(20) /* Atruder Alert */ 1762306a36Sopenharmony_ci#define MAC_INT_PORT_ST_CHG BIT(19) /* Port Status Change */ 1862306a36Sopenharmony_ci#define MAC_INT_BC_STORM BIT(18) /* Broad Cast Storm */ 1962306a36Sopenharmony_ci#define MAC_INT_MUST_DROP_LAN BIT(17) /* Global Queue Exhausted */ 2062306a36Sopenharmony_ci#define MAC_INT_GLOBAL_QUE_FULL BIT(16) /* Global Queue Full */ 2162306a36Sopenharmony_ci#define MAC_INT_TX_SOC_PAUSE_ON BIT(15) /* Soc Port TX Pause On */ 2262306a36Sopenharmony_ci#define MAC_INT_RX_SOC_QUE_FULL BIT(14) /* Soc Port Out Queue Full */ 2362306a36Sopenharmony_ci#define MAC_INT_TX_LAN1_QUE_FULL BIT(9) /* Port 1 Out Queue Full */ 2462306a36Sopenharmony_ci#define MAC_INT_TX_LAN0_QUE_FULL BIT(8) /* Port 0 Out Queue Full */ 2562306a36Sopenharmony_ci#define MAC_INT_RX_L_DESCF BIT(7) /* Low Priority Descriptor Full */ 2662306a36Sopenharmony_ci#define MAC_INT_RX_H_DESCF BIT(6) /* High Priority Descriptor Full */ 2762306a36Sopenharmony_ci#define MAC_INT_RX_DONE_L BIT(5) /* RX Low Priority Done */ 2862306a36Sopenharmony_ci#define MAC_INT_RX_DONE_H BIT(4) /* RX High Priority Done */ 2962306a36Sopenharmony_ci#define MAC_INT_TX_DONE_L BIT(3) /* TX Low Priority Done */ 3062306a36Sopenharmony_ci#define MAC_INT_TX_DONE_H BIT(2) /* TX High Priority Done */ 3162306a36Sopenharmony_ci#define MAC_INT_TX_DES_ERR BIT(1) /* TX Descriptor Error */ 3262306a36Sopenharmony_ci#define MAC_INT_RX_DES_ERR BIT(0) /* Rx Descriptor Error */ 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define MAC_INT_RX (MAC_INT_RX_DONE_H | MAC_INT_RX_DONE_L | \ 3562306a36Sopenharmony_ci MAC_INT_RX_DES_ERR) 3662306a36Sopenharmony_ci#define MAC_INT_TX (MAC_INT_TX_DONE_L | MAC_INT_TX_DONE_H | \ 3762306a36Sopenharmony_ci MAC_INT_TX_DES_ERR) 3862306a36Sopenharmony_ci#define MAC_INT_MASK_DEF (MAC_INT_DAISY_MODE_CHG | MAC_INT_IP_CHKSUM_ERR | \ 3962306a36Sopenharmony_ci MAC_INT_WDOG_TIMER1_EXP | MAC_INT_WDOG_TIMER0_EXP | \ 4062306a36Sopenharmony_ci MAC_INT_INTRUDER_ALERT | MAC_INT_PORT_ST_CHG | \ 4162306a36Sopenharmony_ci MAC_INT_BC_STORM | MAC_INT_MUST_DROP_LAN | \ 4262306a36Sopenharmony_ci MAC_INT_GLOBAL_QUE_FULL | MAC_INT_TX_SOC_PAUSE_ON | \ 4362306a36Sopenharmony_ci MAC_INT_RX_SOC_QUE_FULL | MAC_INT_TX_LAN1_QUE_FULL | \ 4462306a36Sopenharmony_ci MAC_INT_TX_LAN0_QUE_FULL | MAC_INT_RX_L_DESCF | \ 4562306a36Sopenharmony_ci MAC_INT_RX_H_DESCF) 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/* Address table search */ 4862306a36Sopenharmony_ci#define MAC_ADDR_LOOKUP_IDLE BIT(2) 4962306a36Sopenharmony_ci#define MAC_SEARCH_NEXT_ADDR BIT(1) 5062306a36Sopenharmony_ci#define MAC_BEGIN_SEARCH_ADDR BIT(0) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci/* Address table status */ 5362306a36Sopenharmony_ci#define MAC_HASH_LOOKUP_ADDR GENMASK(31, 22) 5462306a36Sopenharmony_ci#define MAC_R_PORT_MAP GENMASK(13, 12) 5562306a36Sopenharmony_ci#define MAC_R_CPU_PORT GENMASK(11, 10) 5662306a36Sopenharmony_ci#define MAC_R_VID GENMASK(9, 7) 5762306a36Sopenharmony_ci#define MAC_R_AGE GENMASK(6, 4) 5862306a36Sopenharmony_ci#define MAC_R_PROXY BIT(3) 5962306a36Sopenharmony_ci#define MAC_R_MC_INGRESS BIT(2) 6062306a36Sopenharmony_ci#define MAC_AT_TABLE_END BIT(1) 6162306a36Sopenharmony_ci#define MAC_AT_DATA_READY BIT(0) 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci/* Wt mac ad0 */ 6462306a36Sopenharmony_ci#define MAC_W_PORT_MAP GENMASK(13, 12) 6562306a36Sopenharmony_ci#define MAC_W_LAN_PORT_1 BIT(13) 6662306a36Sopenharmony_ci#define MAC_W_LAN_PORT_0 BIT(12) 6762306a36Sopenharmony_ci#define MAC_W_CPU_PORT GENMASK(11, 10) 6862306a36Sopenharmony_ci#define MAC_W_CPU_PORT_1 BIT(11) 6962306a36Sopenharmony_ci#define MAC_W_CPU_PORT_0 BIT(10) 7062306a36Sopenharmony_ci#define MAC_W_VID GENMASK(9, 7) 7162306a36Sopenharmony_ci#define MAC_W_AGE GENMASK(6, 4) 7262306a36Sopenharmony_ci#define MAC_W_PROXY BIT(3) 7362306a36Sopenharmony_ci#define MAC_W_MC_INGRESS BIT(2) 7462306a36Sopenharmony_ci#define MAC_W_MAC_DONE BIT(1) 7562306a36Sopenharmony_ci#define MAC_W_MAC_CMD BIT(0) 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci/* W mac 15_0 bus */ 7862306a36Sopenharmony_ci#define MAC_W_MAC_15_0 GENMASK(15, 0) 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci/* W mac 47_16 bus */ 8162306a36Sopenharmony_ci#define MAC_W_MAC_47_16 GENMASK(31, 0) 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci/* PVID config 0 */ 8462306a36Sopenharmony_ci#define MAC_P1_PVID GENMASK(6, 4) 8562306a36Sopenharmony_ci#define MAC_P0_PVID GENMASK(2, 0) 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* VLAN member config 0 */ 8862306a36Sopenharmony_ci#define MAC_VLAN_MEMSET_3 GENMASK(27, 24) 8962306a36Sopenharmony_ci#define MAC_VLAN_MEMSET_2 GENMASK(19, 16) 9062306a36Sopenharmony_ci#define MAC_VLAN_MEMSET_1 GENMASK(11, 8) 9162306a36Sopenharmony_ci#define MAC_VLAN_MEMSET_0 GENMASK(3, 0) 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci/* VLAN member config 1 */ 9462306a36Sopenharmony_ci#define MAC_VLAN_MEMSET_5 GENMASK(11, 8) 9562306a36Sopenharmony_ci#define MAC_VLAN_MEMSET_4 GENMASK(3, 0) 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci/* Port ability */ 9862306a36Sopenharmony_ci#define MAC_PORT_ABILITY_LINK_ST GENMASK(25, 24) 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci/* CPU control */ 10162306a36Sopenharmony_ci#define MAC_EN_SOC1_AGING BIT(15) 10262306a36Sopenharmony_ci#define MAC_EN_SOC0_AGING BIT(14) 10362306a36Sopenharmony_ci#define MAC_DIS_LRN_SOC1 BIT(13) 10462306a36Sopenharmony_ci#define MAC_DIS_LRN_SOC0 BIT(12) 10562306a36Sopenharmony_ci#define MAC_EN_CRC_SOC1 BIT(9) 10662306a36Sopenharmony_ci#define MAC_EN_CRC_SOC0 BIT(8) 10762306a36Sopenharmony_ci#define MAC_DIS_SOC1_CPU BIT(7) 10862306a36Sopenharmony_ci#define MAC_DIS_SOC0_CPU BIT(6) 10962306a36Sopenharmony_ci#define MAC_DIS_BC2CPU_P1 BIT(5) 11062306a36Sopenharmony_ci#define MAC_DIS_BC2CPU_P0 BIT(4) 11162306a36Sopenharmony_ci#define MAC_DIS_MC2CPU GENMASK(3, 2) 11262306a36Sopenharmony_ci#define MAC_DIS_MC2CPU_P1 BIT(3) 11362306a36Sopenharmony_ci#define MAC_DIS_MC2CPU_P0 BIT(2) 11462306a36Sopenharmony_ci#define MAC_DIS_UN2CPU GENMASK(1, 0) 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci/* Port control 0 */ 11762306a36Sopenharmony_ci#define MAC_DIS_PORT GENMASK(25, 24) 11862306a36Sopenharmony_ci#define MAC_DIS_PORT1 BIT(25) 11962306a36Sopenharmony_ci#define MAC_DIS_PORT0 BIT(24) 12062306a36Sopenharmony_ci#define MAC_DIS_RMC2CPU_P1 BIT(17) 12162306a36Sopenharmony_ci#define MAC_DIS_RMC2CPU_P0 BIT(16) 12262306a36Sopenharmony_ci#define MAC_EN_FLOW_CTL_P1 BIT(9) 12362306a36Sopenharmony_ci#define MAC_EN_FLOW_CTL_P0 BIT(8) 12462306a36Sopenharmony_ci#define MAC_EN_BACK_PRESS_P1 BIT(1) 12562306a36Sopenharmony_ci#define MAC_EN_BACK_PRESS_P0 BIT(0) 12662306a36Sopenharmony_ci 12762306a36Sopenharmony_ci/* Port control 1 */ 12862306a36Sopenharmony_ci#define MAC_DIS_SA_LRN_P1 BIT(9) 12962306a36Sopenharmony_ci#define MAC_DIS_SA_LRN_P0 BIT(8) 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci/* Port control 2 */ 13262306a36Sopenharmony_ci#define MAC_EN_AGING_P1 BIT(9) 13362306a36Sopenharmony_ci#define MAC_EN_AGING_P0 BIT(8) 13462306a36Sopenharmony_ci 13562306a36Sopenharmony_ci/* Switch Global control */ 13662306a36Sopenharmony_ci#define MAC_RMC_TB_FAULT_RULE GENMASK(26, 25) 13762306a36Sopenharmony_ci#define MAC_LED_FLASH_TIME GENMASK(24, 23) 13862306a36Sopenharmony_ci#define MAC_BC_STORM_PREV GENMASK(5, 4) 13962306a36Sopenharmony_ci 14062306a36Sopenharmony_ci/* LED port 0 */ 14162306a36Sopenharmony_ci#define MAC_LED_ACT_HI BIT(28) 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_ci/* PHY control register 0 */ 14462306a36Sopenharmony_ci#define MAC_CPU_PHY_WT_DATA GENMASK(31, 16) 14562306a36Sopenharmony_ci#define MAC_CPU_PHY_CMD GENMASK(14, 13) 14662306a36Sopenharmony_ci#define MAC_CPU_PHY_REG_ADDR GENMASK(12, 8) 14762306a36Sopenharmony_ci#define MAC_CPU_PHY_ADDR GENMASK(4, 0) 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci/* PHY control register 1 */ 15062306a36Sopenharmony_ci#define MAC_CPU_PHY_RD_DATA GENMASK(31, 16) 15162306a36Sopenharmony_ci#define MAC_PHY_RD_RDY BIT(1) 15262306a36Sopenharmony_ci#define MAC_PHY_WT_DONE BIT(0) 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_ci/* MAC force mode */ 15562306a36Sopenharmony_ci#define MAC_EXT_PHY1_ADDR GENMASK(28, 24) 15662306a36Sopenharmony_ci#define MAC_EXT_PHY0_ADDR GENMASK(20, 16) 15762306a36Sopenharmony_ci#define MAC_FORCE_RMII_LINK GENMASK(9, 8) 15862306a36Sopenharmony_ci#define MAC_FORCE_RMII_EN_1 BIT(7) 15962306a36Sopenharmony_ci#define MAC_FORCE_RMII_EN_0 BIT(6) 16062306a36Sopenharmony_ci#define MAC_FORCE_RMII_FC GENMASK(5, 4) 16162306a36Sopenharmony_ci#define MAC_FORCE_RMII_DPX GENMASK(3, 2) 16262306a36Sopenharmony_ci#define MAC_FORCE_RMII_SPD GENMASK(1, 0) 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci/* CPU transmit trigger */ 16562306a36Sopenharmony_ci#define MAC_TRIG_L_SOC0 BIT(1) 16662306a36Sopenharmony_ci#define MAC_TRIG_H_SOC0 BIT(0) 16762306a36Sopenharmony_ci 16862306a36Sopenharmony_ci/* Config descriptor queue */ 16962306a36Sopenharmony_ci#define TX_DESC_NUM 16 /* # of descriptors in TX queue */ 17062306a36Sopenharmony_ci#define MAC_GUARD_DESC_NUM 2 /* # of descriptors of gap 0 */ 17162306a36Sopenharmony_ci#define RX_QUEUE0_DESC_NUM 16 /* # of descriptors in RX queue 0 */ 17262306a36Sopenharmony_ci#define RX_QUEUE1_DESC_NUM 16 /* # of descriptors in RX queue 1 */ 17362306a36Sopenharmony_ci#define TX_DESC_QUEUE_NUM 1 /* # of TX queue */ 17462306a36Sopenharmony_ci#define RX_DESC_QUEUE_NUM 2 /* # of RX queue */ 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_ci#define MAC_RX_LEN_MAX 2047 /* Size of RX buffer */ 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci/* Tx descriptor */ 17962306a36Sopenharmony_ci/* cmd1 */ 18062306a36Sopenharmony_ci#define TXD_OWN BIT(31) 18162306a36Sopenharmony_ci#define TXD_ERR_CODE GENMASK(29, 26) 18262306a36Sopenharmony_ci#define TXD_SOP BIT(25) /* start of a packet */ 18362306a36Sopenharmony_ci#define TXD_EOP BIT(24) /* end of a packet */ 18462306a36Sopenharmony_ci#define TXD_VLAN GENMASK(17, 12) 18562306a36Sopenharmony_ci#define TXD_PKT_LEN GENMASK(10, 0) /* packet length */ 18662306a36Sopenharmony_ci/* cmd2 */ 18762306a36Sopenharmony_ci#define TXD_EOR BIT(31) /* end of ring */ 18862306a36Sopenharmony_ci#define TXD_BUF_LEN2 GENMASK(22, 12) 18962306a36Sopenharmony_ci#define TXD_BUF_LEN1 GENMASK(10, 0) 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci/* Rx descriptor */ 19262306a36Sopenharmony_ci/* cmd1 */ 19362306a36Sopenharmony_ci#define RXD_OWN BIT(31) 19462306a36Sopenharmony_ci#define RXD_ERR_CODE GENMASK(29, 26) 19562306a36Sopenharmony_ci#define RXD_TCP_UDP_CHKSUM BIT(23) 19662306a36Sopenharmony_ci#define RXD_PROXY BIT(22) 19762306a36Sopenharmony_ci#define RXD_PROTOCOL GENMASK(21, 20) 19862306a36Sopenharmony_ci#define RXD_VLAN_TAG BIT(19) 19962306a36Sopenharmony_ci#define RXD_IP_CHKSUM BIT(18) 20062306a36Sopenharmony_ci#define RXD_ROUTE_TYPE GENMASK(17, 16) 20162306a36Sopenharmony_ci#define RXD_PKT_SP GENMASK(14, 12) /* packet source port */ 20262306a36Sopenharmony_ci#define RXD_PKT_LEN GENMASK(10, 0) /* packet length */ 20362306a36Sopenharmony_ci/* cmd2 */ 20462306a36Sopenharmony_ci#define RXD_EOR BIT(31) /* end of ring */ 20562306a36Sopenharmony_ci#define RXD_BUF_LEN2 GENMASK(22, 12) 20662306a36Sopenharmony_ci#define RXD_BUF_LEN1 GENMASK(10, 0) 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci/* structure of descriptor */ 20962306a36Sopenharmony_cistruct spl2sw_mac_desc { 21062306a36Sopenharmony_ci u32 cmd1; 21162306a36Sopenharmony_ci u32 cmd2; 21262306a36Sopenharmony_ci u32 addr1; 21362306a36Sopenharmony_ci u32 addr2; 21462306a36Sopenharmony_ci}; 21562306a36Sopenharmony_ci 21662306a36Sopenharmony_cistruct spl2sw_skb_info { 21762306a36Sopenharmony_ci struct sk_buff *skb; 21862306a36Sopenharmony_ci u32 mapping; 21962306a36Sopenharmony_ci u32 len; 22062306a36Sopenharmony_ci}; 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_cistruct spl2sw_common { 22362306a36Sopenharmony_ci void __iomem *l2sw_reg_base; 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci struct platform_device *pdev; 22662306a36Sopenharmony_ci struct reset_control *rstc; 22762306a36Sopenharmony_ci struct clk *clk; 22862306a36Sopenharmony_ci 22962306a36Sopenharmony_ci void *desc_base; 23062306a36Sopenharmony_ci dma_addr_t desc_dma; 23162306a36Sopenharmony_ci s32 desc_size; 23262306a36Sopenharmony_ci struct spl2sw_mac_desc *rx_desc[RX_DESC_QUEUE_NUM]; 23362306a36Sopenharmony_ci struct spl2sw_skb_info *rx_skb_info[RX_DESC_QUEUE_NUM]; 23462306a36Sopenharmony_ci u32 rx_pos[RX_DESC_QUEUE_NUM]; 23562306a36Sopenharmony_ci u32 rx_desc_num[RX_DESC_QUEUE_NUM]; 23662306a36Sopenharmony_ci u32 rx_desc_buff_size; 23762306a36Sopenharmony_ci 23862306a36Sopenharmony_ci struct spl2sw_mac_desc *tx_desc; 23962306a36Sopenharmony_ci struct spl2sw_skb_info tx_temp_skb_info[TX_DESC_NUM]; 24062306a36Sopenharmony_ci u32 tx_done_pos; 24162306a36Sopenharmony_ci u32 tx_pos; 24262306a36Sopenharmony_ci u32 tx_desc_full; 24362306a36Sopenharmony_ci 24462306a36Sopenharmony_ci struct net_device *ndev[MAX_NETDEV_NUM]; 24562306a36Sopenharmony_ci struct mii_bus *mii_bus; 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_ci struct napi_struct rx_napi; 24862306a36Sopenharmony_ci struct napi_struct tx_napi; 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_ci spinlock_t tx_lock; /* spinlock for accessing tx buffer */ 25162306a36Sopenharmony_ci spinlock_t mdio_lock; /* spinlock for mdio commands */ 25262306a36Sopenharmony_ci spinlock_t int_mask_lock; /* spinlock for accessing int mask reg. */ 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_ci u8 enable; 25562306a36Sopenharmony_ci}; 25662306a36Sopenharmony_ci 25762306a36Sopenharmony_cistruct spl2sw_mac { 25862306a36Sopenharmony_ci struct net_device *ndev; 25962306a36Sopenharmony_ci struct spl2sw_common *comm; 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_ci u8 mac_addr[ETH_ALEN]; 26262306a36Sopenharmony_ci phy_interface_t phy_mode; 26362306a36Sopenharmony_ci struct device_node *phy_node; 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_ci u8 lan_port; 26662306a36Sopenharmony_ci u8 to_vlan; 26762306a36Sopenharmony_ci u8 vlan_id; 26862306a36Sopenharmony_ci}; 26962306a36Sopenharmony_ci 27062306a36Sopenharmony_ci#endif 271