1 /* SPDX-License-Identifier: GPL-2.0
2 * Microchip switch driver common header
4 * Copyright (C) 2017-2019 Microchip Technology Inc.
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
,
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
)
46 mutex_lock(&dev
->reg_mutex
);
47 ret
= dev
->ops
->read8(dev
, reg
, val
);
48 mutex_unlock(&dev
->reg_mutex
);
53 static inline int ksz_read16(struct ksz_device
*dev
, u32 reg
, u16
*val
)
57 mutex_lock(&dev
->reg_mutex
);
58 ret
= dev
->ops
->read16(dev
, reg
, val
);
59 mutex_unlock(&dev
->reg_mutex
);
64 static inline int ksz_read24(struct ksz_device
*dev
, u32 reg
, u32
*val
)
68 mutex_lock(&dev
->reg_mutex
);
69 ret
= dev
->ops
->read24(dev
, reg
, val
);
70 mutex_unlock(&dev
->reg_mutex
);
75 static inline int ksz_read32(struct ksz_device
*dev
, u32 reg
, u32
*val
)
79 mutex_lock(&dev
->reg_mutex
);
80 ret
= dev
->ops
->read32(dev
, reg
, val
);
81 mutex_unlock(&dev
->reg_mutex
);
86 static inline int ksz_write8(struct ksz_device
*dev
, u32 reg
, u8 value
)
90 mutex_lock(&dev
->reg_mutex
);
91 ret
= dev
->ops
->write8(dev
, reg
, value
);
92 mutex_unlock(&dev
->reg_mutex
);
97 static inline int ksz_write16(struct ksz_device
*dev
, u32 reg
, u16 value
)
101 mutex_lock(&dev
->reg_mutex
);
102 ret
= dev
->ops
->write16(dev
, reg
, value
);
103 mutex_unlock(&dev
->reg_mutex
);
108 static inline int ksz_write24(struct ksz_device
*dev
, u32 reg
, u32 value
)
112 mutex_lock(&dev
->reg_mutex
);
113 ret
= dev
->ops
->write24(dev
, reg
, value
);
114 mutex_unlock(&dev
->reg_mutex
);
119 static inline int ksz_write32(struct ksz_device
*dev
, u32 reg
, u32 value
)
123 mutex_lock(&dev
->reg_mutex
);
124 ret
= dev
->ops
->write32(dev
, reg
, value
);
125 mutex_unlock(&dev
->reg_mutex
);
130 static inline int ksz_get(struct ksz_device
*dev
, u32 reg
, void *data
,
135 mutex_lock(&dev
->reg_mutex
);
136 ret
= dev
->ops
->get(dev
, reg
, data
, len
);
137 mutex_unlock(&dev
->reg_mutex
);
142 static inline int ksz_set(struct ksz_device
*dev
, u32 reg
, void *data
,
147 mutex_lock(&dev
->reg_mutex
);
148 ret
= dev
->ops
->set(dev
, reg
, data
, len
);
149 mutex_unlock(&dev
->reg_mutex
);
154 static inline void ksz_pread8(struct ksz_device
*dev
, int port
, int offset
,
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
,
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
,
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
,
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
,
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
,
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
)
194 ksz_read8(dev
, addr
, &data
);
199 ksz_write8(dev
, addr
, data
);
202 static void ksz_port_cfg(struct ksz_device
*dev
, int port
, int offset
, u8 bits
,
208 addr
= dev
->dev_ops
->get_port_addr(port
, offset
);
209 ksz_read8(dev
, addr
, &data
);
216 ksz_write8(dev
, addr
, data
);
219 struct ksz_poll_ctx
{
220 struct ksz_device
*dev
;
225 static inline u32
ksz_pread32_poll(struct ksz_poll_ctx
*ctx
)
229 ksz_pread32(ctx
->dev
, ctx
->port
, ctx
->offset
, &data
);