1 /* SPDX-License-Identifier: GPL-2.0
3 * Microchip KSZ series switch common definitions
5 * Copyright (C) 2017-2019 Microchip Technology Inc.
11 #include <linux/kernel.h>
12 #include <linux/mutex.h>
13 #include <linux/phy.h>
14 #include <linux/etherdevice.h>
24 struct mutex cnt_mutex; /* structure access */
33 struct phy_device phydev;
35 u32 on:1; /* port is not disabled by hardware */
36 u32 phy:1; /* port has a PHY */
37 u32 fiber:1; /* port is fiber */
38 u32 sgmii:1; /* port is SGMII */
40 u32 read:1; /* read MIB counters in background */
41 u32 freeze:1; /* MIB counter freeze is enabled */
43 struct ksz_port_mib mib;
47 struct dsa_switch *ds;
48 struct ksz_platform_data *pdata;
51 struct mutex dev_mutex; /* device access */
52 struct mutex reg_mutex; /* register access */
53 struct mutex stats_mutex; /* status access */
54 struct mutex alu_mutex; /* ALU access */
55 struct mutex vlan_mutex; /* vlan access */
56 const struct ksz_io_ops *ops;
57 const struct ksz_dev_ops *dev_ops;
63 struct gpio_desc *reset_gpio; /* Optional reset GPIO */
65 /* chip specific data */
70 int cpu_port; /* port connected to CPU */
71 int cpu_ports; /* port bitmap can be cpu port */
77 int last_port; /* ports after that not used */
78 phy_interface_t interface;
81 struct vlan_table *vlan_cache;
85 struct ksz_port *ports;
86 struct timer_list mib_read_timer;
87 struct work_struct mib_read;
88 unsigned long mib_read_interval;
92 u16 on_ports; /* ports enabled by DSA */
97 u32 features; /* chip specific features */
98 u32 overrides; /* chip functions set by user */
104 int (*read8)(struct ksz_device *dev, u32 reg, u8 *value);
105 int (*read16)(struct ksz_device *dev, u32 reg, u16 *value);
106 int (*read24)(struct ksz_device *dev, u32 reg, u32 *value);
107 int (*read32)(struct ksz_device *dev, u32 reg, u32 *value);
108 int (*write8)(struct ksz_device *dev, u32 reg, u8 value);
109 int (*write16)(struct ksz_device *dev, u32 reg, u16 value);
110 int (*write24)(struct ksz_device *dev, u32 reg, u32 value);
111 int (*write32)(struct ksz_device *dev, u32 reg, u32 value);
112 int (*get)(struct ksz_device *dev, u32 reg, void *data, size_t len);
113 int (*set)(struct ksz_device *dev, u32 reg, void *data, size_t len);
136 u32 (*get_port_addr)(int port, int offset);
137 void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member);
138 void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
139 void (*phy_setup)(struct ksz_device *dev, int port,
140 struct phy_device *phy);
141 void (*port_cleanup)(struct ksz_device *dev, int port);
142 void (*port_setup)(struct ksz_device *dev, int port, bool cpu_port);
143 void (*r_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
144 void (*w_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
145 int (*r_dyn_mac_table)(struct ksz_device *dev, u16 addr, u8 *mac_addr,
146 u8 *fid, u8 *src_port, u8 *timestamp,
148 int (*r_sta_mac_table)(struct ksz_device *dev, u16 addr,
149 struct alu_struct *alu);
150 void (*w_sta_mac_table)(struct ksz_device *dev, u16 addr,
151 struct alu_struct *alu);
152 void (*r_mib_cnt)(struct ksz_device *dev, int port, u16 addr,
154 void (*r_mib_pkt)(struct ksz_device *dev, int port, u16 addr,
155 u64 *dropped, u64 *cnt);
156 void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
157 void (*port_init_cnt)(struct ksz_device *dev, int port);
158 int (*shutdown)(struct ksz_device *dev);
159 int (*detect)(struct ksz_device *dev);
160 int (*init)(struct ksz_device *dev);
161 void (*exit)(struct ksz_device *dev);
164 struct ksz_device *ksz_switch_alloc(struct device *base,
165 const struct ksz_io_ops *ops, void *priv);
166 int ksz_switch_register(struct ksz_device *dev,
167 const struct ksz_dev_ops *ops);
168 void ksz_switch_remove(struct ksz_device *dev);
170 int ksz9477_switch_register(struct ksz_device *dev);