162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2009 Felix Fietkau <nbd@nbd.name> 462306a36Sopenharmony_ci * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org> 562306a36Sopenharmony_ci * Copyright (c) 2015, The Linux Foundation. All rights reserved. 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef __QCA8K_H 962306a36Sopenharmony_ci#define __QCA8K_H 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <linux/delay.h> 1262306a36Sopenharmony_ci#include <linux/regmap.h> 1362306a36Sopenharmony_ci#include <linux/gpio.h> 1462306a36Sopenharmony_ci#include <linux/leds.h> 1562306a36Sopenharmony_ci#include <linux/dsa/tag_qca.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#define QCA8K_ETHERNET_MDIO_PRIORITY 7 1862306a36Sopenharmony_ci#define QCA8K_ETHERNET_PHY_PRIORITY 6 1962306a36Sopenharmony_ci#define QCA8K_ETHERNET_TIMEOUT 5 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#define QCA8K_NUM_PORTS 7 2262306a36Sopenharmony_ci#define QCA8K_NUM_CPU_PORTS 2 2362306a36Sopenharmony_ci#define QCA8K_MAX_MTU 9000 2462306a36Sopenharmony_ci#define QCA8K_NUM_LAGS 4 2562306a36Sopenharmony_ci#define QCA8K_NUM_PORTS_FOR_LAG 4 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci#define PHY_ID_QCA8327 0x004dd034 2862306a36Sopenharmony_ci#define QCA8K_ID_QCA8327 0x12 2962306a36Sopenharmony_ci#define PHY_ID_QCA8337 0x004dd036 3062306a36Sopenharmony_ci#define QCA8K_ID_QCA8337 0x13 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci#define QCA8K_QCA832X_MIB_COUNT 39 3362306a36Sopenharmony_ci#define QCA8K_QCA833X_MIB_COUNT 41 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#define QCA8K_BUSY_WAIT_TIMEOUT 2000 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define QCA8K_NUM_FDB_RECORDS 2048 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci#define QCA8K_PORT_VID_DEF 1 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/* Global control registers */ 4262306a36Sopenharmony_ci#define QCA8K_REG_MASK_CTRL 0x000 4362306a36Sopenharmony_ci#define QCA8K_MASK_CTRL_REV_ID_MASK GENMASK(7, 0) 4462306a36Sopenharmony_ci#define QCA8K_MASK_CTRL_REV_ID(x) FIELD_GET(QCA8K_MASK_CTRL_REV_ID_MASK, x) 4562306a36Sopenharmony_ci#define QCA8K_MASK_CTRL_DEVICE_ID_MASK GENMASK(15, 8) 4662306a36Sopenharmony_ci#define QCA8K_MASK_CTRL_DEVICE_ID(x) FIELD_GET(QCA8K_MASK_CTRL_DEVICE_ID_MASK, x) 4762306a36Sopenharmony_ci#define QCA8K_REG_PORT0_PAD_CTRL 0x004 4862306a36Sopenharmony_ci#define QCA8K_PORT0_PAD_MAC06_EXCHANGE_EN BIT(31) 4962306a36Sopenharmony_ci#define QCA8K_PORT0_PAD_SGMII_RXCLK_FALLING_EDGE BIT(19) 5062306a36Sopenharmony_ci#define QCA8K_PORT0_PAD_SGMII_TXCLK_FALLING_EDGE BIT(18) 5162306a36Sopenharmony_ci#define QCA8K_REG_PORT5_PAD_CTRL 0x008 5262306a36Sopenharmony_ci#define QCA8K_REG_PORT6_PAD_CTRL 0x00c 5362306a36Sopenharmony_ci#define QCA8K_PORT_PAD_RGMII_EN BIT(26) 5462306a36Sopenharmony_ci#define QCA8K_PORT_PAD_RGMII_TX_DELAY_MASK GENMASK(23, 22) 5562306a36Sopenharmony_ci#define QCA8K_PORT_PAD_RGMII_TX_DELAY(x) FIELD_PREP(QCA8K_PORT_PAD_RGMII_TX_DELAY_MASK, x) 5662306a36Sopenharmony_ci#define QCA8K_PORT_PAD_RGMII_RX_DELAY_MASK GENMASK(21, 20) 5762306a36Sopenharmony_ci#define QCA8K_PORT_PAD_RGMII_RX_DELAY(x) FIELD_PREP(QCA8K_PORT_PAD_RGMII_RX_DELAY_MASK, x) 5862306a36Sopenharmony_ci#define QCA8K_PORT_PAD_RGMII_TX_DELAY_EN BIT(25) 5962306a36Sopenharmony_ci#define QCA8K_PORT_PAD_RGMII_RX_DELAY_EN BIT(24) 6062306a36Sopenharmony_ci#define QCA8K_PORT_PAD_SGMII_EN BIT(7) 6162306a36Sopenharmony_ci#define QCA8K_REG_PWS 0x010 6262306a36Sopenharmony_ci#define QCA8K_PWS_POWER_ON_SEL BIT(31) 6362306a36Sopenharmony_ci/* This reg is only valid for QCA832x and toggle the package 6462306a36Sopenharmony_ci * type from 176 pin (by default) to 148 pin used on QCA8327 6562306a36Sopenharmony_ci */ 6662306a36Sopenharmony_ci#define QCA8327_PWS_PACKAGE148_EN BIT(30) 6762306a36Sopenharmony_ci#define QCA8K_PWS_LED_OPEN_EN_CSR BIT(24) 6862306a36Sopenharmony_ci#define QCA8K_PWS_SERDES_AEN_DIS BIT(7) 6962306a36Sopenharmony_ci#define QCA8K_REG_MODULE_EN 0x030 7062306a36Sopenharmony_ci#define QCA8K_MODULE_EN_MIB BIT(0) 7162306a36Sopenharmony_ci#define QCA8K_REG_MIB 0x034 7262306a36Sopenharmony_ci#define QCA8K_MIB_FUNC GENMASK(26, 24) 7362306a36Sopenharmony_ci#define QCA8K_MIB_CPU_KEEP BIT(20) 7462306a36Sopenharmony_ci#define QCA8K_MIB_BUSY BIT(17) 7562306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_CTRL 0x3c 7662306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_BUSY BIT(31) 7762306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_EN BIT(30) 7862306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_READ BIT(27) 7962306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_WRITE 0 8062306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_SUP_PRE BIT(26) 8162306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_PHY_ADDR_MASK GENMASK(25, 21) 8262306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_PHY_ADDR(x) FIELD_PREP(QCA8K_MDIO_MASTER_PHY_ADDR_MASK, x) 8362306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_REG_ADDR_MASK GENMASK(20, 16) 8462306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_REG_ADDR(x) FIELD_PREP(QCA8K_MDIO_MASTER_REG_ADDR_MASK, x) 8562306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_DATA_MASK GENMASK(15, 0) 8662306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_DATA(x) FIELD_PREP(QCA8K_MDIO_MASTER_DATA_MASK, x) 8762306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_MAX_PORTS 5 8862306a36Sopenharmony_ci#define QCA8K_MDIO_MASTER_MAX_REG 32 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci/* LED control register */ 9162306a36Sopenharmony_ci#define QCA8K_LED_PORT_COUNT 3 9262306a36Sopenharmony_ci#define QCA8K_LED_COUNT ((QCA8K_NUM_PORTS - QCA8K_NUM_CPU_PORTS) * QCA8K_LED_PORT_COUNT) 9362306a36Sopenharmony_ci#define QCA8K_LED_RULE_COUNT 6 9462306a36Sopenharmony_ci#define QCA8K_LED_RULE_MAX 11 9562306a36Sopenharmony_ci#define QCA8K_LED_PORT_INDEX(_phy, _led) (((_phy) * QCA8K_LED_PORT_COUNT) + (_led)) 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci#define QCA8K_LED_PHY123_PATTERN_EN_SHIFT(_phy, _led) ((((_phy) - 1) * 6) + 8 + (2 * (_led))) 9862306a36Sopenharmony_ci#define QCA8K_LED_PHY123_PATTERN_EN_MASK GENMASK(1, 0) 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci#define QCA8K_LED_PHY0123_CONTROL_RULE_SHIFT 0 10162306a36Sopenharmony_ci#define QCA8K_LED_PHY4_CONTROL_RULE_SHIFT 16 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#define QCA8K_LED_CTRL_REG(_i) (0x050 + (_i) * 4) 10462306a36Sopenharmony_ci#define QCA8K_LED_CTRL0_REG 0x50 10562306a36Sopenharmony_ci#define QCA8K_LED_CTRL1_REG 0x54 10662306a36Sopenharmony_ci#define QCA8K_LED_CTRL2_REG 0x58 10762306a36Sopenharmony_ci#define QCA8K_LED_CTRL3_REG 0x5C 10862306a36Sopenharmony_ci#define QCA8K_LED_CTRL_SHIFT(_i) (((_i) % 2) * 16) 10962306a36Sopenharmony_ci#define QCA8K_LED_CTRL_MASK GENMASK(15, 0) 11062306a36Sopenharmony_ci#define QCA8K_LED_RULE_MASK GENMASK(13, 0) 11162306a36Sopenharmony_ci#define QCA8K_LED_BLINK_FREQ_MASK GENMASK(1, 0) 11262306a36Sopenharmony_ci#define QCA8K_LED_BLINK_FREQ_SHITF 0 11362306a36Sopenharmony_ci#define QCA8K_LED_BLINK_2HZ 0 11462306a36Sopenharmony_ci#define QCA8K_LED_BLINK_4HZ 1 11562306a36Sopenharmony_ci#define QCA8K_LED_BLINK_8HZ 2 11662306a36Sopenharmony_ci#define QCA8K_LED_BLINK_AUTO 3 11762306a36Sopenharmony_ci#define QCA8K_LED_LINKUP_OVER_MASK BIT(2) 11862306a36Sopenharmony_ci#define QCA8K_LED_TX_BLINK_MASK BIT(4) 11962306a36Sopenharmony_ci#define QCA8K_LED_RX_BLINK_MASK BIT(5) 12062306a36Sopenharmony_ci#define QCA8K_LED_COL_BLINK_MASK BIT(7) 12162306a36Sopenharmony_ci#define QCA8K_LED_LINK_10M_EN_MASK BIT(8) 12262306a36Sopenharmony_ci#define QCA8K_LED_LINK_100M_EN_MASK BIT(9) 12362306a36Sopenharmony_ci#define QCA8K_LED_LINK_1000M_EN_MASK BIT(10) 12462306a36Sopenharmony_ci#define QCA8K_LED_POWER_ON_LIGHT_MASK BIT(11) 12562306a36Sopenharmony_ci#define QCA8K_LED_HALF_DUPLEX_MASK BIT(12) 12662306a36Sopenharmony_ci#define QCA8K_LED_FULL_DUPLEX_MASK BIT(13) 12762306a36Sopenharmony_ci#define QCA8K_LED_PATTERN_EN_MASK GENMASK(15, 14) 12862306a36Sopenharmony_ci#define QCA8K_LED_PATTERN_EN_SHIFT 14 12962306a36Sopenharmony_ci#define QCA8K_LED_ALWAYS_OFF 0 13062306a36Sopenharmony_ci#define QCA8K_LED_ALWAYS_BLINK_4HZ 1 13162306a36Sopenharmony_ci#define QCA8K_LED_ALWAYS_ON 2 13262306a36Sopenharmony_ci#define QCA8K_LED_RULE_CONTROLLED 3 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci#define QCA8K_GOL_MAC_ADDR0 0x60 13562306a36Sopenharmony_ci#define QCA8K_GOL_MAC_ADDR1 0x64 13662306a36Sopenharmony_ci#define QCA8K_MAX_FRAME_SIZE 0x78 13762306a36Sopenharmony_ci#define QCA8K_REG_PORT_STATUS(_i) (0x07c + (_i) * 4) 13862306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_SPEED GENMASK(1, 0) 13962306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_SPEED_10 0 14062306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_SPEED_100 0x1 14162306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_SPEED_1000 0x2 14262306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_TXMAC BIT(2) 14362306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_RXMAC BIT(3) 14462306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_TXFLOW BIT(4) 14562306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_RXFLOW BIT(5) 14662306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_DUPLEX BIT(6) 14762306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_LINK_UP BIT(8) 14862306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_LINK_AUTO BIT(9) 14962306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_LINK_PAUSE BIT(10) 15062306a36Sopenharmony_ci#define QCA8K_PORT_STATUS_FLOW_AUTO BIT(12) 15162306a36Sopenharmony_ci#define QCA8K_REG_PORT_HDR_CTRL(_i) (0x9c + (_i * 4)) 15262306a36Sopenharmony_ci#define QCA8K_PORT_HDR_CTRL_RX_MASK GENMASK(3, 2) 15362306a36Sopenharmony_ci#define QCA8K_PORT_HDR_CTRL_TX_MASK GENMASK(1, 0) 15462306a36Sopenharmony_ci#define QCA8K_PORT_HDR_CTRL_ALL 2 15562306a36Sopenharmony_ci#define QCA8K_PORT_HDR_CTRL_MGMT 1 15662306a36Sopenharmony_ci#define QCA8K_PORT_HDR_CTRL_NONE 0 15762306a36Sopenharmony_ci#define QCA8K_REG_SGMII_CTRL 0x0e0 15862306a36Sopenharmony_ci#define QCA8K_SGMII_EN_PLL BIT(1) 15962306a36Sopenharmony_ci#define QCA8K_SGMII_EN_RX BIT(2) 16062306a36Sopenharmony_ci#define QCA8K_SGMII_EN_TX BIT(3) 16162306a36Sopenharmony_ci#define QCA8K_SGMII_EN_SD BIT(4) 16262306a36Sopenharmony_ci#define QCA8K_SGMII_CLK125M_DELAY BIT(7) 16362306a36Sopenharmony_ci#define QCA8K_SGMII_MODE_CTRL_MASK GENMASK(23, 22) 16462306a36Sopenharmony_ci#define QCA8K_SGMII_MODE_CTRL(x) FIELD_PREP(QCA8K_SGMII_MODE_CTRL_MASK, x) 16562306a36Sopenharmony_ci#define QCA8K_SGMII_MODE_CTRL_BASEX QCA8K_SGMII_MODE_CTRL(0x0) 16662306a36Sopenharmony_ci#define QCA8K_SGMII_MODE_CTRL_PHY QCA8K_SGMII_MODE_CTRL(0x1) 16762306a36Sopenharmony_ci#define QCA8K_SGMII_MODE_CTRL_MAC QCA8K_SGMII_MODE_CTRL(0x2) 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci/* MAC_PWR_SEL registers */ 17062306a36Sopenharmony_ci#define QCA8K_REG_MAC_PWR_SEL 0x0e4 17162306a36Sopenharmony_ci#define QCA8K_MAC_PWR_RGMII1_1_8V BIT(18) 17262306a36Sopenharmony_ci#define QCA8K_MAC_PWR_RGMII0_1_8V BIT(19) 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci/* EEE control registers */ 17562306a36Sopenharmony_ci#define QCA8K_REG_EEE_CTRL 0x100 17662306a36Sopenharmony_ci#define QCA8K_REG_EEE_CTRL_LPI_EN(_i) ((_i + 1) * 2) 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci/* TRUNK_HASH_EN registers */ 17962306a36Sopenharmony_ci#define QCA8K_TRUNK_HASH_EN_CTRL 0x270 18062306a36Sopenharmony_ci#define QCA8K_TRUNK_HASH_SIP_EN BIT(3) 18162306a36Sopenharmony_ci#define QCA8K_TRUNK_HASH_DIP_EN BIT(2) 18262306a36Sopenharmony_ci#define QCA8K_TRUNK_HASH_SA_EN BIT(1) 18362306a36Sopenharmony_ci#define QCA8K_TRUNK_HASH_DA_EN BIT(0) 18462306a36Sopenharmony_ci#define QCA8K_TRUNK_HASH_MASK GENMASK(3, 0) 18562306a36Sopenharmony_ci 18662306a36Sopenharmony_ci/* ACL registers */ 18762306a36Sopenharmony_ci#define QCA8K_REG_PORT_VLAN_CTRL0(_i) (0x420 + (_i * 8)) 18862306a36Sopenharmony_ci#define QCA8K_PORT_VLAN_CVID_MASK GENMASK(27, 16) 18962306a36Sopenharmony_ci#define QCA8K_PORT_VLAN_CVID(x) FIELD_PREP(QCA8K_PORT_VLAN_CVID_MASK, x) 19062306a36Sopenharmony_ci#define QCA8K_PORT_VLAN_SVID_MASK GENMASK(11, 0) 19162306a36Sopenharmony_ci#define QCA8K_PORT_VLAN_SVID(x) FIELD_PREP(QCA8K_PORT_VLAN_SVID_MASK, x) 19262306a36Sopenharmony_ci#define QCA8K_REG_PORT_VLAN_CTRL1(_i) (0x424 + (_i * 8)) 19362306a36Sopenharmony_ci#define QCA8K_REG_IPV4_PRI_BASE_ADDR 0x470 19462306a36Sopenharmony_ci#define QCA8K_REG_IPV4_PRI_ADDR_MASK 0x474 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_ci/* Lookup registers */ 19762306a36Sopenharmony_ci#define QCA8K_ATU_TABLE_SIZE 3 /* 12 bytes wide table / sizeof(u32) */ 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci#define QCA8K_REG_ATU_DATA0 0x600 20062306a36Sopenharmony_ci#define QCA8K_ATU_ADDR2_MASK GENMASK(31, 24) 20162306a36Sopenharmony_ci#define QCA8K_ATU_ADDR3_MASK GENMASK(23, 16) 20262306a36Sopenharmony_ci#define QCA8K_ATU_ADDR4_MASK GENMASK(15, 8) 20362306a36Sopenharmony_ci#define QCA8K_ATU_ADDR5_MASK GENMASK(7, 0) 20462306a36Sopenharmony_ci#define QCA8K_REG_ATU_DATA1 0x604 20562306a36Sopenharmony_ci#define QCA8K_ATU_PORT_MASK GENMASK(22, 16) 20662306a36Sopenharmony_ci#define QCA8K_ATU_ADDR0_MASK GENMASK(15, 8) 20762306a36Sopenharmony_ci#define QCA8K_ATU_ADDR1_MASK GENMASK(7, 0) 20862306a36Sopenharmony_ci#define QCA8K_REG_ATU_DATA2 0x608 20962306a36Sopenharmony_ci#define QCA8K_ATU_VID_MASK GENMASK(19, 8) 21062306a36Sopenharmony_ci#define QCA8K_ATU_STATUS_MASK GENMASK(3, 0) 21162306a36Sopenharmony_ci#define QCA8K_ATU_STATUS_STATIC 0xf 21262306a36Sopenharmony_ci#define QCA8K_REG_ATU_FUNC 0x60c 21362306a36Sopenharmony_ci#define QCA8K_ATU_FUNC_BUSY BIT(31) 21462306a36Sopenharmony_ci#define QCA8K_ATU_FUNC_PORT_EN BIT(14) 21562306a36Sopenharmony_ci#define QCA8K_ATU_FUNC_MULTI_EN BIT(13) 21662306a36Sopenharmony_ci#define QCA8K_ATU_FUNC_FULL BIT(12) 21762306a36Sopenharmony_ci#define QCA8K_ATU_FUNC_PORT_MASK GENMASK(11, 8) 21862306a36Sopenharmony_ci#define QCA8K_REG_VTU_FUNC0 0x610 21962306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_VALID BIT(20) 22062306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_IVL_EN BIT(19) 22162306a36Sopenharmony_ci/* QCA8K_VTU_FUNC0_EG_MODE_MASK GENMASK(17, 4) 22262306a36Sopenharmony_ci * It does contain VLAN_MODE for each port [5:4] for port0, 22362306a36Sopenharmony_ci * [7:6] for port1 ... [17:16] for port6. Use virtual port 22462306a36Sopenharmony_ci * define to handle this. 22562306a36Sopenharmony_ci */ 22662306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_EG_MODE_PORT_SHIFT(_i) (4 + (_i) * 2) 22762306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_EG_MODE_MASK GENMASK(1, 0) 22862306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_EG_MODE_PORT_MASK(_i) (GENMASK(1, 0) << QCA8K_VTU_FUNC0_EG_MODE_PORT_SHIFT(_i)) 22962306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_EG_MODE_UNMOD FIELD_PREP(QCA8K_VTU_FUNC0_EG_MODE_MASK, 0x0) 23062306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_EG_MODE_PORT_UNMOD(_i) (QCA8K_VTU_FUNC0_EG_MODE_UNMOD << QCA8K_VTU_FUNC0_EG_MODE_PORT_SHIFT(_i)) 23162306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_EG_MODE_UNTAG FIELD_PREP(QCA8K_VTU_FUNC0_EG_MODE_MASK, 0x1) 23262306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_EG_MODE_PORT_UNTAG(_i) (QCA8K_VTU_FUNC0_EG_MODE_UNTAG << QCA8K_VTU_FUNC0_EG_MODE_PORT_SHIFT(_i)) 23362306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_EG_MODE_TAG FIELD_PREP(QCA8K_VTU_FUNC0_EG_MODE_MASK, 0x2) 23462306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_EG_MODE_PORT_TAG(_i) (QCA8K_VTU_FUNC0_EG_MODE_TAG << QCA8K_VTU_FUNC0_EG_MODE_PORT_SHIFT(_i)) 23562306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_EG_MODE_NOT FIELD_PREP(QCA8K_VTU_FUNC0_EG_MODE_MASK, 0x3) 23662306a36Sopenharmony_ci#define QCA8K_VTU_FUNC0_EG_MODE_PORT_NOT(_i) (QCA8K_VTU_FUNC0_EG_MODE_NOT << QCA8K_VTU_FUNC0_EG_MODE_PORT_SHIFT(_i)) 23762306a36Sopenharmony_ci#define QCA8K_REG_VTU_FUNC1 0x614 23862306a36Sopenharmony_ci#define QCA8K_VTU_FUNC1_BUSY BIT(31) 23962306a36Sopenharmony_ci#define QCA8K_VTU_FUNC1_VID_MASK GENMASK(27, 16) 24062306a36Sopenharmony_ci#define QCA8K_VTU_FUNC1_FULL BIT(4) 24162306a36Sopenharmony_ci#define QCA8K_REG_ATU_CTRL 0x618 24262306a36Sopenharmony_ci#define QCA8K_ATU_AGE_TIME_MASK GENMASK(15, 0) 24362306a36Sopenharmony_ci#define QCA8K_ATU_AGE_TIME(x) FIELD_PREP(QCA8K_ATU_AGE_TIME_MASK, (x)) 24462306a36Sopenharmony_ci#define QCA8K_REG_GLOBAL_FW_CTRL0 0x620 24562306a36Sopenharmony_ci#define QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN BIT(10) 24662306a36Sopenharmony_ci#define QCA8K_GLOBAL_FW_CTRL0_MIRROR_PORT_NUM GENMASK(7, 4) 24762306a36Sopenharmony_ci#define QCA8K_REG_GLOBAL_FW_CTRL1 0x624 24862306a36Sopenharmony_ci#define QCA8K_GLOBAL_FW_CTRL1_IGMP_DP_MASK GENMASK(30, 24) 24962306a36Sopenharmony_ci#define QCA8K_GLOBAL_FW_CTRL1_BC_DP_MASK GENMASK(22, 16) 25062306a36Sopenharmony_ci#define QCA8K_GLOBAL_FW_CTRL1_MC_DP_MASK GENMASK(14, 8) 25162306a36Sopenharmony_ci#define QCA8K_GLOBAL_FW_CTRL1_UC_DP_MASK GENMASK(6, 0) 25262306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_CTRL(_i) (0x660 + (_i) * 0xc) 25362306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_MEMBER GENMASK(6, 0) 25462306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_VLAN_MODE_MASK GENMASK(9, 8) 25562306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_VLAN_MODE(x) FIELD_PREP(QCA8K_PORT_LOOKUP_VLAN_MODE_MASK, x) 25662306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_VLAN_MODE_NONE QCA8K_PORT_LOOKUP_VLAN_MODE(0x0) 25762306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_VLAN_MODE_FALLBACK QCA8K_PORT_LOOKUP_VLAN_MODE(0x1) 25862306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_VLAN_MODE_CHECK QCA8K_PORT_LOOKUP_VLAN_MODE(0x2) 25962306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_VLAN_MODE_SECURE QCA8K_PORT_LOOKUP_VLAN_MODE(0x3) 26062306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_STATE_MASK GENMASK(18, 16) 26162306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_STATE(x) FIELD_PREP(QCA8K_PORT_LOOKUP_STATE_MASK, x) 26262306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_STATE_DISABLED QCA8K_PORT_LOOKUP_STATE(0x0) 26362306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_STATE_BLOCKING QCA8K_PORT_LOOKUP_STATE(0x1) 26462306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_STATE_LISTENING QCA8K_PORT_LOOKUP_STATE(0x2) 26562306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_STATE_LEARNING QCA8K_PORT_LOOKUP_STATE(0x3) 26662306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_STATE_FORWARD QCA8K_PORT_LOOKUP_STATE(0x4) 26762306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_LEARN BIT(20) 26862306a36Sopenharmony_ci#define QCA8K_PORT_LOOKUP_ING_MIRROR_EN BIT(25) 26962306a36Sopenharmony_ci 27062306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_CTRL0 0x700 27162306a36Sopenharmony_ci/* 4 max trunk first 27262306a36Sopenharmony_ci * first 6 bit for member bitmap 27362306a36Sopenharmony_ci * 7th bit is to enable trunk port 27462306a36Sopenharmony_ci */ 27562306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_SHIFT(_i) ((_i) * 8) 27662306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_EN_MASK BIT(7) 27762306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_EN(_i) (QCA8K_REG_GOL_TRUNK_EN_MASK << QCA8K_REG_GOL_TRUNK_SHIFT(_i)) 27862306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_MEMBER_MASK GENMASK(6, 0) 27962306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_MEMBER(_i) (QCA8K_REG_GOL_TRUNK_MEMBER_MASK << QCA8K_REG_GOL_TRUNK_SHIFT(_i)) 28062306a36Sopenharmony_ci/* 0x704 for TRUNK 0-1 --- 0x708 for TRUNK 2-3 */ 28162306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_CTRL(_i) (0x704 + (((_i) / 2) * 4)) 28262306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_ID_MEM_ID_MASK GENMASK(3, 0) 28362306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_ID_MEM_ID_EN_MASK BIT(3) 28462306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_ID_MEM_ID_PORT_MASK GENMASK(2, 0) 28562306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_ID_SHIFT(_i) (((_i) / 2) * 16) 28662306a36Sopenharmony_ci#define QCA8K_REG_GOL_MEM_ID_SHIFT(_i) ((_i) * 4) 28762306a36Sopenharmony_ci/* Complex shift: FIRST shift for port THEN shift for trunk */ 28862306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_ID_MEM_ID_SHIFT(_i, _j) (QCA8K_REG_GOL_MEM_ID_SHIFT(_j) + QCA8K_REG_GOL_TRUNK_ID_SHIFT(_i)) 28962306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_ID_MEM_ID_EN(_i, _j) (QCA8K_REG_GOL_TRUNK_ID_MEM_ID_EN_MASK << QCA8K_REG_GOL_TRUNK_ID_MEM_ID_SHIFT(_i, _j)) 29062306a36Sopenharmony_ci#define QCA8K_REG_GOL_TRUNK_ID_MEM_ID_PORT(_i, _j) (QCA8K_REG_GOL_TRUNK_ID_MEM_ID_PORT_MASK << QCA8K_REG_GOL_TRUNK_ID_MEM_ID_SHIFT(_i, _j)) 29162306a36Sopenharmony_ci 29262306a36Sopenharmony_ci#define QCA8K_REG_GLOBAL_FC_THRESH 0x800 29362306a36Sopenharmony_ci#define QCA8K_GLOBAL_FC_GOL_XON_THRES_MASK GENMASK(24, 16) 29462306a36Sopenharmony_ci#define QCA8K_GLOBAL_FC_GOL_XON_THRES(x) FIELD_PREP(QCA8K_GLOBAL_FC_GOL_XON_THRES_MASK, x) 29562306a36Sopenharmony_ci#define QCA8K_GLOBAL_FC_GOL_XOFF_THRES_MASK GENMASK(8, 0) 29662306a36Sopenharmony_ci#define QCA8K_GLOBAL_FC_GOL_XOFF_THRES(x) FIELD_PREP(QCA8K_GLOBAL_FC_GOL_XOFF_THRES_MASK, x) 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ci#define QCA8K_REG_PORT_HOL_CTRL0(_i) (0x970 + (_i) * 0x8) 29962306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI0_BUF_MASK GENMASK(3, 0) 30062306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI0(x) FIELD_PREP(QCA8K_PORT_HOL_CTRL0_EG_PRI0_BUF_MASK, x) 30162306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI1_BUF_MASK GENMASK(7, 4) 30262306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI1(x) FIELD_PREP(QCA8K_PORT_HOL_CTRL0_EG_PRI1_BUF_MASK, x) 30362306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI2_BUF_MASK GENMASK(11, 8) 30462306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI2(x) FIELD_PREP(QCA8K_PORT_HOL_CTRL0_EG_PRI2_BUF_MASK, x) 30562306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI3_BUF_MASK GENMASK(15, 12) 30662306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI3(x) FIELD_PREP(QCA8K_PORT_HOL_CTRL0_EG_PRI3_BUF_MASK, x) 30762306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI4_BUF_MASK GENMASK(19, 16) 30862306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI4(x) FIELD_PREP(QCA8K_PORT_HOL_CTRL0_EG_PRI4_BUF_MASK, x) 30962306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI5_BUF_MASK GENMASK(23, 20) 31062306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PRI5(x) FIELD_PREP(QCA8K_PORT_HOL_CTRL0_EG_PRI5_BUF_MASK, x) 31162306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PORT_BUF_MASK GENMASK(29, 24) 31262306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL0_EG_PORT(x) FIELD_PREP(QCA8K_PORT_HOL_CTRL0_EG_PORT_BUF_MASK, x) 31362306a36Sopenharmony_ci 31462306a36Sopenharmony_ci#define QCA8K_REG_PORT_HOL_CTRL1(_i) (0x974 + (_i) * 0x8) 31562306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL1_ING_BUF_MASK GENMASK(3, 0) 31662306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL1_ING(x) FIELD_PREP(QCA8K_PORT_HOL_CTRL1_ING_BUF_MASK, x) 31762306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL1_EG_PRI_BUF_EN BIT(6) 31862306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL1_EG_PORT_BUF_EN BIT(7) 31962306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL1_WRED_EN BIT(8) 32062306a36Sopenharmony_ci#define QCA8K_PORT_HOL_CTRL1_EG_MIRROR_EN BIT(16) 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ci/* Pkt edit registers */ 32362306a36Sopenharmony_ci#define QCA8K_EGREES_VLAN_PORT_SHIFT(_i) (16 * ((_i) % 2)) 32462306a36Sopenharmony_ci#define QCA8K_EGREES_VLAN_PORT_MASK(_i) (GENMASK(11, 0) << QCA8K_EGREES_VLAN_PORT_SHIFT(_i)) 32562306a36Sopenharmony_ci#define QCA8K_EGREES_VLAN_PORT(_i, x) ((x) << QCA8K_EGREES_VLAN_PORT_SHIFT(_i)) 32662306a36Sopenharmony_ci#define QCA8K_EGRESS_VLAN(x) (0x0c70 + (4 * (x / 2))) 32762306a36Sopenharmony_ci 32862306a36Sopenharmony_ci/* L3 registers */ 32962306a36Sopenharmony_ci#define QCA8K_HROUTER_CONTROL 0xe00 33062306a36Sopenharmony_ci#define QCA8K_HROUTER_CONTROL_GLB_LOCKTIME_M GENMASK(17, 16) 33162306a36Sopenharmony_ci#define QCA8K_HROUTER_CONTROL_GLB_LOCKTIME_S 16 33262306a36Sopenharmony_ci#define QCA8K_HROUTER_CONTROL_ARP_AGE_MODE 1 33362306a36Sopenharmony_ci#define QCA8K_HROUTER_PBASED_CONTROL1 0xe08 33462306a36Sopenharmony_ci#define QCA8K_HROUTER_PBASED_CONTROL2 0xe0c 33562306a36Sopenharmony_ci#define QCA8K_HNAT_CONTROL 0xe38 33662306a36Sopenharmony_ci 33762306a36Sopenharmony_ci/* MIB registers */ 33862306a36Sopenharmony_ci#define QCA8K_PORT_MIB_COUNTER(_i) (0x1000 + (_i) * 0x100) 33962306a36Sopenharmony_ci 34062306a36Sopenharmony_ci/* QCA specific MII registers */ 34162306a36Sopenharmony_ci#define MII_ATH_MMD_ADDR 0x0d 34262306a36Sopenharmony_ci#define MII_ATH_MMD_DATA 0x0e 34362306a36Sopenharmony_ci 34462306a36Sopenharmony_cienum { 34562306a36Sopenharmony_ci QCA8K_PORT_SPEED_10M = 0, 34662306a36Sopenharmony_ci QCA8K_PORT_SPEED_100M = 1, 34762306a36Sopenharmony_ci QCA8K_PORT_SPEED_1000M = 2, 34862306a36Sopenharmony_ci QCA8K_PORT_SPEED_ERR = 3, 34962306a36Sopenharmony_ci}; 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_cienum qca8k_fdb_cmd { 35262306a36Sopenharmony_ci QCA8K_FDB_FLUSH = 1, 35362306a36Sopenharmony_ci QCA8K_FDB_LOAD = 2, 35462306a36Sopenharmony_ci QCA8K_FDB_PURGE = 3, 35562306a36Sopenharmony_ci QCA8K_FDB_FLUSH_PORT = 5, 35662306a36Sopenharmony_ci QCA8K_FDB_NEXT = 6, 35762306a36Sopenharmony_ci QCA8K_FDB_SEARCH = 7, 35862306a36Sopenharmony_ci}; 35962306a36Sopenharmony_ci 36062306a36Sopenharmony_cienum qca8k_vlan_cmd { 36162306a36Sopenharmony_ci QCA8K_VLAN_FLUSH = 1, 36262306a36Sopenharmony_ci QCA8K_VLAN_LOAD = 2, 36362306a36Sopenharmony_ci QCA8K_VLAN_PURGE = 3, 36462306a36Sopenharmony_ci QCA8K_VLAN_REMOVE_PORT = 4, 36562306a36Sopenharmony_ci QCA8K_VLAN_NEXT = 5, 36662306a36Sopenharmony_ci QCA8K_VLAN_READ = 6, 36762306a36Sopenharmony_ci}; 36862306a36Sopenharmony_ci 36962306a36Sopenharmony_cienum qca8k_mid_cmd { 37062306a36Sopenharmony_ci QCA8K_MIB_FLUSH = 1, 37162306a36Sopenharmony_ci QCA8K_MIB_FLUSH_PORT = 2, 37262306a36Sopenharmony_ci QCA8K_MIB_CAST = 3, 37362306a36Sopenharmony_ci}; 37462306a36Sopenharmony_ci 37562306a36Sopenharmony_cistruct qca8k_priv; 37662306a36Sopenharmony_ci 37762306a36Sopenharmony_cistruct qca8k_info_ops { 37862306a36Sopenharmony_ci int (*autocast_mib)(struct dsa_switch *ds, int port, u64 *data); 37962306a36Sopenharmony_ci}; 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_cistruct qca8k_match_data { 38262306a36Sopenharmony_ci u8 id; 38362306a36Sopenharmony_ci bool reduced_package; 38462306a36Sopenharmony_ci u8 mib_count; 38562306a36Sopenharmony_ci const struct qca8k_info_ops *ops; 38662306a36Sopenharmony_ci}; 38762306a36Sopenharmony_ci 38862306a36Sopenharmony_cienum { 38962306a36Sopenharmony_ci QCA8K_CPU_PORT0, 39062306a36Sopenharmony_ci QCA8K_CPU_PORT6, 39162306a36Sopenharmony_ci}; 39262306a36Sopenharmony_ci 39362306a36Sopenharmony_cistruct qca8k_mgmt_eth_data { 39462306a36Sopenharmony_ci struct completion rw_done; 39562306a36Sopenharmony_ci struct mutex mutex; /* Enforce one mdio read/write at time */ 39662306a36Sopenharmony_ci bool ack; 39762306a36Sopenharmony_ci u32 seq; 39862306a36Sopenharmony_ci u32 data[4]; 39962306a36Sopenharmony_ci}; 40062306a36Sopenharmony_ci 40162306a36Sopenharmony_cistruct qca8k_mib_eth_data { 40262306a36Sopenharmony_ci struct completion rw_done; 40362306a36Sopenharmony_ci struct mutex mutex; /* Process one command at time */ 40462306a36Sopenharmony_ci refcount_t port_parsed; /* Counter to track parsed port */ 40562306a36Sopenharmony_ci u8 req_port; 40662306a36Sopenharmony_ci u64 *data; /* pointer to ethtool data */ 40762306a36Sopenharmony_ci}; 40862306a36Sopenharmony_ci 40962306a36Sopenharmony_cistruct qca8k_ports_config { 41062306a36Sopenharmony_ci bool sgmii_rx_clk_falling_edge; 41162306a36Sopenharmony_ci bool sgmii_tx_clk_falling_edge; 41262306a36Sopenharmony_ci bool sgmii_enable_pll; 41362306a36Sopenharmony_ci u8 rgmii_rx_delay[QCA8K_NUM_CPU_PORTS]; /* 0: CPU port0, 1: CPU port6 */ 41462306a36Sopenharmony_ci u8 rgmii_tx_delay[QCA8K_NUM_CPU_PORTS]; /* 0: CPU port0, 1: CPU port6 */ 41562306a36Sopenharmony_ci}; 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_cistruct qca8k_mdio_cache { 41862306a36Sopenharmony_ci/* The 32bit switch registers are accessed indirectly. To achieve this we need 41962306a36Sopenharmony_ci * to set the page of the register. Track the last page that was set to reduce 42062306a36Sopenharmony_ci * mdio writes 42162306a36Sopenharmony_ci */ 42262306a36Sopenharmony_ci u16 page; 42362306a36Sopenharmony_ci}; 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_cistruct qca8k_pcs { 42662306a36Sopenharmony_ci struct phylink_pcs pcs; 42762306a36Sopenharmony_ci struct qca8k_priv *priv; 42862306a36Sopenharmony_ci int port; 42962306a36Sopenharmony_ci}; 43062306a36Sopenharmony_ci 43162306a36Sopenharmony_cistruct qca8k_led_pattern_en { 43262306a36Sopenharmony_ci u32 reg; 43362306a36Sopenharmony_ci u8 shift; 43462306a36Sopenharmony_ci}; 43562306a36Sopenharmony_ci 43662306a36Sopenharmony_cistruct qca8k_led { 43762306a36Sopenharmony_ci u8 port_num; 43862306a36Sopenharmony_ci u8 led_num; 43962306a36Sopenharmony_ci u16 old_rule; 44062306a36Sopenharmony_ci struct qca8k_priv *priv; 44162306a36Sopenharmony_ci struct led_classdev cdev; 44262306a36Sopenharmony_ci}; 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_cistruct qca8k_priv { 44562306a36Sopenharmony_ci u8 switch_id; 44662306a36Sopenharmony_ci u8 switch_revision; 44762306a36Sopenharmony_ci u8 mirror_rx; 44862306a36Sopenharmony_ci u8 mirror_tx; 44962306a36Sopenharmony_ci u8 lag_hash_mode; 45062306a36Sopenharmony_ci /* Each bit correspond to a port. This switch can support a max of 7 port. 45162306a36Sopenharmony_ci * Bit 1: port enabled. Bit 0: port disabled. 45262306a36Sopenharmony_ci */ 45362306a36Sopenharmony_ci u8 port_enabled_map; 45462306a36Sopenharmony_ci struct qca8k_ports_config ports_config; 45562306a36Sopenharmony_ci struct regmap *regmap; 45662306a36Sopenharmony_ci struct mii_bus *bus; 45762306a36Sopenharmony_ci struct dsa_switch *ds; 45862306a36Sopenharmony_ci struct mutex reg_mutex; 45962306a36Sopenharmony_ci struct device *dev; 46062306a36Sopenharmony_ci struct gpio_desc *reset_gpio; 46162306a36Sopenharmony_ci struct net_device *mgmt_master; /* Track if mdio/mib Ethernet is available */ 46262306a36Sopenharmony_ci struct qca8k_mgmt_eth_data mgmt_eth_data; 46362306a36Sopenharmony_ci struct qca8k_mib_eth_data mib_eth_data; 46462306a36Sopenharmony_ci struct qca8k_mdio_cache mdio_cache; 46562306a36Sopenharmony_ci struct qca8k_pcs pcs_port_0; 46662306a36Sopenharmony_ci struct qca8k_pcs pcs_port_6; 46762306a36Sopenharmony_ci const struct qca8k_match_data *info; 46862306a36Sopenharmony_ci struct qca8k_led ports_led[QCA8K_LED_COUNT]; 46962306a36Sopenharmony_ci}; 47062306a36Sopenharmony_ci 47162306a36Sopenharmony_cistruct qca8k_mib_desc { 47262306a36Sopenharmony_ci unsigned int size; 47362306a36Sopenharmony_ci unsigned int offset; 47462306a36Sopenharmony_ci const char *name; 47562306a36Sopenharmony_ci}; 47662306a36Sopenharmony_ci 47762306a36Sopenharmony_cistruct qca8k_fdb { 47862306a36Sopenharmony_ci u16 vid; 47962306a36Sopenharmony_ci u8 port_mask; 48062306a36Sopenharmony_ci u8 aging; 48162306a36Sopenharmony_ci u8 mac[6]; 48262306a36Sopenharmony_ci}; 48362306a36Sopenharmony_ci 48462306a36Sopenharmony_cistatic inline u32 qca8k_port_to_phy(int port) 48562306a36Sopenharmony_ci{ 48662306a36Sopenharmony_ci /* From Andrew Lunn: 48762306a36Sopenharmony_ci * Port 0 has no internal phy. 48862306a36Sopenharmony_ci * Port 1 has an internal PHY at MDIO address 0. 48962306a36Sopenharmony_ci * Port 2 has an internal PHY at MDIO address 1. 49062306a36Sopenharmony_ci * ... 49162306a36Sopenharmony_ci * Port 5 has an internal PHY at MDIO address 4. 49262306a36Sopenharmony_ci * Port 6 has no internal PHY. 49362306a36Sopenharmony_ci */ 49462306a36Sopenharmony_ci 49562306a36Sopenharmony_ci return port - 1; 49662306a36Sopenharmony_ci} 49762306a36Sopenharmony_ci 49862306a36Sopenharmony_ci/* Common setup function */ 49962306a36Sopenharmony_ciextern const struct qca8k_mib_desc ar8327_mib[]; 50062306a36Sopenharmony_ciextern const struct regmap_access_table qca8k_readable_table; 50162306a36Sopenharmony_ciint qca8k_mib_init(struct qca8k_priv *priv); 50262306a36Sopenharmony_civoid qca8k_port_set_status(struct qca8k_priv *priv, int port, int enable); 50362306a36Sopenharmony_ciint qca8k_read_switch_id(struct qca8k_priv *priv); 50462306a36Sopenharmony_ci 50562306a36Sopenharmony_ci/* Common read/write/rmw function */ 50662306a36Sopenharmony_ciint qca8k_read(struct qca8k_priv *priv, u32 reg, u32 *val); 50762306a36Sopenharmony_ciint qca8k_write(struct qca8k_priv *priv, u32 reg, u32 val); 50862306a36Sopenharmony_ciint qca8k_rmw(struct qca8k_priv *priv, u32 reg, u32 mask, u32 write_val); 50962306a36Sopenharmony_ci 51062306a36Sopenharmony_ci/* Common ops function */ 51162306a36Sopenharmony_civoid qca8k_fdb_flush(struct qca8k_priv *priv); 51262306a36Sopenharmony_ci 51362306a36Sopenharmony_ci/* Common ethtool stats function */ 51462306a36Sopenharmony_civoid qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *data); 51562306a36Sopenharmony_civoid qca8k_get_ethtool_stats(struct dsa_switch *ds, int port, 51662306a36Sopenharmony_ci uint64_t *data); 51762306a36Sopenharmony_ciint qca8k_get_sset_count(struct dsa_switch *ds, int port, int sset); 51862306a36Sopenharmony_ci 51962306a36Sopenharmony_ci/* Common eee function */ 52062306a36Sopenharmony_ciint qca8k_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *eee); 52162306a36Sopenharmony_ciint qca8k_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e); 52262306a36Sopenharmony_ci 52362306a36Sopenharmony_ci/* Common bridge function */ 52462306a36Sopenharmony_civoid qca8k_port_stp_state_set(struct dsa_switch *ds, int port, u8 state); 52562306a36Sopenharmony_ciint qca8k_port_pre_bridge_flags(struct dsa_switch *ds, int port, 52662306a36Sopenharmony_ci struct switchdev_brport_flags flags, 52762306a36Sopenharmony_ci struct netlink_ext_ack *extack); 52862306a36Sopenharmony_ciint qca8k_port_bridge_flags(struct dsa_switch *ds, int port, 52962306a36Sopenharmony_ci struct switchdev_brport_flags flags, 53062306a36Sopenharmony_ci struct netlink_ext_ack *extack); 53162306a36Sopenharmony_ciint qca8k_port_bridge_join(struct dsa_switch *ds, int port, 53262306a36Sopenharmony_ci struct dsa_bridge bridge, 53362306a36Sopenharmony_ci bool *tx_fwd_offload, 53462306a36Sopenharmony_ci struct netlink_ext_ack *extack); 53562306a36Sopenharmony_civoid qca8k_port_bridge_leave(struct dsa_switch *ds, int port, 53662306a36Sopenharmony_ci struct dsa_bridge bridge); 53762306a36Sopenharmony_ci 53862306a36Sopenharmony_ci/* Common port enable/disable function */ 53962306a36Sopenharmony_ciint qca8k_port_enable(struct dsa_switch *ds, int port, 54062306a36Sopenharmony_ci struct phy_device *phy); 54162306a36Sopenharmony_civoid qca8k_port_disable(struct dsa_switch *ds, int port); 54262306a36Sopenharmony_ci 54362306a36Sopenharmony_ci/* Common MTU function */ 54462306a36Sopenharmony_ciint qca8k_port_change_mtu(struct dsa_switch *ds, int port, int new_mtu); 54562306a36Sopenharmony_ciint qca8k_port_max_mtu(struct dsa_switch *ds, int port); 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_ci/* Common fast age function */ 54862306a36Sopenharmony_civoid qca8k_port_fast_age(struct dsa_switch *ds, int port); 54962306a36Sopenharmony_ciint qca8k_set_ageing_time(struct dsa_switch *ds, unsigned int msecs); 55062306a36Sopenharmony_ci 55162306a36Sopenharmony_ci/* Common FDB function */ 55262306a36Sopenharmony_ciint qca8k_port_fdb_insert(struct qca8k_priv *priv, const u8 *addr, 55362306a36Sopenharmony_ci u16 port_mask, u16 vid); 55462306a36Sopenharmony_ciint qca8k_port_fdb_add(struct dsa_switch *ds, int port, 55562306a36Sopenharmony_ci const unsigned char *addr, u16 vid, 55662306a36Sopenharmony_ci struct dsa_db db); 55762306a36Sopenharmony_ciint qca8k_port_fdb_del(struct dsa_switch *ds, int port, 55862306a36Sopenharmony_ci const unsigned char *addr, u16 vid, 55962306a36Sopenharmony_ci struct dsa_db db); 56062306a36Sopenharmony_ciint qca8k_port_fdb_dump(struct dsa_switch *ds, int port, 56162306a36Sopenharmony_ci dsa_fdb_dump_cb_t *cb, void *data); 56262306a36Sopenharmony_ci 56362306a36Sopenharmony_ci/* Common MDB function */ 56462306a36Sopenharmony_ciint qca8k_port_mdb_add(struct dsa_switch *ds, int port, 56562306a36Sopenharmony_ci const struct switchdev_obj_port_mdb *mdb, 56662306a36Sopenharmony_ci struct dsa_db db); 56762306a36Sopenharmony_ciint qca8k_port_mdb_del(struct dsa_switch *ds, int port, 56862306a36Sopenharmony_ci const struct switchdev_obj_port_mdb *mdb, 56962306a36Sopenharmony_ci struct dsa_db db); 57062306a36Sopenharmony_ci 57162306a36Sopenharmony_ci/* Common port mirror function */ 57262306a36Sopenharmony_ciint qca8k_port_mirror_add(struct dsa_switch *ds, int port, 57362306a36Sopenharmony_ci struct dsa_mall_mirror_tc_entry *mirror, 57462306a36Sopenharmony_ci bool ingress, struct netlink_ext_ack *extack); 57562306a36Sopenharmony_civoid qca8k_port_mirror_del(struct dsa_switch *ds, int port, 57662306a36Sopenharmony_ci struct dsa_mall_mirror_tc_entry *mirror); 57762306a36Sopenharmony_ci 57862306a36Sopenharmony_ci/* Common port VLAN function */ 57962306a36Sopenharmony_ciint qca8k_port_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering, 58062306a36Sopenharmony_ci struct netlink_ext_ack *extack); 58162306a36Sopenharmony_ciint qca8k_port_vlan_add(struct dsa_switch *ds, int port, 58262306a36Sopenharmony_ci const struct switchdev_obj_port_vlan *vlan, 58362306a36Sopenharmony_ci struct netlink_ext_ack *extack); 58462306a36Sopenharmony_ciint qca8k_port_vlan_del(struct dsa_switch *ds, int port, 58562306a36Sopenharmony_ci const struct switchdev_obj_port_vlan *vlan); 58662306a36Sopenharmony_ci 58762306a36Sopenharmony_ci/* Common port LAG function */ 58862306a36Sopenharmony_ciint qca8k_port_lag_join(struct dsa_switch *ds, int port, struct dsa_lag lag, 58962306a36Sopenharmony_ci struct netdev_lag_upper_info *info, 59062306a36Sopenharmony_ci struct netlink_ext_ack *extack); 59162306a36Sopenharmony_ciint qca8k_port_lag_leave(struct dsa_switch *ds, int port, 59262306a36Sopenharmony_ci struct dsa_lag lag); 59362306a36Sopenharmony_ci 59462306a36Sopenharmony_ci#endif /* __QCA8K_H */ 595