dt-bindings: mtd: ingenic: Use standard ecc-engine property
[linux/fpc-iii.git] / drivers / net / dsa / microchip / ksz_common.h
blob21cd794e18f1f83bc5ed00a3f7648b9fdf6b0c4d
1 /* SPDX-License-Identifier: GPL-2.0
2 * Microchip switch driver common header
4 * Copyright (C) 2017-2019 Microchip Technology Inc.
5 */
7 #ifndef __KSZ_COMMON_H
8 #define __KSZ_COMMON_H
10 void ksz_port_cleanup(struct ksz_device *dev, int port);
11 void ksz_update_port_member(struct ksz_device *dev, int port);
12 void ksz_init_mib_timer(struct ksz_device *dev);
14 /* Common DSA access functions */
16 int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg);
17 int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val);
18 void ksz_adjust_link(struct dsa_switch *ds, int port,
19 struct phy_device *phydev);
20 int ksz_sset_count(struct dsa_switch *ds, int port, int sset);
21 void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf);
22 int ksz_port_bridge_join(struct dsa_switch *ds, int port,
23 struct net_device *br);
24 void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
25 struct net_device *br);
26 void ksz_port_fast_age(struct dsa_switch *ds, int port);
27 int ksz_port_vlan_prepare(struct dsa_switch *ds, int port,
28 const struct switchdev_obj_port_vlan *vlan);
29 int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
30 void *data);
31 int ksz_port_mdb_prepare(struct dsa_switch *ds, int port,
32 const struct switchdev_obj_port_mdb *mdb);
33 void ksz_port_mdb_add(struct dsa_switch *ds, int port,
34 const struct switchdev_obj_port_mdb *mdb);
35 int ksz_port_mdb_del(struct dsa_switch *ds, int port,
36 const struct switchdev_obj_port_mdb *mdb);
37 int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
38 void ksz_disable_port(struct dsa_switch *ds, int port);
40 /* Common register access functions */
42 static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val)
44 int ret;
46 mutex_lock(&dev->reg_mutex);
47 ret = dev->ops->read8(dev, reg, val);
48 mutex_unlock(&dev->reg_mutex);
50 return ret;
53 static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val)
55 int ret;
57 mutex_lock(&dev->reg_mutex);
58 ret = dev->ops->read16(dev, reg, val);
59 mutex_unlock(&dev->reg_mutex);
61 return ret;
64 static inline int ksz_read24(struct ksz_device *dev, u32 reg, u32 *val)
66 int ret;
68 mutex_lock(&dev->reg_mutex);
69 ret = dev->ops->read24(dev, reg, val);
70 mutex_unlock(&dev->reg_mutex);
72 return ret;
75 static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val)
77 int ret;
79 mutex_lock(&dev->reg_mutex);
80 ret = dev->ops->read32(dev, reg, val);
81 mutex_unlock(&dev->reg_mutex);
83 return ret;
86 static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value)
88 int ret;
90 mutex_lock(&dev->reg_mutex);
91 ret = dev->ops->write8(dev, reg, value);
92 mutex_unlock(&dev->reg_mutex);
94 return ret;
97 static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value)
99 int ret;
101 mutex_lock(&dev->reg_mutex);
102 ret = dev->ops->write16(dev, reg, value);
103 mutex_unlock(&dev->reg_mutex);
105 return ret;
108 static inline int ksz_write24(struct ksz_device *dev, u32 reg, u32 value)
110 int ret;
112 mutex_lock(&dev->reg_mutex);
113 ret = dev->ops->write24(dev, reg, value);
114 mutex_unlock(&dev->reg_mutex);
116 return ret;
119 static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value)
121 int ret;
123 mutex_lock(&dev->reg_mutex);
124 ret = dev->ops->write32(dev, reg, value);
125 mutex_unlock(&dev->reg_mutex);
127 return ret;
130 static inline int ksz_get(struct ksz_device *dev, u32 reg, void *data,
131 size_t len)
133 int ret;
135 mutex_lock(&dev->reg_mutex);
136 ret = dev->ops->get(dev, reg, data, len);
137 mutex_unlock(&dev->reg_mutex);
139 return ret;
142 static inline int ksz_set(struct ksz_device *dev, u32 reg, void *data,
143 size_t len)
145 int ret;
147 mutex_lock(&dev->reg_mutex);
148 ret = dev->ops->set(dev, reg, data, len);
149 mutex_unlock(&dev->reg_mutex);
151 return ret;
154 static inline void ksz_pread8(struct ksz_device *dev, int port, int offset,
155 u8 *data)
157 ksz_read8(dev, dev->dev_ops->get_port_addr(port, offset), data);
160 static inline void ksz_pread16(struct ksz_device *dev, int port, int offset,
161 u16 *data)
163 ksz_read16(dev, dev->dev_ops->get_port_addr(port, offset), data);
166 static inline void ksz_pread32(struct ksz_device *dev, int port, int offset,
167 u32 *data)
169 ksz_read32(dev, dev->dev_ops->get_port_addr(port, offset), data);
172 static inline void ksz_pwrite8(struct ksz_device *dev, int port, int offset,
173 u8 data)
175 ksz_write8(dev, dev->dev_ops->get_port_addr(port, offset), data);
178 static inline void ksz_pwrite16(struct ksz_device *dev, int port, int offset,
179 u16 data)
181 ksz_write16(dev, dev->dev_ops->get_port_addr(port, offset), data);
184 static inline void ksz_pwrite32(struct ksz_device *dev, int port, int offset,
185 u32 data)
187 ksz_write32(dev, dev->dev_ops->get_port_addr(port, offset), data);
190 static void ksz_cfg(struct ksz_device *dev, u32 addr, u8 bits, bool set)
192 u8 data;
194 ksz_read8(dev, addr, &data);
195 if (set)
196 data |= bits;
197 else
198 data &= ~bits;
199 ksz_write8(dev, addr, data);
202 static void ksz_port_cfg(struct ksz_device *dev, int port, int offset, u8 bits,
203 bool set)
205 u32 addr;
206 u8 data;
208 addr = dev->dev_ops->get_port_addr(port, offset);
209 ksz_read8(dev, addr, &data);
211 if (set)
212 data |= bits;
213 else
214 data &= ~bits;
216 ksz_write8(dev, addr, data);
219 struct ksz_poll_ctx {
220 struct ksz_device *dev;
221 int port;
222 int offset;
225 static inline u32 ksz_pread32_poll(struct ksz_poll_ctx *ctx)
227 u32 data;
229 ksz_pread32(ctx->dev, ctx->port, ctx->offset, &data);
230 return data;
233 #endif