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