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