Lines Matching +full:port +full:- +full:id
1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /* Copyright (c) 2019-2020 Marvell International Ltd. All rights reserved */
50 int prestera_port_learning_set(struct prestera_port *port, bool learn) in prestera_port_learning_set() argument
52 return prestera_hw_port_learning_set(port, learn); in prestera_port_learning_set()
55 int prestera_port_uc_flood_set(struct prestera_port *port, bool flood) in prestera_port_uc_flood_set() argument
57 return prestera_hw_port_uc_flood_set(port, flood); in prestera_port_uc_flood_set()
60 int prestera_port_mc_flood_set(struct prestera_port *port, bool flood) in prestera_port_mc_flood_set() argument
62 return prestera_hw_port_mc_flood_set(port, flood); in prestera_port_mc_flood_set()
65 int prestera_port_br_locked_set(struct prestera_port *port, bool br_locked) in prestera_port_br_locked_set() argument
67 return prestera_hw_port_br_locked_set(port, br_locked); in prestera_port_br_locked_set()
70 int prestera_port_pvid_set(struct prestera_port *port, u16 vid) in prestera_port_pvid_set() argument
78 err = prestera_hw_vlan_port_vid_set(port, vid); in prestera_port_pvid_set()
85 err = prestera_hw_port_accept_frm_type(port, frm_type); in prestera_port_pvid_set()
87 prestera_hw_vlan_port_vid_set(port, port->pvid); in prestera_port_pvid_set()
89 port->pvid = vid; in prestera_port_pvid_set()
96 struct prestera_port *port = NULL, *tmp; in prestera_port_find_by_hwid() local
98 read_lock(&sw->port_list_lock); in prestera_port_find_by_hwid()
99 list_for_each_entry(tmp, &sw->port_list, list) { in prestera_port_find_by_hwid()
100 if (tmp->dev_id == dev_id && tmp->hw_id == hw_id) { in prestera_port_find_by_hwid()
101 port = tmp; in prestera_port_find_by_hwid()
105 read_unlock(&sw->port_list_lock); in prestera_port_find_by_hwid()
107 return port; in prestera_port_find_by_hwid()
110 struct prestera_port *prestera_find_port(struct prestera_switch *sw, u32 id) in prestera_find_port() argument
112 struct prestera_port *port = NULL, *tmp; in prestera_find_port() local
114 read_lock(&sw->port_list_lock); in prestera_find_port()
115 list_for_each_entry(tmp, &sw->port_list, list) { in prestera_find_port()
116 if (tmp->id == id) { in prestera_find_port()
117 port = tmp; in prestera_find_port()
121 read_unlock(&sw->port_list_lock); in prestera_find_port()
123 return port; in prestera_find_port()
128 struct prestera_port *port; in prestera_switch_get() local
130 port = prestera_port_dev_lower_find(dev); in prestera_switch_get()
131 return port ? port->sw : NULL; in prestera_switch_get()
134 int prestera_port_cfg_mac_read(struct prestera_port *port, in prestera_port_cfg_mac_read() argument
137 *cfg = port->cfg_mac; in prestera_port_cfg_mac_read()
141 int prestera_port_cfg_mac_write(struct prestera_port *port, in prestera_port_cfg_mac_write() argument
146 err = prestera_hw_port_mac_mode_set(port, cfg->admin, in prestera_port_cfg_mac_write()
147 cfg->mode, cfg->inband, cfg->speed, in prestera_port_cfg_mac_write()
148 cfg->duplex, cfg->fec); in prestera_port_cfg_mac_write()
152 port->cfg_mac = *cfg; in prestera_port_cfg_mac_write()
158 struct prestera_port *port = netdev_priv(dev); in prestera_port_open() local
162 if (port->phy_link) { in prestera_port_open()
163 phylink_start(port->phy_link); in prestera_port_open()
165 if (port->caps.transceiver == PRESTERA_PORT_TCVR_SFP) { in prestera_port_open()
166 err = prestera_port_cfg_mac_read(port, &cfg_mac); in prestera_port_open()
169 err = prestera_port_cfg_mac_write(port, in prestera_port_open()
173 port->cfg_phy.admin = true; in prestera_port_open()
174 err = prestera_hw_port_phy_mode_set(port, true, in prestera_port_open()
175 port->autoneg, in prestera_port_open()
176 port->cfg_phy.mode, in prestera_port_open()
177 port->adver_link_modes, in prestera_port_open()
178 port->cfg_phy.mdix); in prestera_port_open()
189 struct prestera_port *port = netdev_priv(dev); in prestera_port_close() local
195 if (port->phy_link) { in prestera_port_close()
196 phylink_stop(port->phy_link); in prestera_port_close()
197 phylink_disconnect_phy(port->phy_link); in prestera_port_close()
198 err = prestera_port_cfg_mac_read(port, &cfg_mac); in prestera_port_close()
201 prestera_port_cfg_mac_write(port, &cfg_mac); in prestera_port_close()
204 if (port->caps.transceiver == PRESTERA_PORT_TCVR_SFP) { in prestera_port_close()
205 err = prestera_port_cfg_mac_read(port, &cfg_mac); in prestera_port_close()
208 prestera_port_cfg_mac_write(port, &cfg_mac); in prestera_port_close()
211 port->cfg_phy.admin = false; in prestera_port_close()
212 err = prestera_hw_port_phy_mode_set(port, false, port->autoneg, in prestera_port_close()
213 port->cfg_phy.mode, in prestera_port_close()
214 port->adver_link_modes, in prestera_port_close()
215 port->cfg_phy.mdix); in prestera_port_close()
223 prestera_port_mac_state_cache_read(struct prestera_port *port, in prestera_port_mac_state_cache_read() argument
226 spin_lock(&port->state_mac_lock); in prestera_port_mac_state_cache_read()
227 *state = port->state_mac; in prestera_port_mac_state_cache_read()
228 spin_unlock(&port->state_mac_lock); in prestera_port_mac_state_cache_read()
232 prestera_port_mac_state_cache_write(struct prestera_port *port, in prestera_port_mac_state_cache_write() argument
235 spin_lock(&port->state_mac_lock); in prestera_port_mac_state_cache_write()
236 port->state_mac = *state; in prestera_port_mac_state_cache_write()
237 spin_unlock(&port->state_mac_lock); in prestera_port_mac_state_cache_write()
254 struct net_device *ndev = to_net_dev(config->dev); in prestera_mac_link_down()
255 struct prestera_port *port = netdev_priv(ndev); in prestera_mac_link_down() local
261 prestera_port_mac_state_cache_write(port, &state_mac); in prestera_mac_link_down()
276 struct net_device *dev = to_net_dev(config->dev); in prestera_mac_select_pcs()
277 struct prestera_port *port = netdev_priv(dev); in prestera_mac_select_pcs() local
279 return &port->phylink_pcs; in prestera_mac_select_pcs()
285 struct prestera_port *port = container_of(pcs, struct prestera_port, in prestera_pcs_get_state() local
289 prestera_port_mac_state_cache_read(port, &smac); in prestera_pcs_get_state()
292 state->link = smac.oper ? 1 : 0; in prestera_pcs_get_state()
293 /* AN is completed, when port is up */ in prestera_pcs_get_state()
294 state->an_complete = (smac.oper && port->autoneg) ? 1 : 0; in prestera_pcs_get_state()
295 state->speed = smac.speed; in prestera_pcs_get_state()
296 state->duplex = smac.duplex; in prestera_pcs_get_state()
298 state->link = 0; in prestera_pcs_get_state()
299 state->an_complete = 0; in prestera_pcs_get_state()
308 struct prestera_port *port = prestera_pcs_to_port(pcs); in prestera_pcs_config() local
312 err = prestera_port_cfg_mac_read(port, &cfg_mac); in prestera_pcs_config()
341 err = prestera_port_cfg_mac_write(port, &cfg_mac); in prestera_pcs_config()
369 static int prestera_port_sfp_bind(struct prestera_port *port) in prestera_port_sfp_bind() argument
371 struct prestera_switch *sw = port->sw; in prestera_port_sfp_bind()
377 if (!sw->np) in prestera_port_sfp_bind()
380 of_node_get(sw->np); in prestera_port_sfp_bind()
381 ports = of_find_node_by_name(sw->np, "ports"); in prestera_port_sfp_bind()
386 err = of_property_read_u32(node, "prestera,port-num", &num); in prestera_port_sfp_bind()
388 dev_err(sw->dev->dev, in prestera_port_sfp_bind()
394 if (port->fp_id != num) in prestera_port_sfp_bind()
397 port->phylink_pcs.ops = &prestera_pcs_ops; in prestera_port_sfp_bind()
398 port->phylink_pcs.neg_mode = true; in prestera_port_sfp_bind()
400 port->phy_config.dev = &port->dev->dev; in prestera_port_sfp_bind()
401 port->phy_config.type = PHYLINK_NETDEV; in prestera_port_sfp_bind()
406 port->phy_config.supported_interfaces); in prestera_port_sfp_bind()
408 port->phy_config.supported_interfaces); in prestera_port_sfp_bind()
410 port->phy_config.supported_interfaces); in prestera_port_sfp_bind()
412 port->phy_config.supported_interfaces); in prestera_port_sfp_bind()
414 port->phy_config.mac_capabilities = in prestera_port_sfp_bind()
417 phy_link = phylink_create(&port->phy_config, fwnode, in prestera_port_sfp_bind()
421 netdev_err(port->dev, "failed to create phylink\n"); in prestera_port_sfp_bind()
426 port->phy_link = phy_link; in prestera_port_sfp_bind()
436 static int prestera_port_sfp_unbind(struct prestera_port *port) in prestera_port_sfp_unbind() argument
438 if (port->phy_link) in prestera_port_sfp_unbind()
439 phylink_destroy(port->phy_link); in prestera_port_sfp_unbind()
450 int prestera_is_valid_mac_addr(struct prestera_port *port, const u8 *addr) in prestera_is_valid_mac_addr() argument
453 return -EADDRNOTAVAIL; in prestera_is_valid_mac_addr()
455 /* firmware requires that port's MAC address contains first 5 bytes in prestera_is_valid_mac_addr()
458 if (memcmp(port->sw->base_mac, addr, ETH_ALEN - 1)) in prestera_is_valid_mac_addr()
459 return -EINVAL; in prestera_is_valid_mac_addr()
466 struct prestera_port *port = netdev_priv(dev); in prestera_port_set_mac_address() local
470 err = prestera_is_valid_mac_addr(port, addr->sa_data); in prestera_port_set_mac_address()
474 err = prestera_hw_port_mac_set(port, addr->sa_data); in prestera_port_set_mac_address()
478 eth_hw_addr_set(dev, addr->sa_data); in prestera_port_set_mac_address()
485 struct prestera_port *port = netdev_priv(dev); in prestera_port_change_mtu() local
488 err = prestera_hw_port_mtu_set(port, mtu); in prestera_port_change_mtu()
492 WRITE_ONCE(dev->mtu, mtu); in prestera_port_change_mtu()
500 struct prestera_port *port = netdev_priv(dev); in prestera_port_get_stats64() local
501 struct prestera_port_stats *port_stats = &port->cached_hw_stats.stats; in prestera_port_get_stats64()
503 stats->rx_packets = port_stats->broadcast_frames_received + in prestera_port_get_stats64()
504 port_stats->multicast_frames_received + in prestera_port_get_stats64()
505 port_stats->unicast_frames_received; in prestera_port_get_stats64()
507 stats->tx_packets = port_stats->broadcast_frames_sent + in prestera_port_get_stats64()
508 port_stats->multicast_frames_sent + in prestera_port_get_stats64()
509 port_stats->unicast_frames_sent; in prestera_port_get_stats64()
511 stats->rx_bytes = port_stats->good_octets_received; in prestera_port_get_stats64()
513 stats->tx_bytes = port_stats->good_octets_sent; in prestera_port_get_stats64()
515 stats->rx_errors = port_stats->rx_error_frame_received; in prestera_port_get_stats64()
516 stats->tx_errors = port_stats->mac_trans_error; in prestera_port_get_stats64()
518 stats->rx_dropped = port_stats->buffer_overrun; in prestera_port_get_stats64()
519 stats->tx_dropped = 0; in prestera_port_get_stats64()
521 stats->multicast = port_stats->multicast_frames_received; in prestera_port_get_stats64()
522 stats->collisions = port_stats->excessive_collision; in prestera_port_get_stats64()
524 stats->rx_crc_errors = port_stats->bad_crc; in prestera_port_get_stats64()
527 static void prestera_port_get_hw_stats(struct prestera_port *port) in prestera_port_get_hw_stats() argument
529 prestera_hw_port_stats_get(port, &port->cached_hw_stats.stats); in prestera_port_get_hw_stats()
534 struct prestera_port *port = in prestera_port_stats_update() local
538 prestera_port_get_hw_stats(port); in prestera_port_stats_update()
540 queue_delayed_work(prestera_wq, &port->cached_hw_stats.caching_dw, in prestera_port_stats_update()
548 struct prestera_port *port = netdev_priv(dev); in prestera_port_setup_tc() local
552 return prestera_flow_block_setup(port, type_data); in prestera_port_setup_tc()
554 return -EOPNOTSUPP; in prestera_port_setup_tc()
568 int prestera_port_autoneg_set(struct prestera_port *port, u64 link_modes) in prestera_port_autoneg_set() argument
572 if (port->autoneg && port->adver_link_modes == link_modes) in prestera_port_autoneg_set()
575 err = prestera_hw_port_phy_mode_set(port, port->cfg_phy.admin, in prestera_port_autoneg_set()
577 port->cfg_phy.mdix); in prestera_port_autoneg_set()
581 port->adver_fec = BIT(PRESTERA_PORT_FEC_OFF); in prestera_port_autoneg_set()
582 port->adver_link_modes = link_modes; in prestera_port_autoneg_set()
583 port->cfg_phy.mode = 0; in prestera_port_autoneg_set()
584 port->autoneg = true; in prestera_port_autoneg_set()
589 static void prestera_port_list_add(struct prestera_port *port) in prestera_port_list_add() argument
591 write_lock(&port->sw->port_list_lock); in prestera_port_list_add()
592 list_add(&port->list, &port->sw->port_list); in prestera_port_list_add()
593 write_unlock(&port->sw->port_list_lock); in prestera_port_list_add()
596 static void prestera_port_list_del(struct prestera_port *port) in prestera_port_list_del() argument
598 write_lock(&port->sw->port_list_lock); in prestera_port_list_del()
599 list_del(&port->list); in prestera_port_list_del()
600 write_unlock(&port->sw->port_list_lock); in prestera_port_list_del()
603 static int prestera_port_create(struct prestera_switch *sw, u32 id) in prestera_port_create() argument
606 struct prestera_port *port; in prestera_port_create() local
610 dev = alloc_etherdev(sizeof(*port)); in prestera_port_create()
612 return -ENOMEM; in prestera_port_create()
614 port = netdev_priv(dev); in prestera_port_create()
616 INIT_LIST_HEAD(&port->vlans_list); in prestera_port_create()
617 port->pvid = PRESTERA_DEFAULT_VID; in prestera_port_create()
618 port->lag = NULL; in prestera_port_create()
619 port->dev = dev; in prestera_port_create()
620 port->id = id; in prestera_port_create()
621 port->sw = sw; in prestera_port_create()
623 spin_lock_init(&port->state_mac_lock); in prestera_port_create()
625 err = prestera_hw_port_info_get(port, &port->dev_id, &port->hw_id, in prestera_port_create()
626 &port->fp_id); in prestera_port_create()
628 dev_err(prestera_dev(sw), "Failed to get port(%u) info\n", id); in prestera_port_create()
632 err = prestera_devlink_port_register(port); in prestera_port_create()
636 dev->features |= NETIF_F_HW_TC; in prestera_port_create()
637 dev->netns_local = true; in prestera_port_create()
638 dev->netdev_ops = &prestera_netdev_ops; in prestera_port_create()
639 dev->ethtool_ops = &prestera_ethtool_ops; in prestera_port_create()
640 SET_NETDEV_DEV(dev, sw->dev->dev); in prestera_port_create()
641 SET_NETDEV_DEVLINK_PORT(dev, &port->dl_port); in prestera_port_create()
643 if (port->caps.transceiver != PRESTERA_PORT_TCVR_SFP) in prestera_port_create()
646 dev->mtu = min_t(unsigned int, sw->mtu_max, PRESTERA_MTU_DEFAULT); in prestera_port_create()
647 dev->min_mtu = sw->mtu_min; in prestera_port_create()
648 dev->max_mtu = sw->mtu_max; in prestera_port_create()
650 err = prestera_hw_port_mtu_set(port, dev->mtu); in prestera_port_create()
652 dev_err(prestera_dev(sw), "Failed to set port(%u) mtu(%d)\n", in prestera_port_create()
653 id, dev->mtu); in prestera_port_create()
657 if (port->fp_id >= PRESTERA_MAC_ADDR_NUM_MAX) { in prestera_port_create()
658 err = -EINVAL; in prestera_port_create()
662 eth_hw_addr_gen(dev, sw->base_mac, port->fp_id); in prestera_port_create()
663 /* firmware requires that port's MAC address consist of the first in prestera_port_create()
666 if (memcmp(dev->dev_addr, sw->base_mac, ETH_ALEN - 1)) { in prestera_port_create()
667 dev_warn(prestera_dev(sw), "Port MAC address wraps for port(%u)\n", id); in prestera_port_create()
668 dev_addr_mod(dev, 0, sw->base_mac, ETH_ALEN - 1); in prestera_port_create()
671 err = prestera_hw_port_mac_set(port, dev->dev_addr); in prestera_port_create()
673 dev_err(prestera_dev(sw), "Failed to set port(%u) mac addr\n", id); in prestera_port_create()
677 err = prestera_hw_port_cap_get(port, &port->caps); in prestera_port_create()
679 dev_err(prestera_dev(sw), "Failed to get port(%u) caps\n", id); in prestera_port_create()
683 port->adver_link_modes = port->caps.supp_link_modes; in prestera_port_create()
684 port->adver_fec = 0; in prestera_port_create()
685 port->autoneg = true; in prestera_port_create()
688 if (port->caps.transceiver != PRESTERA_PORT_TCVR_SFP) { in prestera_port_create()
700 err = prestera_port_cfg_mac_write(port, &cfg_mac); in prestera_port_create()
703 "Failed to set port(%u) mac mode\n", id); in prestera_port_create()
708 if (port->caps.transceiver != PRESTERA_PORT_TCVR_SFP) { in prestera_port_create()
709 port->cfg_phy.mdix = ETH_TP_MDI_AUTO; in prestera_port_create()
710 port->cfg_phy.admin = false; in prestera_port_create()
711 err = prestera_hw_port_phy_mode_set(port, in prestera_port_create()
712 port->cfg_phy.admin, in prestera_port_create()
714 port->cfg_phy.mdix); in prestera_port_create()
717 "Failed to set port(%u) phy mode\n", id); in prestera_port_create()
722 err = prestera_rxtx_port_init(port); in prestera_port_create()
726 INIT_DELAYED_WORK(&port->cached_hw_stats.caching_dw, in prestera_port_create()
729 prestera_port_list_add(port); in prestera_port_create()
735 err = prestera_port_sfp_bind(port); in prestera_port_create()
744 prestera_port_list_del(port); in prestera_port_create()
746 prestera_devlink_port_unregister(port); in prestera_port_create()
753 static void prestera_port_destroy(struct prestera_port *port) in prestera_port_destroy() argument
755 struct net_device *dev = port->dev; in prestera_port_destroy()
757 cancel_delayed_work_sync(&port->cached_hw_stats.caching_dw); in prestera_port_destroy()
759 prestera_port_list_del(port); in prestera_port_destroy()
760 prestera_devlink_port_unregister(port); in prestera_port_destroy()
766 struct prestera_port *port, *tmp; in prestera_destroy_ports() local
768 list_for_each_entry_safe(port, tmp, &sw->port_list, list) in prestera_destroy_ports()
769 prestera_port_destroy(port); in prestera_destroy_ports()
774 struct prestera_port *port, *tmp; in prestera_create_ports() local
778 for (port_idx = 0; port_idx < sw->port_count; port_idx++) { in prestera_create_ports()
787 list_for_each_entry_safe(port, tmp, &sw->port_list, list) { in prestera_create_ports()
788 prestera_port_sfp_unbind(port); in prestera_create_ports()
789 prestera_port_destroy(port); in prestera_create_ports()
801 struct prestera_port *port; in prestera_port_handle_event() local
803 if (evt->id == PRESTERA_PORT_EVENT_MAC_STATE_CHANGED) { in prestera_port_handle_event()
804 pevt = &evt->port_evt; in prestera_port_handle_event()
805 port = prestera_find_port(sw, pevt->port_id); in prestera_port_handle_event()
806 if (!port || !port->dev) in prestera_port_handle_event()
809 caching_dw = &port->cached_hw_stats.caching_dw; in prestera_port_handle_event()
813 smac.oper = pevt->data.mac.oper; in prestera_port_handle_event()
815 smac.mode = pevt->data.mac.mode; in prestera_port_handle_event()
816 smac.speed = pevt->data.mac.speed; in prestera_port_handle_event()
817 smac.duplex = pevt->data.mac.duplex; in prestera_port_handle_event()
818 smac.fc = pevt->data.mac.fc; in prestera_port_handle_event()
819 smac.fec = pevt->data.mac.fec; in prestera_port_handle_event()
821 prestera_port_mac_state_cache_write(port, &smac); in prestera_port_handle_event()
823 if (port->state_mac.oper) { in prestera_port_handle_event()
824 if (port->phy_link) in prestera_port_handle_event()
825 phylink_pcs_change(&port->phylink_pcs, true); in prestera_port_handle_event()
827 netif_carrier_on(port->dev); in prestera_port_handle_event()
832 if (port->phy_link) in prestera_port_handle_event()
833 phylink_pcs_change(&port->phylink_pcs, false); in prestera_port_handle_event()
834 else if (netif_running(port->dev) && netif_carrier_ok(port->dev)) in prestera_port_handle_event()
835 netif_carrier_off(port->dev); in prestera_port_handle_event()
860 if (sw->np) in prestera_switch_set_base_mac_addr()
861 ret = of_get_mac_address(sw->np, sw->base_mac); in prestera_switch_set_base_mac_addr()
862 if (!is_valid_ether_addr(sw->base_mac) || ret) { in prestera_switch_set_base_mac_addr()
863 eth_random_addr(sw->base_mac); in prestera_switch_set_base_mac_addr()
867 return prestera_hw_switch_mac_set(sw, sw->base_mac); in prestera_switch_set_base_mac_addr()
870 struct prestera_lag *prestera_lag_by_id(struct prestera_switch *sw, u16 id) in prestera_lag_by_id() argument
872 return id < sw->lag_max ? &sw->lags[id] : NULL; in prestera_lag_by_id()
879 u16 id; in prestera_lag_by_dev() local
881 for (id = 0; id < sw->lag_max; id++) { in prestera_lag_by_dev()
882 lag = &sw->lags[id]; in prestera_lag_by_dev()
883 if (lag->dev == dev) in prestera_lag_by_dev()
894 int free_id = -1; in prestera_lag_id()
895 int id; in prestera_lag_id() local
897 for (id = 0; id < sw->lag_max; id++) { in prestera_lag_id()
898 lag = prestera_lag_by_id(sw, id); in prestera_lag_id()
899 if (lag->member_count) { in prestera_lag_id()
900 if (lag->dev == lag_dev) { in prestera_lag_id()
901 *lag_id = id; in prestera_lag_id()
905 free_id = id; in prestera_lag_id()
909 return -ENOSPC; in prestera_lag_id()
918 u16 id; in prestera_lag_create() local
920 for (id = 0; id < sw->lag_max; id++) { in prestera_lag_create()
921 lag = &sw->lags[id]; in prestera_lag_create()
922 if (!lag->dev) in prestera_lag_create()
926 INIT_LIST_HEAD(&lag->members); in prestera_lag_create()
927 lag->dev = lag_dev; in prestera_lag_create()
936 WARN_ON(!list_empty(&lag->members)); in prestera_lag_destroy()
937 lag->member_count = 0; in prestera_lag_destroy()
938 lag->dev = NULL; in prestera_lag_destroy()
941 static int prestera_lag_port_add(struct prestera_port *port, in prestera_lag_port_add() argument
944 struct prestera_switch *sw = port->sw; in prestera_lag_port_add()
952 return -ENOSPC; in prestera_lag_port_add()
955 if (lag->member_count >= sw->lag_member_max) in prestera_lag_port_add()
956 return -ENOSPC; in prestera_lag_port_add()
958 err = prestera_hw_lag_member_add(port, lag->lag_id); in prestera_lag_port_add()
960 if (!lag->member_count) in prestera_lag_port_add()
965 list_add(&port->lag_member, &lag->members); in prestera_lag_port_add()
966 lag->member_count++; in prestera_lag_port_add()
967 port->lag = lag; in prestera_lag_port_add()
972 static int prestera_lag_port_del(struct prestera_port *port) in prestera_lag_port_del() argument
974 struct prestera_switch *sw = port->sw; in prestera_lag_port_del()
975 struct prestera_lag *lag = port->lag; in prestera_lag_port_del()
978 if (!lag || !lag->member_count) in prestera_lag_port_del()
979 return -EINVAL; in prestera_lag_port_del()
981 err = prestera_hw_lag_member_del(port, lag->lag_id); in prestera_lag_port_del()
985 list_del(&port->lag_member); in prestera_lag_port_del()
986 lag->member_count--; in prestera_lag_port_del()
987 port->lag = NULL; in prestera_lag_port_del()
989 if (netif_is_bridge_port(lag->dev)) { in prestera_lag_port_del()
992 br_dev = netdev_master_upper_dev_get(lag->dev); in prestera_lag_port_del()
994 prestera_bridge_port_leave(br_dev, port); in prestera_lag_port_del()
997 if (!lag->member_count) in prestera_lag_port_del()
1003 bool prestera_port_is_lag_member(const struct prestera_port *port) in prestera_port_is_lag_member() argument
1005 return !!port->lag; in prestera_port_is_lag_member()
1008 u16 prestera_port_lag_id(const struct prestera_port *port) in prestera_port_lag_id() argument
1010 return port->lag->lag_id; in prestera_port_lag_id()
1015 u16 id; in prestera_lag_init() local
1017 sw->lags = kcalloc(sw->lag_max, sizeof(*sw->lags), GFP_KERNEL); in prestera_lag_init()
1018 if (!sw->lags) in prestera_lag_init()
1019 return -ENOMEM; in prestera_lag_init()
1021 for (id = 0; id < sw->lag_max; id++) in prestera_lag_init()
1022 sw->lags[id].lag_id = id; in prestera_lag_init()
1031 for (idx = 0; idx < sw->lag_max; idx++) in prestera_lag_fini()
1032 WARN_ON(sw->lags[idx].member_count); in prestera_lag_fini()
1034 kfree(sw->lags); in prestera_lag_fini()
1039 return dev->netdev_ops == &prestera_netdev_ops; in prestera_netdev_check()
1045 struct prestera_port **pport = (struct prestera_port **)priv->data; in prestera_lower_dev_walk()
1057 struct prestera_port *port = NULL; in prestera_port_dev_lower_find() local
1059 .data = (void *)&port, in prestera_port_dev_lower_find()
1067 return port; in prestera_port_dev_lower_find()
1075 struct prestera_port *port = netdev_priv(dev); in prestera_netdev_port_lower_event() local
1080 if (!prestera_port_is_lag_member(port)) in prestera_netdev_port_lower_event()
1083 lower_state_info = info->lower_state_info; in prestera_netdev_port_lower_event()
1084 enabled = lower_state_info->link_up && lower_state_info->tx_enabled; in prestera_netdev_port_lower_event()
1086 return prestera_hw_lag_member_enable(port, port->lag->lag_id, enabled); in prestera_netdev_port_lower_event()
1093 if (info->tx_type != NETDEV_LAG_TX_TYPE_HASH) { in prestera_lag_master_check()
1107 struct prestera_port *port = netdev_priv(dev); in prestera_netdev_port_event() local
1118 upper = cu_info->upper_dev; in prestera_netdev_port_event()
1122 return -EINVAL; in prestera_netdev_port_event()
1125 if (!cu_info->linking) in prestera_netdev_port_event()
1130 return -EINVAL; in prestera_netdev_port_event()
1134 !prestera_lag_master_check(upper, cu_info->upper_info, extack)) in prestera_netdev_port_event()
1135 return -EOPNOTSUPP; in prestera_netdev_port_event()
1138 "Master device is a LAG master and port has a VLAN"); in prestera_netdev_port_event()
1139 return -EINVAL; in prestera_netdev_port_event()
1144 "Can not put a VLAN on a LAG port"); in prestera_netdev_port_event()
1145 return -EINVAL; in prestera_netdev_port_event()
1150 upper = cu_info->upper_dev; in prestera_netdev_port_event()
1152 if (cu_info->linking) in prestera_netdev_port_event()
1153 return prestera_bridge_port_join(upper, port, in prestera_netdev_port_event()
1156 prestera_bridge_port_leave(upper, port); in prestera_netdev_port_event()
1158 if (cu_info->linking) in prestera_netdev_port_event()
1159 return prestera_lag_port_add(port, upper); in prestera_netdev_port_event()
1161 prestera_lag_port_del(port); in prestera_netdev_port_event()
1220 mdb_entry->sw = sw; in prestera_mdb_entry_create()
1221 mdb_entry->vid = vid; in prestera_mdb_entry_create()
1222 mdb_entry->flood_domain = flood_domain; in prestera_mdb_entry_create()
1223 ether_addr_copy(mdb_entry->addr, addr); in prestera_mdb_entry_create()
1241 prestera_flood_domain_destroy(mdb_entry->flood_domain); in prestera_mdb_entry_destroy()
1254 domain->sw = sw; in prestera_flood_domain_create()
1261 INIT_LIST_HEAD(&domain->flood_domain_port_list); in prestera_flood_domain_create()
1268 WARN_ON(!list_empty(&flood_domain->flood_domain_port_list)); in prestera_flood_domain_destroy()
1284 err = -ENOMEM; in prestera_flood_domain_port_create()
1288 flood_domain_port->vid = vid; in prestera_flood_domain_port_create()
1290 if (list_empty(&flood_domain->flood_domain_port_list)) in prestera_flood_domain_port_create()
1293 list_add(&flood_domain_port->flood_domain_port_node, in prestera_flood_domain_port_create()
1294 &flood_domain->flood_domain_port_list); in prestera_flood_domain_port_create()
1296 flood_domain_port->flood_domain = flood_domain; in prestera_flood_domain_port_create()
1297 flood_domain_port->dev = dev; in prestera_flood_domain_port_create()
1312 list_del(&flood_domain_port->flood_domain_port_node); in prestera_flood_domain_port_create()
1319 prestera_flood_domain_port_destroy(struct prestera_flood_domain_port *port) in prestera_flood_domain_port_destroy() argument
1321 struct prestera_flood_domain *flood_domain = port->flood_domain; in prestera_flood_domain_port_destroy()
1323 list_del(&port->flood_domain_port_node); in prestera_flood_domain_port_destroy()
1327 if (!list_empty(&flood_domain->flood_domain_port_list)) in prestera_flood_domain_port_destroy()
1330 kfree(port); in prestera_flood_domain_port_destroy()
1340 &flood_domain->flood_domain_port_list, in prestera_flood_domain_port_find()
1342 if (flood_domain_port->dev == dev && in prestera_flood_domain_port_find()
1343 vid == flood_domain_port->vid) in prestera_flood_domain_port_find()
1351 sw->netdev_nb.notifier_call = prestera_netdev_event_handler; in prestera_netdev_event_handler_register()
1353 return register_netdevice_notifier(&sw->netdev_nb); in prestera_netdev_event_handler_register()
1358 unregister_netdevice_notifier(&sw->netdev_nb); in prestera_netdev_event_handler_unregister()
1365 sw->np = sw->dev->dev->of_node; in prestera_switch_init()
1373 rwlock_init(&sw->port_list_lock); in prestera_switch_init()
1374 INIT_LIST_HEAD(&sw->port_list); in prestera_switch_init()
1467 of_node_put(sw->np); in prestera_switch_fini()
1477 return -ENOMEM; in prestera_device_register()
1479 dev->priv = sw; in prestera_device_register()
1480 sw->dev = dev; in prestera_device_register()
1494 struct prestera_switch *sw = dev->priv; in prestera_device_unregister()
1505 return -ENOMEM; in prestera_module_init()
1510 return -ENOMEM; in prestera_module_init()