]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - net/dsa/dsa_priv.h
dsa: Rename dsa_resolve_tag_protocol() to _get ready for locking
[mirror_ubuntu-jammy-kernel.git] / net / dsa / dsa_priv.h
CommitLineData
91da11f8
LB
1/*
2 * net/dsa/dsa_priv.h - Hardware switch handling
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 __DSA_PRIV_H
12#define __DSA_PRIV_H
13
91da11f8 14#include <linux/phy.h>
5075314e 15#include <linux/netdevice.h>
04ff53f9 16#include <linux/netpoll.h>
ea5dd34b 17#include <net/dsa.h>
5075314e 18
52c96f9d 19enum {
1faabf74 20 DSA_NOTIFIER_AGEING_TIME,
52c96f9d
VD
21 DSA_NOTIFIER_BRIDGE_JOIN,
22 DSA_NOTIFIER_BRIDGE_LEAVE,
685fb6a4
VD
23 DSA_NOTIFIER_FDB_ADD,
24 DSA_NOTIFIER_FDB_DEL,
8ae5bcdc
VD
25 DSA_NOTIFIER_MDB_ADD,
26 DSA_NOTIFIER_MDB_DEL,
d0c627b8
VD
27 DSA_NOTIFIER_VLAN_ADD,
28 DSA_NOTIFIER_VLAN_DEL,
52c96f9d
VD
29};
30
1faabf74
VD
31/* DSA_NOTIFIER_AGEING_TIME */
32struct dsa_notifier_ageing_time_info {
33 struct switchdev_trans *trans;
34 unsigned int ageing_time;
1faabf74
VD
35};
36
52c96f9d
VD
37/* DSA_NOTIFIER_BRIDGE_* */
38struct dsa_notifier_bridge_info {
39 struct net_device *br;
40 int sw_index;
41 int port;
42};
43
685fb6a4
VD
44/* DSA_NOTIFIER_FDB_* */
45struct dsa_notifier_fdb_info {
685fb6a4
VD
46 int sw_index;
47 int port;
2acf4e6a
AS
48 const unsigned char *addr;
49 u16 vid;
685fb6a4
VD
50};
51
8ae5bcdc
VD
52/* DSA_NOTIFIER_MDB_* */
53struct dsa_notifier_mdb_info {
54 const struct switchdev_obj_port_mdb *mdb;
55 struct switchdev_trans *trans;
56 int sw_index;
57 int port;
58};
59
d0c627b8
VD
60/* DSA_NOTIFIER_VLAN_* */
61struct dsa_notifier_vlan_info {
62 const struct switchdev_obj_port_vlan *vlan;
63 struct switchdev_trans *trans;
64 int sw_index;
65 int port;
66};
67
91da11f8 68struct dsa_slave_priv {
15240248 69 /* Copy of CPU port xmit for faster access in slave transmit hot path */
4ed70ce9 70 struct sk_buff * (*xmit)(struct sk_buff *skb,
5075314e 71 struct net_device *dev);
e84665c9 72
5f6b4e14 73 struct pcpu_sw_netstats *stats64;
f613ed66 74
afdcf151
VD
75 /* DSA port data, such as switch, port index, etc. */
76 struct dsa_port *dp;
e84665c9 77
04ff53f9
FF
78#ifdef CONFIG_NET_POLL_CONTROLLER
79 struct netpoll *netpoll;
80#endif
f50f2127
FF
81
82 /* TC context */
83 struct list_head mall_tc_list;
91da11f8
LB
84};
85
91da11f8 86/* dsa.c */
c39e2a1d
AL
87const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol);
88
c9eb3e0f 89bool dsa_schedule_work(struct work_struct *work);
98cdb480 90const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops);
91da11f8 91
a6a71f19 92/* legacy.c */
2a93c1a3 93#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
a6a71f19
VD
94int dsa_legacy_register(void);
95void dsa_legacy_unregister(void);
2a93c1a3
FF
96#else
97static inline int dsa_legacy_register(void)
98{
21602e1a 99 return 0;
2a93c1a3
FF
100}
101
102static inline void dsa_legacy_unregister(void) { }
103#endif
37b8da1a
AS
104int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
105 struct net_device *dev,
106 const unsigned char *addr, u16 vid,
87b0984e
PM
107 u16 flags,
108 struct netlink_ext_ack *extack);
37b8da1a
AS
109int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
110 struct net_device *dev,
111 const unsigned char *addr, u16 vid);
a6a71f19 112
f2f23566 113/* master.c */
17a22fcf
VD
114int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
115void dsa_master_teardown(struct net_device *dev);
f2f23566 116
2231c43b
VD
117static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
118 int device, int port)
3775b1b7 119{
2f657a60
VD
120 struct dsa_port *cpu_dp = dev->dsa_ptr;
121 struct dsa_switch_tree *dst = cpu_dp->dst;
3775b1b7 122 struct dsa_switch *ds;
fc5f3376 123 struct dsa_port *slave_port;
3775b1b7
VD
124
125 if (device < 0 || device >= DSA_MAX_SWITCHES)
126 return NULL;
127
128 ds = dst->ds[device];
129 if (!ds)
130 return NULL;
131
132 if (port < 0 || port >= ds->num_ports)
133 return NULL;
134
fc5f3376
AL
135 slave_port = &ds->ports[port];
136
137 if (unlikely(slave_port->type != DSA_PORT_TYPE_USER))
138 return NULL;
139
140 return slave_port->slave;
3775b1b7
VD
141}
142
a40c175b
VD
143/* port.c */
144int dsa_port_set_state(struct dsa_port *dp, u8 state,
145 struct switchdev_trans *trans);
fb8a6a2b 146int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy);
75104db0 147void dsa_port_disable(struct dsa_port *dp);
cfbed329
VD
148int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br);
149void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br);
4d61d304
VD
150int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
151 struct switchdev_trans *trans);
d87bd94e
VD
152int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock,
153 struct switchdev_trans *trans);
2acf4e6a
AS
154int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
155 u16 vid);
156int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
157 u16 vid);
de40fc5d 158int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data);
bb9f6031 159int dsa_port_mdb_add(const struct dsa_port *dp,
3a9afea3
VD
160 const struct switchdev_obj_port_mdb *mdb,
161 struct switchdev_trans *trans);
bb9f6031 162int dsa_port_mdb_del(const struct dsa_port *dp,
3a9afea3 163 const struct switchdev_obj_port_mdb *mdb);
ea87005a
FF
164int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags,
165 struct switchdev_trans *trans);
57652796
RK
166int dsa_port_bridge_flags(const struct dsa_port *dp, unsigned long flags,
167 struct switchdev_trans *trans);
076e7133
VD
168int dsa_port_vlan_add(struct dsa_port *dp,
169 const struct switchdev_obj_port_vlan *vlan,
170 struct switchdev_trans *trans);
171int dsa_port_vlan_del(struct dsa_port *dp,
172 const struct switchdev_obj_port_vlan *vlan);
33615367
SR
173int dsa_port_link_register_of(struct dsa_port *dp);
174void dsa_port_link_unregister_of(struct dsa_port *dp);
57ab1ca2 175
91da11f8 176/* slave.c */
5075314e 177extern const struct dsa_device_ops notag_netdev_ops;
91da11f8 178void dsa_slave_mii_bus_init(struct dsa_switch *ds);
951259aa 179int dsa_slave_create(struct dsa_port *dp);
cda5c15b 180void dsa_slave_destroy(struct net_device *slave_dev);
24462549
FF
181int dsa_slave_suspend(struct net_device *slave_dev);
182int dsa_slave_resume(struct net_device *slave_dev);
88e4f0ca
VD
183int dsa_slave_register_notifier(void);
184void dsa_slave_unregister_notifier(void);
91da11f8 185
d945097b
VD
186static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
187{
188 struct dsa_slave_priv *p = netdev_priv(dev);
189
190 return p->dp;
191}
192
d0006b00
VD
193static inline struct net_device *
194dsa_slave_to_master(const struct net_device *dev)
195{
196 struct dsa_port *dp = dsa_slave_to_port(dev);
197
f8b8b1cd 198 return dp->cpu_dp->master;
d0006b00
VD
199}
200
f515f192
VD
201/* switch.c */
202int dsa_switch_register_notifier(struct dsa_switch *ds);
203void dsa_switch_unregister_notifier(struct dsa_switch *ds);
204
eb7b7211
AL
205/* tag_brcm.c */
206extern const struct dsa_device_ops brcm_netdev_ops;
b74b70c4 207extern const struct dsa_device_ops brcm_prepend_netdev_ops;
eb7b7211 208
cf85d08f 209/* tag_dsa.c */
3e8a72d1 210extern const struct dsa_device_ops dsa_netdev_ops;
cf85d08f 211
91da11f8 212/* tag_edsa.c */
3e8a72d1 213extern const struct dsa_device_ops edsa_netdev_ops;
91da11f8 214
79691192
HM
215/* tag_gswip.c */
216extern const struct dsa_device_ops gswip_netdev_ops;
217
8b8010fb 218/* tag_ksz.c */
39d6b96f 219extern const struct dsa_device_ops ksz9477_netdev_ops;
88b573af 220extern const struct dsa_device_ops ksz9893_netdev_ops;
8b8010fb 221
eb7b7211
AL
222/* tag_lan9303.c */
223extern const struct dsa_device_ops lan9303_netdev_ops;
396138f0 224
eb7b7211
AL
225/* tag_mtk.c */
226extern const struct dsa_device_ops mtk_netdev_ops;
5037d532 227
cafdc45c
JC
228/* tag_qca.c */
229extern const struct dsa_device_ops qca_netdev_ops;
91da11f8 230
eb7b7211
AL
231/* tag_trailer.c */
232extern const struct dsa_device_ops trailer_netdev_ops;
e8fe177a 233
91da11f8 234#endif