1
2
3
4
5
6
7
8
9
10
11#ifndef __LINUX_NET_DSA_H
12#define __LINUX_NET_DSA_H
13
14#include <linux/if_ether.h>
15#include <linux/list.h>
16#include <linux/timer.h>
17#include <linux/workqueue.h>
18
19#define DSA_MAX_SWITCHES 4
20#define DSA_MAX_PORTS 12
21
22struct dsa_chip_data {
23
24
25
26 struct device *mii_bus;
27 int sw_addr;
28
29
30
31
32
33
34
35
36 char *port_names[DSA_MAX_PORTS];
37
38
39
40
41
42
43
44 s8 *rtable;
45};
46
47struct dsa_platform_data {
48
49
50
51
52 struct device *netdev;
53
54
55
56
57
58 int nr_chips;
59 struct dsa_chip_data *chip;
60};
61
62struct dsa_switch_tree {
63
64
65
66
67 struct dsa_platform_data *pd;
68
69
70
71
72
73 struct net_device *master_netdev;
74 __be16 tag_protocol;
75
76
77
78
79 s8 cpu_switch;
80 s8 cpu_port;
81
82
83
84
85 int link_poll_needed;
86 struct work_struct link_poll_work;
87 struct timer_list link_poll_timer;
88
89
90
91
92 struct dsa_switch *ds[DSA_MAX_SWITCHES];
93};
94
95struct dsa_switch {
96
97
98
99 struct dsa_switch_tree *dst;
100 int index;
101
102
103
104
105 struct dsa_chip_data *pd;
106
107
108
109
110 struct dsa_switch_driver *drv;
111
112
113
114
115 struct mii_bus *master_mii_bus;
116
117
118
119
120 u32 dsa_port_mask;
121 u32 phys_port_mask;
122 struct mii_bus *slave_mii_bus;
123 struct net_device *ports[DSA_MAX_PORTS];
124};
125
126static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
127{
128 return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
129}
130
131static inline u8 dsa_upstream_port(struct dsa_switch *ds)
132{
133 struct dsa_switch_tree *dst = ds->dst;
134
135
136
137
138
139
140
141 if (dst->cpu_switch == ds->index)
142 return dst->cpu_port;
143 else
144 return ds->pd->rtable[dst->cpu_switch];
145}
146
147struct dsa_switch_driver {
148 struct list_head list;
149
150 __be16 tag_protocol;
151 int priv_size;
152
153
154
155
156 char *(*probe)(struct mii_bus *bus, int sw_addr);
157 int (*setup)(struct dsa_switch *ds);
158 int (*set_addr)(struct dsa_switch *ds, u8 *addr);
159
160
161
162
163 int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
164 int (*phy_write)(struct dsa_switch *ds, int port,
165 int regnum, u16 val);
166
167
168
169
170 void (*poll_link)(struct dsa_switch *ds);
171
172
173
174
175 void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
176 void (*get_ethtool_stats)(struct dsa_switch *ds,
177 int port, uint64_t *data);
178 int (*get_sset_count)(struct dsa_switch *ds);
179};
180
181void register_switch_driver(struct dsa_switch_driver *type);
182void unregister_switch_driver(struct dsa_switch_driver *type);
183
184
185
186
187
188
189
190
191static inline bool dsa_uses_dsa_tags(struct dsa_switch_tree *dst)
192{
193 return !!(dst->tag_protocol == htons(ETH_P_DSA));
194}
195
196static inline bool dsa_uses_trailer_tags(struct dsa_switch_tree *dst)
197{
198 return !!(dst->tag_protocol == htons(ETH_P_TRAILER));
199}
200
201#endif
202