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
{
28 struct rtl8366_vlan_mc
{
36 struct rtl8366_vlan_4k
{
45 struct gpio_desc
*reset
;
46 struct gpio_desc
*mdc
;
47 struct gpio_desc
*mdio
;
49 struct mii_bus
*slave_mii_bus
;
51 unsigned int clk_delay
;
54 spinlock_t lock
; /* Locks around command writes */
55 struct dsa_switch
*ds
;
56 struct irq_domain
*irqdomain
;
59 unsigned int cpu_port
;
60 unsigned int num_ports
;
61 unsigned int num_vlan_mc
;
62 unsigned int num_mib_counters
;
63 struct rtl8366_mib_counter
*mib_counters
;
65 const struct realtek_smi_ops
*ops
;
74 * struct realtek_smi_ops - vtable for the per-SMI-chiptype operations
75 * @detect: detects the chiptype
77 struct realtek_smi_ops
{
78 int (*detect
)(struct realtek_smi
*smi
);
79 int (*reset_chip
)(struct realtek_smi
*smi
);
80 int (*setup
)(struct realtek_smi
*smi
);
81 void (*cleanup
)(struct realtek_smi
*smi
);
82 int (*get_mib_counter
)(struct realtek_smi
*smi
,
84 struct rtl8366_mib_counter
*mib
,
86 int (*get_vlan_mc
)(struct realtek_smi
*smi
, u32 index
,
87 struct rtl8366_vlan_mc
*vlanmc
);
88 int (*set_vlan_mc
)(struct realtek_smi
*smi
, u32 index
,
89 const struct rtl8366_vlan_mc
*vlanmc
);
90 int (*get_vlan_4k
)(struct realtek_smi
*smi
, u32 vid
,
91 struct rtl8366_vlan_4k
*vlan4k
);
92 int (*set_vlan_4k
)(struct realtek_smi
*smi
,
93 const struct rtl8366_vlan_4k
*vlan4k
);
94 int (*get_mc_index
)(struct realtek_smi
*smi
, int port
, int *val
);
95 int (*set_mc_index
)(struct realtek_smi
*smi
, int port
, int index
);
96 bool (*is_vlan_valid
)(struct realtek_smi
*smi
, unsigned int vlan
);
97 int (*enable_vlan
)(struct realtek_smi
*smi
, bool enable
);
98 int (*enable_vlan4k
)(struct realtek_smi
*smi
, bool enable
);
99 int (*enable_port
)(struct realtek_smi
*smi
, int port
, bool enable
);
100 int (*phy_read
)(struct realtek_smi
*smi
, int phy
, int regnum
);
101 int (*phy_write
)(struct realtek_smi
*smi
, int phy
, int regnum
,
105 struct realtek_smi_variant
{
106 const struct dsa_switch_ops
*ds_ops
;
107 const struct realtek_smi_ops
*ops
;
108 unsigned int clk_delay
;
114 int realtek_smi_write_reg_noack(struct realtek_smi
*smi
, u32 addr
,
116 int realtek_smi_setup_mdio(struct realtek_smi
*smi
);
118 /* RTL8366 library helpers */
119 int rtl8366_mc_is_used(struct realtek_smi
*smi
, int mc_index
, int *used
);
120 int rtl8366_set_vlan(struct realtek_smi
*smi
, int vid
, u32 member
,
122 int rtl8366_get_pvid(struct realtek_smi
*smi
, int port
, int *val
);
123 int rtl8366_set_pvid(struct realtek_smi
*smi
, unsigned int port
,
125 int rtl8366_enable_vlan4k(struct realtek_smi
*smi
, bool enable
);
126 int rtl8366_enable_vlan(struct realtek_smi
*smi
, bool enable
);
127 int rtl8366_reset_vlan(struct realtek_smi
*smi
);
128 int rtl8366_init_vlan(struct realtek_smi
*smi
);
129 int rtl8366_vlan_filtering(struct dsa_switch
*ds
, int port
,
130 bool vlan_filtering
);
131 int rtl8366_vlan_prepare(struct dsa_switch
*ds
, int port
,
132 const struct switchdev_obj_port_vlan
*vlan
);
133 void rtl8366_vlan_add(struct dsa_switch
*ds
, int port
,
134 const struct switchdev_obj_port_vlan
*vlan
);
135 int rtl8366_vlan_del(struct dsa_switch
*ds
, int port
,
136 const struct switchdev_obj_port_vlan
*vlan
);
137 void rtl8366_get_strings(struct dsa_switch
*ds
, int port
, u32 stringset
,
139 int rtl8366_get_sset_count(struct dsa_switch
*ds
, int port
, int sset
);
140 void rtl8366_get_ethtool_stats(struct dsa_switch
*ds
, int port
, uint64_t *data
);
142 extern const struct realtek_smi_variant rtl8366rb_variant
;
144 #endif /* _REALTEK_SMI_H */