Lines Matching full:sparx5

2 /* Microchip Sparx5 Switch driver
6 * The Sparx5 Chip Register Model can be browsed at this location:
214 static int sparx5_create_targets(struct sparx5 *sparx5) in sparx5_create_targets() argument
231 iores[idx] = platform_get_resource(sparx5->pdev, IORESOURCE_MEM, in sparx5_create_targets()
234 dev_err(sparx5->dev, "Invalid resource\n"); in sparx5_create_targets()
237 iomem[idx] = devm_ioremap(sparx5->dev, in sparx5_create_targets()
241 dev_err(sparx5->dev, "Unable to get switch registers: %s\n", in sparx5_create_targets()
250 sparx5->regs[iomap->id] = begin[iomap->range] + iomap->offset; in sparx5_create_targets()
255 static int sparx5_create_port(struct sparx5 *sparx5, in sparx5_create_port() argument
263 ndev = sparx5_create_netdev(sparx5, config->portno); in sparx5_create_port()
265 dev_err(sparx5->dev, "Could not create net device: %02u\n", in sparx5_create_port()
282 sparx5->ports[config->portno] = spx5_port; in sparx5_create_port()
284 err = sparx5_port_init(sparx5, spx5_port, &config->conf); in sparx5_create_port()
286 dev_err(sparx5->dev, "port init failed\n"); in sparx5_create_port()
292 sparx5_vlan_port_setup(sparx5, spx5_port->portno); in sparx5_create_port()
337 static int sparx5_init_ram(struct sparx5 *s5) in sparx5_init_ram()
381 static int sparx5_init_switchcore(struct sparx5 *sparx5) in sparx5_init_switchcore() argument
388 sparx5, in sparx5_init_switchcore()
393 sparx5, in sparx5_init_switchcore()
397 value = spx5_rd(sparx5, HSCH_RESET_CFG); in sparx5_init_switchcore()
399 err = sparx5_init_ram(sparx5); in sparx5_init_switchcore()
405 spx5_wr(ANA_AC_STAT_RESET_RESET_SET(1), sparx5, ANA_AC_STAT_RESET); in sparx5_init_switchcore()
406 spx5_wr(ASM_STAT_CFG_STAT_CNT_CLR_SHOT_SET(1), sparx5, ASM_STAT_CFG); in sparx5_init_switchcore()
409 spx5_wr(HSCH_RESET_CFG_CORE_ENA_SET(1), sparx5, HSCH_RESET_CFG); in sparx5_init_switchcore()
414 static int sparx5_init_coreclock(struct sparx5 *sparx5) in sparx5_init_coreclock() argument
416 enum sparx5_core_clockfreq freq = sparx5->coreclock; in sparx5_init_coreclock()
423 switch (sparx5->target_ct) { in sparx5_init_coreclock()
425 if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT) in sparx5_init_coreclock()
427 else if (sparx5->coreclock != SPX5_CORE_CLOCK_250MHZ) in sparx5_init_coreclock()
433 if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT) in sparx5_init_coreclock()
435 else if (sparx5->coreclock != SPX5_CORE_CLOCK_500MHZ) in sparx5_init_coreclock()
440 if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT) in sparx5_init_coreclock()
442 else if (sparx5->coreclock != SPX5_CORE_CLOCK_625MHZ) in sparx5_init_coreclock()
446 if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT) in sparx5_init_coreclock()
452 if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT) in sparx5_init_coreclock()
454 else if (sparx5->coreclock == SPX5_CORE_CLOCK_250MHZ) in sparx5_init_coreclock()
458 dev_err(sparx5->dev, "Target (%#04x) not supported\n", in sparx5_init_coreclock()
459 sparx5->target_ct); in sparx5_init_coreclock()
477 dev_err(sparx5->dev, "%d coreclock not supported on (%#04x)\n", in sparx5_init_coreclock()
478 sparx5->coreclock, sparx5->target_ct); in sparx5_init_coreclock()
483 sparx5->coreclock = freq; in sparx5_init_coreclock()
498 sparx5, in sparx5_init_coreclock()
505 sparx5, in sparx5_init_coreclock()
510 sparx5, in sparx5_init_coreclock()
515 sparx5, in sparx5_init_coreclock()
520 sparx5, in sparx5_init_coreclock()
526 sparx5, in sparx5_init_coreclock()
532 sparx5, in sparx5_init_coreclock()
537 sparx5, in sparx5_init_coreclock()
543 static int sparx5_qlim_set(struct sparx5 *sparx5) in sparx5_qlim_set() argument
549 spx5_wr(0xFFF, sparx5, in sparx5_qlim_set()
553 spx5_wr(0xFFF, sparx5, in sparx5_qlim_set()
558 spx5_wr(QLIM_WM(80), sparx5, XQS_QLIMIT_SHR_QLIM_CFG(0)); in sparx5_qlim_set()
559 spx5_wr(QLIM_WM(90), sparx5, XQS_QLIMIT_SHR_CTOP_CFG(0)); in sparx5_qlim_set()
560 spx5_wr(QLIM_WM(95), sparx5, XQS_QLIMIT_SHR_ATOP_CFG(0)); in sparx5_qlim_set()
561 spx5_wr(QLIM_WM(100), sparx5, XQS_QLIMIT_SHR_TOP_CFG(0)); in sparx5_qlim_set()
569 static void sparx5_board_init(struct sparx5 *sparx5) in sparx5_board_init() argument
573 if (!sparx5->sd_sgpio_remapping) in sparx5_board_init()
579 sparx5, in sparx5_board_init()
584 if (sparx5->ports[idx]) in sparx5_board_init()
585 if (sparx5->ports[idx]->conf.sd_sgpio != ~0) in sparx5_board_init()
586 spx5_wr(sparx5->ports[idx]->conf.sd_sgpio, in sparx5_board_init()
587 sparx5, in sparx5_board_init()
591 static int sparx5_start(struct sparx5 *sparx5) in sparx5_start() argument
600 spx5_wr(idx, sparx5, ANA_AC_OWN_UPSID(idx)); in sparx5_start()
601 spx5_wr(idx, sparx5, ANA_CL_OWN_UPSID(idx)); in sparx5_start()
602 spx5_wr(idx, sparx5, ANA_L2_OWN_UPSID(idx)); in sparx5_start()
603 spx5_wr(idx, sparx5, REW_OWN_UPSID(idx)); in sparx5_start()
610 sparx5, in sparx5_start()
614 sparx5_update_fwd(sparx5); in sparx5_start()
618 sparx5, ANA_AC_PGID_MISC_CFG(PGID_CPU)); in sparx5_start()
620 sparx5, ANA_AC_PGID_MISC_CFG(PGID_BCAST)); in sparx5_start()
626 sparx5, ANA_CL_FILTER_CTRL(idx)); in sparx5_start()
629 sparx5_mact_init(sparx5); in sparx5_start()
632 sparx5_pgid_init(sparx5); in sparx5_start()
635 sparx5_vlan_init(sparx5); in sparx5_start()
638 sparx5_mact_learn(sparx5, PGID_CPU, broadcast, NULL_VID); in sparx5_start()
641 sparx5_qlim_set(sparx5); in sparx5_start()
643 err = sparx5_config_auto_calendar(sparx5); in sparx5_start()
647 err = sparx5_config_dsm_calendar(sparx5); in sparx5_start()
652 err = sparx_stats_init(sparx5); in sparx5_start()
657 mutex_init(&sparx5->mact_lock); in sparx5_start()
658 INIT_LIST_HEAD(&sparx5->mact_entries); in sparx5_start()
660 dev_name(sparx5->dev)); in sparx5_start()
661 sparx5->mact_queue = create_singlethread_workqueue(queue_name); in sparx5_start()
662 if (!sparx5->mact_queue) in sparx5_start()
665 INIT_DELAYED_WORK(&sparx5->mact_work, sparx5_mact_pull_work); in sparx5_start()
666 queue_delayed_work(sparx5->mact_queue, &sparx5->mact_work, in sparx5_start()
669 mutex_init(&sparx5->mdb_lock); in sparx5_start()
670 INIT_LIST_HEAD(&sparx5->mdb_entries); in sparx5_start()
672 err = sparx5_register_netdevs(sparx5); in sparx5_start()
676 sparx5_board_init(sparx5); in sparx5_start()
677 err = sparx5_register_notifier_blocks(sparx5); in sparx5_start()
681 if (sparx5->fdma_irq >= 0) { in sparx5_start()
682 if (GCB_CHIP_ID_REV_ID_GET(sparx5->chip_id) > 0) in sparx5_start()
683 err = devm_request_threaded_irq(sparx5->dev, in sparx5_start()
684 sparx5->fdma_irq, in sparx5_start()
688 "sparx5-fdma", sparx5); in sparx5_start()
690 err = sparx5_fdma_start(sparx5); in sparx5_start()
692 sparx5->fdma_irq = -ENXIO; in sparx5_start()
694 sparx5->fdma_irq = -ENXIO; in sparx5_start()
696 if (err && sparx5->xtr_irq >= 0) { in sparx5_start()
697 err = devm_request_irq(sparx5->dev, sparx5->xtr_irq, in sparx5_start()
699 "sparx5-xtr", sparx5); in sparx5_start()
701 err = sparx5_manual_injection_mode(sparx5); in sparx5_start()
703 sparx5->xtr_irq = -ENXIO; in sparx5_start()
705 sparx5->xtr_irq = -ENXIO; in sparx5_start()
708 if (sparx5->ptp_irq >= 0) { in sparx5_start()
709 err = devm_request_threaded_irq(sparx5->dev, sparx5->ptp_irq, in sparx5_start()
711 IRQF_ONESHOT, "sparx5-ptp", in sparx5_start()
712 sparx5); in sparx5_start()
714 sparx5->ptp_irq = -ENXIO; in sparx5_start()
716 sparx5->ptp = 1; in sparx5_start()
722 static void sparx5_cleanup_ports(struct sparx5 *sparx5) in sparx5_cleanup_ports() argument
724 sparx5_unregister_netdevs(sparx5); in sparx5_cleanup_ports()
725 sparx5_destroy_netdevs(sparx5); in sparx5_cleanup_ports()
734 struct sparx5 *sparx5; in mchp_sparx5_probe() local
740 sparx5 = devm_kzalloc(&pdev->dev, sizeof(*sparx5), GFP_KERNEL); in mchp_sparx5_probe()
741 if (!sparx5) in mchp_sparx5_probe()
744 platform_set_drvdata(pdev, sparx5); in mchp_sparx5_probe()
745 sparx5->pdev = pdev; in mchp_sparx5_probe()
746 sparx5->dev = &pdev->dev; in mchp_sparx5_probe()
756 sparx5->coreclock = SPX5_CORE_CLOCK_DEFAULT; in mchp_sparx5_probe()
760 dev_err(sparx5->dev, "no ethernet-ports child node found\n"); in mchp_sparx5_probe()
763 sparx5->port_count = of_get_child_count(ports); in mchp_sparx5_probe()
765 configs = kcalloc(sparx5->port_count, in mchp_sparx5_probe()
779 dev_err(sparx5->dev, "port reg property error\n"); in mchp_sparx5_probe()
788 dev_err(sparx5->dev, "port %u: missing phy-mode\n", in mchp_sparx5_probe()
795 dev_err(sparx5->dev, "port %u: missing bandwidth\n", in mchp_sparx5_probe()
803 sparx5->sd_sgpio_remapping = true; in mchp_sparx5_probe()
804 serdes = devm_of_phy_get(sparx5->dev, portnp, NULL); in mchp_sparx5_probe()
806 err = dev_err_probe(sparx5->dev, PTR_ERR(serdes), in mchp_sparx5_probe()
823 err = sparx5_create_targets(sparx5); in mchp_sparx5_probe()
827 if (!of_get_mac_address(np, sparx5->base_mac)) { in mchp_sparx5_probe()
828 dev_info(sparx5->dev, "MAC addr was not set, use random MAC\n"); in mchp_sparx5_probe()
829 eth_random_addr(sparx5->base_mac); in mchp_sparx5_probe()
830 sparx5->base_mac[5] = 0; in mchp_sparx5_probe()
833 sparx5->fdma_irq = platform_get_irq_byname(sparx5->pdev, "fdma"); in mchp_sparx5_probe()
834 sparx5->xtr_irq = platform_get_irq_byname(sparx5->pdev, "xtr"); in mchp_sparx5_probe()
835 sparx5->ptp_irq = platform_get_irq_byname(sparx5->pdev, "ptp"); in mchp_sparx5_probe()
838 sparx5->chip_id = spx5_rd(sparx5, GCB_CHIP_ID); in mchp_sparx5_probe()
840 sparx5->target_ct = (enum spx5_target_chiptype) in mchp_sparx5_probe()
841 GCB_CHIP_ID_PART_ID_GET(sparx5->chip_id); in mchp_sparx5_probe()
844 err = sparx5_init_switchcore(sparx5); in mchp_sparx5_probe()
846 dev_err(sparx5->dev, "Switchcore initialization error\n"); in mchp_sparx5_probe()
851 err = sparx5_init_coreclock(sparx5); in mchp_sparx5_probe()
853 dev_err(sparx5->dev, "LC-PLL initialization error\n"); in mchp_sparx5_probe()
857 for (idx = 0; idx < sparx5->port_count; ++idx) { in mchp_sparx5_probe()
862 err = sparx5_create_port(sparx5, config); in mchp_sparx5_probe()
864 dev_err(sparx5->dev, "port create error\n"); in mchp_sparx5_probe()
869 err = sparx5_start(sparx5); in mchp_sparx5_probe()
871 dev_err(sparx5->dev, "Start failed\n"); in mchp_sparx5_probe()
875 err = sparx5_qos_init(sparx5); in mchp_sparx5_probe()
877 dev_err(sparx5->dev, "Failed to initialize QoS\n"); in mchp_sparx5_probe()
881 err = sparx5_ptp_init(sparx5); in mchp_sparx5_probe()
883 dev_err(sparx5->dev, "PTP failed\n"); in mchp_sparx5_probe()
889 sparx5_cleanup_ports(sparx5); in mchp_sparx5_probe()
890 if (sparx5->mact_queue) in mchp_sparx5_probe()
891 destroy_workqueue(sparx5->mact_queue); in mchp_sparx5_probe()
901 struct sparx5 *sparx5 = platform_get_drvdata(pdev); in mchp_sparx5_remove() local
903 if (sparx5->xtr_irq) { in mchp_sparx5_remove()
904 disable_irq(sparx5->xtr_irq); in mchp_sparx5_remove()
905 sparx5->xtr_irq = -ENXIO; in mchp_sparx5_remove()
907 if (sparx5->fdma_irq) { in mchp_sparx5_remove()
908 disable_irq(sparx5->fdma_irq); in mchp_sparx5_remove()
909 sparx5->fdma_irq = -ENXIO; in mchp_sparx5_remove()
911 sparx5_ptp_deinit(sparx5); in mchp_sparx5_remove()
912 sparx5_fdma_stop(sparx5); in mchp_sparx5_remove()
913 sparx5_cleanup_ports(sparx5); in mchp_sparx5_remove()
915 sparx5_unregister_notifier_blocks(sparx5); in mchp_sparx5_remove()
916 destroy_workqueue(sparx5->mact_queue); in mchp_sparx5_remove()
922 { .compatible = "microchip,sparx5-switch" },
931 .name = "sparx5-switch",
938 MODULE_DESCRIPTION("Microchip Sparx5 switch driver");