generic: rtl8366: add generic code to enable VLANs
[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
17 struct rtl8366_smi_ops;
18 struct rtl8366_vlan_ops;
19 struct mii_bus;
20 struct dentry;
21 struct inode;
22 struct file;
23
24 struct rtl8366_mib_counter {
25         unsigned        base;
26         unsigned        offset;
27         unsigned        length;
28         const char      *name;
29 };
30
31 struct rtl8366_smi {
32         struct device           *parent;
33         unsigned int            gpio_sda;
34         unsigned int            gpio_sck;
35         spinlock_t              lock;
36         struct mii_bus          *mii_bus;
37         int                     mii_irq[PHY_MAX_ADDR];
38         struct switch_dev       sw_dev;
39
40         unsigned int            cpu_port;
41         unsigned int            num_ports;
42         unsigned int            num_vlan_mc;
43         unsigned int            num_mib_counters;
44         struct rtl8366_mib_counter *mib_counters;
45
46         struct rtl8366_smi_ops  *ops;
47
48         int                     vlan_enabled;
49         int                     vlan4k_enabled;
50
51         char                    buf[4096];
52 #ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
53         struct dentry           *debugfs_root;
54         u16                     dbg_reg;
55 #endif
56 };
57
58 struct rtl8366_vlan_mc {
59         u16     vid;
60         u8      priority;
61         u8      untag;
62         u8      member;
63         u8      fid;
64 };
65
66 struct rtl8366_vlan_4k {
67         u16     vid;
68         u8      untag;
69         u8      member;
70         u8      fid;
71 };
72
73 struct rtl8366_smi_ops {
74         int     (*detect)(struct rtl8366_smi *smi);
75         int     (*setup)(struct rtl8366_smi *smi);
76
77         int     (*mii_read)(struct mii_bus *bus, int addr, int reg);
78         int     (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val);
79
80         int     (*get_vlan_mc)(struct rtl8366_smi *smi, u32 index,
81                                struct rtl8366_vlan_mc *vlanmc);
82         int     (*set_vlan_mc)(struct rtl8366_smi *smi, u32 index,
83                                const struct rtl8366_vlan_mc *vlanmc);
84         int     (*get_vlan_4k)(struct rtl8366_smi *smi, u32 vid,
85                                struct rtl8366_vlan_4k *vlan4k);
86         int     (*set_vlan_4k)(struct rtl8366_smi *smi,
87                                const struct rtl8366_vlan_4k *vlan4k);
88         int     (*get_mc_index)(struct rtl8366_smi *smi, int port, int *val);
89         int     (*set_mc_index)(struct rtl8366_smi *smi, int port, int index);
90         int     (*get_mib_counter)(struct rtl8366_smi *smi, int counter,
91                                    int port, unsigned long long *val);
92         int     (*is_vlan_valid)(struct rtl8366_smi *smi, unsigned vlan);
93         int     (*enable_vlan)(struct rtl8366_smi *smi, int enable);
94         int     (*enable_vlan4k)(struct rtl8366_smi *smi, int enable);
95 };
96
97 struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent);
98 int rtl8366_smi_init(struct rtl8366_smi *smi);
99 void rtl8366_smi_cleanup(struct rtl8366_smi *smi);
100 int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data);
101 int rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data);
102 int rtl8366_smi_rmwr(struct rtl8366_smi *smi, u32 addr, u32 mask, u32 data);
103
104 int rtl8366_reset_vlan(struct rtl8366_smi *smi);
105
106 #ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
107 int rtl8366_debugfs_open(struct inode *inode, struct file *file);
108 #endif
109
110 static inline struct rtl8366_smi *sw_to_rtl8366_smi(struct switch_dev *sw)
111 {
112         return container_of(sw, struct rtl8366_smi, sw_dev);
113 }
114
115 int rtl8366_sw_get_port_pvid(struct switch_dev *dev, int port, int *val);
116 int rtl8366_sw_set_port_pvid(struct switch_dev *dev, int port, int val);
117 int rtl8366_sw_get_port_mib(struct switch_dev *dev,
118                             const struct switch_attr *attr,
119                             struct switch_val *val);
120 int rtl8366_sw_get_vlan_info(struct switch_dev *dev,
121                              const struct switch_attr *attr,
122                              struct switch_val *val);
123 int rtl8366_sw_get_vlan_ports(struct switch_dev *dev, struct switch_val *val);
124 int rtl8366_sw_set_vlan_ports(struct switch_dev *dev, struct switch_val *val);
125 int rtl8366_sw_get_vlan_enable(struct switch_dev *dev,
126                                const struct switch_attr *attr,
127                                struct switch_val *val);
128 int rtl8366_sw_set_vlan_enable(struct switch_dev *dev,
129                                const struct switch_attr *attr,
130                                struct switch_val *val);
131
132 #endif /*  _RTL8366_SMI_H */