Lines Matching +full:gbe +full:- +full:core

1 // SPDX-License-Identifier: GPL-2.0+
33 * enum mlxreg_lc_type - line cards types
35 * @MLXREG_LC_SN4800_C16: 100GbE line card with 16 QSFP28 ports;
42 * enum mlxreg_lc_state - line cards state
56 /* mlxreg_lc - device private data
60 * @data: platform core data;
186 I2C_BOARD_INFO("i2c-mux-mlxcpld", 0x32),
420 dev->client = i2c_new_client_device(dev->adapter, dev->brdinfo); in mlxreg_lc_create_static_devices()
421 if (IS_ERR(dev->client)) { in mlxreg_lc_create_static_devices()
422 dev_err(mlxreg_lc->dev, "Failed to create client %s at bus %d at addr 0x%02x\n", in mlxreg_lc_create_static_devices()
423 dev->brdinfo->type, dev->nr, dev->brdinfo->addr); in mlxreg_lc_create_static_devices()
425 dev->adapter = NULL; in mlxreg_lc_create_static_devices()
426 ret = PTR_ERR(dev->client); in mlxreg_lc_create_static_devices()
434 while (--i >= 0) { in mlxreg_lc_create_static_devices()
436 i2c_unregister_device(dev->client); in mlxreg_lc_create_static_devices()
437 dev->client = NULL; in mlxreg_lc_create_static_devices()
451 if (dev->client) { in mlxreg_lc_destroy_static_devices()
452 i2c_unregister_device(dev->client); in mlxreg_lc_destroy_static_devices()
453 dev->client = NULL; in mlxreg_lc_destroy_static_devices()
463 err = regmap_read(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_pwr, &regval); in mlxreg_lc_power_on_off()
468 regval |= BIT(mlxreg_lc->data->slot - 1); in mlxreg_lc_power_on_off()
470 regval &= ~BIT(mlxreg_lc->data->slot - 1); in mlxreg_lc_power_on_off()
472 err = regmap_write(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_pwr, regval); in mlxreg_lc_power_on_off()
487 * disabled for moving it to non-operational state. Enabling line card does not affect the in mlxreg_lc_enable_disable()
491 err = regmap_read(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_ena, &regval); in mlxreg_lc_enable_disable()
496 regval |= BIT(mlxreg_lc->data->slot - 1); in mlxreg_lc_enable_disable()
498 regval &= ~BIT(mlxreg_lc->data->slot - 1); in mlxreg_lc_enable_disable()
500 err = regmap_write(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_ena, regval); in mlxreg_lc_enable_disable()
510 struct device *dev = &data->hpdev.client->dev; in mlxreg_lc_sn4800_c16_config_init()
513 mlxreg_lc->mux_data = mlxreg_lc_mux_data; in mlxreg_lc_sn4800_c16_config_init()
514 mlxreg_lc->io_data = &mlxreg_lc_regs_io; in mlxreg_lc_sn4800_c16_config_init()
515 mlxreg_lc->led_data = &mlxreg_lc_led; in mlxreg_lc_sn4800_c16_config_init()
516 mlxreg_lc->mux_brdinfo = &mlxreg_lc_mux_brdinfo; in mlxreg_lc_sn4800_c16_config_init()
518 mlxreg_lc->aux_devs = devm_kmemdup(dev, mlxreg_lc_aux_pwr_brdinfo, in mlxreg_lc_sn4800_c16_config_init()
520 if (!mlxreg_lc->aux_devs) in mlxreg_lc_sn4800_c16_config_init()
521 return -ENOMEM; in mlxreg_lc_sn4800_c16_config_init()
522 mlxreg_lc->aux_devs_num = ARRAY_SIZE(mlxreg_lc_aux_pwr_brdinfo); in mlxreg_lc_sn4800_c16_config_init()
523 mlxreg_lc->main_devs = devm_kmemdup(dev, mlxreg_lc_main_pwr_brdinfo, in mlxreg_lc_sn4800_c16_config_init()
525 if (!mlxreg_lc->main_devs) in mlxreg_lc_sn4800_c16_config_init()
526 return -ENOMEM; in mlxreg_lc_sn4800_c16_config_init()
527 mlxreg_lc->main_devs_num = ARRAY_SIZE(mlxreg_lc_main_pwr_brdinfo); in mlxreg_lc_sn4800_c16_config_init()
536 mlxreg_lc->state |= state; in mlxreg_lc_state_update()
538 mlxreg_lc->state &= ~state; in mlxreg_lc_state_update()
544 mutex_lock(&mlxreg_lc->lock); in mlxreg_lc_state_update_locked()
547 mlxreg_lc->state |= state; in mlxreg_lc_state_update_locked()
549 mlxreg_lc->state &= ~state; in mlxreg_lc_state_update_locked()
551 mutex_unlock(&mlxreg_lc->lock); in mlxreg_lc_state_update_locked()
555 * Callback is to be called from mlxreg-hotplug driver to notify about line card about received
563 dev_info(mlxreg_lc->dev, "linecard#%d state %d event kind %d action %d\n", in mlxreg_lc_event_handler()
564 mlxreg_lc->data->slot, mlxreg_lc->state, kind, action); in mlxreg_lc_event_handler()
566 mutex_lock(&mlxreg_lc->lock); in mlxreg_lc_event_handler()
567 if (!(mlxreg_lc->state & MLXREG_LC_INITIALIZED)) in mlxreg_lc_event_handler()
573 * Synchronization event - hardware and firmware are synchronized. Power on/off in mlxreg_lc_event_handler()
574 * line card - to allow/disallow main power source. in mlxreg_lc_event_handler()
578 if (!(mlxreg_lc->state & MLXREG_LC_POWERED) && action) { in mlxreg_lc_event_handler()
583 /* In case line card is configured - enable it. */ in mlxreg_lc_event_handler()
584 if (mlxreg_lc->state & MLXREG_LC_CONFIGURED && action) in mlxreg_lc_event_handler()
588 /* Power event - attach or de-attach line card device feeding by the main power. */ in mlxreg_lc_event_handler()
591 if (mlxreg_lc->state & MLXREG_LC_POWERED) { in mlxreg_lc_event_handler()
592 /* In case line card is configured - enable it. */ in mlxreg_lc_event_handler()
593 if (mlxreg_lc->state & MLXREG_LC_CONFIGURED) in mlxreg_lc_event_handler()
598 err = mlxreg_lc_create_static_devices(mlxreg_lc, mlxreg_lc->main_devs, in mlxreg_lc_event_handler()
599 mlxreg_lc->main_devs_num); in mlxreg_lc_event_handler()
603 /* In case line card is already in ready state - enable it. */ in mlxreg_lc_event_handler()
604 if (mlxreg_lc->state & MLXREG_LC_CONFIGURED) in mlxreg_lc_event_handler()
607 mlxreg_lc_destroy_static_devices(mlxreg_lc, mlxreg_lc->main_devs, in mlxreg_lc_event_handler()
608 mlxreg_lc->main_devs_num); in mlxreg_lc_event_handler()
632 mutex_unlock(&mlxreg_lc->lock); in mlxreg_lc_event_handler()
638 * Callback is to be called from i2c-mux-mlxcpld driver to indicate that all adapter devices has
650 aux_dev = mlxreg_lc->aux_devs; in mlxreg_lc_completion_notify()
651 for (i = 0; i < mlxreg_lc->aux_devs_num; i++, aux_dev++) { in mlxreg_lc_completion_notify()
652 aux_dev->adapter = adapters[aux_dev->nr]; in mlxreg_lc_completion_notify()
653 aux_dev->nr = adapters[aux_dev->nr]->nr; in mlxreg_lc_completion_notify()
656 err = mlxreg_lc_create_static_devices(mlxreg_lc, mlxreg_lc->aux_devs, in mlxreg_lc_completion_notify()
657 mlxreg_lc->aux_devs_num); in mlxreg_lc_completion_notify()
662 main_dev = mlxreg_lc->main_devs; in mlxreg_lc_completion_notify()
663 for (i = 0; i < mlxreg_lc->main_devs_num; i++, main_dev++) { in mlxreg_lc_completion_notify()
664 main_dev->adapter = adapters[main_dev->nr]; in mlxreg_lc_completion_notify()
665 main_dev->nr = adapters[main_dev->nr]->nr; in mlxreg_lc_completion_notify()
669 err = regmap_read(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_pwr, &regval); in mlxreg_lc_completion_notify()
673 if (regval & mlxreg_lc->data->mask) { in mlxreg_lc_completion_notify()
674 err = mlxreg_lc_create_static_devices(mlxreg_lc, mlxreg_lc->main_devs, in mlxreg_lc_completion_notify()
675 mlxreg_lc->main_devs_num); in mlxreg_lc_completion_notify()
683 err = regmap_read(mlxreg_lc->par_regmap, mlxreg_lc->data->reg_sync, &regval); in mlxreg_lc_completion_notify()
688 if (regval & mlxreg_lc->data->mask) { in mlxreg_lc_completion_notify()
689 mlxreg_lc->state |= MLXREG_LC_SYNCED; in mlxreg_lc_completion_notify()
691 if (!(mlxreg_lc->state & MLXREG_LC_POWERED)) { in mlxreg_lc_completion_notify()
704 if (mlxreg_lc->state & MLXREG_LC_POWERED) in mlxreg_lc_completion_notify()
705 mlxreg_lc_destroy_static_devices(mlxreg_lc, mlxreg_lc->main_devs, in mlxreg_lc_completion_notify()
706 mlxreg_lc->main_devs_num); in mlxreg_lc_completion_notify()
708 mlxreg_lc_destroy_static_devices(mlxreg_lc, mlxreg_lc->aux_devs, mlxreg_lc->aux_devs_num); in mlxreg_lc_completion_notify()
717 struct device *dev = &data->hpdev.client->dev; in mlxreg_lc_config_init()
732 data->hpdev.brdinfo->type, data->hpdev.nr, in mlxreg_lc_config_init()
733 data->hpdev.brdinfo->addr); in mlxreg_lc_config_init()
738 return -ENODEV; in mlxreg_lc_config_init()
742 mlxreg_lc->mux_data->handle = mlxreg_lc; in mlxreg_lc_config_init()
743 mlxreg_lc->mux_data->completion_notify = mlxreg_lc_completion_notify; in mlxreg_lc_config_init()
744 mlxreg_lc->mux_brdinfo->platform_data = mlxreg_lc->mux_data; in mlxreg_lc_config_init()
745 mlxreg_lc->mux = platform_device_register_resndata(dev, "i2c-mux-mlxcpld", data->hpdev.nr, in mlxreg_lc_config_init()
746 NULL, 0, mlxreg_lc->mux_data, in mlxreg_lc_config_init()
747 sizeof(*mlxreg_lc->mux_data)); in mlxreg_lc_config_init()
748 if (IS_ERR(mlxreg_lc->mux)) { in mlxreg_lc_config_init()
750 data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr); in mlxreg_lc_config_init()
751 return PTR_ERR(mlxreg_lc->mux); in mlxreg_lc_config_init()
755 if (mlxreg_lc->io_data) { in mlxreg_lc_config_init()
756 mlxreg_lc->io_data->regmap = regmap; in mlxreg_lc_config_init()
757 mlxreg_lc->io_regs = in mlxreg_lc_config_init()
758 platform_device_register_resndata(dev, "mlxreg-io", data->hpdev.nr, NULL, 0, in mlxreg_lc_config_init()
759 mlxreg_lc->io_data, sizeof(*mlxreg_lc->io_data)); in mlxreg_lc_config_init()
760 if (IS_ERR(mlxreg_lc->io_regs)) { in mlxreg_lc_config_init()
762 data->hpdev.brdinfo->type, data->hpdev.nr, in mlxreg_lc_config_init()
763 data->hpdev.brdinfo->addr); in mlxreg_lc_config_init()
764 err = PTR_ERR(mlxreg_lc->io_regs); in mlxreg_lc_config_init()
770 if (mlxreg_lc->led_data) { in mlxreg_lc_config_init()
771 mlxreg_lc->led_data->regmap = regmap; in mlxreg_lc_config_init()
772 mlxreg_lc->led = in mlxreg_lc_config_init()
773 platform_device_register_resndata(dev, "leds-mlxreg", data->hpdev.nr, NULL, 0, in mlxreg_lc_config_init()
774 mlxreg_lc->led_data, in mlxreg_lc_config_init()
775 sizeof(*mlxreg_lc->led_data)); in mlxreg_lc_config_init()
776 if (IS_ERR(mlxreg_lc->led)) { in mlxreg_lc_config_init()
778 data->hpdev.brdinfo->type, data->hpdev.nr, in mlxreg_lc_config_init()
779 data->hpdev.brdinfo->addr); in mlxreg_lc_config_init()
780 err = PTR_ERR(mlxreg_lc->led); in mlxreg_lc_config_init()
788 if (mlxreg_lc->io_regs) in mlxreg_lc_config_init()
789 platform_device_unregister(mlxreg_lc->io_regs); in mlxreg_lc_config_init()
791 if (mlxreg_lc->mux) in mlxreg_lc_config_init()
792 platform_device_unregister(mlxreg_lc->mux); in mlxreg_lc_config_init()
800 if (mlxreg_lc->led) in mlxreg_lc_config_exit()
801 platform_device_unregister(mlxreg_lc->led); in mlxreg_lc_config_exit()
803 if (mlxreg_lc->io_regs) in mlxreg_lc_config_exit()
804 platform_device_unregister(mlxreg_lc->io_regs); in mlxreg_lc_config_exit()
806 if (mlxreg_lc->mux) in mlxreg_lc_config_exit()
807 platform_device_unregister(mlxreg_lc->mux); in mlxreg_lc_config_exit()
818 data = dev_get_platdata(&pdev->dev); in mlxreg_lc_probe()
820 return -EINVAL; in mlxreg_lc_probe()
822 mlxreg_lc = devm_kzalloc(&pdev->dev, sizeof(*mlxreg_lc), GFP_KERNEL); in mlxreg_lc_probe()
824 return -ENOMEM; in mlxreg_lc_probe()
826 mutex_init(&mlxreg_lc->lock); in mlxreg_lc_probe()
828 data->notifier->user_handler = mlxreg_lc_event_handler; in mlxreg_lc_probe()
829 data->notifier->handle = mlxreg_lc; in mlxreg_lc_probe()
831 data->hpdev.adapter = i2c_get_adapter(data->hpdev.nr); in mlxreg_lc_probe()
832 if (!data->hpdev.adapter) { in mlxreg_lc_probe()
833 dev_err(&pdev->dev, "Failed to get adapter for bus %d\n", in mlxreg_lc_probe()
834 data->hpdev.nr); in mlxreg_lc_probe()
835 err = -EFAULT; in mlxreg_lc_probe()
840 data->hpdev.client = i2c_new_client_device(data->hpdev.adapter, in mlxreg_lc_probe()
841 data->hpdev.brdinfo); in mlxreg_lc_probe()
842 if (IS_ERR(data->hpdev.client)) { in mlxreg_lc_probe()
843 dev_err(&pdev->dev, "Failed to create client %s at bus %d at addr 0x%02x\n", in mlxreg_lc_probe()
844 data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr); in mlxreg_lc_probe()
845 err = PTR_ERR(data->hpdev.client); in mlxreg_lc_probe()
849 regmap = devm_regmap_init_i2c(data->hpdev.client, in mlxreg_lc_probe()
852 dev_err(&pdev->dev, "Failed to create regmap for client %s at bus %d at addr 0x%02x\n", in mlxreg_lc_probe()
853 data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr); in mlxreg_lc_probe()
863 dev_err(&pdev->dev, "Failed to set default regmap %d for client %s at bus %d at addr 0x%02x\n", in mlxreg_lc_probe()
864 i, data->hpdev.brdinfo->type, data->hpdev.nr, in mlxreg_lc_probe()
865 data->hpdev.brdinfo->addr); in mlxreg_lc_probe()
874 dev_err(&pdev->dev, "Failed to sync regmap for client %s at bus %d at addr 0x%02x\n", in mlxreg_lc_probe()
875 data->hpdev.brdinfo->type, data->hpdev.nr, data->hpdev.brdinfo->addr); in mlxreg_lc_probe()
879 par_pdata = data->hpdev.brdinfo->platform_data; in mlxreg_lc_probe()
880 mlxreg_lc->par_regmap = par_pdata->regmap; in mlxreg_lc_probe()
881 mlxreg_lc->data = data; in mlxreg_lc_probe()
882 mlxreg_lc->dev = &pdev->dev; in mlxreg_lc_probe()
896 i2c_unregister_device(data->hpdev.client); in mlxreg_lc_probe()
897 data->hpdev.client = NULL; in mlxreg_lc_probe()
899 i2c_put_adapter(data->hpdev.adapter); in mlxreg_lc_probe()
900 data->hpdev.adapter = NULL; in mlxreg_lc_probe()
903 if (data->notifier) { in mlxreg_lc_probe()
904 data->notifier->user_handler = NULL; in mlxreg_lc_probe()
905 data->notifier->handle = NULL; in mlxreg_lc_probe()
912 struct mlxreg_core_data *data = dev_get_platdata(&pdev->dev); in mlxreg_lc_remove()
923 if (!data->notifier || !data->notifier->handle) in mlxreg_lc_remove()
927 data->notifier->user_handler = NULL; in mlxreg_lc_remove()
928 data->notifier->handle = NULL; in mlxreg_lc_remove()
931 mlxreg_lc_destroy_static_devices(mlxreg_lc, mlxreg_lc->main_devs, in mlxreg_lc_remove()
932 mlxreg_lc->main_devs_num); in mlxreg_lc_remove()
934 mlxreg_lc_destroy_static_devices(mlxreg_lc, mlxreg_lc->aux_devs, mlxreg_lc->aux_devs_num); in mlxreg_lc_remove()
937 if (data->hpdev.client) { in mlxreg_lc_remove()
938 i2c_unregister_device(data->hpdev.client); in mlxreg_lc_remove()
939 data->hpdev.client = NULL; in mlxreg_lc_remove()
940 i2c_put_adapter(data->hpdev.adapter); in mlxreg_lc_remove()
941 data->hpdev.adapter = NULL; in mlxreg_lc_remove()
949 .name = "mlxreg-lc",
958 MODULE_ALIAS("platform:mlxreg-lc");