#include <linux/bitops.h>
#include <linux/etherdevice.h>
#include <linux/if_bridge.h>
#include <linux/if_vlan.h>
#include <linux/interrupt.h>
#include <linux/irqdomain.h>
#include <linux/irqchip/chained_irq.h>
#include <linux/of_irq.h>
#include <linux/regmap.h>
#include "realtek.h"
#include "realtek-smi.h"
#include "realtek-mdio.h"
#include "rtl83xx.h"
#define RTL8366RB_PORT_NUM_CPU …
#define RTL8366RB_NUM_PORTS …
#define RTL8366RB_PHY_NO_MAX …
#define RTL8366RB_PHY_ADDR_MAX …
#define RTL8366RB_SGCR …
#define RTL8366RB_SGCR_EN_BC_STORM_CTRL …
#define RTL8366RB_SGCR_MAX_LENGTH(a) …
#define RTL8366RB_SGCR_MAX_LENGTH_MASK …
#define RTL8366RB_SGCR_MAX_LENGTH_1522 …
#define RTL8366RB_SGCR_MAX_LENGTH_1536 …
#define RTL8366RB_SGCR_MAX_LENGTH_1552 …
#define RTL8366RB_SGCR_MAX_LENGTH_16000 …
#define RTL8366RB_SGCR_EN_VLAN …
#define RTL8366RB_SGCR_EN_VLAN_4KTB …
#define RTL8366RB_PECR …
#define RTL8366RB_PORT_LEARNDIS_CTRL …
#define RTL8366RB_SECURITY_CTRL …
#define RTL8366RB_SSCR2 …
#define RTL8366RB_SSCR2_DROP_UNKNOWN_DA …
#define RTL8366RB_PMC0 …
#define RTL8366RB_PMC0_SPI …
#define RTL8366RB_PMC0_EN_AUTOLOAD …
#define RTL8366RB_PMC0_PROBE …
#define RTL8366RB_PMC0_DIS_BISR …
#define RTL8366RB_PMC0_ADCTEST …
#define RTL8366RB_PMC0_SRAM_DIAG …
#define RTL8366RB_PMC0_EN_SCAN …
#define RTL8366RB_PMC0_P4_IOMODE_SHIFT …
#define RTL8366RB_PMC0_P4_IOMODE_MASK …
#define RTL8366RB_PMC0_P5_IOMODE_SHIFT …
#define RTL8366RB_PMC0_P5_IOMODE_MASK …
#define RTL8366RB_PMC0_SDSMODE_SHIFT …
#define RTL8366RB_PMC0_SDSMODE_MASK …
#define RTL8366RB_PMC1 …
#define RTL8366RB_PMCR …
#define RTL8366RB_PMCR_SOURCE_PORT(a) …
#define RTL8366RB_PMCR_SOURCE_PORT_MASK …
#define RTL8366RB_PMCR_MONITOR_PORT(a) …
#define RTL8366RB_PMCR_MONITOR_PORT_MASK …
#define RTL8366RB_PMCR_MIRROR_RX …
#define RTL8366RB_PMCR_MIRROR_TX …
#define RTL8366RB_PMCR_MIRROR_SPC …
#define RTL8366RB_PMCR_MIRROR_ISO …
#define RTL8366RB_PAACR0 …
#define RTL8366RB_PAACR1 …
#define RTL8366RB_PAACR2 …
#define RTL8366RB_PAACR_SPEED_10M …
#define RTL8366RB_PAACR_SPEED_100M …
#define RTL8366RB_PAACR_SPEED_1000M …
#define RTL8366RB_PAACR_FULL_DUPLEX …
#define RTL8366RB_PAACR_LINK_UP …
#define RTL8366RB_PAACR_TX_PAUSE …
#define RTL8366RB_PAACR_RX_PAUSE …
#define RTL8366RB_PAACR_AN …
#define RTL8366RB_PSTAT0 …
#define RTL8366RB_PSTAT1 …
#define RTL8366RB_PSTAT2 …
#define RTL8366RB_POWER_SAVING_REG …
#define RTL8366RB_STP_STATE_BASE …
#define RTL8366RB_STP_STATE_DISABLED …
#define RTL8366RB_STP_STATE_BLOCKING …
#define RTL8366RB_STP_STATE_LEARNING …
#define RTL8366RB_STP_STATE_FORWARDING …
#define RTL8366RB_STP_MASK …
#define RTL8366RB_STP_STATE(port, state) …
#define RTL8366RB_STP_STATE_MASK(port) …
#define RTL8366RB_CPU_CTRL_REG …
#define RTL8366RB_CPU_PORTS_MSK …
#define RTL8366RB_CPU_NO_TAG …
#define RTL8366RB_CPU_TAG_SIZE …
#define RTL8366RB_SMAR0 …
#define RTL8366RB_SMAR1 …
#define RTL8366RB_SMAR2 …
#define RTL8366RB_RESET_CTRL_REG …
#define RTL8366RB_CHIP_CTRL_RESET_HW …
#define RTL8366RB_CHIP_CTRL_RESET_SW …
#define RTL8366RB_CHIP_ID_REG …
#define RTL8366RB_CHIP_ID_8366 …
#define RTL8366RB_CHIP_VERSION_CTRL_REG …
#define RTL8366RB_CHIP_VERSION_MASK …
#define RTL8366RB_PHY_ACCESS_CTRL_REG …
#define RTL8366RB_PHY_CTRL_READ …
#define RTL8366RB_PHY_CTRL_WRITE …
#define RTL8366RB_PHY_ACCESS_BUSY_REG …
#define RTL8366RB_PHY_INT_BUSY …
#define RTL8366RB_PHY_EXT_BUSY …
#define RTL8366RB_PHY_ACCESS_DATA_REG …
#define RTL8366RB_PHY_EXT_CTRL_REG …
#define RTL8366RB_PHY_EXT_WRDATA_REG …
#define RTL8366RB_PHY_EXT_RDDATA_REG …
#define RTL8366RB_PHY_REG_MASK …
#define RTL8366RB_PHY_PAGE_OFFSET …
#define RTL8366RB_PHY_PAGE_MASK …
#define RTL8366RB_PHY_NO_OFFSET …
#define RTL8366RB_PHY_NO_MASK …
#define RTL8366RB_VLAN_INGRESS_CTRL1_REG …
#define RTL8366RB_VLAN_INGRESS_CTRL1_DROP(port) …
#define RTL8366RB_VLAN_INGRESS_CTRL2_REG …
#define RTL8366RB_LED_BLINKRATE_REG …
#define RTL8366RB_LED_BLINKRATE_MASK …
#define RTL8366RB_LED_BLINKRATE_28MS …
#define RTL8366RB_LED_BLINKRATE_56MS …
#define RTL8366RB_LED_BLINKRATE_84MS …
#define RTL8366RB_LED_BLINKRATE_111MS …
#define RTL8366RB_LED_BLINKRATE_222MS …
#define RTL8366RB_LED_BLINKRATE_446MS …
#define RTL8366RB_LED_CTRL_REG …
#define RTL8366RB_LED_CTRL_OFFSET(led_group) …
#define RTL8366RB_LED_CTRL_MASK(led_group) …
#define RTL8366RB_LED_0_1_CTRL_REG …
#define RTL8366RB_LED_2_3_CTRL_REG …
#define RTL8366RB_LED_X_X_CTRL_REG(led_group) …
#define RTL8366RB_LED_0_X_CTRL_MASK …
#define RTL8366RB_LED_X_1_CTRL_MASK …
#define RTL8366RB_LED_2_X_CTRL_MASK …
#define RTL8366RB_LED_X_3_CTRL_MASK …
#define RTL8366RB_MIB_COUNT …
#define RTL8366RB_GLOBAL_MIB_COUNT …
#define RTL8366RB_MIB_COUNTER_PORT_OFFSET …
#define RTL8366RB_MIB_COUNTER_BASE …
#define RTL8366RB_MIB_CTRL_REG …
#define RTL8366RB_MIB_CTRL_USER_MASK …
#define RTL8366RB_MIB_CTRL_BUSY_MASK …
#define RTL8366RB_MIB_CTRL_RESET_MASK …
#define RTL8366RB_MIB_CTRL_PORT_RESET(_p) …
#define RTL8366RB_MIB_CTRL_GLOBAL_RESET …
#define RTL8366RB_PORT_VLAN_CTRL_BASE …
#define RTL8366RB_PORT_VLAN_CTRL_REG(_p) …
#define RTL8366RB_PORT_VLAN_CTRL_MASK …
#define RTL8366RB_PORT_VLAN_CTRL_SHIFT(_p) …
#define RTL8366RB_VLAN_TABLE_READ_BASE …
#define RTL8366RB_VLAN_TABLE_WRITE_BASE …
#define RTL8366RB_TABLE_ACCESS_CTRL_REG …
#define RTL8366RB_TABLE_VLAN_READ_CTRL …
#define RTL8366RB_TABLE_VLAN_WRITE_CTRL …
#define RTL8366RB_VLAN_MC_BASE(_x) …
#define RTL8366RB_PORT_LINK_STATUS_BASE …
#define RTL8366RB_PORT_STATUS_SPEED_MASK …
#define RTL8366RB_PORT_STATUS_DUPLEX_MASK …
#define RTL8366RB_PORT_STATUS_LINK_MASK …
#define RTL8366RB_PORT_STATUS_TXPAUSE_MASK …
#define RTL8366RB_PORT_STATUS_RXPAUSE_MASK …
#define RTL8366RB_PORT_STATUS_AN_MASK …
#define RTL8366RB_NUM_VLANS …
#define RTL8366RB_NUM_LEDGROUPS …
#define RTL8366RB_NUM_VIDS …
#define RTL8366RB_PRIORITYMAX …
#define RTL8366RB_NUM_FIDS …
#define RTL8366RB_FIDMAX …
#define RTL8366RB_PORT_1 …
#define RTL8366RB_PORT_2 …
#define RTL8366RB_PORT_3 …
#define RTL8366RB_PORT_4 …
#define RTL8366RB_PORT_5 …
#define RTL8366RB_PORT_CPU …
#define RTL8366RB_PORT_ALL …
#define RTL8366RB_PORT_ALL_BUT_CPU …
#define RTL8366RB_PORT_ALL_EXTERNAL …
#define RTL8366RB_PORT_ALL_INTERNAL …
#define RTL8366RB_VLAN_VID_MASK …
#define RTL8366RB_VLAN_PRIORITY_SHIFT …
#define RTL8366RB_VLAN_PRIORITY_MASK …
#define RTL8366RB_VLAN_UNTAG_SHIFT …
#define RTL8366RB_VLAN_UNTAG_MASK …
#define RTL8366RB_VLAN_MEMBER_MASK …
#define RTL8366RB_VLAN_STAG_MBR_MASK …
#define RTL8366RB_VLAN_STAG_MBR_SHIFT …
#define RTL8366RB_VLAN_STAG_IDX_MASK …
#define RTL8366RB_VLAN_STAG_IDX_SHIFT …
#define RTL8366RB_VLAN_FID_MASK …
#define RTL8366RB_IB_BASE …
#define RTL8366RB_IB_REG(pnum) …
#define RTL8366RB_IB_BDTH_MASK …
#define RTL8366RB_IB_PREIFG …
#define RTL8366RB_EB_BASE …
#define RTL8366RB_EB_REG(pnum) …
#define RTL8366RB_EB_BDTH_MASK …
#define RTL8366RB_EB_PREIFG_REG …
#define RTL8366RB_EB_PREIFG …
#define RTL8366RB_BDTH_SW_MAX …
#define RTL8366RB_BDTH_UNIT …
#define RTL8366RB_BDTH_REG_DEFAULT …
#define RTL8366RB_QOS …
#define RTL8366RB_QOS_DEFAULT_PREIFG …
#define RTL8366RB_INTERRUPT_CONTROL_REG …
#define RTL8366RB_INTERRUPT_POLARITY …
#define RTL8366RB_P4_RGMII_LED …
#define RTL8366RB_INTERRUPT_MASK_REG …
#define RTL8366RB_INTERRUPT_LINK_CHGALL …
#define RTL8366RB_INTERRUPT_ACLEXCEED …
#define RTL8366RB_INTERRUPT_STORMEXCEED …
#define RTL8366RB_INTERRUPT_P4_FIBER …
#define RTL8366RB_INTERRUPT_P4_UTP …
#define RTL8366RB_INTERRUPT_VALID …
#define RTL8366RB_INTERRUPT_STATUS_REG …
#define RTL8366RB_NUM_INTERRUPT …
#define RTL8366RB_PORT_ISO_BASE …
#define RTL8366RB_PORT_ISO(pnum) …
#define RTL8366RB_PORT_ISO_EN …
#define RTL8366RB_PORT_ISO_PORTS_MASK …
#define RTL8366RB_PORT_ISO_PORTS(pmask) …
#define RTL8366RB_MAC_FORCE_CTRL_REG …
#define RTL8366RB_OAM_PARSER_REG …
#define RTL8366RB_OAM_MULTIPLEXER_REG …
#define RTL8366RB_GREEN_FEATURE_REG …
#define RTL8366RB_GREEN_FEATURE_MSK …
#define RTL8366RB_GREEN_FEATURE_TX …
#define RTL8366RB_GREEN_FEATURE_RX …
enum rtl8366_ledgroup_mode { … };
struct rtl8366rb_led { … };
struct rtl8366rb { … };
static struct rtl8366_mib_counter rtl8366rb_mib_counters[] = …;
static int rtl8366rb_get_mib_counter(struct realtek_priv *priv,
int port,
struct rtl8366_mib_counter *mib,
u64 *mibvalue)
{ … }
static u32 rtl8366rb_get_irqmask(struct irq_data *d)
{ … }
static void rtl8366rb_mask_irq(struct irq_data *d)
{ … }
static void rtl8366rb_unmask_irq(struct irq_data *d)
{ … }
static irqreturn_t rtl8366rb_irq(int irq, void *data)
{ … }
static struct irq_chip rtl8366rb_irq_chip = …;
static int rtl8366rb_irq_map(struct irq_domain *domain, unsigned int irq,
irq_hw_number_t hwirq)
{ … }
static void rtl8366rb_irq_unmap(struct irq_domain *d, unsigned int irq)
{ … }
static const struct irq_domain_ops rtl8366rb_irqdomain_ops = …;
static int rtl8366rb_setup_cascaded_irq(struct realtek_priv *priv)
{ … }
static int rtl8366rb_set_addr(struct realtek_priv *priv)
{ … }
struct rtl8366rb_jam_tbl_entry { … };
static const struct rtl8366rb_jam_tbl_entry rtl8366rb_init_jam_ver_0[] = …;
static const struct rtl8366rb_jam_tbl_entry rtl8366rb_init_jam_ver_1[] = …;
static const struct rtl8366rb_jam_tbl_entry rtl8366rb_init_jam_ver_2[] = …;
static const struct rtl8366rb_jam_tbl_entry rtl8366rb_init_jam_ver_3[] = …;
static const struct rtl8366rb_jam_tbl_entry rtl8366rb_init_jam_f5d8235[] = …;
static const struct rtl8366rb_jam_tbl_entry rtl8366rb_init_jam_dgn3500[] = …;
static const struct rtl8366rb_jam_tbl_entry rtl8366rb_green_jam[] = …;
static int rtl8366rb_jam_table(const struct rtl8366rb_jam_tbl_entry *jam_table,
int jam_size, struct realtek_priv *priv,
bool write_dbg)
{ … }
static int rb8366rb_set_ledgroup_mode(struct realtek_priv *priv,
u8 led_group,
enum rtl8366_ledgroup_mode mode)
{ … }
static inline u32 rtl8366rb_led_group_port_mask(u8 led_group, u8 port)
{ … }
static int rb8366rb_get_port_led(struct rtl8366rb_led *led)
{ … }
static int rb8366rb_set_port_led(struct rtl8366rb_led *led, bool enable)
{ … }
static int
rtl8366rb_cled_brightness_set_blocking(struct led_classdev *ldev,
enum led_brightness brightness)
{ … }
static int rtl8366rb_setup_led(struct realtek_priv *priv, struct dsa_port *dp,
struct fwnode_handle *led_fwnode)
{ … }
static int rtl8366rb_setup_all_leds_off(struct realtek_priv *priv)
{ … }
static int rtl8366rb_setup_leds(struct realtek_priv *priv)
{ … }
static int rtl8366rb_setup(struct dsa_switch *ds)
{ … }
static enum dsa_tag_protocol rtl8366_get_tag_protocol(struct dsa_switch *ds,
int port,
enum dsa_tag_protocol mp)
{ … }
static void rtl8366rb_phylink_get_caps(struct dsa_switch *ds, int port,
struct phylink_config *config)
{ … }
static void
rtl8366rb_mac_config(struct phylink_config *config, unsigned int mode,
const struct phylink_link_state *state)
{ … }
static void
rtl8366rb_mac_link_up(struct phylink_config *config, struct phy_device *phydev,
unsigned int mode, phy_interface_t interface,
int speed, int duplex, bool tx_pause, bool rx_pause)
{ … }
static void
rtl8366rb_mac_link_down(struct phylink_config *config, unsigned int mode,
phy_interface_t interface)
{ … }
static int
rtl8366rb_port_enable(struct dsa_switch *ds, int port,
struct phy_device *phy)
{ … }
static void
rtl8366rb_port_disable(struct dsa_switch *ds, int port)
{ … }
static int
rtl8366rb_port_bridge_join(struct dsa_switch *ds, int port,
struct dsa_bridge bridge,
bool *tx_fwd_offload,
struct netlink_ext_ack *extack)
{ … }
static void
rtl8366rb_port_bridge_leave(struct dsa_switch *ds, int port,
struct dsa_bridge bridge)
{ … }
static int rtl8366rb_drop_untagged(struct realtek_priv *priv, int port, bool drop)
{ … }
static int rtl8366rb_vlan_filtering(struct dsa_switch *ds, int port,
bool vlan_filtering,
struct netlink_ext_ack *extack)
{ … }
static int
rtl8366rb_port_pre_bridge_flags(struct dsa_switch *ds, int port,
struct switchdev_brport_flags flags,
struct netlink_ext_ack *extack)
{ … }
static int
rtl8366rb_port_bridge_flags(struct dsa_switch *ds, int port,
struct switchdev_brport_flags flags,
struct netlink_ext_ack *extack)
{ … }
static void
rtl8366rb_port_stp_state_set(struct dsa_switch *ds, int port, u8 state)
{ … }
static void
rtl8366rb_port_fast_age(struct dsa_switch *ds, int port)
{ … }
static int rtl8366rb_change_mtu(struct dsa_switch *ds, int port, int new_mtu)
{ … }
static int rtl8366rb_max_mtu(struct dsa_switch *ds, int port)
{ … }
static int rtl8366rb_get_vlan_4k(struct realtek_priv *priv, u32 vid,
struct rtl8366_vlan_4k *vlan4k)
{ … }
static int rtl8366rb_set_vlan_4k(struct realtek_priv *priv,
const struct rtl8366_vlan_4k *vlan4k)
{ … }
static int rtl8366rb_get_vlan_mc(struct realtek_priv *priv, u32 index,
struct rtl8366_vlan_mc *vlanmc)
{ … }
static int rtl8366rb_set_vlan_mc(struct realtek_priv *priv, u32 index,
const struct rtl8366_vlan_mc *vlanmc)
{ … }
static int rtl8366rb_get_mc_index(struct realtek_priv *priv, int port, int *val)
{ … }
static int rtl8366rb_set_mc_index(struct realtek_priv *priv, int port, int index)
{ … }
static bool rtl8366rb_is_vlan_valid(struct realtek_priv *priv, unsigned int vlan)
{ … }
static int rtl8366rb_enable_vlan(struct realtek_priv *priv, bool enable)
{ … }
static int rtl8366rb_enable_vlan4k(struct realtek_priv *priv, bool enable)
{ … }
static int rtl8366rb_phy_read(struct realtek_priv *priv, int phy, int regnum)
{ … }
static int rtl8366rb_phy_write(struct realtek_priv *priv, int phy, int regnum,
u16 val)
{ … }
static int rtl8366rb_reset_chip(struct realtek_priv *priv)
{ … }
static int rtl8366rb_detect(struct realtek_priv *priv)
{ … }
static const struct phylink_mac_ops rtl8366rb_phylink_mac_ops = …;
static const struct dsa_switch_ops rtl8366rb_switch_ops = …;
static const struct realtek_ops rtl8366rb_ops = …;
const struct realtek_variant rtl8366rb_variant = …;
static const struct of_device_id rtl8366rb_of_match[] = …;
MODULE_DEVICE_TABLE(of, rtl8366rb_of_match);
static struct platform_driver rtl8366rb_smi_driver = …;
static struct mdio_driver rtl8366rb_mdio_driver = …;
static int rtl8366rb_init(void)
{ … }
module_init(…) …;
static void __exit rtl8366rb_exit(void)
{ … }
module_exit(rtl8366rb_exit);
MODULE_AUTHOR(…) …;
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;
MODULE_IMPORT_NS(…);