Lines Matching +full:speed +full:- +full:bins
1 // SPDX-License-Identifier: GPL-2.0
5 #include <linux/clk-provider.h>
14 #define DRIVER_NAME "dwmac-loongson-pci"
87 plat->bus_id = pci_dev_id(pdev); in loongson_default_data()
89 plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */ in loongson_default_data()
90 plat->has_gmac = 1; in loongson_default_data()
91 plat->force_sf_dma_mode = 1; in loongson_default_data()
93 /* Set default value for multicast hash bins */ in loongson_default_data()
94 plat->multicast_filter_bins = 256; in loongson_default_data()
96 plat->mac_interface = PHY_INTERFACE_MODE_NA; in loongson_default_data()
99 plat->unicast_filter_entries = 1; in loongson_default_data()
102 plat->maxmtu = JUMBO_LEN; in loongson_default_data()
105 plat->tx_queues_cfg[0].use_prio = false; in loongson_default_data()
106 plat->rx_queues_cfg[0].use_prio = false; in loongson_default_data()
109 plat->rx_queues_cfg[0].pkt_route = 0x0; in loongson_default_data()
111 plat->clk_ref_rate = 125000000; in loongson_default_data()
112 plat->clk_ptp_rate = 125000000; in loongson_default_data()
114 /* Default to phy auto-detection */ in loongson_default_data()
115 plat->phy_addr = -1; in loongson_default_data()
117 plat->dma_cfg->pbl = 32; in loongson_default_data()
118 plat->dma_cfg->pblx8 = true; in loongson_default_data()
127 ld = plat->bsp_priv; in loongson_gmac_data()
131 if (ld->loongson_id == DWMAC_CORE_LS_MULTICHAN) { in loongson_gmac_data()
132 plat->rx_queues_to_use = CHANNEL_NUM; in loongson_gmac_data()
133 plat->tx_queues_to_use = CHANNEL_NUM; in loongson_gmac_data()
139 plat->tx_queues_cfg[i].coe_unsupported = 1; in loongson_gmac_data()
141 plat->tx_queues_to_use = 1; in loongson_gmac_data()
142 plat->rx_queues_to_use = 1; in loongson_gmac_data()
145 plat->phy_interface = PHY_INTERFACE_MODE_RGMII_ID; in loongson_gmac_data()
154 static void loongson_gnet_fix_speed(void *priv, int speed, unsigned int mode) in loongson_gnet_fix_speed() argument
157 struct net_device *ndev = dev_get_drvdata(ld->dev); in loongson_gnet_fix_speed()
161 * speeds to 1000Mbps mode. The speedup procedure requires the PHY-link in loongson_gnet_fix_speed()
162 * re-negotiation. in loongson_gnet_fix_speed()
164 if (speed == SPEED_1000) { in loongson_gnet_fix_speed()
165 if (readl(ptr->ioaddr + MAC_CTRL_REG) & in loongson_gnet_fix_speed()
168 phy_restart_aneg(ndev->phydev); in loongson_gnet_fix_speed()
178 ld = plat->bsp_priv; in loongson_gnet_data()
182 if (ld->loongson_id == DWMAC_CORE_LS_MULTICHAN) { in loongson_gnet_data()
183 plat->rx_queues_to_use = CHANNEL_NUM; in loongson_gnet_data()
184 plat->tx_queues_to_use = CHANNEL_NUM; in loongson_gnet_data()
190 plat->tx_queues_cfg[i].coe_unsupported = 1; in loongson_gnet_data()
192 plat->tx_queues_to_use = 1; in loongson_gnet_data()
193 plat->rx_queues_to_use = 1; in loongson_gnet_data()
196 plat->phy_interface = PHY_INTERFACE_MODE_GMII; in loongson_gnet_data()
197 plat->mdio_bus_data->phy_mask = ~(u32)BIT(2); in loongson_gnet_data()
198 plat->fix_mac_speed = loongson_gnet_fix_speed; in loongson_gnet_data()
212 int txpbl = dma_cfg->txpbl ?: dma_cfg->pbl; in loongson_dwmac_dma_init_channel()
213 int rxpbl = dma_cfg->rxpbl ?: dma_cfg->pbl; in loongson_dwmac_dma_init_channel()
218 if (dma_cfg->pblx8) in loongson_dwmac_dma_init_channel()
227 if (dma_cfg->fixed_burst) in loongson_dwmac_dma_init_channel()
231 if (dma_cfg->mixed_burst) in loongson_dwmac_dma_init_channel()
234 if (dma_cfg->atds) in loongson_dwmac_dma_init_channel()
237 if (dma_cfg->aal) in loongson_dwmac_dma_init_channel()
252 struct stmmac_pcpu_stats *stats = this_cpu_ptr(priv->xstats.pcpu_stats); in loongson_dwmac_dma_interrupt()
278 x->tx_undeflow_irq++; in loongson_dwmac_dma_interrupt()
281 x->tx_jabber_irq++; in loongson_dwmac_dma_interrupt()
283 x->rx_overflow_irq++; in loongson_dwmac_dma_interrupt()
285 x->rx_buf_unav_irq++; in loongson_dwmac_dma_interrupt()
287 x->rx_process_stopped_irq++; in loongson_dwmac_dma_interrupt()
289 x->rx_watchdog_irq++; in loongson_dwmac_dma_interrupt()
291 x->tx_early_irq++; in loongson_dwmac_dma_interrupt()
293 x->tx_process_stopped_irq++; in loongson_dwmac_dma_interrupt()
297 x->fatal_bus_error_irq++; in loongson_dwmac_dma_interrupt()
307 u64_stats_update_begin(&stats->syncp); in loongson_dwmac_dma_interrupt()
308 u64_stats_inc(&stats->rx_normal_irq_n[chan]); in loongson_dwmac_dma_interrupt()
309 u64_stats_update_end(&stats->syncp); in loongson_dwmac_dma_interrupt()
314 u64_stats_update_begin(&stats->syncp); in loongson_dwmac_dma_interrupt()
315 u64_stats_inc(&stats->tx_normal_irq_n[chan]); in loongson_dwmac_dma_interrupt()
316 u64_stats_update_end(&stats->syncp); in loongson_dwmac_dma_interrupt()
320 x->rx_early_irq++; in loongson_dwmac_dma_interrupt()
327 /* Clear the interrupt by writing a logic 1 to the CSR5[19-0] */ in loongson_dwmac_dma_interrupt()
341 ld = priv->plat->bsp_priv; in loongson_dwmac_setup()
342 pdev = to_pci_dev(priv->device); in loongson_dwmac_setup()
344 mac = devm_kzalloc(priv->device, sizeof(*mac), GFP_KERNEL); in loongson_dwmac_setup()
348 dma = devm_kzalloc(priv->device, sizeof(*dma), GFP_KERNEL); in loongson_dwmac_setup()
353 * v3.50a and v3.73a IP-cores. But the HW designers have changed the in loongson_dwmac_setup()
355 * network controllers with the multi-channels feature in loongson_dwmac_setup()
356 * available to emphasize the differences: multiple DMA-channels, in loongson_dwmac_setup()
358 * original value so the correct HW-interface would be selected. in loongson_dwmac_setup()
360 if (ld->loongson_id == DWMAC_CORE_LS_MULTICHAN) { in loongson_dwmac_setup()
361 priv->synopsys_id = DWMAC_CORE_3_70; in loongson_dwmac_setup()
363 dma->init_chan = loongson_dwmac_dma_init_channel; in loongson_dwmac_setup()
364 dma->dma_interrupt = loongson_dwmac_dma_interrupt; in loongson_dwmac_setup()
365 mac->dma = dma; in loongson_dwmac_setup()
368 priv->dev->priv_flags |= IFF_UNICAST_FLT; in loongson_dwmac_setup()
370 /* Pre-initialize the respective "mac" fields as it's done in in loongson_dwmac_setup()
373 mac->pcsr = priv->ioaddr; in loongson_dwmac_setup()
374 mac->multicast_filter_bins = priv->plat->multicast_filter_bins; in loongson_dwmac_setup()
375 mac->unicast_filter_entries = priv->plat->unicast_filter_entries; in loongson_dwmac_setup()
376 mac->mcast_bits_log2 = 0; in loongson_dwmac_setup()
378 if (mac->multicast_filter_bins) in loongson_dwmac_setup()
379 mac->mcast_bits_log2 = ilog2(mac->multicast_filter_bins); in loongson_dwmac_setup()
382 * GNET doesn't support the half-duplex link mode. in loongson_dwmac_setup()
384 if (pdev->device == PCI_DEVICE_ID_LOONGSON_GMAC) { in loongson_dwmac_setup()
385 mac->link.caps = MAC_10 | MAC_100 | MAC_1000; in loongson_dwmac_setup()
387 if (ld->loongson_id == DWMAC_CORE_LS_MULTICHAN) in loongson_dwmac_setup()
388 mac->link.caps = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | in loongson_dwmac_setup()
391 mac->link.caps = MAC_ASYM_PAUSE | MAC_SYM_PAUSE | in loongson_dwmac_setup()
395 mac->link.duplex = GMAC_CONTROL_DM; in loongson_dwmac_setup()
396 mac->link.speed10 = GMAC_CONTROL_PS; in loongson_dwmac_setup()
397 mac->link.speed100 = GMAC_CONTROL_PS | GMAC_CONTROL_FES; in loongson_dwmac_setup()
398 mac->link.speed1000 = 0; in loongson_dwmac_setup()
399 mac->link.speed_mask = GMAC_CONTROL_PS | GMAC_CONTROL_FES; in loongson_dwmac_setup()
400 mac->mii.addr = GMAC_MII_ADDR; in loongson_dwmac_setup()
401 mac->mii.data = GMAC_MII_DATA; in loongson_dwmac_setup()
402 mac->mii.addr_shift = 11; in loongson_dwmac_setup()
403 mac->mii.addr_mask = 0x0000F800; in loongson_dwmac_setup()
404 mac->mii.reg_shift = 6; in loongson_dwmac_setup()
405 mac->mii.reg_mask = 0x000007C0; in loongson_dwmac_setup()
406 mac->mii.clk_csr_shift = 2; in loongson_dwmac_setup()
407 mac->mii.clk_csr_mask = GENMASK(5, 2); in loongson_dwmac_setup()
421 dev_warn(&pdev->dev, "Failed to allocate MSI IRQs\n"); in loongson_dwmac_msi_config()
425 res->irq = pci_irq_vector(pdev, 0); in loongson_dwmac_msi_config()
427 for (i = 0; i < plat->rx_queues_to_use; i++) { in loongson_dwmac_msi_config()
428 res->rx_irq[CHANNEL_NUM - 1 - i] = in loongson_dwmac_msi_config()
432 for (i = 0; i < plat->tx_queues_to_use; i++) { in loongson_dwmac_msi_config()
433 res->tx_irq[CHANNEL_NUM - 1 - i] = in loongson_dwmac_msi_config()
437 plat->flags |= STMMAC_FLAG_MULTI_MSI_EN; in loongson_dwmac_msi_config()
451 struct device_node *np = dev_of_node(&pdev->dev); in loongson_dwmac_dt_config()
454 plat->mdio_node = of_get_child_by_name(np, "mdio"); in loongson_dwmac_dt_config()
455 if (plat->mdio_node) { in loongson_dwmac_dt_config()
456 dev_info(&pdev->dev, "Found MDIO subnode\n"); in loongson_dwmac_dt_config()
457 plat->mdio_bus_data->needs_reset = true; in loongson_dwmac_dt_config()
462 plat->bus_id = ret; in loongson_dwmac_dt_config()
464 res->irq = of_irq_get_byname(np, "macirq"); in loongson_dwmac_dt_config()
465 if (res->irq < 0) { in loongson_dwmac_dt_config()
466 dev_err(&pdev->dev, "IRQ macirq not found\n"); in loongson_dwmac_dt_config()
467 ret = -ENODEV; in loongson_dwmac_dt_config()
471 res->wol_irq = of_irq_get_byname(np, "eth_wake_irq"); in loongson_dwmac_dt_config()
472 if (res->wol_irq < 0) { in loongson_dwmac_dt_config()
473 dev_info(&pdev->dev, in loongson_dwmac_dt_config()
475 res->wol_irq = res->irq; in loongson_dwmac_dt_config()
478 res->lpi_irq = of_irq_get_byname(np, "eth_lpi"); in loongson_dwmac_dt_config()
479 if (res->lpi_irq < 0) { in loongson_dwmac_dt_config()
480 dev_err(&pdev->dev, "IRQ eth_lpi not found\n"); in loongson_dwmac_dt_config()
481 ret = -ENODEV; in loongson_dwmac_dt_config()
485 ret = device_get_phy_mode(&pdev->dev); in loongson_dwmac_dt_config()
487 dev_err(&pdev->dev, "phy_mode not found\n"); in loongson_dwmac_dt_config()
488 ret = -ENODEV; in loongson_dwmac_dt_config()
492 plat->phy_interface = ret; in loongson_dwmac_dt_config()
497 of_node_put(plat->mdio_node); in loongson_dwmac_dt_config()
505 of_node_put(plat->mdio_node); in loongson_dwmac_dt_clear()
512 if (!pdev->irq) in loongson_dwmac_acpi_config()
513 return -EINVAL; in loongson_dwmac_acpi_config()
515 res->irq = pdev->irq; in loongson_dwmac_acpi_config()
541 plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL); in loongson_dwmac_probe()
543 return -ENOMEM; in loongson_dwmac_probe()
545 plat->mdio_bus_data = devm_kzalloc(&pdev->dev, in loongson_dwmac_probe()
546 sizeof(*plat->mdio_bus_data), in loongson_dwmac_probe()
548 if (!plat->mdio_bus_data) in loongson_dwmac_probe()
549 return -ENOMEM; in loongson_dwmac_probe()
551 plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg), GFP_KERNEL); in loongson_dwmac_probe()
552 if (!plat->dma_cfg) in loongson_dwmac_probe()
553 return -ENOMEM; in loongson_dwmac_probe()
555 ld = devm_kzalloc(&pdev->dev, sizeof(*ld), GFP_KERNEL); in loongson_dwmac_probe()
557 return -ENOMEM; in loongson_dwmac_probe()
562 dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n", __func__); in loongson_dwmac_probe()
574 plat->bsp_priv = ld; in loongson_dwmac_probe()
575 plat->setup = loongson_dwmac_setup; in loongson_dwmac_probe()
576 plat->fix_soc_reset = loongson_dwmac_fix_reset; in loongson_dwmac_probe()
577 ld->dev = &pdev->dev; in loongson_dwmac_probe()
578 ld->loongson_id = readl(res.addr + GMAC_VERSION) & 0xff; in loongson_dwmac_probe()
580 info = (struct stmmac_pci_info *)id->driver_data; in loongson_dwmac_probe()
581 ret = info->setup(pdev, plat); in loongson_dwmac_probe()
585 plat->tx_fifo_size = SZ_16K * plat->tx_queues_to_use; in loongson_dwmac_probe()
586 plat->rx_fifo_size = SZ_16K * plat->rx_queues_to_use; in loongson_dwmac_probe()
588 if (dev_of_node(&pdev->dev)) in loongson_dwmac_probe()
595 /* Use the common MAC IRQ if per-channel MSIs allocation failed */ in loongson_dwmac_probe()
596 if (ld->loongson_id == DWMAC_CORE_LS_MULTICHAN) in loongson_dwmac_probe()
599 ret = stmmac_dvr_probe(&pdev->dev, plat, &res); in loongson_dwmac_probe()
606 if (dev_of_node(&pdev->dev)) in loongson_dwmac_probe()
608 if (ld->loongson_id == DWMAC_CORE_LS_MULTICHAN) in loongson_dwmac_probe()
617 struct net_device *ndev = dev_get_drvdata(&pdev->dev); in loongson_dwmac_remove()
621 ld = priv->plat->bsp_priv; in loongson_dwmac_remove()
622 stmmac_dvr_remove(&pdev->dev); in loongson_dwmac_remove()
624 if (dev_of_node(&pdev->dev)) in loongson_dwmac_remove()
625 loongson_dwmac_dt_clear(pdev, priv->plat); in loongson_dwmac_remove()
627 if (ld->loongson_id == DWMAC_CORE_LS_MULTICHAN) in loongson_dwmac_remove()