]>
Commit | Line | Data |
---|---|---|
2874c5fd | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
91da11f8 LB |
2 | /* |
3 | * net/dsa/dsa_priv.h - Hardware switch handling | |
e84665c9 | 4 | * Copyright (c) 2008-2009 Marvell Semiconductor |
91da11f8 LB |
5 | */ |
6 | ||
7 | #ifndef __DSA_PRIV_H | |
8 | #define __DSA_PRIV_H | |
9 | ||
91da11f8 | 10 | #include <linux/phy.h> |
5075314e | 11 | #include <linux/netdevice.h> |
04ff53f9 | 12 | #include <linux/netpoll.h> |
ea5dd34b | 13 | #include <net/dsa.h> |
5075314e | 14 | |
52c96f9d | 15 | enum { |
1faabf74 | 16 | DSA_NOTIFIER_AGEING_TIME, |
52c96f9d VD |
17 | DSA_NOTIFIER_BRIDGE_JOIN, |
18 | DSA_NOTIFIER_BRIDGE_LEAVE, | |
685fb6a4 VD |
19 | DSA_NOTIFIER_FDB_ADD, |
20 | DSA_NOTIFIER_FDB_DEL, | |
8ae5bcdc VD |
21 | DSA_NOTIFIER_MDB_ADD, |
22 | DSA_NOTIFIER_MDB_DEL, | |
d0c627b8 VD |
23 | DSA_NOTIFIER_VLAN_ADD, |
24 | DSA_NOTIFIER_VLAN_DEL, | |
52c96f9d VD |
25 | }; |
26 | ||
1faabf74 VD |
27 | /* DSA_NOTIFIER_AGEING_TIME */ |
28 | struct dsa_notifier_ageing_time_info { | |
29 | struct switchdev_trans *trans; | |
30 | unsigned int ageing_time; | |
1faabf74 VD |
31 | }; |
32 | ||
52c96f9d VD |
33 | /* DSA_NOTIFIER_BRIDGE_* */ |
34 | struct dsa_notifier_bridge_info { | |
35 | struct net_device *br; | |
36 | int sw_index; | |
37 | int port; | |
38 | }; | |
39 | ||
685fb6a4 VD |
40 | /* DSA_NOTIFIER_FDB_* */ |
41 | struct dsa_notifier_fdb_info { | |
685fb6a4 VD |
42 | int sw_index; |
43 | int port; | |
2acf4e6a AS |
44 | const unsigned char *addr; |
45 | u16 vid; | |
685fb6a4 VD |
46 | }; |
47 | ||
8ae5bcdc VD |
48 | /* DSA_NOTIFIER_MDB_* */ |
49 | struct dsa_notifier_mdb_info { | |
50 | const struct switchdev_obj_port_mdb *mdb; | |
51 | struct switchdev_trans *trans; | |
52 | int sw_index; | |
53 | int port; | |
54 | }; | |
55 | ||
d0c627b8 VD |
56 | /* DSA_NOTIFIER_VLAN_* */ |
57 | struct dsa_notifier_vlan_info { | |
58 | const struct switchdev_obj_port_vlan *vlan; | |
59 | struct switchdev_trans *trans; | |
60 | int sw_index; | |
61 | int port; | |
62 | }; | |
63 | ||
91da11f8 | 64 | struct dsa_slave_priv { |
15240248 | 65 | /* Copy of CPU port xmit for faster access in slave transmit hot path */ |
4ed70ce9 | 66 | struct sk_buff * (*xmit)(struct sk_buff *skb, |
5075314e | 67 | struct net_device *dev); |
e84665c9 | 68 | |
5f6b4e14 | 69 | struct pcpu_sw_netstats *stats64; |
f613ed66 | 70 | |
afdcf151 VD |
71 | /* DSA port data, such as switch, port index, etc. */ |
72 | struct dsa_port *dp; | |
e84665c9 | 73 | |
04ff53f9 FF |
74 | #ifdef CONFIG_NET_POLL_CONTROLLER |
75 | struct netpoll *netpoll; | |
76 | #endif | |
f50f2127 FF |
77 | |
78 | /* TC context */ | |
79 | struct list_head mall_tc_list; | |
91da11f8 LB |
80 | }; |
81 | ||
91da11f8 | 82 | /* dsa.c */ |
c39e2a1d | 83 | const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol); |
4dad81ee | 84 | void dsa_tag_driver_put(const struct dsa_device_ops *ops); |
c39e2a1d | 85 | |
c9eb3e0f | 86 | bool dsa_schedule_work(struct work_struct *work); |
98cdb480 | 87 | const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops); |
91da11f8 | 88 | |
37b8da1a AS |
89 | int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
90 | struct net_device *dev, | |
91 | const unsigned char *addr, u16 vid, | |
87b0984e PM |
92 | u16 flags, |
93 | struct netlink_ext_ack *extack); | |
37b8da1a AS |
94 | int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], |
95 | struct net_device *dev, | |
96 | const unsigned char *addr, u16 vid); | |
a6a71f19 | 97 | |
f2f23566 | 98 | /* master.c */ |
17a22fcf VD |
99 | int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp); |
100 | void dsa_master_teardown(struct net_device *dev); | |
f2f23566 | 101 | |
2231c43b VD |
102 | static inline struct net_device *dsa_master_find_slave(struct net_device *dev, |
103 | int device, int port) | |
3775b1b7 | 104 | { |
2f657a60 VD |
105 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
106 | struct dsa_switch_tree *dst = cpu_dp->dst; | |
3775b1b7 | 107 | struct dsa_switch *ds; |
fc5f3376 | 108 | struct dsa_port *slave_port; |
3775b1b7 VD |
109 | |
110 | if (device < 0 || device >= DSA_MAX_SWITCHES) | |
111 | return NULL; | |
112 | ||
113 | ds = dst->ds[device]; | |
114 | if (!ds) | |
115 | return NULL; | |
116 | ||
117 | if (port < 0 || port >= ds->num_ports) | |
118 | return NULL; | |
119 | ||
fc5f3376 AL |
120 | slave_port = &ds->ports[port]; |
121 | ||
122 | if (unlikely(slave_port->type != DSA_PORT_TYPE_USER)) | |
123 | return NULL; | |
124 | ||
125 | return slave_port->slave; | |
3775b1b7 VD |
126 | } |
127 | ||
a40c175b VD |
128 | /* port.c */ |
129 | int dsa_port_set_state(struct dsa_port *dp, u8 state, | |
130 | struct switchdev_trans *trans); | |
fb8a6a2b | 131 | int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy); |
75104db0 | 132 | void dsa_port_disable(struct dsa_port *dp); |
cfbed329 VD |
133 | int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br); |
134 | void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br); | |
4d61d304 VD |
135 | int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, |
136 | struct switchdev_trans *trans); | |
d87bd94e VD |
137 | int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock, |
138 | struct switchdev_trans *trans); | |
2acf4e6a AS |
139 | int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
140 | u16 vid); | |
141 | int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, | |
142 | u16 vid); | |
de40fc5d | 143 | int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data); |
bb9f6031 | 144 | int dsa_port_mdb_add(const struct dsa_port *dp, |
3a9afea3 VD |
145 | const struct switchdev_obj_port_mdb *mdb, |
146 | struct switchdev_trans *trans); | |
bb9f6031 | 147 | int dsa_port_mdb_del(const struct dsa_port *dp, |
3a9afea3 | 148 | const struct switchdev_obj_port_mdb *mdb); |
ea87005a FF |
149 | int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags, |
150 | struct switchdev_trans *trans); | |
57652796 RK |
151 | int dsa_port_bridge_flags(const struct dsa_port *dp, unsigned long flags, |
152 | struct switchdev_trans *trans); | |
076e7133 VD |
153 | int dsa_port_vlan_add(struct dsa_port *dp, |
154 | const struct switchdev_obj_port_vlan *vlan, | |
155 | struct switchdev_trans *trans); | |
156 | int dsa_port_vlan_del(struct dsa_port *dp, | |
157 | const struct switchdev_obj_port_vlan *vlan); | |
314f76d7 VO |
158 | int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags); |
159 | int dsa_port_vid_del(struct dsa_port *dp, u16 vid); | |
33615367 SR |
160 | int dsa_port_link_register_of(struct dsa_port *dp); |
161 | void dsa_port_link_unregister_of(struct dsa_port *dp); | |
57ab1ca2 | 162 | |
91da11f8 | 163 | /* slave.c */ |
5075314e | 164 | extern const struct dsa_device_ops notag_netdev_ops; |
91da11f8 | 165 | void dsa_slave_mii_bus_init(struct dsa_switch *ds); |
951259aa | 166 | int dsa_slave_create(struct dsa_port *dp); |
cda5c15b | 167 | void dsa_slave_destroy(struct net_device *slave_dev); |
24462549 FF |
168 | int dsa_slave_suspend(struct net_device *slave_dev); |
169 | int dsa_slave_resume(struct net_device *slave_dev); | |
88e4f0ca VD |
170 | int dsa_slave_register_notifier(void); |
171 | void dsa_slave_unregister_notifier(void); | |
91da11f8 | 172 | |
97a69a0d VO |
173 | void *dsa_defer_xmit(struct sk_buff *skb, struct net_device *dev); |
174 | ||
d945097b VD |
175 | static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev) |
176 | { | |
177 | struct dsa_slave_priv *p = netdev_priv(dev); | |
178 | ||
179 | return p->dp; | |
180 | } | |
181 | ||
d0006b00 VD |
182 | static inline struct net_device * |
183 | dsa_slave_to_master(const struct net_device *dev) | |
184 | { | |
185 | struct dsa_port *dp = dsa_slave_to_port(dev); | |
186 | ||
f8b8b1cd | 187 | return dp->cpu_dp->master; |
d0006b00 VD |
188 | } |
189 | ||
f515f192 VD |
190 | /* switch.c */ |
191 | int dsa_switch_register_notifier(struct dsa_switch *ds); | |
192 | void dsa_switch_unregister_notifier(struct dsa_switch *ds); | |
91da11f8 | 193 | #endif |