David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2 | /* |
| 3 | * net/dsa/dsa_priv.h - Hardware switch handling |
| 4 | * Copyright (c) 2008-2009 Marvell Semiconductor |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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> |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 14 | #include <net/gro_cells.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 15 | |
| 16 | enum { |
| 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 | }; |
| 27 | |
| 28 | /* DSA_NOTIFIER_AGEING_TIME */ |
| 29 | struct dsa_notifier_ageing_time_info { |
| 30 | struct switchdev_trans *trans; |
| 31 | unsigned int ageing_time; |
| 32 | }; |
| 33 | |
| 34 | /* DSA_NOTIFIER_BRIDGE_* */ |
| 35 | struct dsa_notifier_bridge_info { |
| 36 | struct net_device *br; |
| 37 | int sw_index; |
| 38 | int port; |
| 39 | }; |
| 40 | |
| 41 | /* DSA_NOTIFIER_FDB_* */ |
| 42 | struct dsa_notifier_fdb_info { |
| 43 | int sw_index; |
| 44 | int port; |
| 45 | const unsigned char *addr; |
| 46 | u16 vid; |
| 47 | }; |
| 48 | |
| 49 | /* DSA_NOTIFIER_MDB_* */ |
| 50 | struct dsa_notifier_mdb_info { |
| 51 | const struct switchdev_obj_port_mdb *mdb; |
| 52 | struct switchdev_trans *trans; |
| 53 | int sw_index; |
| 54 | int port; |
| 55 | }; |
| 56 | |
| 57 | /* DSA_NOTIFIER_VLAN_* */ |
| 58 | struct dsa_notifier_vlan_info { |
| 59 | const struct switchdev_obj_port_vlan *vlan; |
| 60 | struct switchdev_trans *trans; |
| 61 | int sw_index; |
| 62 | int port; |
| 63 | }; |
| 64 | |
| 65 | struct dsa_slave_priv { |
| 66 | /* Copy of CPU port xmit for faster access in slave transmit hot path */ |
| 67 | struct sk_buff * (*xmit)(struct sk_buff *skb, |
| 68 | struct net_device *dev); |
| 69 | |
| 70 | struct pcpu_sw_netstats *stats64; |
| 71 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 72 | struct gro_cells gcells; |
| 73 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 74 | /* DSA port data, such as switch, port index, etc. */ |
| 75 | struct dsa_port *dp; |
| 76 | |
| 77 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 78 | struct netpoll *netpoll; |
| 79 | #endif |
| 80 | |
| 81 | /* TC context */ |
| 82 | struct list_head mall_tc_list; |
| 83 | }; |
| 84 | |
| 85 | /* dsa.c */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 86 | const struct dsa_device_ops *dsa_tag_driver_get(int tag_protocol); |
| 87 | void dsa_tag_driver_put(const struct dsa_device_ops *ops); |
| 88 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 89 | bool dsa_schedule_work(struct work_struct *work); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 90 | const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 91 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 92 | int dsa_legacy_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], |
| 93 | struct net_device *dev, |
| 94 | const unsigned char *addr, u16 vid, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 95 | u16 flags, |
| 96 | struct netlink_ext_ack *extack); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 97 | int dsa_legacy_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], |
| 98 | struct net_device *dev, |
| 99 | const unsigned char *addr, u16 vid); |
| 100 | |
| 101 | /* master.c */ |
| 102 | int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp); |
| 103 | void dsa_master_teardown(struct net_device *dev); |
| 104 | |
| 105 | static inline struct net_device *dsa_master_find_slave(struct net_device *dev, |
| 106 | int device, int port) |
| 107 | { |
| 108 | struct dsa_port *cpu_dp = dev->dsa_ptr; |
| 109 | struct dsa_switch_tree *dst = cpu_dp->dst; |
| 110 | struct dsa_switch *ds; |
| 111 | struct dsa_port *slave_port; |
| 112 | |
| 113 | if (device < 0 || device >= DSA_MAX_SWITCHES) |
| 114 | return NULL; |
| 115 | |
| 116 | ds = dst->ds[device]; |
| 117 | if (!ds) |
| 118 | return NULL; |
| 119 | |
| 120 | if (port < 0 || port >= ds->num_ports) |
| 121 | return NULL; |
| 122 | |
| 123 | slave_port = &ds->ports[port]; |
| 124 | |
| 125 | if (unlikely(slave_port->type != DSA_PORT_TYPE_USER)) |
| 126 | return NULL; |
| 127 | |
| 128 | return slave_port->slave; |
| 129 | } |
| 130 | |
| 131 | /* port.c */ |
| 132 | int dsa_port_set_state(struct dsa_port *dp, u8 state, |
| 133 | struct switchdev_trans *trans); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 134 | int dsa_port_enable_rt(struct dsa_port *dp, struct phy_device *phy); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 135 | int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 136 | void dsa_port_disable_rt(struct dsa_port *dp); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 137 | void dsa_port_disable(struct dsa_port *dp); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 138 | int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br); |
| 139 | void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br); |
| 140 | int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, |
| 141 | struct switchdev_trans *trans); |
| 142 | int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock, |
| 143 | struct switchdev_trans *trans); |
| 144 | int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, |
| 145 | u16 vid); |
| 146 | int dsa_port_fdb_del(struct dsa_port *dp, const unsigned char *addr, |
| 147 | u16 vid); |
| 148 | int dsa_port_fdb_dump(struct dsa_port *dp, dsa_fdb_dump_cb_t *cb, void *data); |
| 149 | int dsa_port_mdb_add(const struct dsa_port *dp, |
| 150 | const struct switchdev_obj_port_mdb *mdb, |
| 151 | struct switchdev_trans *trans); |
| 152 | int dsa_port_mdb_del(const struct dsa_port *dp, |
| 153 | const struct switchdev_obj_port_mdb *mdb); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 154 | int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags, |
| 155 | struct switchdev_trans *trans); |
| 156 | int dsa_port_bridge_flags(const struct dsa_port *dp, unsigned long flags, |
| 157 | struct switchdev_trans *trans); |
| 158 | int dsa_port_mrouter(struct dsa_port *dp, bool mrouter, |
| 159 | struct switchdev_trans *trans); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 160 | int dsa_port_vlan_add(struct dsa_port *dp, |
| 161 | const struct switchdev_obj_port_vlan *vlan, |
| 162 | struct switchdev_trans *trans); |
| 163 | int dsa_port_vlan_del(struct dsa_port *dp, |
| 164 | const struct switchdev_obj_port_vlan *vlan); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 165 | int dsa_port_vid_add(struct dsa_port *dp, u16 vid, u16 flags); |
| 166 | int dsa_port_vid_del(struct dsa_port *dp, u16 vid); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 167 | int dsa_port_link_register_of(struct dsa_port *dp); |
| 168 | void dsa_port_link_unregister_of(struct dsa_port *dp); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 169 | void dsa_port_phylink_validate(struct phylink_config *config, |
| 170 | unsigned long *supported, |
| 171 | struct phylink_link_state *state); |
| 172 | int dsa_port_phylink_mac_link_state(struct phylink_config *config, |
| 173 | struct phylink_link_state *state); |
| 174 | void dsa_port_phylink_mac_config(struct phylink_config *config, |
| 175 | unsigned int mode, |
| 176 | const struct phylink_link_state *state); |
| 177 | void dsa_port_phylink_mac_an_restart(struct phylink_config *config); |
| 178 | void dsa_port_phylink_mac_link_down(struct phylink_config *config, |
| 179 | unsigned int mode, |
| 180 | phy_interface_t interface); |
| 181 | void dsa_port_phylink_mac_link_up(struct phylink_config *config, |
| 182 | unsigned int mode, |
| 183 | phy_interface_t interface, |
| 184 | struct phy_device *phydev); |
| 185 | extern const struct phylink_mac_ops dsa_port_phylink_mac_ops; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 186 | |
| 187 | /* slave.c */ |
| 188 | extern const struct dsa_device_ops notag_netdev_ops; |
| 189 | void dsa_slave_mii_bus_init(struct dsa_switch *ds); |
| 190 | int dsa_slave_create(struct dsa_port *dp); |
| 191 | void dsa_slave_destroy(struct net_device *slave_dev); |
| 192 | int dsa_slave_suspend(struct net_device *slave_dev); |
| 193 | int dsa_slave_resume(struct net_device *slave_dev); |
| 194 | int dsa_slave_register_notifier(void); |
| 195 | void dsa_slave_unregister_notifier(void); |
| 196 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 197 | void *dsa_defer_xmit(struct sk_buff *skb, struct net_device *dev); |
| 198 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 199 | static inline struct dsa_port *dsa_slave_to_port(const struct net_device *dev) |
| 200 | { |
| 201 | struct dsa_slave_priv *p = netdev_priv(dev); |
| 202 | |
| 203 | return p->dp; |
| 204 | } |
| 205 | |
| 206 | static inline struct net_device * |
| 207 | dsa_slave_to_master(const struct net_device *dev) |
| 208 | { |
| 209 | struct dsa_port *dp = dsa_slave_to_port(dev); |
| 210 | |
| 211 | return dp->cpu_dp->master; |
| 212 | } |
| 213 | |
| 214 | /* switch.c */ |
| 215 | int dsa_switch_register_notifier(struct dsa_switch *ds); |
| 216 | void dsa_switch_unregister_notifier(struct dsa_switch *ds); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 217 | #endif |