Loading...
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
18struct dsa_device_ops {
19 struct sk_buff *(*xmit)(struct sk_buff *skb, struct net_device *dev);
20 int (*rcv)(struct sk_buff *skb, struct net_device *dev,
21 struct packet_type *pt, struct net_device *orig_dev);
22};
23
24struct dsa_slave_priv {
25 struct sk_buff * (*xmit)(struct sk_buff *skb,
26 struct net_device *dev);
27
28 /*
29 * Which switch this port is a part of, and the port index
30 * for this port.
31 */
32 struct dsa_switch *parent;
33 u8 port;
34
35 /*
36 * The phylib phy_device pointer for the PHY connected
37 * to this port.
38 */
39 struct phy_device *phy;
40 phy_interface_t phy_interface;
41 int old_link;
42 int old_pause;
43 int old_duplex;
44
45 struct net_device *bridge_dev;
46#ifdef CONFIG_NET_POLL_CONTROLLER
47 struct netpoll *netpoll;
48#endif
49};
50
51/* dsa.c */
52extern char dsa_driver_version[];
53int dsa_cpu_dsa_setup(struct dsa_switch *ds, struct device *dev,
54 struct device_node *port_dn, int port);
55void dsa_cpu_dsa_destroy(struct device_node *port_dn);
56const struct dsa_device_ops *dsa_resolve_tag_protocol(int tag_protocol);
57int dsa_cpu_port_ethtool_setup(struct dsa_switch *ds);
58void dsa_cpu_port_ethtool_restore(struct dsa_switch *ds);
59
60/* slave.c */
61extern const struct dsa_device_ops notag_netdev_ops;
62void dsa_slave_mii_bus_init(struct dsa_switch *ds);
63void dsa_cpu_port_ethtool_init(struct ethtool_ops *ops);
64int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
65 int port, const char *name);
66void dsa_slave_destroy(struct net_device *slave_dev);
67int dsa_slave_suspend(struct net_device *slave_dev);
68int dsa_slave_resume(struct net_device *slave_dev);
69int dsa_slave_netdevice_event(struct notifier_block *unused,
70 unsigned long event, void *ptr);
71
72/* tag_dsa.c */
73extern const struct dsa_device_ops dsa_netdev_ops;
74
75/* tag_edsa.c */
76extern const struct dsa_device_ops edsa_netdev_ops;
77
78/* tag_trailer.c */
79extern const struct dsa_device_ops trailer_netdev_ops;
80
81/* tag_brcm.c */
82extern const struct dsa_device_ops brcm_netdev_ops;
83
84/* tag_qca.c */
85extern const struct dsa_device_ops qca_netdev_ops;
86
87#endif
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#include <net/gro_cells.h>
15
16enum {
17 DSA_NOTIFIER_AGEING_TIME,
18 DSA_NOTIFIER_BRIDGE_JOIN,
19 DSA_NOTIFIER_BRIDGE_LEAVE,
20 DSA_NOTIFIER_FDB_ADD,
21 DSA_NOTIFIER_FDB_DEL,
22 DSA_NOTIFIER_MDB_ADD,
23 DSA_NOTIFIER_MDB_DEL,
24 DSA_NOTIFIER_VLAN_ADD,
25 DSA_NOTIFIER_VLAN_DEL,
26 DSA_NOTIFIER_MTU,
27};
28
29/* DSA_NOTIFIER_AGEING_TIME */
30struct dsa_notifier_ageing_time_info {
31 struct switchdev_trans *trans;
32 unsigned int ageing_time;
33};
34
35/* DSA_NOTIFIER_BRIDGE_* */
36struct dsa_notifier_bridge_info {
37 struct net_device *br;
38 int tree_index;
39 int sw_index;
40 int port;
41};
42
43/* DSA_NOTIFIER_FDB_* */
44struct dsa_notifier_fdb_info {
45 int sw_index;
46 int port;
47 const unsigned char *addr;
48 u16 vid;
49};
50
51/* DSA_NOTIFIER_MDB_* */
52struct dsa_notifier_mdb_info {
53 const struct switchdev_obj_port_mdb *mdb;
54 struct switchdev_trans *trans;
55 int sw_index;
56 int port;
57};
58
59/* DSA_NOTIFIER_VLAN_* */
60struct dsa_notifier_vlan_info {
61 const struct switchdev_obj_port_vlan *vlan;
62 struct switchdev_trans *trans;
63 int sw_index;
64 int port;
65};
66
67/* DSA_NOTIFIER_MTU */
68struct dsa_notifier_mtu_info {
69 bool propagate_upstream;
70 int sw_index;
71 int port;
72 int mtu;
73};
74
75struct dsa_slave_priv {
76 /* Copy of CPU port xmit for faster access in slave transmit hot path */
77 struct sk_buff * (*xmit)(struct sk_buff *skb,
78 struct net_device *dev);
79
80 struct pcpu_sw_netstats __percpu *stats64;
81
82 struct gro_cells gcells;
83
84 /* DSA port data, such as switch, port index, etc. */
85 struct dsa_port *dp;
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_tag_driver_get(int tag_protocol);
97void dsa_tag_driver_put(const struct dsa_device_ops *ops);
98
99bool dsa_schedule_work(struct work_struct *work);
100const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops);
101
102int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
103 struct net_device *dev,
104 const unsigned char *addr, u16 vid,
105 u16 flags,
106 struct netlink_ext_ack *extack);
107int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
108 struct net_device *dev,
109 const unsigned char *addr, u16 vid);
110
111/* master.c */
112int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp);
113void dsa_master_teardown(struct net_device *dev);
114
115static inline struct net_device *dsa_master_find_slave(struct net_device *dev,
116 int device, int port)
117{
118 struct dsa_port *cpu_dp = dev->dsa_ptr;
119 struct dsa_switch_tree *dst = cpu_dp->dst;
120 struct dsa_port *dp;
121
122 list_for_each_entry(dp, &dst->ports, list)
123 if (dp->ds->index == device && dp->index == port &&
124 dp->type == DSA_PORT_TYPE_USER)
125 return dp->slave;
126
127 return NULL;
128}
129
130/* port.c */
131int dsa_port_set_state(struct dsa_port *dp, u8 state,
132 struct switchdev_trans *trans);
133int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy);
134int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy);
135void dsa_port_disable_rt(struct dsa_port *dp);
136void dsa_port_disable(struct dsa_port *dp);
137int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br);
138void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br);
139int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
140 struct switchdev_trans *trans);
141bool dsa_port_skip_vlan_configuration(struct dsa_port *dp);
142int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock,
143 struct switchdev_trans *trans);
144int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu,
145 bool propagate_upstream);
146int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr,
147 u16 vid);
148int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr,
149 u16 vid);
150int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data);
151int dsa_port_mdb_add(const struct dsa_port *dp,
152 const struct switchdev_obj_port_mdb *mdb,
153 struct switchdev_trans *trans);
154int dsa_port_mdb_del(const struct dsa_port *dp,
155 const struct switchdev_obj_port_mdb *mdb);
156int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags,
157 struct switchdev_trans *trans);
158int dsa_port_bridge_flags(const struct dsa_port *dp, unsigned long flags,
159 struct switchdev_trans *trans);
160int dsa_port_mrouter(struct dsa_port *dp, bool mrouter,
161 struct switchdev_trans *trans);
162int dsa_port_vlan_add(struct dsa_port *dp,
163 const struct switchdev_obj_port_vlan *vlan,
164 struct switchdev_trans *trans);
165int dsa_port_vlan_del(struct dsa_port *dp,
166 const struct switchdev_obj_port_vlan *vlan);
167int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags);
168int dsa_port_vid_del(struct dsa_port *dp, u16 vid);
169int dsa_port_link_register_of(struct dsa_port *dp);
170void dsa_port_link_unregister_of(struct dsa_port *dp);
171extern const struct phylink_mac_ops dsa_port_phylink_mac_ops;
172
173/* slave.c */
174extern const struct dsa_device_ops notag_netdev_ops;
175void dsa_slave_mii_bus_init(struct dsa_switch *ds);
176int dsa_slave_create(struct dsa_port *dp);
177void dsa_slave_destroy(struct net_device *slave_dev);
178bool dsa_slave_dev_check(const struct net_device *dev);
179int dsa_slave_suspend(struct net_device *slave_dev);
180int dsa_slave_resume(struct net_device *slave_dev);
181int dsa_slave_register_notifier(void);
182void dsa_slave_unregister_notifier(void);
183
184static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev)
185{
186 struct dsa_slave_priv *p = netdev_priv(dev);
187
188 return p->dp;
189}
190
191static inline struct net_device *
192dsa_slave_to_master(const struct net_device *dev)
193{
194 struct dsa_port *dp = dsa_slave_to_port(dev);
195
196 return dp->cpu_dp->master;
197}
198
199/* switch.c */
200int dsa_switch_register_notifier(struct dsa_switch *ds);
201void dsa_switch_unregister_notifier(struct dsa_switch *ds);
202
203/* dsa2.c */
204extern struct list_head dsa_tree_list;
205
206#endif