Linux Audio

Check our new training course

Loading...
v4.17
 
  1/*
  2 * net/dsa/dsa_priv.h - Hardware switch handling
  3 * Copyright (c) 2008-2009 Marvell Semiconductor
  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
 14#include <linux/phy.h>
 15#include <linux/netdevice.h>
 16#include <linux/netpoll.h>
 17#include <net/dsa.h>
 18
 19enum {
 20	DSA_NOTIFIER_AGEING_TIME,
 21	DSA_NOTIFIER_BRIDGE_JOIN,
 22	DSA_NOTIFIER_BRIDGE_LEAVE,
 23	DSA_NOTIFIER_FDB_ADD,
 24	DSA_NOTIFIER_FDB_DEL,
 25	DSA_NOTIFIER_MDB_ADD,
 26	DSA_NOTIFIER_MDB_DEL,
 27	DSA_NOTIFIER_VLAN_ADD,
 28	DSA_NOTIFIER_VLAN_DEL,
 29};
 30
 31/* DSA_NOTIFIER_AGEING_TIME */
 32struct dsa_notifier_ageing_time_info {
 33	struct switchdev_trans *trans;
 34	unsigned int ageing_time;
 35};
 36
 37/* DSA_NOTIFIER_BRIDGE_* */
 38struct dsa_notifier_bridge_info {
 39	struct net_device *br;
 40	int sw_index;
 41	int port;
 42};
 43
 44/* DSA_NOTIFIER_FDB_* */
 45struct dsa_notifier_fdb_info {
 46	int sw_index;
 47	int port;
 48	const unsigned char *addr;
 49	u16 vid;
 50};
 51
 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
 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
 68struct dsa_slave_priv {
 69	/* Copy of CPU port xmit for faster access in slave transmit hot path */
 70	struct sk_buff *	(*xmit)(struct sk_buff *skb,
 71					struct net_device *dev);
 72
 73	struct pcpu_sw_netstats	*stats64;
 74
 75	/* DSA port data, such as switch, port index, etc. */
 76	struct dsa_port		*dp;
 77
 78	/*
 79	 * The phylib phy_device pointer for the PHY connected
 80	 * to this port.
 81	 */
 82	phy_interface_t		phy_interface;
 83	int			old_link;
 84	int			old_pause;
 85	int			old_duplex;
 86
 87#ifdef CONFIG_NET_POLL_CONTROLLER
 88	struct netpoll		*netpoll;
 89#endif
 90
 91	/* TC context */
 92	struct list_head	mall_tc_list;
 93};
 94
 95/* dsa.c */
 96const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
 97bool dsa_schedule_work(struct work_struct *work);
 98
 99/* legacy.c */
100#if IS_ENABLED(CONFIG_NET_DSA_LEGACY)
101int dsa_legacy_register(void);
102void dsa_legacy_unregister(void);
103#else
104static inline int dsa_legacy_register(void)
105{
106	return 0;
107}
108
109static inline void dsa_legacy_unregister(void) { }
110#endif
111int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
112		       struct net_device *dev,
113		       const unsigned char *addr, u16 vid,
114		       u16 flags);
 
115int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
116		       struct net_device *dev,
117		       const unsigned char *addr, u16 vid);
118
119/* master.c */
120int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
121void dsa_master_teardown(struct net_device *dev);
122
123static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
124						       int device, int port)
125{
126	struct dsa_port *cpu_dp = dev->dsa_ptr;
127	struct dsa_switch_tree *dst = cpu_dp->dst;
128	struct dsa_switch *ds;
129	struct dsa_port *slave_port;
130
131	if (device < 0 || device >= DSA_MAX_SWITCHES)
132		return NULL;
133
134	ds = dst->ds[device];
135	if (!ds)
136		return NULL;
137
138	if (port < 0 || port >= ds->num_ports)
139		return NULL;
140
141	slave_port = &ds->ports[port];
142
143	if (unlikely(slave_port->type != DSA_PORT_TYPE_USER))
144		return NULL;
145
146	return slave_port->slave;
147}
148
149/* port.c */
150int dsa_port_set_state(struct dsa_port *dp, u8 state,
151		       struct switchdev_trans *trans);
152int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy);
153void dsa_port_disable(struct dsa_port *dp, struct phy_device *phy);
154int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br);
155void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br);
156int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
157			    struct switchdev_trans *trans);
158int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock,
159			 struct switchdev_trans *trans);
160int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
161		     u16 vid);
162int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
163		     u16 vid);
164int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data);
165int dsa_port_mdb_add(const struct dsa_port *dp,
166		     const struct switchdev_obj_port_mdb *mdb,
167		     struct switchdev_trans *trans);
168int dsa_port_mdb_del(const struct dsa_port *dp,
169		     const struct switchdev_obj_port_mdb *mdb);
 
 
 
 
 
 
170int dsa_port_vlan_add(struct dsa_port *dp,
171		      const struct switchdev_obj_port_vlan *vlan,
172		      struct switchdev_trans *trans);
173int dsa_port_vlan_del(struct dsa_port *dp,
174		      const struct switchdev_obj_port_vlan *vlan);
 
 
175int dsa_port_link_register_of(struct dsa_port *dp);
176void dsa_port_link_unregister_of(struct dsa_port *dp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
178/* slave.c */
179extern const struct dsa_device_ops notag_netdev_ops;
180void dsa_slave_mii_bus_init(struct dsa_switch *ds);
181int dsa_slave_create(struct dsa_port *dp);
182void dsa_slave_destroy(struct net_device *slave_dev);
183int dsa_slave_suspend(struct net_device *slave_dev);
184int dsa_slave_resume(struct net_device *slave_dev);
185int dsa_slave_register_notifier(void);
186void dsa_slave_unregister_notifier(void);
187
 
 
188static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
189{
190	struct dsa_slave_priv *p = netdev_priv(dev);
191
192	return p->dp;
193}
194
195static inline struct net_device *
196dsa_slave_to_master(const struct net_device *dev)
197{
198	struct dsa_port *dp = dsa_slave_to_port(dev);
199
200	return dp->cpu_dp->master;
201}
202
203/* switch.c */
204int dsa_switch_register_notifier(struct dsa_switch *ds);
205void dsa_switch_unregister_notifier(struct dsa_switch *ds);
206
207/* tag_brcm.c */
208extern const struct dsa_device_ops brcm_netdev_ops;
209extern const struct dsa_device_ops brcm_prepend_netdev_ops;
210
211/* tag_dsa.c */
212extern const struct dsa_device_ops dsa_netdev_ops;
213
214/* tag_edsa.c */
215extern const struct dsa_device_ops edsa_netdev_ops;
216
217/* tag_ksz.c */
218extern const struct dsa_device_ops ksz_netdev_ops;
219
220/* tag_lan9303.c */
221extern const struct dsa_device_ops lan9303_netdev_ops;
222
223/* tag_mtk.c */
224extern const struct dsa_device_ops mtk_netdev_ops;
225
226/* tag_qca.c */
227extern const struct dsa_device_ops qca_netdev_ops;
228
229/* tag_trailer.c */
230extern const struct dsa_device_ops trailer_netdev_ops;
231
232#endif
v5.4
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2/*
  3 * net/dsa/dsa_priv.h - Hardware switch handling
  4 * Copyright (c) 2008-2009 Marvell Semiconductor
 
 
 
 
 
  5 */
  6
  7#ifndef __DSA_PRIV_H
  8#define __DSA_PRIV_H
  9
 10#include <linux/phy.h>
 11#include <linux/netdevice.h>
 12#include <linux/netpoll.h>
 13#include <net/dsa.h>
 14
 15enum {
 16	DSA_NOTIFIER_AGEING_TIME,
 17	DSA_NOTIFIER_BRIDGE_JOIN,
 18	DSA_NOTIFIER_BRIDGE_LEAVE,
 19	DSA_NOTIFIER_FDB_ADD,
 20	DSA_NOTIFIER_FDB_DEL,
 21	DSA_NOTIFIER_MDB_ADD,
 22	DSA_NOTIFIER_MDB_DEL,
 23	DSA_NOTIFIER_VLAN_ADD,
 24	DSA_NOTIFIER_VLAN_DEL,
 25};
 26
 27/* DSA_NOTIFIER_AGEING_TIME */
 28struct dsa_notifier_ageing_time_info {
 29	struct switchdev_trans *trans;
 30	unsigned int ageing_time;
 31};
 32
 33/* DSA_NOTIFIER_BRIDGE_* */
 34struct dsa_notifier_bridge_info {
 35	struct net_device *br;
 36	int sw_index;
 37	int port;
 38};
 39
 40/* DSA_NOTIFIER_FDB_* */
 41struct dsa_notifier_fdb_info {
 42	int sw_index;
 43	int port;
 44	const unsigned char *addr;
 45	u16 vid;
 46};
 47
 48/* DSA_NOTIFIER_MDB_* */
 49struct 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
 56/* DSA_NOTIFIER_VLAN_* */
 57struct 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
 64struct 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);
 68
 69	struct pcpu_sw_netstats	*stats64;
 70
 71	/* DSA port data, such as switch, port index, etc. */
 72	struct dsa_port		*dp;
 73
 
 
 
 
 
 
 
 
 
 74#ifdef CONFIG_NET_POLL_CONTROLLER
 75	struct netpoll		*netpoll;
 76#endif
 77
 78	/* TC context */
 79	struct list_head	mall_tc_list;
 80};
 81
 82/* dsa.c */
 83const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol);
 84void dsa_tag_driver_put(const struct dsa_device_ops *ops);
 85
 86bool dsa_schedule_work(struct work_struct *work);
 87const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops);
 
 
 
 
 
 
 
 88
 
 
 89int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
 90		       struct net_device *dev,
 91		       const unsigned char *addr, u16 vid,
 92		       u16 flags,
 93		       struct netlink_ext_ack *extack);
 94int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
 95		       struct net_device *dev,
 96		       const unsigned char *addr, u16 vid);
 97
 98/* master.c */
 99int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
100void dsa_master_teardown(struct net_device *dev);
101
102static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
103						       int device, int port)
104{
105	struct dsa_port *cpu_dp = dev->dsa_ptr;
106	struct dsa_switch_tree *dst = cpu_dp->dst;
107	struct dsa_switch *ds;
108	struct dsa_port *slave_port;
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
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;
126}
127
128/* port.c */
129int dsa_port_set_state(struct dsa_port *dp, u8 state,
130		       struct switchdev_trans *trans);
131int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy);
132void dsa_port_disable(struct dsa_port *dp);
133int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br);
134void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br);
135int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
136			    struct switchdev_trans *trans);
137int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock,
138			 struct switchdev_trans *trans);
139int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
140		     u16 vid);
141int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
142		     u16 vid);
143int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data);
144int dsa_port_mdb_add(const struct dsa_port *dp,
145		     const struct switchdev_obj_port_mdb *mdb,
146		     struct switchdev_trans *trans);
147int dsa_port_mdb_del(const struct dsa_port *dp,
148		     const struct switchdev_obj_port_mdb *mdb);
149int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags,
150			      struct switchdev_trans *trans);
151int dsa_port_bridge_flags(const struct dsa_port *dp, unsigned long flags,
152			  struct switchdev_trans *trans);
153int dsa_port_mrouter(struct dsa_port *dp, bool mrouter,
154		     struct switchdev_trans *trans);
155int dsa_port_vlan_add(struct dsa_port *dp,
156		      const struct switchdev_obj_port_vlan *vlan,
157		      struct switchdev_trans *trans);
158int dsa_port_vlan_del(struct dsa_port *dp,
159		      const struct switchdev_obj_port_vlan *vlan);
160int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags);
161int dsa_port_vid_del(struct dsa_port *dp, u16 vid);
162int dsa_port_link_register_of(struct dsa_port *dp);
163void dsa_port_link_unregister_of(struct dsa_port *dp);
164void dsa_port_phylink_validate(struct phylink_config *config,
165			       unsigned long *supported,
166			       struct phylink_link_state *state);
167int dsa_port_phylink_mac_link_state(struct phylink_config *config,
168				    struct phylink_link_state *state);
169void dsa_port_phylink_mac_config(struct phylink_config *config,
170				 unsigned int mode,
171				 const struct phylink_link_state *state);
172void dsa_port_phylink_mac_an_restart(struct phylink_config *config);
173void dsa_port_phylink_mac_link_down(struct phylink_config *config,
174				    unsigned int mode,
175				    phy_interface_t interface);
176void dsa_port_phylink_mac_link_up(struct phylink_config *config,
177				  unsigned int mode,
178				  phy_interface_t interface,
179				  struct phy_device *phydev);
180extern const struct phylink_mac_ops dsa_port_phylink_mac_ops;
181
182/* slave.c */
183extern const struct dsa_device_ops notag_netdev_ops;
184void dsa_slave_mii_bus_init(struct dsa_switch *ds);
185int dsa_slave_create(struct dsa_port *dp);
186void dsa_slave_destroy(struct net_device *slave_dev);
187int dsa_slave_suspend(struct net_device *slave_dev);
188int dsa_slave_resume(struct net_device *slave_dev);
189int dsa_slave_register_notifier(void);
190void dsa_slave_unregister_notifier(void);
191
192void *dsa_defer_xmit(struct sk_buff *skb, struct net_device *dev);
193
194static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
195{
196	struct dsa_slave_priv *p = netdev_priv(dev);
197
198	return p->dp;
199}
200
201static inline struct net_device *
202dsa_slave_to_master(const struct net_device *dev)
203{
204	struct dsa_port *dp = dsa_slave_to_port(dev);
205
206	return dp->cpu_dp->master;
207}
208
209/* switch.c */
210int dsa_switch_register_notifier(struct dsa_switch *ds);
211void dsa_switch_unregister_notifier(struct dsa_switch *ds);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212#endif