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;
83 struct vlan_table *vlan_cache;
87 struct ksz_port *ports;
88 struct timer_list mib_read_timer;
89 struct work_struct mib_read;
90 unsigned long mib_read_interval;
94 u16 on_ports; /* ports enabled by DSA */
99 u32 features; /* chip specific features */
100 u32 overrides; /* chip functions set by user */
106 int (*read8)(struct ksz_device *dev, u32 reg, u8 *value);
107 int (*read16)(struct ksz_device *dev, u32 reg, u16 *value);
108 int (*read24)(struct ksz_device *dev, u32 reg, u32 *value);
109 int (*read32)(struct ksz_device *dev, u32 reg, u32 *value);
110 int (*write8)(struct ksz_device *dev, u32 reg, u8 value);
111 int (*write16)(struct ksz_device *dev, u32 reg, u16 value);
112 int (*write24)(struct ksz_device *dev, u32 reg, u32 value);
113 int (*write32)(struct ksz_device *dev, u32 reg, u32 value);
114 int (*get)(struct ksz_device *dev, u32 reg, void *data, size_t len);
115 int (*set)(struct ksz_device *dev, u32 reg, void *data, size_t len);
138 u32 (*get_port_addr)(int port, int offset);
139 void (*cfg_port_member)(struct ksz_device *dev, int port, u8 member);
140 void (*flush_dyn_mac_table)(struct ksz_device *dev, int port);
141 void (*phy_setup)(struct ksz_device *dev, int port,
142 struct phy_device *phy);
143 void (*port_cleanup)(struct ksz_device *dev, int port);
144 void (*port_setup)(struct ksz_device *dev, int port, bool cpu_port);
145 void (*r_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 *val);
146 void (*w_phy)(struct ksz_device *dev, u16 phy, u16 reg, u16 val);
147 int (*r_dyn_mac_table)(struct ksz_device *dev, u16 addr, u8 *mac_addr,
148 u8 *fid, u8 *src_port, u8 *timestamp,
150 int (*r_sta_mac_table)(struct ksz_device *dev, u16 addr,
151 struct alu_struct *alu);
152 void (*w_sta_mac_table)(struct ksz_device *dev, u16 addr,
153 struct alu_struct *alu);
154 void (*r_mib_cnt)(struct ksz_device *dev, int port, u16 addr,
156 void (*r_mib_pkt)(struct ksz_device *dev, int port, u16 addr,
157 u64 *dropped, u64 *cnt);
158 void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze);
159 void (*port_init_cnt)(struct ksz_device *dev, int port);
160 int (*shutdown)(struct ksz_device *dev);
161 int (*detect)(struct ksz_device *dev);
162 int (*init)(struct ksz_device *dev);
163 void (*exit)(struct ksz_device *dev);
166 struct ksz_device *ksz_switch_alloc(struct device *base,
167 const struct ksz_io_ops *ops, void *priv);
168 int ksz_switch_register(struct ksz_device *dev,
169 const struct ksz_dev_ops *ops);
170 void ksz_switch_remove(struct ksz_device *dev);
172 int ksz9477_switch_register(struct ksz_device *dev);