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