WIP FPC-III support
[linux/fpc-iii.git] / drivers / net / dsa / realtek-smi-core.h
blob6b6a3dec09840373384e58a9a1fa11338eec6cb8
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>
6 */
8 #ifndef _REALTEK_SMI_H
9 #define _REALTEK_SMI_H
11 #include <linux/phy.h>
12 #include <linux/platform_device.h>
13 #include <linux/gpio/consumer.h>
14 #include <net/dsa.h>
16 struct realtek_smi_ops;
17 struct dentry;
18 struct inode;
19 struct file;
21 struct rtl8366_mib_counter {
22 unsigned int base;
23 unsigned int offset;
24 unsigned int length;
25 const char *name;
28 /**
29 * struct rtl8366_vlan_mc - Virtual LAN member configuration
31 struct rtl8366_vlan_mc {
32 u16 vid;
33 u16 untag;
34 u16 member;
35 u8 fid;
36 u8 priority;
39 struct rtl8366_vlan_4k {
40 u16 vid;
41 u16 untag;
42 u16 member;
43 u8 fid;
46 struct realtek_smi {
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;
54 unsigned int clk_delay;
55 u8 cmd_read;
56 u8 cmd_write;
57 spinlock_t lock; /* Locks around command writes */
58 struct dsa_switch *ds;
59 struct irq_domain *irqdomain;
60 bool leds_disabled;
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;
70 int vlan_enabled;
71 int vlan4k_enabled;
73 char buf[4096];
74 void *chip_data; /* Per-chip extra variant data */
77 /**
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,
87 int port,
88 struct rtl8366_mib_counter *mib,
89 u64 *mibvalue);
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,
106 u16 val);
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;
113 u8 cmd_read;
114 u8 cmd_write;
115 size_t chip_data_sz;
118 /* SMI core calls */
119 int realtek_smi_write_reg_noack(struct realtek_smi *smi, u32 addr,
120 u32 data);
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,
126 u32 untag, u32 fid);
127 int rtl8366_set_pvid(struct realtek_smi *smi, unsigned int port,
128 unsigned int vid);
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,
134 bool vlan_filtering,
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,
143 uint8_t *data);
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 */