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