1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Realtek SMI interface driver defines
4 * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
5 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
11 #include <linux/phy.h>
12 #include <linux/platform_device.h>
13 #include <linux/gpio/consumer.h>
16 struct realtek_smi_ops
;
21 struct rtl8366_mib_counter
{
29 * struct rtl8366_vlan_mc - Virtual LAN member configuration
31 struct rtl8366_vlan_mc
{
39 struct rtl8366_vlan_4k
{
48 struct gpio_desc
*reset
;
49 struct gpio_desc
*mdc
;
50 struct gpio_desc
*mdio
;
52 struct mii_bus
*slave_mii_bus
;
54 unsigned int clk_delay
;
57 spinlock_t lock
; /* Locks around command writes */
58 struct dsa_switch
*ds
;
59 struct irq_domain
*irqdomain
;
62 unsigned int cpu_port
;
63 unsigned int num_ports
;
64 unsigned int num_vlan_mc
;
65 unsigned int num_mib_counters
;
66 struct rtl8366_mib_counter
*mib_counters
;
68 const struct realtek_smi_ops
*ops
;
74 void *chip_data
; /* Per-chip extra variant data */
78 * struct realtek_smi_ops - vtable for the per-SMI-chiptype operations
79 * @detect: detects the chiptype
81 struct realtek_smi_ops
{
82 int (*detect
)(struct realtek_smi
*smi
);
83 int (*reset_chip
)(struct realtek_smi
*smi
);
84 int (*setup
)(struct realtek_smi
*smi
);
85 void (*cleanup
)(struct realtek_smi
*smi
);
86 int (*get_mib_counter
)(struct realtek_smi
*smi
,
88 struct rtl8366_mib_counter
*mib
,
90 int (*get_vlan_mc
)(struct realtek_smi
*smi
, u32 index
,
91 struct rtl8366_vlan_mc
*vlanmc
);
92 int (*set_vlan_mc
)(struct realtek_smi
*smi
, u32 index
,
93 const struct rtl8366_vlan_mc
*vlanmc
);
94 int (*get_vlan_4k
)(struct realtek_smi
*smi
, u32 vid
,
95 struct rtl8366_vlan_4k
*vlan4k
);
96 int (*set_vlan_4k
)(struct realtek_smi
*smi
,
97 const struct rtl8366_vlan_4k
*vlan4k
);
98 int (*get_mc_index
)(struct realtek_smi
*smi
, int port
, int *val
);
99 int (*set_mc_index
)(struct realtek_smi
*smi
, int port
, int index
);
100 bool (*is_vlan_valid
)(struct realtek_smi
*smi
, unsigned int vlan
);
101 int (*enable_vlan
)(struct realtek_smi
*smi
, bool enable
);
102 int (*enable_vlan4k
)(struct realtek_smi
*smi
, bool enable
);
103 int (*enable_port
)(struct realtek_smi
*smi
, int port
, bool enable
);
104 int (*phy_read
)(struct realtek_smi
*smi
, int phy
, int regnum
);
105 int (*phy_write
)(struct realtek_smi
*smi
, int phy
, int regnum
,
109 struct realtek_smi_variant
{
110 const struct dsa_switch_ops
*ds_ops
;
111 const struct realtek_smi_ops
*ops
;
112 unsigned int clk_delay
;
119 int realtek_smi_write_reg_noack(struct realtek_smi
*smi
, u32 addr
,
121 int realtek_smi_setup_mdio(struct realtek_smi
*smi
);
123 /* RTL8366 library helpers */
124 int rtl8366_mc_is_used(struct realtek_smi
*smi
, int mc_index
, int *used
);
125 int rtl8366_set_vlan(struct realtek_smi
*smi
, int vid
, u32 member
,
127 int rtl8366_set_pvid(struct realtek_smi
*smi
, unsigned int port
,
129 int rtl8366_enable_vlan4k(struct realtek_smi
*smi
, bool enable
);
130 int rtl8366_enable_vlan(struct realtek_smi
*smi
, bool enable
);
131 int rtl8366_reset_vlan(struct realtek_smi
*smi
);
132 int rtl8366_init_vlan(struct realtek_smi
*smi
);
133 int rtl8366_vlan_filtering(struct dsa_switch
*ds
, int port
,
135 struct switchdev_trans
*trans
);
136 int rtl8366_vlan_prepare(struct dsa_switch
*ds
, int port
,
137 const struct switchdev_obj_port_vlan
*vlan
);
138 void rtl8366_vlan_add(struct dsa_switch
*ds
, int port
,
139 const struct switchdev_obj_port_vlan
*vlan
);
140 int rtl8366_vlan_del(struct dsa_switch
*ds
, int port
,
141 const struct switchdev_obj_port_vlan
*vlan
);
142 void rtl8366_get_strings(struct dsa_switch
*ds
, int port
, u32 stringset
,
144 int rtl8366_get_sset_count(struct dsa_switch
*ds
, int port
, int sset
);
145 void rtl8366_get_ethtool_stats(struct dsa_switch
*ds
, int port
, uint64_t *data
);
147 extern const struct realtek_smi_variant rtl8366rb_variant
;
149 #endif /* _REALTEK_SMI_H */