net: dsa: allow switches to work without tagging
[deliverable/linux.git] / include / net / dsa.h
CommitLineData
91da11f8
LB
1/*
2 * include/net/dsa.h - Driver for Distributed Switch Architecture switch chips
e84665c9 3 * Copyright (c) 2008-2009 Marvell Semiconductor
91da11f8
LB
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 */
10
11#ifndef __LINUX_NET_DSA_H
12#define __LINUX_NET_DSA_H
13
ea1f51be 14#include <linux/if_ether.h>
c8f0b869 15#include <linux/list.h>
cf50dcc2
BH
16#include <linux/timer.h>
17#include <linux/workqueue.h>
fa981d9a 18#include <linux/of.h>
cf50dcc2 19
e84665c9
LB
20#define DSA_MAX_SWITCHES 4
21#define DSA_MAX_PORTS 12
22
23struct dsa_chip_data {
24 /*
25 * How to access the switch configuration registers.
26 */
27 struct device *mii_bus;
28 int sw_addr;
29
fa981d9a
FF
30 /* Device tree node pointer for this specific switch chip
31 * used during switch setup in case additional properties
32 * and resources needs to be used
33 */
34 struct device_node *of_node;
35
e84665c9
LB
36 /*
37 * The names of the switch's ports. Use "cpu" to
38 * designate the switch port that the cpu is connected to,
39 * "dsa" to indicate that this port is a DSA link to
40 * another switch, NULL to indicate the port is unused,
41 * or any other string to indicate this is a physical port.
42 */
43 char *port_names[DSA_MAX_PORTS];
bd47497a 44 struct device_node *port_dn[DSA_MAX_PORTS];
e84665c9
LB
45
46 /*
47 * An array (with nr_chips elements) of which element [a]
48 * indicates which port on this switch should be used to
49 * send packets to that are destined for switch a. Can be
50 * NULL if there is only one switch chip.
51 */
52 s8 *rtable;
53};
91da11f8
LB
54
55struct dsa_platform_data {
56 /*
57 * Reference to a Linux network interface that connects
e84665c9 58 * to the root switch chip of the tree.
91da11f8
LB
59 */
60 struct device *netdev;
61
62 /*
e84665c9
LB
63 * Info structs describing each of the switch chips
64 * connected via this network interface.
91da11f8 65 */
e84665c9
LB
66 int nr_chips;
67 struct dsa_chip_data *chip;
91da11f8
LB
68};
69
3e8a72d1
FF
70struct dsa_device_ops;
71
cf50dcc2
BH
72struct dsa_switch_tree {
73 /*
74 * Configuration data for the platform device that owns
75 * this dsa switch tree instance.
76 */
77 struct dsa_platform_data *pd;
78
79 /*
80 * Reference to network device to use, and which tagging
81 * protocol to use.
82 */
83 struct net_device *master_netdev;
3e8a72d1 84 const struct dsa_device_ops *ops;
cf50dcc2
BH
85 __be16 tag_protocol;
86
87 /*
88 * The switch and port to which the CPU is attached.
89 */
90 s8 cpu_switch;
91 s8 cpu_port;
92
93 /*
94 * Link state polling.
95 */
96 int link_poll_needed;
97 struct work_struct link_poll_work;
98 struct timer_list link_poll_timer;
99
100 /*
101 * Data for the individual switch chips.
102 */
103 struct dsa_switch *ds[DSA_MAX_SWITCHES];
104};
105
c8f0b869
BH
106struct dsa_switch {
107 /*
108 * Parent switch tree, and switch index.
109 */
110 struct dsa_switch_tree *dst;
111 int index;
112
113 /*
114 * Configuration data for this switch.
115 */
116 struct dsa_chip_data *pd;
117
118 /*
119 * The used switch driver.
120 */
121 struct dsa_switch_driver *drv;
122
123 /*
124 * Reference to mii bus to use.
125 */
126 struct mii_bus *master_mii_bus;
127
128 /*
129 * Slave mii_bus and devices for the individual ports.
130 */
131 u32 dsa_port_mask;
132 u32 phys_port_mask;
0d8bcdd3 133 u32 phys_mii_mask;
c8f0b869
BH
134 struct mii_bus *slave_mii_bus;
135 struct net_device *ports[DSA_MAX_PORTS];
136};
137
138static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p)
139{
140 return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port);
141}
142
143static inline u8 dsa_upstream_port(struct dsa_switch *ds)
144{
145 struct dsa_switch_tree *dst = ds->dst;
146
147 /*
148 * If this is the root switch (i.e. the switch that connects
149 * to the CPU), return the cpu port number on this switch.
150 * Else return the (DSA) port number that connects to the
151 * switch that is one hop closer to the cpu.
152 */
153 if (dst->cpu_switch == ds->index)
154 return dst->cpu_port;
155 else
156 return ds->pd->rtable[dst->cpu_switch];
157}
158
159struct dsa_switch_driver {
160 struct list_head list;
161
162 __be16 tag_protocol;
163 int priv_size;
164
165 /*
166 * Probing and setup.
167 */
168 char *(*probe)(struct mii_bus *bus, int sw_addr);
169 int (*setup)(struct dsa_switch *ds);
170 int (*set_addr)(struct dsa_switch *ds, u8 *addr);
171
172 /*
173 * Access to the switch's PHY registers.
174 */
175 int (*phy_read)(struct dsa_switch *ds, int port, int regnum);
176 int (*phy_write)(struct dsa_switch *ds, int port,
177 int regnum, u16 val);
178
179 /*
180 * Link state polling and IRQ handling.
181 */
182 void (*poll_link)(struct dsa_switch *ds);
183
184 /*
185 * ethtool hardware statistics.
186 */
187 void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data);
188 void (*get_ethtool_stats)(struct dsa_switch *ds,
189 int port, uint64_t *data);
190 int (*get_sset_count)(struct dsa_switch *ds);
191};
192
193void register_switch_driver(struct dsa_switch_driver *type);
194void unregister_switch_driver(struct dsa_switch_driver *type);
195
7fa857ed
FF
196static inline void *ds_to_priv(struct dsa_switch *ds)
197{
198 return (void *)(ds + 1);
199}
200
5aed85ce
FF
201static inline bool dsa_uses_tagged_protocol(struct dsa_switch_tree *dst)
202{
203 return dst->tag_protocol != 0;
204}
205
91da11f8 206#endif
This page took 0.4675 seconds and 5 git commands to generate.