xref: /linux/drivers/net/dsa/realtek/realtek.h (revision 1f8d99de1d1b4b3764203ae02db57041475dab84)
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Realtek SMI interface driver defines
3  *
4  * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org>
5  * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
6  */
7 
8 #ifndef _REALTEK_SMI_H
9 #define _REALTEK_SMI_H
10 
11 #include <linux/phy.h>
12 #include <linux/platform_device.h>
13 #include <linux/gpio/consumer.h>
14 #include <net/dsa.h>
15 
16 struct realtek_ops;
17 struct dentry;
18 struct inode;
19 struct file;
20 
21 struct rtl8366_mib_counter {
22 	unsigned int	base;
23 	unsigned int	offset;
24 	unsigned int	length;
25 	const char	*name;
26 };
27 
28 /*
29  * struct rtl8366_vlan_mc - Virtual LAN member configuration
30  */
31 struct rtl8366_vlan_mc {
32 	u16	vid;
33 	u16	untag;
34 	u16	member;
35 	u8	fid;
36 	u8	priority;
37 };
38 
39 struct rtl8366_vlan_4k {
40 	u16	vid;
41 	u16	untag;
42 	u16	member;
43 	u8	fid;
44 };
45 
46 struct realtek_priv {
47 	struct device		*dev;
48 	struct gpio_desc	*reset;
49 	struct gpio_desc	*mdc;
50 	struct gpio_desc	*mdio;
51 	struct regmap		*map;
52 	struct mii_bus		*slave_mii_bus;
53 	struct mii_bus		*bus;
54 	int			mdio_addr;
55 
56 	unsigned int		clk_delay;
57 	u8			cmd_read;
58 	u8			cmd_write;
59 	spinlock_t		lock; /* Locks around command writes */
60 	struct dsa_switch	*ds;
61 	struct irq_domain	*irqdomain;
62 	bool			leds_disabled;
63 
64 	unsigned int		cpu_port;
65 	unsigned int		num_ports;
66 	unsigned int		num_vlan_mc;
67 	unsigned int		num_mib_counters;
68 	struct rtl8366_mib_counter *mib_counters;
69 
70 	const struct realtek_ops *ops;
71 	int			(*setup_interface)(struct dsa_switch *ds);
72 	int			(*write_reg_noack)(void *ctx, u32 addr, u32 data);
73 
74 	int			vlan_enabled;
75 	int			vlan4k_enabled;
76 
77 	char			buf[4096];
78 	void			*chip_data; /* Per-chip extra variant data */
79 };
80 
81 /*
82  * struct realtek_ops - vtable for the per-SMI-chiptype operations
83  * @detect: detects the chiptype
84  */
85 struct realtek_ops {
86 	int	(*detect)(struct realtek_priv *priv);
87 	int	(*reset_chip)(struct realtek_priv *priv);
88 	int	(*setup)(struct realtek_priv *priv);
89 	void	(*cleanup)(struct realtek_priv *priv);
90 	int	(*get_mib_counter)(struct realtek_priv *priv,
91 				   int port,
92 				   struct rtl8366_mib_counter *mib,
93 				   u64 *mibvalue);
94 	int	(*get_vlan_mc)(struct realtek_priv *priv, u32 index,
95 			       struct rtl8366_vlan_mc *vlanmc);
96 	int	(*set_vlan_mc)(struct realtek_priv *priv, u32 index,
97 			       const struct rtl8366_vlan_mc *vlanmc);
98 	int	(*get_vlan_4k)(struct realtek_priv *priv, u32 vid,
99 			       struct rtl8366_vlan_4k *vlan4k);
100 	int	(*set_vlan_4k)(struct realtek_priv *priv,
101 			       const struct rtl8366_vlan_4k *vlan4k);
102 	int	(*get_mc_index)(struct realtek_priv *priv, int port, int *val);
103 	int	(*set_mc_index)(struct realtek_priv *priv, int port, int index);
104 	bool	(*is_vlan_valid)(struct realtek_priv *priv, unsigned int vlan);
105 	int	(*enable_vlan)(struct realtek_priv *priv, bool enable);
106 	int	(*enable_vlan4k)(struct realtek_priv *priv, bool enable);
107 	int	(*enable_port)(struct realtek_priv *priv, int port, bool enable);
108 	int	(*phy_read)(struct realtek_priv *priv, int phy, int regnum);
109 	int	(*phy_write)(struct realtek_priv *priv, int phy, int regnum,
110 			     u16 val);
111 };
112 
113 struct realtek_variant {
114 	const struct dsa_switch_ops *ds_ops_smi;
115 	const struct dsa_switch_ops *ds_ops_mdio;
116 	const struct realtek_ops *ops;
117 	unsigned int clk_delay;
118 	u8 cmd_read;
119 	u8 cmd_write;
120 	size_t chip_data_sz;
121 };
122 
123 /* RTL8366 library helpers */
124 int rtl8366_mc_is_used(struct realtek_priv *priv, int mc_index, int *used);
125 int rtl8366_set_vlan(struct realtek_priv *priv, int vid, u32 member,
126 		     u32 untag, u32 fid);
127 int rtl8366_set_pvid(struct realtek_priv *priv, unsigned int port,
128 		     unsigned int vid);
129 int rtl8366_enable_vlan4k(struct realtek_priv *priv, bool enable);
130 int rtl8366_enable_vlan(struct realtek_priv *priv, bool enable);
131 int rtl8366_reset_vlan(struct realtek_priv *priv);
132 int rtl8366_vlan_add(struct dsa_switch *ds, int port,
133 		     const struct switchdev_obj_port_vlan *vlan,
134 		     struct netlink_ext_ack *extack);
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,
138 			 uint8_t *data);
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);
141 
142 extern const struct realtek_variant rtl8366rb_variant;
143 extern const struct realtek_variant rtl8365mb_variant;
144 
145 #endif /*  _REALTEK_SMI_H */
146