ksz_common.h 3.8 KB
Newer Older
1 2 3
/* SPDX-License-Identifier: GPL-2.0
 * Microchip switch driver common header
 *
4
 * Copyright (C) 2017-2019 Microchip Technology Inc.
5 6 7 8 9
 */

#ifndef __KSZ_COMMON_H
#define __KSZ_COMMON_H

10 11
#include <linux/regmap.h>

12
void ksz_port_cleanup(struct ksz_device *dev, int port);
13
void ksz_update_port_member(struct ksz_device *dev, int port);
14
void ksz_init_mib_timer(struct ksz_device *dev);
15 16 17 18 19

/* Common DSA access functions */

int ksz_phy_read16(struct dsa_switch *ds, int addr, int reg);
int ksz_phy_write16(struct dsa_switch *ds, int addr, int reg, u16 val);
20 21
void ksz_adjust_link(struct dsa_switch *ds, int port,
		     struct phy_device *phydev);
22
int ksz_sset_count(struct dsa_switch *ds, int port, int sset);
23
void ksz_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *buf);
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
int ksz_port_bridge_join(struct dsa_switch *ds, int port,
			 struct net_device *br);
void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
			   struct net_device *br);
void ksz_port_fast_age(struct dsa_switch *ds, int port);
int ksz_port_vlan_prepare(struct dsa_switch *ds, int port,
			  const struct switchdev_obj_port_vlan *vlan);
int ksz_port_fdb_dump(struct dsa_switch *ds, int port, dsa_fdb_dump_cb_t *cb,
		      void *data);
int ksz_port_mdb_prepare(struct dsa_switch *ds, int port,
			 const struct switchdev_obj_port_mdb *mdb);
void ksz_port_mdb_add(struct dsa_switch *ds, int port,
		      const struct switchdev_obj_port_mdb *mdb);
int ksz_port_mdb_del(struct dsa_switch *ds, int port,
		     const struct switchdev_obj_port_mdb *mdb);
int ksz_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy);
40
void ksz_disable_port(struct dsa_switch *ds, int port);
41 42 43 44 45

/* Common register access functions */

static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val)
{
46 47
	unsigned int value;
	int ret = regmap_read(dev->regmap[0], reg, &value);
48

49
	*val = value;
50 51 52 53 54
	return ret;
}

static inline int ksz_read16(struct ksz_device *dev, u32 reg, u16 *val)
{
55 56
	unsigned int value;
	int ret = regmap_read(dev->regmap[1], reg, &value);
57

58
	*val = value;
59 60 61 62 63
	return ret;
}

static inline int ksz_read32(struct ksz_device *dev, u32 reg, u32 *val)
{
64 65
	unsigned int value;
	int ret = regmap_read(dev->regmap[2], reg, &value);
66

67
	*val = value;
68 69 70 71 72
	return ret;
}

static inline int ksz_write8(struct ksz_device *dev, u32 reg, u8 value)
{
73
	return regmap_write(dev->regmap[0], reg, value);
74 75 76 77
}

static inline int ksz_write16(struct ksz_device *dev, u32 reg, u16 value)
{
78
	return regmap_write(dev->regmap[1], reg, value);
79 80 81 82
}

static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value)
{
83
	return regmap_write(dev->regmap[2], reg, value);
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
}

static inline void ksz_pread8(struct ksz_device *dev, int port, int offset,
			      u8 *data)
{
	ksz_read8(dev, dev->dev_ops->get_port_addr(port, offset), data);
}

static inline void ksz_pread16(struct ksz_device *dev, int port, int offset,
			       u16 *data)
{
	ksz_read16(dev, dev->dev_ops->get_port_addr(port, offset), data);
}

static inline void ksz_pread32(struct ksz_device *dev, int port, int offset,
			       u32 *data)
{
	ksz_read32(dev, dev->dev_ops->get_port_addr(port, offset), data);
}

static inline void ksz_pwrite8(struct ksz_device *dev, int port, int offset,
			       u8 data)
{
	ksz_write8(dev, dev->dev_ops->get_port_addr(port, offset), data);
}

static inline void ksz_pwrite16(struct ksz_device *dev, int port, int offset,
				u16 data)
{
	ksz_write16(dev, dev->dev_ops->get_port_addr(port, offset), data);
}

static inline void ksz_pwrite32(struct ksz_device *dev, int port, int offset,
				u32 data)
{
	ksz_write32(dev, dev->dev_ops->get_port_addr(port, offset), data);
}

122 123 124 125 126 127 128 129 130 131 132 133 134 135
struct ksz_poll_ctx {
	struct ksz_device *dev;
	int port;
	int offset;
};

static inline u32 ksz_pread32_poll(struct ksz_poll_ctx *ctx)
{
	u32 data;

	ksz_pread32(ctx->dev, ctx->port, ctx->offset, &data);
	return data;
}

136
#endif