Lines Matching full: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()
378 struct prestera_switch *sw = port->sw; in prestera_port_sfp_bind() local
384 if (!sw->np) in prestera_port_sfp_bind()
387 of_node_get(sw->np); in prestera_port_sfp_bind()
388 ports = of_find_node_by_name(sw->np, "ports"); in prestera_port_sfp_bind()
395 dev_err(sw->dev->dev, in prestera_port_sfp_bind()
464 if (memcmp(port->sw->base_mac, addr, ETH_ALEN - 1)) in prestera_is_valid_mac_addr()
598 write_lock(&port->sw->port_list_lock); in prestera_port_list_add()
599 list_add(&port->list, &port->sw->port_list); in prestera_port_list_add()
600 write_unlock(&port->sw->port_list_lock); in prestera_port_list_add()
605 write_lock(&port->sw->port_list_lock); in prestera_port_list_del()
607 write_unlock(&port->sw->port_list_lock); in prestera_port_list_del()
610 static int prestera_port_create(struct prestera_switch *sw, u32 id) in prestera_port_create() argument
628 port->sw = sw; in prestera_port_create()
635 dev_err(prestera_dev(sw), "Failed to get port(%u) info\n", id); in prestera_port_create()
646 SET_NETDEV_DEV(dev, sw->dev->dev); in prestera_port_create()
651 dev->mtu = min_t(unsigned int, sw->mtu_max, PRESTERA_MTU_DEFAULT); in prestera_port_create()
652 dev->min_mtu = sw->mtu_min; in prestera_port_create()
653 dev->max_mtu = sw->mtu_max; in prestera_port_create()
657 dev_err(prestera_dev(sw), "Failed to set port(%u) mtu(%d)\n", in prestera_port_create()
667 eth_hw_addr_gen(dev, sw->base_mac, port->fp_id); in prestera_port_create()
671 if (memcmp(dev->dev_addr, sw->base_mac, ETH_ALEN - 1)) { in prestera_port_create()
672 dev_warn(prestera_dev(sw), "Port MAC address wraps for port(%u)\n", id); in prestera_port_create()
673 dev_addr_mod(dev, 0, sw->base_mac, ETH_ALEN - 1); in prestera_port_create()
678 dev_err(prestera_dev(sw), "Failed to set port(%u) mac addr\n", id); in prestera_port_create()
684 dev_err(prestera_dev(sw), "Failed to get port(%u) caps\n", id); in prestera_port_create()
707 dev_err(prestera_dev(sw), in prestera_port_create()
721 dev_err(prestera_dev(sw), in prestera_port_create()
772 static void prestera_destroy_ports(struct prestera_switch *sw) in prestera_destroy_ports() argument
776 list_for_each_entry_safe(port, tmp, &sw->port_list, list) in prestera_destroy_ports()
780 static int prestera_create_ports(struct prestera_switch *sw) in prestera_create_ports() argument
786 for (port_idx = 0; port_idx < sw->port_count; port_idx++) { in prestera_create_ports()
787 err = prestera_port_create(sw, port_idx); in prestera_create_ports()
795 list_for_each_entry_safe(port, tmp, &sw->port_list, list) { in prestera_create_ports()
803 static void prestera_port_handle_event(struct prestera_switch *sw, in prestera_port_handle_event() argument
813 port = prestera_find_port(sw, pevt->port_id); in prestera_port_handle_event()
851 static int prestera_event_handlers_register(struct prestera_switch *sw) in prestera_event_handlers_register() argument
853 return prestera_hw_event_handler_register(sw, PRESTERA_EVENT_TYPE_PORT, in prestera_event_handlers_register()
858 static void prestera_event_handlers_unregister(struct prestera_switch *sw) in prestera_event_handlers_unregister() argument
860 prestera_hw_event_handler_unregister(sw, PRESTERA_EVENT_TYPE_PORT, in prestera_event_handlers_unregister()
864 static int prestera_switch_set_base_mac_addr(struct prestera_switch *sw) in prestera_switch_set_base_mac_addr() argument
869 if (sw->np) { in prestera_switch_set_base_mac_addr()
870 base_mac_np = of_parse_phandle(sw->np, "base-mac-provider", 0); in prestera_switch_set_base_mac_addr()
872 ret = of_get_mac_address(base_mac_np, sw->base_mac); in prestera_switch_set_base_mac_addr()
877 if (!is_valid_ether_addr(sw->base_mac) || ret) { in prestera_switch_set_base_mac_addr()
878 eth_random_addr(sw->base_mac); in prestera_switch_set_base_mac_addr()
879 dev_info(prestera_dev(sw), "using random base mac address\n"); in prestera_switch_set_base_mac_addr()
882 return prestera_hw_switch_mac_set(sw, sw->base_mac); in prestera_switch_set_base_mac_addr()
885 struct prestera_lag *prestera_lag_by_id(struct prestera_switch *sw, u16 id) in prestera_lag_by_id() argument
887 return id < sw->lag_max ? &sw->lags[id] : NULL; in prestera_lag_by_id()
890 static struct prestera_lag *prestera_lag_by_dev(struct prestera_switch *sw, in prestera_lag_by_dev() argument
896 for (id = 0; id < sw->lag_max; id++) { in prestera_lag_by_dev()
897 lag = &sw->lags[id]; in prestera_lag_by_dev()
905 int prestera_lag_id(struct prestera_switch *sw, in prestera_lag_id() argument
912 for (id = 0; id < sw->lag_max; id++) { in prestera_lag_id()
913 lag = prestera_lag_by_id(sw, id); in prestera_lag_id()
929 static struct prestera_lag *prestera_lag_create(struct prestera_switch *sw, in prestera_lag_create() argument
935 for (id = 0; id < sw->lag_max; id++) { in prestera_lag_create()
936 lag = &sw->lags[id]; in prestera_lag_create()
948 static void prestera_lag_destroy(struct prestera_switch *sw, in prestera_lag_destroy() argument
959 struct prestera_switch *sw = port->sw; in prestera_lag_port_add() local
963 lag = prestera_lag_by_dev(sw, lag_dev); in prestera_lag_port_add()
965 lag = prestera_lag_create(sw, lag_dev); in prestera_lag_port_add()
970 if (lag->member_count >= sw->lag_member_max) in prestera_lag_port_add()
976 prestera_lag_destroy(sw, lag); in prestera_lag_port_add()
989 struct prestera_switch *sw = port->sw; in prestera_lag_port_del() local
1013 prestera_lag_destroy(sw, lag); in prestera_lag_port_del()
1028 static int prestera_lag_init(struct prestera_switch *sw) in prestera_lag_init() argument
1032 sw->lags = kcalloc(sw->lag_max, sizeof(*sw->lags), GFP_KERNEL); in prestera_lag_init()
1033 if (!sw->lags) in prestera_lag_init()
1036 for (id = 0; id < sw->lag_max; id++) in prestera_lag_init()
1037 sw->lags[id].lag_id = id; in prestera_lag_init()
1042 static void prestera_lag_fini(struct prestera_switch *sw) in prestera_lag_fini() argument
1046 for (idx = 0; idx < sw->lag_max; idx++) in prestera_lag_fini()
1047 WARN_ON(sw->lags[idx].member_count); in prestera_lag_fini()
1049 kfree(sw->lags); in prestera_lag_fini()
1221 prestera_mdb_entry_create(struct prestera_switch *sw, in prestera_mdb_entry_create() argument
1231 flood_domain = prestera_flood_domain_create(sw); in prestera_mdb_entry_create()
1235 mdb_entry->sw = sw; in prestera_mdb_entry_create()
1261 prestera_flood_domain_create(struct prestera_switch *sw) in prestera_flood_domain_create() argument
1269 domain->sw = sw; in prestera_flood_domain_create()
1364 static int prestera_netdev_event_handler_register(struct prestera_switch *sw) in prestera_netdev_event_handler_register() argument
1366 sw->netdev_nb.notifier_call = prestera_netdev_event_handler; in prestera_netdev_event_handler_register()
1368 return register_netdevice_notifier(&sw->netdev_nb); in prestera_netdev_event_handler_register()
1371 static void prestera_netdev_event_handler_unregister(struct prestera_switch *sw) in prestera_netdev_event_handler_unregister() argument
1373 unregister_netdevice_notifier(&sw->netdev_nb); in prestera_netdev_event_handler_unregister()
1376 static int prestera_switch_init(struct prestera_switch *sw) in prestera_switch_init() argument
1380 sw->np = of_find_compatible_node(NULL, NULL, "marvell,prestera"); in prestera_switch_init()
1382 err = prestera_hw_switch_init(sw); in prestera_switch_init()
1384 dev_err(prestera_dev(sw), "Failed to init Switch device\n"); in prestera_switch_init()
1388 rwlock_init(&sw->port_list_lock); in prestera_switch_init()
1389 INIT_LIST_HEAD(&sw->port_list); in prestera_switch_init()
1391 err = prestera_switch_set_base_mac_addr(sw); in prestera_switch_init()
1395 err = prestera_netdev_event_handler_register(sw); in prestera_switch_init()
1399 err = prestera_router_init(sw); in prestera_switch_init()
1403 err = prestera_switchdev_init(sw); in prestera_switch_init()
1407 err = prestera_rxtx_switch_init(sw); in prestera_switch_init()
1411 err = prestera_event_handlers_register(sw); in prestera_switch_init()
1415 err = prestera_counter_init(sw); in prestera_switch_init()
1419 err = prestera_acl_init(sw); in prestera_switch_init()
1423 err = prestera_span_init(sw); in prestera_switch_init()
1427 err = prestera_devlink_traps_register(sw); in prestera_switch_init()
1431 err = prestera_lag_init(sw); in prestera_switch_init()
1435 err = prestera_create_ports(sw); in prestera_switch_init()
1439 prestera_devlink_register(sw); in prestera_switch_init()
1443 prestera_lag_fini(sw); in prestera_switch_init()
1445 prestera_devlink_traps_unregister(sw); in prestera_switch_init()
1447 prestera_span_fini(sw); in prestera_switch_init()
1449 prestera_acl_fini(sw); in prestera_switch_init()
1451 prestera_counter_fini(sw); in prestera_switch_init()
1453 prestera_event_handlers_unregister(sw); in prestera_switch_init()
1455 prestera_rxtx_switch_fini(sw); in prestera_switch_init()
1457 prestera_switchdev_fini(sw); in prestera_switch_init()
1459 prestera_router_fini(sw); in prestera_switch_init()
1461 prestera_netdev_event_handler_unregister(sw); in prestera_switch_init()
1462 prestera_hw_switch_fini(sw); in prestera_switch_init()
1467 static void prestera_switch_fini(struct prestera_switch *sw) in prestera_switch_fini() argument
1469 prestera_devlink_unregister(sw); in prestera_switch_fini()
1470 prestera_destroy_ports(sw); in prestera_switch_fini()
1471 prestera_lag_fini(sw); in prestera_switch_fini()
1472 prestera_devlink_traps_unregister(sw); in prestera_switch_fini()
1473 prestera_span_fini(sw); in prestera_switch_fini()
1474 prestera_acl_fini(sw); in prestera_switch_fini()
1475 prestera_counter_fini(sw); in prestera_switch_fini()
1476 prestera_event_handlers_unregister(sw); in prestera_switch_fini()
1477 prestera_rxtx_switch_fini(sw); in prestera_switch_fini()
1478 prestera_switchdev_fini(sw); in prestera_switch_fini()
1479 prestera_router_fini(sw); in prestera_switch_fini()
1480 prestera_netdev_event_handler_unregister(sw); in prestera_switch_fini()
1481 prestera_hw_switch_fini(sw); in prestera_switch_fini()
1482 of_node_put(sw->np); in prestera_switch_fini()
1487 struct prestera_switch *sw; in prestera_device_register() local
1490 sw = prestera_devlink_alloc(dev); in prestera_device_register()
1491 if (!sw) in prestera_device_register()
1494 dev->priv = sw; in prestera_device_register()
1495 sw->dev = dev; in prestera_device_register()
1497 err = prestera_switch_init(sw); in prestera_device_register()
1499 prestera_devlink_free(sw); in prestera_device_register()
1509 struct prestera_switch *sw = dev->priv; in prestera_device_unregister() local
1511 prestera_switch_fini(sw); in prestera_device_unregister()
1512 prestera_devlink_free(sw); in prestera_device_unregister()