generic: rtl8366: introduce rtl8366_smi_alloc
[openwrt/svn-archive/archive.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 char buf[4096];
49 #ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
50 struct dentry *debugfs_root;
51 u16 dbg_reg;
52 #endif
53 };
54
55 struct rtl8366_vlan_mc {
56 u16 vid;
57 u8 priority;
58 u8 untag;
59 u8 member;
60 u8 fid;
61 };
62
63 struct rtl8366_vlan_4k {
64 u16 vid;
65 u8 untag;
66 u8 member;
67 u8 fid;
68 };
69
70 struct rtl8366_smi_ops {
71 int (*detect)(struct rtl8366_smi *smi);
72
73 int (*mii_read)(struct mii_bus *bus, int addr, int reg);
74 int (*mii_write)(struct mii_bus *bus, int addr, int reg, u16 val);
75
76 int (*get_vlan_mc)(struct rtl8366_smi *smi, u32 index,
77 struct rtl8366_vlan_mc *vlanmc);
78 int (*set_vlan_mc)(struct rtl8366_smi *smi, u32 index,
79 const struct rtl8366_vlan_mc *vlanmc);
80 int (*get_vlan_4k)(struct rtl8366_smi *smi, u32 vid,
81 struct rtl8366_vlan_4k *vlan4k);
82 int (*set_vlan_4k)(struct rtl8366_smi *smi,
83 const struct rtl8366_vlan_4k *vlan4k);
84 int (*get_mc_index)(struct rtl8366_smi *smi, int port, int *val);
85 int (*set_mc_index)(struct rtl8366_smi *smi, int port, int index);
86 int (*get_mib_counter)(struct rtl8366_smi *smi, int counter,
87 int port, unsigned long long *val);
88 };
89
90 struct rtl8366_smi *rtl8366_smi_alloc(struct device *parent);
91 int rtl8366_smi_init(struct rtl8366_smi *smi);
92 void rtl8366_smi_cleanup(struct rtl8366_smi *smi);
93 int rtl8366_smi_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data);
94 int rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data);
95 int rtl8366_smi_rmwr(struct rtl8366_smi *smi, u32 addr, u32 mask, u32 data);
96
97 int rtl8366_set_vlan(struct rtl8366_smi *smi, int vid, u32 member, u32 untag,
98 u32 fid);
99 int rtl8366_reset_vlan(struct rtl8366_smi *smi);
100 int rtl8366_get_pvid(struct rtl8366_smi *smi, int port, int *val);
101 int rtl8366_set_pvid(struct rtl8366_smi *smi, unsigned port, unsigned vid);
102
103 #ifdef CONFIG_RTL8366S_PHY_DEBUG_FS
104 int rtl8366_debugfs_open(struct inode *inode, struct file *file);
105 #endif
106
107 static inline struct rtl8366_smi *sw_to_rtl8366_smi(struct switch_dev *sw)
108 {
109 return container_of(sw, struct rtl8366_smi, sw_dev);
110 }
111
112 #endif /* _RTL8366_SMI_H */