1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * net/dsa/dsa_priv.h - Hardware switch handling
4 * Copyright (c) 2008-2009 Marvell Semiconductor
10 #include <linux/phy.h>
11 #include <linux/netdevice.h>
12 #include <linux/netpoll.h>
16 DSA_NOTIFIER_AGEING_TIME
,
17 DSA_NOTIFIER_BRIDGE_JOIN
,
18 DSA_NOTIFIER_BRIDGE_LEAVE
,
23 DSA_NOTIFIER_VLAN_ADD
,
24 DSA_NOTIFIER_VLAN_DEL
,
27 /* DSA_NOTIFIER_AGEING_TIME */
28 struct dsa_notifier_ageing_time_info
{
29 struct switchdev_trans
*trans
;
30 unsigned int ageing_time
;
33 /* DSA_NOTIFIER_BRIDGE_* */
34 struct dsa_notifier_bridge_info
{
35 struct net_device
*br
;
40 /* DSA_NOTIFIER_FDB_* */
41 struct dsa_notifier_fdb_info
{
44 const unsigned char *addr
;
48 /* DSA_NOTIFIER_MDB_* */
49 struct dsa_notifier_mdb_info
{
50 const struct switchdev_obj_port_mdb
*mdb
;
51 struct switchdev_trans
*trans
;
56 /* DSA_NOTIFIER_VLAN_* */
57 struct dsa_notifier_vlan_info
{
58 const struct switchdev_obj_port_vlan
*vlan
;
59 struct switchdev_trans
*trans
;
64 struct dsa_slave_priv
{
65 /* Copy of CPU port xmit for faster access in slave transmit hot path */
66 struct sk_buff
* (*xmit
)(struct sk_buff
*skb
,
67 struct net_device
*dev
);
69 struct pcpu_sw_netstats
*stats64
;
71 /* DSA port data, such as switch, port index, etc. */
74 #ifdef CONFIG_NET_POLL_CONTROLLER
75 struct netpoll
*netpoll
;
79 struct list_head mall_tc_list
;
83 const struct dsa_device_ops
*dsa_tag_driver_get(int tag_protocol
);
84 void dsa_tag_driver_put(const struct dsa_device_ops
*ops
);
86 bool dsa_schedule_work(struct work_struct
*work
);
87 const char *dsa_tag_protocol_to_str(const struct dsa_device_ops
*ops
);
89 int dsa_legacy_fdb_add(struct ndmsg
*ndm
, struct nlattr
*tb
[],
90 struct net_device
*dev
,
91 const unsigned char *addr
, u16 vid
,
93 struct netlink_ext_ack
*extack
);
94 int dsa_legacy_fdb_del(struct ndmsg
*ndm
, struct nlattr
*tb
[],
95 struct net_device
*dev
,
96 const unsigned char *addr
, u16 vid
);
99 int dsa_master_setup(struct net_device
*dev
, struct dsa_port
*cpu_dp
);
100 void dsa_master_teardown(struct net_device
*dev
);
102 static inline struct net_device
*dsa_master_find_slave(struct net_device
*dev
,
103 int device
, int port
)
105 struct dsa_port
*cpu_dp
= dev
->dsa_ptr
;
106 struct dsa_switch_tree
*dst
= cpu_dp
->dst
;
109 list_for_each_entry(dp
, &dst
->ports
, list
)
110 if (dp
->ds
->index
== device
&& dp
->index
== port
&&
111 dp
->type
== DSA_PORT_TYPE_USER
)
118 int dsa_port_set_state(struct dsa_port
*dp
, u8 state
,
119 struct switchdev_trans
*trans
);
120 int dsa_port_enable(struct dsa_port
*dp
, struct phy_device
*phy
);
121 void dsa_port_disable(struct dsa_port
*dp
);
122 int dsa_port_bridge_join(struct dsa_port
*dp
, struct net_device
*br
);
123 void dsa_port_bridge_leave(struct dsa_port
*dp
, struct net_device
*br
);
124 int dsa_port_vlan_filtering(struct dsa_port
*dp
, bool vlan_filtering
,
125 struct switchdev_trans
*trans
);
126 int dsa_port_ageing_time(struct dsa_port
*dp
, clock_t ageing_clock
,
127 struct switchdev_trans
*trans
);
128 int dsa_port_fdb_add(struct dsa_port
*dp
, const unsigned char *addr
,
130 int dsa_port_fdb_del(struct dsa_port
*dp
, const unsigned char *addr
,
132 int dsa_port_fdb_dump(struct dsa_port
*dp
, dsa_fdb_dump_cb_t
*cb
, void *data
);
133 int dsa_port_mdb_add(const struct dsa_port
*dp
,
134 const struct switchdev_obj_port_mdb
*mdb
,
135 struct switchdev_trans
*trans
);
136 int dsa_port_mdb_del(const struct dsa_port
*dp
,
137 const struct switchdev_obj_port_mdb
*mdb
);
138 int dsa_port_pre_bridge_flags(const struct dsa_port
*dp
, unsigned long flags
,
139 struct switchdev_trans
*trans
);
140 int dsa_port_bridge_flags(const struct dsa_port
*dp
, unsigned long flags
,
141 struct switchdev_trans
*trans
);
142 int dsa_port_mrouter(struct dsa_port
*dp
, bool mrouter
,
143 struct switchdev_trans
*trans
);
144 int dsa_port_vlan_add(struct dsa_port
*dp
,
145 const struct switchdev_obj_port_vlan
*vlan
,
146 struct switchdev_trans
*trans
);
147 int dsa_port_vlan_del(struct dsa_port
*dp
,
148 const struct switchdev_obj_port_vlan
*vlan
);
149 int dsa_port_vid_add(struct dsa_port
*dp
, u16 vid
, u16 flags
);
150 int dsa_port_vid_del(struct dsa_port
*dp
, u16 vid
);
151 int dsa_port_link_register_of(struct dsa_port
*dp
);
152 void dsa_port_link_unregister_of(struct dsa_port
*dp
);
153 void dsa_port_phylink_validate(struct phylink_config
*config
,
154 unsigned long *supported
,
155 struct phylink_link_state
*state
);
156 void dsa_port_phylink_mac_pcs_get_state(struct phylink_config
*config
,
157 struct phylink_link_state
*state
);
158 void dsa_port_phylink_mac_config(struct phylink_config
*config
,
160 const struct phylink_link_state
*state
);
161 void dsa_port_phylink_mac_an_restart(struct phylink_config
*config
);
162 void dsa_port_phylink_mac_link_down(struct phylink_config
*config
,
164 phy_interface_t interface
);
165 void dsa_port_phylink_mac_link_up(struct phylink_config
*config
,
167 phy_interface_t interface
,
168 struct phy_device
*phydev
);
169 extern const struct phylink_mac_ops dsa_port_phylink_mac_ops
;
172 extern const struct dsa_device_ops notag_netdev_ops
;
173 void dsa_slave_mii_bus_init(struct dsa_switch
*ds
);
174 int dsa_slave_create(struct dsa_port
*dp
);
175 void dsa_slave_destroy(struct net_device
*slave_dev
);
176 int dsa_slave_suspend(struct net_device
*slave_dev
);
177 int dsa_slave_resume(struct net_device
*slave_dev
);
178 int dsa_slave_register_notifier(void);
179 void dsa_slave_unregister_notifier(void);
181 void *dsa_defer_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
183 static inline struct dsa_port
*dsa_slave_to_port(const struct net_device
*dev
)
185 struct dsa_slave_priv
*p
= netdev_priv(dev
);
190 static inline struct net_device
*
191 dsa_slave_to_master(const struct net_device
*dev
)
193 struct dsa_port
*dp
= dsa_slave_to_port(dev
);
195 return dp
->cpu_dp
->master
;
199 int dsa_switch_register_notifier(struct dsa_switch
*ds
);
200 void dsa_switch_unregister_notifier(struct dsa_switch
*ds
);