Lines Matching refs:mlxsw_m

34 struct mlxsw_m {  struct
47 struct mlxsw_m *mlxsw_m; argument
54 static int mlxsw_m_base_mac_get(struct mlxsw_m *mlxsw_m) in mlxsw_m_base_mac_get() argument
59 err = mlxsw_reg_query(mlxsw_m->core, MLXSW_REG(spad), spad_pl); in mlxsw_m_base_mac_get()
62 mlxsw_reg_spad_base_mac_memcpy_from(spad_pl, mlxsw_m->base_mac); in mlxsw_m_base_mac_get()
69 struct mlxsw_m *mlxsw_m = mlxsw_m_port->mlxsw_m; in mlxsw_m_port_open() local
71 return mlxsw_env_module_port_up(mlxsw_m->core, 0, in mlxsw_m_port_open()
78 struct mlxsw_m *mlxsw_m = mlxsw_m_port->mlxsw_m; in mlxsw_m_port_stop() local
80 mlxsw_env_module_port_down(mlxsw_m->core, 0, mlxsw_m_port->module); in mlxsw_m_port_stop()
88 struct mlxsw_m *mlxsw_m = mlxsw_m_port->mlxsw_m; in mlxsw_m_port_get_devlink_port() local
90 return mlxsw_core_port_devlink_port_get(mlxsw_m->core, in mlxsw_m_port_get_devlink_port()
104 struct mlxsw_m *mlxsw_m = mlxsw_m_port->mlxsw_m; in mlxsw_m_module_get_drvinfo() local
106 strscpy(drvinfo->driver, mlxsw_m->bus_info->device_kind, in mlxsw_m_module_get_drvinfo()
110 mlxsw_m->bus_info->fw_rev.major, in mlxsw_m_module_get_drvinfo()
111 mlxsw_m->bus_info->fw_rev.minor, in mlxsw_m_module_get_drvinfo()
112 mlxsw_m->bus_info->fw_rev.subminor); in mlxsw_m_module_get_drvinfo()
113 strscpy(drvinfo->bus_info, mlxsw_m->bus_info->device_name, in mlxsw_m_module_get_drvinfo()
121 struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; in mlxsw_m_get_module_info()
133 struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; in mlxsw_m_get_module_eeprom()
146 struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; in mlxsw_m_get_module_eeprom_by_page()
157 struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; in mlxsw_m_reset()
170 struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; in mlxsw_m_get_module_power_mode()
183 struct mlxsw_core *core = mlxsw_m_port->mlxsw_m->core; in mlxsw_m_set_module_power_mode()
201 mlxsw_m_port_module_info_get(struct mlxsw_m *mlxsw_m, u16 local_port, in mlxsw_m_port_module_info_get() argument
208 err = mlxsw_reg_query(mlxsw_m->core, MLXSW_REG(pmlp), pmlp_pl); in mlxsw_m_port_module_info_get()
221 struct mlxsw_m *mlxsw_m = mlxsw_m_port->mlxsw_m; in mlxsw_m_port_dev_addr_get() local
227 err = mlxsw_reg_query(mlxsw_m->core, MLXSW_REG(ppad), ppad_pl); in mlxsw_m_port_dev_addr_get()
236 static bool mlxsw_m_port_created(struct mlxsw_m *mlxsw_m, u16 local_port) in mlxsw_m_port_created() argument
238 return mlxsw_m->ports[local_port]; in mlxsw_m_port_created()
242 mlxsw_m_port_create(struct mlxsw_m *mlxsw_m, u16 local_port, u8 slot_index, in mlxsw_m_port_create() argument
249 err = mlxsw_core_port_init(mlxsw_m->core, local_port, slot_index, in mlxsw_m_port_create()
251 0, mlxsw_m->base_mac, in mlxsw_m_port_create()
252 sizeof(mlxsw_m->base_mac)); in mlxsw_m_port_create()
254 dev_err(mlxsw_m->bus_info->dev, "Port %d: Failed to init core port\n", in mlxsw_m_port_create()
265 SET_NETDEV_DEV(dev, mlxsw_m->bus_info->dev); in mlxsw_m_port_create()
266 dev_net_set(dev, mlxsw_core_net(mlxsw_m->core)); in mlxsw_m_port_create()
269 mlxsw_m_port->mlxsw_m = mlxsw_m; in mlxsw_m_port_create()
280 mlxsw_m->max_modules_per_slot : 0; in mlxsw_m_port_create()
287 dev_err(mlxsw_m->bus_info->dev, "Port %d: Unable to get port mac address\n", in mlxsw_m_port_create()
293 mlxsw_m->ports[local_port] = mlxsw_m_port; in mlxsw_m_port_create()
296 dev_err(mlxsw_m->bus_info->dev, "Port %d: Failed to register netdev\n", in mlxsw_m_port_create()
301 mlxsw_core_port_eth_set(mlxsw_m->core, mlxsw_m_port->local_port, in mlxsw_m_port_create()
307 mlxsw_m->ports[local_port] = NULL; in mlxsw_m_port_create()
311 mlxsw_core_port_fini(mlxsw_m->core, local_port); in mlxsw_m_port_create()
315 static void mlxsw_m_port_remove(struct mlxsw_m *mlxsw_m, u16 local_port) in mlxsw_m_port_remove() argument
317 struct mlxsw_m_port *mlxsw_m_port = mlxsw_m->ports[local_port]; in mlxsw_m_port_remove()
319 mlxsw_core_port_clear(mlxsw_m->core, local_port, mlxsw_m); in mlxsw_m_port_remove()
321 mlxsw_m->ports[local_port] = NULL; in mlxsw_m_port_remove()
323 mlxsw_core_port_fini(mlxsw_m->core, local_port); in mlxsw_m_port_remove()
327 mlxsw_m_port_mapping_get(struct mlxsw_m *mlxsw_m, u8 slot_index, u8 module) in mlxsw_m_port_mapping_get() argument
329 return &mlxsw_m->line_cards[slot_index]->module_to_port[module]; in mlxsw_m_port_mapping_get()
332 static int mlxsw_m_port_module_map(struct mlxsw_m *mlxsw_m, u16 local_port, in mlxsw_m_port_module_map() argument
335 unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core); in mlxsw_m_port_module_map()
341 err = mlxsw_m_port_module_info_get(mlxsw_m, local_port, &module, in mlxsw_m_port_module_map()
347 if (mlxsw_m->line_cards[slot_index]->active) in mlxsw_m_port_module_map()
358 mlxsw_env_module_port_map(mlxsw_m->core, slot_index, module); in mlxsw_m_port_module_map()
359 module_to_port = mlxsw_m_port_mapping_get(mlxsw_m, slot_index, module); in mlxsw_m_port_module_map()
366 mlxsw_m_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 slot_index, u8 module) in mlxsw_m_port_module_unmap() argument
368 int *module_to_port = mlxsw_m_port_mapping_get(mlxsw_m, slot_index, in mlxsw_m_port_module_unmap()
371 mlxsw_env_module_port_unmap(mlxsw_m->core, slot_index, module); in mlxsw_m_port_module_unmap()
374 static int mlxsw_m_linecards_init(struct mlxsw_m *mlxsw_m) in mlxsw_m_linecards_init() argument
376 unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core); in mlxsw_m_linecards_init()
382 err = mlxsw_reg_query(mlxsw_m->core, MLXSW_REG(mgpir), mgpir_pl); in mlxsw_m_linecards_init()
387 &mlxsw_m->num_of_slots); in mlxsw_m_linecards_init()
391 if (mlxsw_m->num_of_slots) in mlxsw_m_linecards_init()
392 mlxsw_m->max_modules_per_slot = in mlxsw_m_linecards_init()
395 mlxsw_m->max_modules_per_slot = num_of_modules; in mlxsw_m_linecards_init()
397 mlxsw_m->num_of_slots += 1; in mlxsw_m_linecards_init()
399 mlxsw_m->ports = kcalloc(max_ports, sizeof(*mlxsw_m->ports), in mlxsw_m_linecards_init()
401 if (!mlxsw_m->ports) in mlxsw_m_linecards_init()
404 mlxsw_m->line_cards = kcalloc(mlxsw_m->num_of_slots, in mlxsw_m_linecards_init()
405 sizeof(*mlxsw_m->line_cards), in mlxsw_m_linecards_init()
407 if (!mlxsw_m->line_cards) { in mlxsw_m_linecards_init()
412 for (i = 0; i < mlxsw_m->num_of_slots; i++) { in mlxsw_m_linecards_init()
413 mlxsw_m->line_cards[i] = in mlxsw_m_linecards_init()
414 kzalloc(struct_size(mlxsw_m->line_cards[i], in mlxsw_m_linecards_init()
416 mlxsw_m->max_modules_per_slot), in mlxsw_m_linecards_init()
418 if (!mlxsw_m->line_cards[i]) { in mlxsw_m_linecards_init()
424 for (j = 0; j < mlxsw_m->max_modules_per_slot; j++) in mlxsw_m_linecards_init()
425 mlxsw_m->line_cards[i]->module_to_port[j] = -1; in mlxsw_m_linecards_init()
432 kfree(mlxsw_m->line_cards[i]); in mlxsw_m_linecards_init()
434 kfree(mlxsw_m->ports); in mlxsw_m_linecards_init()
438 static void mlxsw_m_linecards_fini(struct mlxsw_m *mlxsw_m) in mlxsw_m_linecards_fini() argument
440 int i = mlxsw_m->num_of_slots; in mlxsw_m_linecards_fini()
443 kfree(mlxsw_m->line_cards[i]); in mlxsw_m_linecards_fini()
444 kfree(mlxsw_m->line_cards); in mlxsw_m_linecards_fini()
445 kfree(mlxsw_m->ports); in mlxsw_m_linecards_fini()
449 mlxsw_m_linecard_port_module_unmap(struct mlxsw_m *mlxsw_m, u8 slot_index) in mlxsw_m_linecard_port_module_unmap() argument
453 for (i = mlxsw_m->max_modules_per_slot - 1; i >= 0; i--) { in mlxsw_m_linecard_port_module_unmap()
456 module_to_port = mlxsw_m_port_mapping_get(mlxsw_m, slot_index, i); in mlxsw_m_linecard_port_module_unmap()
458 mlxsw_m_port_module_unmap(mlxsw_m, slot_index, i); in mlxsw_m_linecard_port_module_unmap()
463 mlxsw_m_linecard_ports_create(struct mlxsw_m *mlxsw_m, u8 slot_index) in mlxsw_m_linecard_ports_create() argument
468 for (i = 0; i < mlxsw_m->max_modules_per_slot; i++) { in mlxsw_m_linecard_ports_create()
469 module_to_port = mlxsw_m_port_mapping_get(mlxsw_m, slot_index, i); in mlxsw_m_linecard_ports_create()
471 err = mlxsw_m_port_create(mlxsw_m, *module_to_port, in mlxsw_m_linecard_ports_create()
476 if (!mlxsw_m->line_cards[slot_index]->active) in mlxsw_m_linecard_ports_create()
477 mlxsw_m->line_cards[slot_index]->active = true; in mlxsw_m_linecard_ports_create()
484 module_to_port = mlxsw_m_port_mapping_get(mlxsw_m, slot_index, i); in mlxsw_m_linecard_ports_create()
486 mlxsw_m_port_created(mlxsw_m, *module_to_port)) { in mlxsw_m_linecard_ports_create()
487 mlxsw_m_port_remove(mlxsw_m, *module_to_port); in mlxsw_m_linecard_ports_create()
489 if (mlxsw_m->line_cards[slot_index]->active) in mlxsw_m_linecard_ports_create()
490 mlxsw_m->line_cards[slot_index]->active = false; in mlxsw_m_linecard_ports_create()
497 mlxsw_m_linecard_ports_remove(struct mlxsw_m *mlxsw_m, u8 slot_index) in mlxsw_m_linecard_ports_remove() argument
501 for (i = 0; i < mlxsw_m->max_modules_per_slot; i++) { in mlxsw_m_linecard_ports_remove()
502 int *module_to_port = mlxsw_m_port_mapping_get(mlxsw_m, in mlxsw_m_linecard_ports_remove()
506 mlxsw_m_port_created(mlxsw_m, *module_to_port)) { in mlxsw_m_linecard_ports_remove()
507 mlxsw_m_port_remove(mlxsw_m, *module_to_port); in mlxsw_m_linecard_ports_remove()
508 mlxsw_m_port_module_unmap(mlxsw_m, slot_index, i); in mlxsw_m_linecard_ports_remove()
513 static int mlxsw_m_ports_module_map(struct mlxsw_m *mlxsw_m) in mlxsw_m_ports_module_map() argument
515 unsigned int max_ports = mlxsw_core_max_ports(mlxsw_m->core); in mlxsw_m_ports_module_map()
520 err = mlxsw_m_port_module_map(mlxsw_m, i, &last_module); in mlxsw_m_ports_module_map()
528 static int mlxsw_m_ports_create(struct mlxsw_m *mlxsw_m) in mlxsw_m_ports_create() argument
533 err = mlxsw_m_ports_module_map(mlxsw_m); in mlxsw_m_ports_create()
538 err = mlxsw_m_linecard_ports_create(mlxsw_m, 0); in mlxsw_m_ports_create()
546 mlxsw_m_linecard_port_module_unmap(mlxsw_m, 0); in mlxsw_m_ports_create()
551 static void mlxsw_m_ports_remove(struct mlxsw_m *mlxsw_m) in mlxsw_m_ports_remove() argument
553 mlxsw_m_linecard_ports_remove(mlxsw_m, 0); in mlxsw_m_ports_remove()
561 struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core); in mlxsw_m_ports_remove_selected() local
565 linecard = mlxsw_m->line_cards[linecard_priv->slot_index]; in mlxsw_m_ports_remove_selected()
570 mlxsw_m_linecard_ports_remove(mlxsw_m, linecard_priv->slot_index); in mlxsw_m_ports_remove_selected()
574 static int mlxsw_m_fw_rev_validate(struct mlxsw_m *mlxsw_m) in mlxsw_m_fw_rev_validate() argument
576 const struct mlxsw_fw_rev *rev = &mlxsw_m->bus_info->fw_rev; in mlxsw_m_fw_rev_validate()
585 …dev_err(mlxsw_m->bus_info->dev, "The firmware version %d.%d.%d is incompatible with the driver (re… in mlxsw_m_fw_rev_validate()
596 struct mlxsw_m *mlxsw_m = priv; in mlxsw_m_got_active() local
599 linecard = mlxsw_m->line_cards[slot_index]; in mlxsw_m_got_active()
605 err = mlxsw_m_ports_module_map(mlxsw_m); in mlxsw_m_got_active()
610 err = mlxsw_m_linecard_ports_create(mlxsw_m, slot_index); in mlxsw_m_got_active()
612 dev_err(mlxsw_m->bus_info->dev, "Failed to create port for line card at slot %d\n", in mlxsw_m_got_active()
623 mlxsw_m_linecard_port_module_unmap(mlxsw_m, slot_index); in mlxsw_m_got_active()
630 struct mlxsw_m *mlxsw_m = priv; in mlxsw_m_got_inactive() local
632 linecard = mlxsw_m->line_cards[slot_index]; in mlxsw_m_got_inactive()
637 mlxsw_m_linecard_ports_remove(mlxsw_m, slot_index); in mlxsw_m_got_inactive()
650 struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core); in mlxsw_m_init() local
653 mlxsw_m->core = mlxsw_core; in mlxsw_m_init()
654 mlxsw_m->bus_info = mlxsw_bus_info; in mlxsw_m_init()
656 err = mlxsw_m_fw_rev_validate(mlxsw_m); in mlxsw_m_init()
660 err = mlxsw_m_base_mac_get(mlxsw_m); in mlxsw_m_init()
662 dev_err(mlxsw_m->bus_info->dev, "Failed to get base mac\n"); in mlxsw_m_init()
666 err = mlxsw_m_linecards_init(mlxsw_m); in mlxsw_m_init()
668 dev_err(mlxsw_m->bus_info->dev, "Failed to create line cards\n"); in mlxsw_m_init()
673 &mlxsw_m_event_ops, mlxsw_m); in mlxsw_m_init()
675 dev_err(mlxsw_m->bus_info->dev, "Failed to register line cards operations\n"); in mlxsw_m_init()
679 err = mlxsw_m_ports_create(mlxsw_m); in mlxsw_m_init()
681 dev_err(mlxsw_m->bus_info->dev, "Failed to create ports\n"); in mlxsw_m_init()
689 &mlxsw_m_event_ops, mlxsw_m); in mlxsw_m_init()
691 mlxsw_m_linecards_fini(mlxsw_m); in mlxsw_m_init()
697 struct mlxsw_m *mlxsw_m = mlxsw_core_driver_priv(mlxsw_core); in mlxsw_m_fini() local
699 mlxsw_m_ports_remove(mlxsw_m); in mlxsw_m_fini()
701 &mlxsw_m_event_ops, mlxsw_m); in mlxsw_m_fini()
702 mlxsw_m_linecards_fini(mlxsw_m); in mlxsw_m_fini()
709 .priv_size = sizeof(struct mlxsw_m),