| 1 |
/* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 |
/* Realtek SMI interface driver defines |
| 3 |
* |
| 4 |
* Copyright (C) 2017 Linus Walleij <[email protected]> |
| 5 |
* Copyright (C) 2009-2010 Gabor Juhos <[email protected]> |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef _REALTEK_H |
| 9 |
#define _REALTEK_H |
| 10 |
|
| 11 |
#include <linux/phy.h> |
| 12 |
#include <linux/platform_device.h> |
| 13 |
#include <linux/gpio/consumer.h> |
| 14 |
#include <net/dsa.h> |
| 15 |
#include <linux/reset.h> |
| 16 |
|
| 17 |
#define REALTEK_HW_STOP_DELAY 25 /* msecs */ |
| 18 |
#define REALTEK_HW_START_DELAY 100 /* msecs */ |
| 19 |
|
| 20 |
struct phylink_mac_ops; |
| 21 |
struct realtek_ops; |
| 22 |
|
| 23 |
struct rtl8366_mib_counter { |
| 24 |
unsigned int base; |
| 25 |
unsigned int offset; |
| 26 |
unsigned int length; |
| 27 |
const char *name; |
| 28 |
}; |
| 29 |
|
| 30 |
/* |
| 31 |
* struct rtl8366_vlan_mc - Virtual LAN member configuration |
| 32 |
*/ |
| 33 |
struct rtl8366_vlan_mc { |
| 34 |
u16 vid; |
| 35 |
u16 untag; |
| 36 |
u16 member; |
| 37 |
u8 fid; |
| 38 |
u8 priority; |
| 39 |
}; |
| 40 |
|
| 41 |
struct rtl8366_vlan_4k { |
| 42 |
u16 vid; |
| 43 |
u16 untag; |
| 44 |
u16 member; |
| 45 |
u8 fid; |
| 46 |
}; |
| 47 |
|
| 48 |
struct realtek_priv { |
| 49 |
struct device *dev; |
| 50 |
struct reset_control *reset_ctl; |
| 51 |
struct gpio_desc *reset; |
| 52 |
struct gpio_desc *mdc; |
| 53 |
struct gpio_desc *mdio; |
| 54 |
struct regmap *map; |
| 55 |
struct regmap *map_nolock; |
| 56 |
struct mutex map_lock; |
| 57 |
struct mii_bus *user_mii_bus; |
| 58 |
struct mii_bus *bus; |
| 59 |
int mdio_addr; |
| 60 |
|
| 61 |
const struct realtek_variant *variant; |
| 62 |
|
| 63 |
spinlock_t lock; /* Locks around command writes */ |
| 64 |
struct dsa_switch ds; |
| 65 |
struct irq_domain *irqdomain; |
| 66 |
bool leds_disabled; |
| 67 |
|
| 68 |
unsigned int cpu_port; |
| 69 |
unsigned int num_ports; |
| 70 |
unsigned int num_vlan_mc; |
| 71 |
unsigned int num_mib_counters; |
| 72 |
struct rtl8366_mib_counter *mib_counters; |
| 73 |
|
| 74 |
const struct realtek_ops *ops; |
| 75 |
int (*write_reg_noack)(void *ctx, u32 addr, u32 data); |
| 76 |
|
| 77 |
int vlan_enabled; |
| 78 |
int vlan4k_enabled; |
| 79 |
|
| 80 |
char buf[4096]; |
| 81 |
void *chip_data; /* Per-chip extra variant data */ |
| 82 |
}; |
| 83 |
|
| 84 |
/* |
| 85 |
* struct realtek_ops - vtable for the per-SMI-chiptype operations |
| 86 |
* @detect: detects the chiptype |
| 87 |
*/ |
| 88 |
struct realtek_ops { |
| 89 |
int (*detect)(struct realtek_priv *priv); |
| 90 |
int (*reset_chip)(struct realtek_priv *priv); |
| 91 |
int (*setup)(struct realtek_priv *priv); |
| 92 |
int (*get_mib_counter)(struct realtek_priv *priv, |
| 93 |
int port, |
| 94 |
struct rtl8366_mib_counter *mib, |
| 95 |
u64 *mibvalue); |
| 96 |
int (*get_vlan_mc)(struct realtek_priv *priv, u32 index, |
| 97 |
struct rtl8366_vlan_mc *vlanmc); |
| 98 |
int (*set_vlan_mc)(struct realtek_priv *priv, u32 index, |
| 99 |
const struct rtl8366_vlan_mc *vlanmc); |
| 100 |
int (*get_vlan_4k)(struct realtek_priv *priv, u32 vid, |
| 101 |
struct rtl8366_vlan_4k *vlan4k); |
| 102 |
int (*set_vlan_4k)(struct realtek_priv *priv, |
| 103 |
const struct rtl8366_vlan_4k *vlan4k); |
| 104 |
int (*get_mc_index)(struct realtek_priv *priv, int port, int *val); |
| 105 |
int (*set_mc_index)(struct realtek_priv *priv, int port, int index); |
| 106 |
bool (*is_vlan_valid)(struct realtek_priv *priv, unsigned int vlan); |
| 107 |
int (*enable_vlan)(struct realtek_priv *priv, bool enable); |
| 108 |
int (*enable_vlan4k)(struct realtek_priv *priv, bool enable); |
| 109 |
int (*enable_port)(struct realtek_priv *priv, int port, bool enable); |
| 110 |
int (*phy_read)(struct realtek_priv *priv, int phy, int regnum); |
| 111 |
int (*phy_write)(struct realtek_priv *priv, int phy, int regnum, |
| 112 |
u16 val); |
| 113 |
}; |
| 114 |
|
| 115 |
struct realtek_variant { |
| 116 |
const struct dsa_switch_ops *ds_ops; |
| 117 |
const struct realtek_ops *ops; |
| 118 |
const struct phylink_mac_ops *phylink_mac_ops; |
| 119 |
unsigned int clk_delay; |
| 120 |
u8 cmd_read; |
| 121 |
u8 cmd_write; |
| 122 |
size_t chip_data_sz; |
| 123 |
}; |
| 124 |
|
| 125 |
/* RTL8366 library helpers */ |
| 126 |
int rtl8366_mc_is_used(struct realtek_priv *priv, int mc_index, int *used); |
| 127 |
int rtl8366_set_vlan(struct realtek_priv *priv, int vid, u32 member, |
| 128 |
u32 untag, u32 fid); |
| 129 |
int rtl8366_set_pvid(struct realtek_priv *priv, unsigned int port, |
| 130 |
unsigned int vid); |
| 131 |
int rtl8366_enable_vlan4k(struct realtek_priv *priv, bool enable); |
| 132 |
int rtl8366_enable_vlan(struct realtek_priv *priv, bool enable); |
| 133 |
int rtl8366_reset_vlan(struct realtek_priv *priv); |
| 134 |
int rtl8366_vlan_add(struct dsa_switch *ds, int port, |
| 135 |
const struct switchdev_obj_port_vlan *vlan, |
| 136 |
struct netlink_ext_ack *extack); |
| 137 |
int rtl8366_vlan_del(struct dsa_switch *ds, int port, |
| 138 |
const struct switchdev_obj_port_vlan *vlan); |
| 139 |
void rtl8366_get_strings(struct dsa_switch *ds, int port, u32 stringset, |
| 140 |
uint8_t *data); |
| 141 |
int rtl8366_get_sset_count(struct dsa_switch *ds, int port, int sset); |
| 142 |
void rtl8366_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data); |
| 143 |
|
| 144 |
extern const struct realtek_variant rtl8366rb_variant; |
| 145 |
extern const struct realtek_variant rtl8365mb_variant; |
| 146 |
|
| 147 |
#endif /* _REALTEK_H */ |