3fcae81fa45d617e794c9f4d24ff5d4e4d14e40e
[openwrt/openwrt.git] / target / linux / generic / files / drivers / net / phy / rtl8366_smi.h
1 /*
2 * Realtek RTL8366 SMI interface driver defines
3 *
4 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11 #ifndef _RTL8366_SMI_H
12 #define _RTL8366_SMI_H
13
14 #include <linux/phy.h>
15 #include <linux/switch.h>
16 #include <linux/platform_device.h>
17 #include <linux/reset.h>
18
19 struct rtl8366_smi_ops;
20 struct rtl8366_vlan_ops;
21 struct mii_bus;
22 struct dentry;
23 struct inode;
24 struct file;
25
26 struct rtl8366_mib_counter {
27 unsigned base;
28 unsigned offset;
29 unsigned length;
30 const char *name;
31 };
32
33 struct rtl8366_smi {
34 struct device *parent;
35 unsigned int gpio_sda;
36 unsigned int gpio_sck;
37 void (*hw_reset)(struct rtl8366_smi *smi, bool active);
38 unsigned int clk_delay; /* ns */
39 u8 cmd_read;
40 u8 cmd_write;
41 spinlock_t lock;
42 struct mii_bus *mii_bus;
43 int mii_irq[PHY_MAX_ADDR];
44 struct switch_dev sw_dev;
45
46 unsigned int cpu_port;
47 unsigned int num_ports;
48 unsigned int num_vlan_mc;
49 unsigned int num_mib_counters;
50 struct rtl8366_mib_counter *mib_counters;
51
52 struct rtl8366_smi_ops *ops;
53
54 int vlan_enabled;
55 int vlan4k_enabled;
56
57 char buf[4096];
58
59 struct reset_control *reset;
60
61 #ifdef CONFIG_RTL8366_SMI_DEBUG_FS
62 struct dentry *debugfs_root;
63 u16 dbg_reg;
64 u8 dbg_vlan_4k_page;
65 #endif
66 u32 phy_id;
67 struct mii_bus *ext_mbus;
68 };
69
70 struct rtl8366_vlan_mc {
71 u16 vid;
72 u16 untag;
73 u16 member;
74 u8 fid;
75 u8 priority;
76 };
77
78 struct rtl8366_vlan_4k {
79 u16 vid;
80 u16 untag;
81 u16 member;
82 u8 fid;
83 };
84
85 struct rtl8366_smi_ops {
86 int (*detect)(struct rtl8366_smi *smi);
87 int (*reset_chip)(struct rtl8366_smi *smi);
88 int (*setup)(struct rtl8366_smi *smi);
89
90 int (*mii_read)(struct mii_bus *bus, int addr, int reg);
91 int (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val);
92
93 int (*get_vlan_mc)(struct rtl8366_smi *smi, u32 index,
94 struct rtl8366_vlan_mc *vlanmc);
95 int (*set_vlan_mc)(struct rtl8366_smi *smi, u32 index,
96 const struct rtl8366_vlan_mc *vlanmc);
97 int (*get_vlan_4k)(struct rtl8366_smi *smi, u32 vid,
98 struct rtl8366_vlan_4k *vlan4k);
99 int (*set_vlan_4k)(struct rtl8366_smi *smi,
100 const struct rtl8366_vlan_4k *vlan4k);
101 int (*get_mc_index)(struct rtl8366_smi *smi, int port, int *val);
102 int (*set_mc_index)(struct rtl8366_smi *smi, int port, int index);
103 int (*get_mib_counter)(struct rtl8366_smi *smi, int counter,
104 int port, unsigned long long *val);
105 int (*is_vlan_valid)(struct rtl8366_smi *smi, unsigned vlan);
106 int (*enable_vlan)(struct rtl8366_smi *smi, int enable);
107 int (*enable_vlan4k)(struct rtl8366_smi *smi, int enable);
108 int (*enable_port)(struct rtl8366_smi *smi, int port, int enable);
109 };
110
111 struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent);
112 int rtl8366_smi_init(struct rtl8366_smi *smi);
113 void rtl8366_smi_cleanup(struct rtl8366_smi *smi);
114 int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data);
115 int rtl8366_smi_write_reg_noack(struct rtl8366_smi *smi, u32 addr, u32 data);
116 int rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data);
117 int rtl8366_smi_rmwr(struct rtl8366_smi *smi, u32 addr, u32 mask, u32 data);
118
119 #ifdef CONFIG_RTL8366_SMI_DEBUG_FS
120 int rtl8366_debugfs_open(struct inode *inode, struct file *file);
121 #endif
122
123 static inline struct rtl8366_smi *sw_to_rtl8366_smi(struct switch_dev *sw)
124 {
125 return container_of(sw, struct rtl8366_smi, sw_dev);
126 }
127
128 int rtl8366_sw_reset_switch(struct switch_dev *dev);
129 int rtl8366_sw_get_port_pvid(struct switch_dev *dev, int port, int *val);
130 int rtl8366_sw_set_port_pvid(struct switch_dev *dev, int port, int val);
131 int rtl8366_sw_get_port_mib(struct switch_dev *dev,
132 const struct switch_attr *attr,
133 struct switch_val *val);
134 int rtl8366_sw_get_vlan_info(struct switch_dev *dev,
135 const struct switch_attr *attr,
136 struct switch_val *val);
137 int rtl8366_sw_get_vlan_fid(struct switch_dev *dev,
138 const struct switch_attr *attr,
139 struct switch_val *val);
140 int rtl8366_sw_set_vlan_fid(struct switch_dev *dev,
141 const struct switch_attr *attr,
142 struct switch_val *val);
143 int rtl8366_sw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val);
144 int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val);
145 int rtl8366_sw_get_vlan_enable(struct switch_dev *dev,
146 const struct switch_attr *attr,
147 struct switch_val *val);
148 int rtl8366_sw_set_vlan_enable(struct switch_dev *dev,
149 const struct switch_attr *attr,
150 struct switch_val *val);
151 int rtl8366_sw_get_port_stats(struct switch_dev *dev, int port,
152 struct switch_port_stats *stats,
153 int txb_id, int rxb_id);
154
155 struct rtl8366_smi* rtl8366_smi_probe(struct platform_device *pdev);
156
157 #endif /* _RTL8366_SMI_H */