| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame^] | 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 | struct rtl8366_vlan_mc { |
| 29 | u16 vid; |
| 30 | u16 untag; |
| 31 | u16 member; |
| 32 | u8 fid; |
| 33 | u8 priority; |
| 34 | }; |
| 35 | |
| 36 | struct rtl8366_vlan_4k { |
| 37 | u16 vid; |
| 38 | u16 untag; |
| 39 | u16 member; |
| 40 | u8 fid; |
| 41 | }; |
| 42 | |
| 43 | struct realtek_smi { |
| 44 | struct device *dev; |
| 45 | struct gpio_desc *reset; |
| 46 | struct gpio_desc *mdc; |
| 47 | struct gpio_desc *mdio; |
| 48 | struct regmap *map; |
| 49 | struct mii_bus *slave_mii_bus; |
| 50 | |
| 51 | unsigned int clk_delay; |
| 52 | u8 cmd_read; |
| 53 | u8 cmd_write; |
| 54 | spinlock_t lock; /* Locks around command writes */ |
| 55 | struct dsa_switch *ds; |
| 56 | struct irq_domain *irqdomain; |
| 57 | bool leds_disabled; |
| 58 | |
| 59 | unsigned int cpu_port; |
| 60 | unsigned int num_ports; |
| 61 | unsigned int num_vlan_mc; |
| 62 | unsigned int num_mib_counters; |
| 63 | struct rtl8366_mib_counter *mib_counters; |
| 64 | |
| 65 | const struct realtek_smi_ops *ops; |
| 66 | |
| 67 | int vlan_enabled; |
| 68 | int vlan4k_enabled; |
| 69 | |
| 70 | char buf[4096]; |
| 71 | }; |
| 72 | |
| 73 | /** |
| 74 | * struct realtek_smi_ops - vtable for the per-SMI-chiptype operations |
| 75 | * @detect: detects the chiptype |
| 76 | */ |
| 77 | struct realtek_smi_ops { |
| 78 | int (*detect)(struct realtek_smi *smi); |
| 79 | int (*reset_chip)(struct realtek_smi *smi); |
| 80 | int (*setup)(struct realtek_smi *smi); |
| 81 | void (*cleanup)(struct realtek_smi *smi); |
| 82 | int (*get_mib_counter)(struct realtek_smi *smi, |
| 83 | int port, |
| 84 | struct rtl8366_mib_counter *mib, |
| 85 | u64 *mibvalue); |
| 86 | int (*get_vlan_mc)(struct realtek_smi *smi, u32 index, |
| 87 | struct rtl8366_vlan_mc *vlanmc); |
| 88 | int (*set_vlan_mc)(struct realtek_smi *smi, u32 index, |
| 89 | const struct rtl8366_vlan_mc *vlanmc); |
| 90 | int (*get_vlan_4k)(struct realtek_smi *smi, u32 vid, |
| 91 | struct rtl8366_vlan_4k *vlan4k); |
| 92 | int (*set_vlan_4k)(struct realtek_smi *smi, |
| 93 | const struct rtl8366_vlan_4k *vlan4k); |
| 94 | int (*get_mc_index)(struct realtek_smi *smi, int port, int *val); |
| 95 | int (*set_mc_index)(struct realtek_smi *smi, int port, int index); |
| 96 | bool (*is_vlan_valid)(struct realtek_smi *smi, unsigned int vlan); |
| 97 | int (*enable_vlan)(struct realtek_smi *smi, bool enable); |
| 98 | int (*enable_vlan4k)(struct realtek_smi *smi, bool enable); |
| 99 | int (*enable_port)(struct realtek_smi *smi, int port, bool enable); |
| 100 | int (*phy_read)(struct realtek_smi *smi, int phy, int regnum); |
| 101 | int (*phy_write)(struct realtek_smi *smi, int phy, int regnum, |
| 102 | u16 val); |
| 103 | }; |
| 104 | |
| 105 | struct realtek_smi_variant { |
| 106 | const struct dsa_switch_ops *ds_ops; |
| 107 | const struct realtek_smi_ops *ops; |
| 108 | unsigned int clk_delay; |
| 109 | u8 cmd_read; |
| 110 | u8 cmd_write; |
| 111 | }; |
| 112 | |
| 113 | /* SMI core calls */ |
| 114 | int realtek_smi_write_reg_noack(struct realtek_smi *smi, u32 addr, |
| 115 | u32 data); |
| 116 | int realtek_smi_setup_mdio(struct realtek_smi *smi); |
| 117 | |
| 118 | /* RTL8366 library helpers */ |
| 119 | int rtl8366_mc_is_used(struct realtek_smi *smi, int mc_index, int *used); |
| 120 | int rtl8366_set_vlan(struct realtek_smi *smi, int vid, u32 member, |
| 121 | u32 untag, u32 fid); |
| 122 | int rtl8366_get_pvid(struct realtek_smi *smi, int port, int *val); |
| 123 | int rtl8366_set_pvid(struct realtek_smi *smi, unsigned int port, |
| 124 | unsigned int vid); |
| 125 | int rtl8366_enable_vlan4k(struct realtek_smi *smi, bool enable); |
| 126 | int rtl8366_enable_vlan(struct realtek_smi *smi, bool enable); |
| 127 | int rtl8366_reset_vlan(struct realtek_smi *smi); |
| 128 | int rtl8366_init_vlan(struct realtek_smi *smi); |
| 129 | int rtl8366_vlan_filtering(struct dsa_switch *ds, int port, |
| 130 | bool vlan_filtering); |
| 131 | int rtl8366_vlan_prepare(struct dsa_switch *ds, int port, |
| 132 | const struct switchdev_obj_port_vlan *vlan); |
| 133 | void rtl8366_vlan_add(struct dsa_switch *ds, int port, |
| 134 | const struct switchdev_obj_port_vlan *vlan); |
| 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 | |
| 144 | #endif /* _REALTEK_SMI_H */ |