Lines Matching refs:sw

93 struct prestera_port *prestera_port_find_by_hwid(struct prestera_switch *sw,  in prestera_port_find_by_hwid()  argument
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()
105 read_unlock(&sw->port_list_lock); in prestera_port_find_by_hwid()
110 struct prestera_port *prestera_find_port(struct prestera_switch *sw, u32 id) in prestera_find_port() argument
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()
121 read_unlock(&sw->port_list_lock); in prestera_find_port()
131 return port ? port->sw : NULL; in prestera_switch_get()
371 struct prestera_switch *sw = port->sw; in prestera_port_sfp_bind() local
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()
388 dev_err(sw->dev->dev, in prestera_port_sfp_bind()
458 if (memcmp(port->sw->base_mac, addr, ETH_ALEN - 1)) in prestera_is_valid_mac_addr()
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()
598 write_lock(&port->sw->port_list_lock); 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
621 port->sw = sw; in prestera_port_create()
628 dev_err(prestera_dev(sw), "Failed to get port(%u) info\n", id); in prestera_port_create()
640 SET_NETDEV_DEV(dev, sw->dev->dev); 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()
652 dev_err(prestera_dev(sw), "Failed to set port(%u) mtu(%d)\n", in prestera_port_create()
662 eth_hw_addr_gen(dev, sw->base_mac, port->fp_id); 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()
673 dev_err(prestera_dev(sw), "Failed to set port(%u) mac addr\n", id); in prestera_port_create()
679 dev_err(prestera_dev(sw), "Failed to get port(%u) caps\n", id); in prestera_port_create()
702 dev_err(prestera_dev(sw), in prestera_port_create()
716 dev_err(prestera_dev(sw), in prestera_port_create()
764 static void prestera_destroy_ports(struct prestera_switch *sw) in prestera_destroy_ports() argument
768 list_for_each_entry_safe(port, tmp, &sw->port_list, list) in prestera_destroy_ports()
772 static int prestera_create_ports(struct prestera_switch *sw) in prestera_create_ports() argument
778 for (port_idx = 0; port_idx < sw->port_count; port_idx++) { in prestera_create_ports()
779 err = prestera_port_create(sw, port_idx); in prestera_create_ports()
787 list_for_each_entry_safe(port, tmp, &sw->port_list, list) { in prestera_create_ports()
795 static void prestera_port_handle_event(struct prestera_switch *sw, in prestera_port_handle_event() argument
805 port = prestera_find_port(sw, pevt->port_id); in prestera_port_handle_event()
843 static int prestera_event_handlers_register(struct prestera_switch *sw) in prestera_event_handlers_register() argument
845 return prestera_hw_event_handler_register(sw, PRESTERA_EVENT_TYPE_PORT, in prestera_event_handlers_register()
850 static void prestera_event_handlers_unregister(struct prestera_switch *sw) in prestera_event_handlers_unregister() argument
852 prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_PORT, in prestera_event_handlers_unregister()
856 static int prestera_switch_set_base_mac_addr(struct prestera_switch *sw) in prestera_switch_set_base_mac_addr() argument
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()
864 dev_info(prestera_dev(sw), "using random base mac address\n"); 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()
875 static struct prestera_lag *prestera_lag_by_dev(struct prestera_switch *sw, in prestera_lag_by_dev() argument
881 for (id = 0; id < sw->lag_max; id++) { in prestera_lag_by_dev()
882 lag = &sw->lags[id]; in prestera_lag_by_dev()
890 int prestera_lag_id(struct prestera_switch *sw, in prestera_lag_id() argument
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()
914 static struct prestera_lag *prestera_lag_create(struct prestera_switch *sw, in prestera_lag_create() argument
920 for (id = 0; id < sw->lag_max; id++) { in prestera_lag_create()
921 lag = &sw->lags[id]; in prestera_lag_create()
933 static void prestera_lag_destroy(struct prestera_switch *sw, in prestera_lag_destroy() argument
944 struct prestera_switch *sw = port->sw; in prestera_lag_port_add() local
948 lag = prestera_lag_by_dev(sw, lag_dev); in prestera_lag_port_add()
950 lag = prestera_lag_create(sw, lag_dev); in prestera_lag_port_add()
955 if (lag->member_count >= sw->lag_member_max) in prestera_lag_port_add()
961 prestera_lag_destroy(sw, lag); in prestera_lag_port_add()
974 struct prestera_switch *sw = port->sw; in prestera_lag_port_del() local
998 prestera_lag_destroy(sw, lag); in prestera_lag_port_del()
1013 static int prestera_lag_init(struct prestera_switch *sw) in prestera_lag_init() argument
1017 sw->lags = kcalloc(sw->lag_max, sizeof(*sw->lags), GFP_KERNEL); in prestera_lag_init()
1018 if (!sw->lags) 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()
1027 static void prestera_lag_fini(struct prestera_switch *sw) in prestera_lag_fini() argument
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()
1206 prestera_mdb_entry_create(struct prestera_switch *sw, in prestera_mdb_entry_create() argument
1216 flood_domain = prestera_flood_domain_create(sw); in prestera_mdb_entry_create()
1220 mdb_entry->sw = sw; in prestera_mdb_entry_create()
1246 prestera_flood_domain_create(struct prestera_switch *sw) in prestera_flood_domain_create() argument
1254 domain->sw = sw; in prestera_flood_domain_create()
1349 static int prestera_netdev_event_handler_register(struct prestera_switch *sw) in prestera_netdev_event_handler_register() argument
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()
1356 static void prestera_netdev_event_handler_unregister(struct prestera_switch *sw) in prestera_netdev_event_handler_unregister() argument
1358 unregister_netdevice_notifier(&sw->netdev_nb); in prestera_netdev_event_handler_unregister()
1361 static int prestera_switch_init(struct prestera_switch *sw) in prestera_switch_init() argument
1365 sw->np = sw->dev->dev->of_node; in prestera_switch_init()
1367 err = prestera_hw_switch_init(sw); in prestera_switch_init()
1369 dev_err(prestera_dev(sw), "Failed to init Switch device\n"); 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()
1376 err = prestera_switch_set_base_mac_addr(sw); in prestera_switch_init()
1380 err = prestera_netdev_event_handler_register(sw); in prestera_switch_init()
1384 err = prestera_router_init(sw); in prestera_switch_init()
1388 err = prestera_switchdev_init(sw); in prestera_switch_init()
1392 err = prestera_rxtx_switch_init(sw); in prestera_switch_init()
1396 err = prestera_event_handlers_register(sw); in prestera_switch_init()
1400 err = prestera_counter_init(sw); in prestera_switch_init()
1404 err = prestera_acl_init(sw); in prestera_switch_init()
1408 err = prestera_span_init(sw); in prestera_switch_init()
1412 err = prestera_devlink_traps_register(sw); in prestera_switch_init()
1416 err = prestera_lag_init(sw); in prestera_switch_init()
1420 err = prestera_create_ports(sw); in prestera_switch_init()
1424 prestera_devlink_register(sw); in prestera_switch_init()
1428 prestera_lag_fini(sw); in prestera_switch_init()
1430 prestera_devlink_traps_unregister(sw); in prestera_switch_init()
1432 prestera_span_fini(sw); in prestera_switch_init()
1434 prestera_acl_fini(sw); in prestera_switch_init()
1436 prestera_counter_fini(sw); in prestera_switch_init()
1438 prestera_event_handlers_unregister(sw); in prestera_switch_init()
1440 prestera_rxtx_switch_fini(sw); in prestera_switch_init()
1442 prestera_switchdev_fini(sw); in prestera_switch_init()
1444 prestera_router_fini(sw); in prestera_switch_init()
1446 prestera_netdev_event_handler_unregister(sw); in prestera_switch_init()
1447 prestera_hw_switch_fini(sw); in prestera_switch_init()
1452 static void prestera_switch_fini(struct prestera_switch *sw) in prestera_switch_fini() argument
1454 prestera_devlink_unregister(sw); in prestera_switch_fini()
1455 prestera_destroy_ports(sw); in prestera_switch_fini()
1456 prestera_lag_fini(sw); in prestera_switch_fini()
1457 prestera_devlink_traps_unregister(sw); in prestera_switch_fini()
1458 prestera_span_fini(sw); in prestera_switch_fini()
1459 prestera_acl_fini(sw); in prestera_switch_fini()
1460 prestera_counter_fini(sw); in prestera_switch_fini()
1461 prestera_event_handlers_unregister(sw); in prestera_switch_fini()
1462 prestera_rxtx_switch_fini(sw); in prestera_switch_fini()
1463 prestera_switchdev_fini(sw); in prestera_switch_fini()
1464 prestera_router_fini(sw); in prestera_switch_fini()
1465 prestera_netdev_event_handler_unregister(sw); in prestera_switch_fini()
1466 prestera_hw_switch_fini(sw); in prestera_switch_fini()
1467 of_node_put(sw->np); in prestera_switch_fini()
1472 struct prestera_switch *sw; in prestera_device_register() local
1475 sw = prestera_devlink_alloc(dev); in prestera_device_register()
1476 if (!sw) in prestera_device_register()
1479 dev->priv = sw; in prestera_device_register()
1480 sw->dev = dev; in prestera_device_register()
1482 err = prestera_switch_init(sw); in prestera_device_register()
1484 prestera_devlink_free(sw); in prestera_device_register()
1494 struct prestera_switch *sw = dev->priv; in prestera_device_unregister() local
1496 prestera_switch_fini(sw); in prestera_device_unregister()
1497 prestera_devlink_free(sw); in prestera_device_unregister()