port.c (0fdc50dfab47d525b71a9f0d8310746cdc0c09c5) | port.c (54a0ed0df49609f4e3f098f8943e38e389dc2e15) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Handling of a single switch port 4 * 5 * Copyright (c) 2017 Savoir-faire Linux Inc. 6 * Vivien Didelot <vivien.didelot@savoirfairelinux.com> 7 */ 8 9#include <linux/if_bridge.h> 10#include <linux/notifier.h> 11#include <linux/of_mdio.h> 12#include <linux/of_net.h> 13 14#include "dsa_priv.h" 15 | 1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Handling of a single switch port 4 * 5 * Copyright (c) 2017 Savoir-faire Linux Inc. 6 * Vivien Didelot <vivien.didelot@savoirfairelinux.com> 7 */ 8 9#include <linux/if_bridge.h> 10#include <linux/notifier.h> 11#include <linux/of_mdio.h> 12#include <linux/of_net.h> 13 14#include "dsa_priv.h" 15 |
16static int dsa_broadcast(unsigned long e, void *v) 17{ 18 struct dsa_switch_tree *dst; 19 int err = 0; 20 21 list_for_each_entry(dst, &dsa_tree_list, list) { 22 struct raw_notifier_head *nh = &dst->nh; 23 24 err = raw_notifier_call_chain(nh, e, v); 25 err = notifier_to_errno(err); 26 if (err) 27 break; 28 } 29 30 return err; 31} 32 |
|
16static int dsa_port_notify(const struct dsa_port *dp, unsigned long e, void *v) 17{ 18 struct raw_notifier_head *nh = &dp->ds->dst->nh; 19 int err; 20 21 err = raw_notifier_call_chain(nh, e, v); 22 23 return notifier_to_errno(err); --- 91 unchanged lines hidden (view full) --- 115 rtnl_lock(); 116 dsa_port_disable_rt(dp); 117 rtnl_unlock(); 118} 119 120int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br) 121{ 122 struct dsa_notifier_bridge_info info = { | 33static int dsa_port_notify(const struct dsa_port *dp, unsigned long e, void *v) 34{ 35 struct raw_notifier_head *nh = &dp->ds->dst->nh; 36 int err; 37 38 err = raw_notifier_call_chain(nh, e, v); 39 40 return notifier_to_errno(err); --- 91 unchanged lines hidden (view full) --- 132 rtnl_lock(); 133 dsa_port_disable_rt(dp); 134 rtnl_unlock(); 135} 136 137int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br) 138{ 139 struct dsa_notifier_bridge_info info = { |
140 .tree_index = dp->ds->dst->index, |
|
123 .sw_index = dp->ds->index, 124 .port = dp->index, 125 .br = br, 126 }; 127 int err; 128 129 /* Set the flooding mode before joining the port in the switch */ 130 err = dsa_port_bridge_flags(dp, BR_FLOOD | BR_MCAST_FLOOD, NULL); 131 if (err) 132 return err; 133 134 /* Here the interface is already bridged. Reflect the current 135 * configuration so that drivers can program their chips accordingly. 136 */ 137 dp->bridge_dev = br; 138 | 141 .sw_index = dp->ds->index, 142 .port = dp->index, 143 .br = br, 144 }; 145 int err; 146 147 /* Set the flooding mode before joining the port in the switch */ 148 err = dsa_port_bridge_flags(dp, BR_FLOOD | BR_MCAST_FLOOD, NULL); 149 if (err) 150 return err; 151 152 /* Here the interface is already bridged. Reflect the current 153 * configuration so that drivers can program their chips accordingly. 154 */ 155 dp->bridge_dev = br; 156 |
139 err = dsa_port_notify(dp, DSA_NOTIFIER_BRIDGE_JOIN, &info); | 157 err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_JOIN, &info); |
140 141 /* The bridging is rolled back on error */ 142 if (err) { 143 dsa_port_bridge_flags(dp, 0, NULL); 144 dp->bridge_dev = NULL; 145 } 146 147 return err; 148} 149 150void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br) 151{ 152 struct dsa_notifier_bridge_info info = { | 158 159 /* The bridging is rolled back on error */ 160 if (err) { 161 dsa_port_bridge_flags(dp, 0, NULL); 162 dp->bridge_dev = NULL; 163 } 164 165 return err; 166} 167 168void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br) 169{ 170 struct dsa_notifier_bridge_info info = { |
171 .tree_index = dp->ds->dst->index, |
|
153 .sw_index = dp->ds->index, 154 .port = dp->index, 155 .br = br, 156 }; 157 int err; 158 159 /* Here the port is already unbridged. Reflect the current configuration 160 * so that drivers can program their chips accordingly. 161 */ 162 dp->bridge_dev = NULL; 163 | 172 .sw_index = dp->ds->index, 173 .port = dp->index, 174 .br = br, 175 }; 176 int err; 177 178 /* Here the port is already unbridged. Reflect the current configuration 179 * so that drivers can program their chips accordingly. 180 */ 181 dp->bridge_dev = NULL; 182 |
164 err = dsa_port_notify(dp, DSA_NOTIFIER_BRIDGE_LEAVE, &info); | 183 err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info); |
165 if (err) 166 pr_err("DSA: failed to notify DSA_NOTIFIER_BRIDGE_LEAVE\n"); 167 168 /* Port is leaving the bridge, disable flooding */ 169 dsa_port_bridge_flags(dp, 0, NULL); 170 171 /* Port left the bridge, put in BR_STATE_DISABLED by the bridge layer, 172 * so allow it to be in BR_STATE_FORWARDING to be kept functional --- 60 unchanged lines hidden (view full) --- 233 234 if (ds->vlan_filtering_is_global) 235 ds->vlan_filtering = vlan_filtering; 236 else 237 dp->vlan_filtering = vlan_filtering; 238 return 0; 239} 240 | 184 if (err) 185 pr_err("DSA: failed to notify DSA_NOTIFIER_BRIDGE_LEAVE\n"); 186 187 /* Port is leaving the bridge, disable flooding */ 188 dsa_port_bridge_flags(dp, 0, NULL); 189 190 /* Port left the bridge, put in BR_STATE_DISABLED by the bridge layer, 191 * so allow it to be in BR_STATE_FORWARDING to be kept functional --- 60 unchanged lines hidden (view full) --- 252 253 if (ds->vlan_filtering_is_global) 254 ds->vlan_filtering = vlan_filtering; 255 else 256 dp->vlan_filtering = vlan_filtering; 257 return 0; 258} 259 |
260/* This enforces legacy behavior for switch drivers which assume they can't 261 * receive VLAN configuration when enslaved to a bridge with vlan_filtering=0 262 */ 263bool dsa_port_skip_vlan_configuration(struct dsa_port *dp) 264{ 265 struct dsa_switch *ds = dp->ds; 266 267 if (!dp->bridge_dev) 268 return false; 269 270 return (!ds->configure_vlan_while_not_filtering && 271 !br_vlan_enabled(dp->bridge_dev)); 272} 273 |
|
241int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock, 242 struct switchdev_trans *trans) 243{ 244 unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock); 245 unsigned int ageing_time = jiffies_to_msecs(ageing_jiffies); 246 struct dsa_notifier_ageing_time_info info = { 247 .ageing_time = ageing_time, 248 .trans = trans, --- 43 unchanged lines hidden (view full) --- 292 int port = dp->index; 293 294 if (switchdev_trans_ph_prepare(trans)) 295 return ds->ops->port_egress_floods ? 0 : -EOPNOTSUPP; 296 297 return ds->ops->port_egress_floods(ds, port, true, mrouter); 298} 299 | 274int dsa_port_ageing_time(struct dsa_port *dp, clock_t ageing_clock, 275 struct switchdev_trans *trans) 276{ 277 unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock); 278 unsigned int ageing_time = jiffies_to_msecs(ageing_jiffies); 279 struct dsa_notifier_ageing_time_info info = { 280 .ageing_time = ageing_time, 281 .trans = trans, --- 43 unchanged lines hidden (view full) --- 325 int port = dp->index; 326 327 if (switchdev_trans_ph_prepare(trans)) 328 return ds->ops->port_egress_floods ? 0 : -EOPNOTSUPP; 329 330 return ds->ops->port_egress_floods(ds, port, true, mrouter); 331} 332 |
333int dsa_port_mtu_change(struct dsa_port *dp, int new_mtu, 334 bool propagate_upstream) 335{ 336 struct dsa_notifier_mtu_info info = { 337 .sw_index = dp->ds->index, 338 .propagate_upstream = propagate_upstream, 339 .port = dp->index, 340 .mtu = new_mtu, 341 }; 342 343 return dsa_port_notify(dp, DSA_NOTIFIER_MTU, &info); 344} 345 |
|
300int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, 301 u16 vid) 302{ 303 struct dsa_notifier_fdb_info info = { 304 .sw_index = dp->ds->index, 305 .port = dp->index, 306 .addr = addr, 307 .vid = vid, --- 144 unchanged lines hidden (view full) --- 452 ds->ops->phylink_validate(ds, dp->index, supported, state); 453} 454 455static void dsa_port_phylink_mac_pcs_get_state(struct phylink_config *config, 456 struct phylink_link_state *state) 457{ 458 struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); 459 struct dsa_switch *ds = dp->ds; | 346int dsa_port_fdb_add(struct dsa_port *dp, const unsigned char *addr, 347 u16 vid) 348{ 349 struct dsa_notifier_fdb_info info = { 350 .sw_index = dp->ds->index, 351 .port = dp->index, 352 .addr = addr, 353 .vid = vid, --- 144 unchanged lines hidden (view full) --- 498 ds->ops->phylink_validate(ds, dp->index, supported, state); 499} 500 501static void dsa_port_phylink_mac_pcs_get_state(struct phylink_config *config, 502 struct phylink_link_state *state) 503{ 504 struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); 505 struct dsa_switch *ds = dp->ds; |
506 int err; |
|
460 461 /* Only called for inband modes */ 462 if (!ds->ops->phylink_mac_link_state) { 463 state->link = 0; 464 return; 465 } 466 | 507 508 /* Only called for inband modes */ 509 if (!ds->ops->phylink_mac_link_state) { 510 state->link = 0; 511 return; 512 } 513 |
467 if (ds->ops->phylink_mac_link_state(ds, dp->index, state) < 0) | 514 err = ds->ops->phylink_mac_link_state(ds, dp->index, state); 515 if (err < 0) { 516 dev_err(ds->dev, "p%d: phylink_mac_link_state() failed: %d\n", 517 dp->index, err); |
468 state->link = 0; | 518 state->link = 0; |
519 } |
|
469} 470 471static void dsa_port_phylink_mac_config(struct phylink_config *config, 472 unsigned int mode, 473 const struct phylink_link_state *state) 474{ 475 struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); 476 struct dsa_switch *ds = dp->ds; --- 31 unchanged lines hidden (view full) --- 508 ds->ops->adjust_link(ds, dp->index, phydev); 509 return; 510 } 511 512 ds->ops->phylink_mac_link_down(ds, dp->index, mode, interface); 513} 514 515static void dsa_port_phylink_mac_link_up(struct phylink_config *config, | 520} 521 522static void dsa_port_phylink_mac_config(struct phylink_config *config, 523 unsigned int mode, 524 const struct phylink_link_state *state) 525{ 526 struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); 527 struct dsa_switch *ds = dp->ds; --- 31 unchanged lines hidden (view full) --- 559 ds->ops->adjust_link(ds, dp->index, phydev); 560 return; 561 } 562 563 ds->ops->phylink_mac_link_down(ds, dp->index, mode, interface); 564} 565 566static void dsa_port_phylink_mac_link_up(struct phylink_config *config, |
567 struct phy_device *phydev, |
|
516 unsigned int mode, 517 phy_interface_t interface, | 568 unsigned int mode, 569 phy_interface_t interface, |
518 struct phy_device *phydev) | 570 int speed, int duplex, 571 bool tx_pause, bool rx_pause) |
519{ 520 struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); 521 struct dsa_switch *ds = dp->ds; 522 523 if (!ds->ops->phylink_mac_link_up) { 524 if (ds->ops->adjust_link && phydev) 525 ds->ops->adjust_link(ds, dp->index, phydev); 526 return; 527 } 528 | 572{ 573 struct dsa_port *dp = container_of(config, struct dsa_port, pl_config); 574 struct dsa_switch *ds = dp->ds; 575 576 if (!ds->ops->phylink_mac_link_up) { 577 if (ds->ops->adjust_link && phydev) 578 ds->ops->adjust_link(ds, dp->index, phydev); 579 return; 580 } 581 |
529 ds->ops->phylink_mac_link_up(ds, dp->index, mode, interface, phydev); | 582 ds->ops->phylink_mac_link_up(ds, dp->index, mode, interface, phydev, 583 speed, duplex, tx_pause, rx_pause); |
530} 531 532const struct phylink_mac_ops dsa_port_phylink_mac_ops = { 533 .validate = dsa_port_phylink_validate, 534 .mac_pcs_get_state = dsa_port_phylink_mac_pcs_get_state, 535 .mac_config = dsa_port_phylink_mac_config, 536 .mac_an_restart = dsa_port_phylink_mac_an_restart, 537 .mac_link_down = dsa_port_phylink_mac_link_down, --- 106 unchanged lines hidden (view full) --- 644 phylink_destroy(dp->pl); 645 return err; 646} 647 648int dsa_port_link_register_of(struct dsa_port *dp) 649{ 650 struct dsa_switch *ds = dp->ds; 651 struct device_node *phy_np; | 584} 585 586const struct phylink_mac_ops dsa_port_phylink_mac_ops = { 587 .validate = dsa_port_phylink_validate, 588 .mac_pcs_get_state = dsa_port_phylink_mac_pcs_get_state, 589 .mac_config = dsa_port_phylink_mac_config, 590 .mac_an_restart = dsa_port_phylink_mac_an_restart, 591 .mac_link_down = dsa_port_phylink_mac_link_down, --- 106 unchanged lines hidden (view full) --- 698 phylink_destroy(dp->pl); 699 return err; 700} 701 702int dsa_port_link_register_of(struct dsa_port *dp) 703{ 704 struct dsa_switch *ds = dp->ds; 705 struct device_node *phy_np; |
706 int port = dp->index; |
|
652 653 if (!ds->ops->adjust_link) { 654 phy_np = of_parse_phandle(dp->dn, "phy-handle", 0); | 707 708 if (!ds->ops->adjust_link) { 709 phy_np = of_parse_phandle(dp->dn, "phy-handle", 0); |
655 if (of_phy_is_fixed_link(dp->dn) || phy_np) | 710 if (of_phy_is_fixed_link(dp->dn) || phy_np) { 711 if (ds->ops->phylink_mac_link_down) 712 ds->ops->phylink_mac_link_down(ds, port, 713 MLO_AN_FIXED, PHY_INTERFACE_MODE_NA); |
656 return dsa_port_phylink_register(dp); | 714 return dsa_port_phylink_register(dp); |
715 } |
|
657 return 0; 658 } 659 660 dev_warn(ds->dev, 661 "Using legacy PHYLIB callbacks. Please migrate to PHYLINK!\n"); 662 663 if (of_phy_is_fixed_link(dp->dn)) 664 return dsa_port_fixed_link_register_of(dp); --- 79 unchanged lines hidden --- | 716 return 0; 717 } 718 719 dev_warn(ds->dev, 720 "Using legacy PHYLIB callbacks. Please migrate to PHYLINK!\n"); 721 722 if (of_phy_is_fixed_link(dp->dn)) 723 return dsa_port_fixed_link_register_of(dp); --- 79 unchanged lines hidden --- |