1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2016, NVIDIA CORPORATION.
5 * Portions based on U-Boot's rtl8169.c.
9 * This driver supports the Synopsys Designware Ethernet QOS (Quality Of
10 * Service) IP block. The IP supports multiple options for bus type, clocking/
11 * reset structure, and feature list.
13 * The driver is written such that generic core logic is kept separate from
14 * configuration-specific logic. Code that interacts with configuration-
15 * specific resources is split out into separate functions to avoid polluting
16 * common code. If/when this driver is enhanced to support multiple
17 * configurations, the core code should be adapted to call all configuration-
18 * specific functions through function pointers, with the definition of those
19 * function pointers being supplied by struct udevice_id eqos_ids[]'s .data
22 * The following configurations are currently supported:
24 * NVIDIA's Tegra186 chip. This configuration uses an AXI master/DMA bus, an
25 * AHB slave/register bus, contains the DMA, MTL, and MAC sub-blocks, and
26 * supports a single RGMII PHY. This configuration also has SW control over
27 * all clock and reset signals to the HW block.
30 #define LOG_CATEGORY UCLASS_ETH
46 #include <asm/cache.h>
49 #ifdef CONFIG_ARCH_IMX8M
50 #include <asm/arch/clock.h>
51 #include <asm/mach-imx/sys_proto.h>
53 #include <linux/bitfield.h>
54 #include <linux/delay.h>
55 #include <linux/printk.h>
57 #include "dwc_eth_qos.h"
60 * TX and RX descriptors are 16 bytes. This causes problems with the cache
61 * maintenance on CPUs where the cache-line size exceeds the size of these
62 * descriptors. What will happen is that when the driver receives a packet
63 * it will be immediately requeued for the hardware to reuse. The CPU will
64 * therefore need to flush the cache-line containing the descriptor, which
65 * will cause all other descriptors in the same cache-line to be flushed
66 * along with it. If one of those descriptors had been written to by the
67 * device those changes (and the associated packet) will be lost.
69 * To work around this, we make use of non-cached memory if available. If
70 * descriptors are mapped uncached there's no need to manually flush them
73 * Note that this only applies to descriptors. The packet data buffers do
74 * not have the same constraints since they are 1536 bytes large, so they
75 * are unlikely to share cache-lines.
77 static void *eqos_alloc_descs(struct eqos_priv *eqos, unsigned int num)
79 return memalign(ARCH_DMA_MINALIGN, num * eqos->desc_size);
82 static void eqos_free_descs(void *descs)
87 static struct eqos_desc *eqos_get_desc(struct eqos_priv *eqos,
88 unsigned int num, bool rx)
90 return (rx ? eqos->rx_descs : eqos->tx_descs) +
91 (num * eqos->desc_size);
94 void eqos_inval_desc_generic(void *desc)
96 unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1);
97 unsigned long end = ALIGN(start + sizeof(struct eqos_desc),
100 invalidate_dcache_range(start, end);
103 void eqos_flush_desc_generic(void *desc)
105 unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1);
106 unsigned long end = ALIGN(start + sizeof(struct eqos_desc),
109 flush_dcache_range(start, end);
112 static void eqos_inval_buffer_tegra186(void *buf, size_t size)
114 unsigned long start = (unsigned long)buf & ~(ARCH_DMA_MINALIGN - 1);
115 unsigned long end = ALIGN(start + size, ARCH_DMA_MINALIGN);
117 invalidate_dcache_range(start, end);
120 void eqos_inval_buffer_generic(void *buf, size_t size)
122 unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN);
123 unsigned long end = roundup((unsigned long)buf + size,
126 invalidate_dcache_range(start, end);
129 static void eqos_flush_buffer_tegra186(void *buf, size_t size)
131 flush_cache((unsigned long)buf, size);
134 void eqos_flush_buffer_generic(void *buf, size_t size)
136 unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN);
137 unsigned long end = roundup((unsigned long)buf + size,
140 flush_dcache_range(start, end);
143 static int eqos_mdio_wait_idle(struct eqos_priv *eqos)
145 return wait_for_bit_le32(&eqos->mac_regs->mdio_address,
146 EQOS_MAC_MDIO_ADDRESS_GB, false,
150 /* Bitmask common for mdio_read and mdio_write */
151 #define EQOS_MDIO_BITFIELD(pa, rda, cr) \
152 FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_PA_MASK, pa) | \
153 FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_RDA_MASK, rda) | \
154 FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_CR_MASK, cr) | \
155 EQOS_MAC_MDIO_ADDRESS_GB
157 static u32 eqos_mdio_bitfield(struct eqos_priv *eqos, int addr, int devad, int reg)
159 int cr = eqos->config->config_mac_mdio;
160 bool c22 = devad == MDIO_DEVAD_NONE ? true : false;
163 return EQOS_MDIO_BITFIELD(addr, reg, cr);
165 return EQOS_MDIO_BITFIELD(addr, devad, cr) |
166 EQOS_MAC_MDIO_ADDRESS_C45E;
169 static int eqos_mdio_read(struct mii_dev *bus, int mdio_addr, int mdio_devad,
172 struct eqos_priv *eqos = bus->priv;
176 debug("%s(dev=%p, addr=%x, reg=%d):\n", __func__, eqos->dev, mdio_addr,
179 ret = eqos_mdio_wait_idle(eqos);
181 pr_err("MDIO not idle at entry\n");
185 val = readl(&eqos->mac_regs->mdio_address);
186 val &= EQOS_MAC_MDIO_ADDRESS_SKAP;
188 val |= eqos_mdio_bitfield(eqos, mdio_addr, mdio_devad, mdio_reg) |
189 FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_GOC_MASK,
190 EQOS_MAC_MDIO_ADDRESS_GOC_READ);
192 if (val & EQOS_MAC_MDIO_ADDRESS_C45E) {
193 writel(FIELD_PREP(EQOS_MAC_MDIO_DATA_RA_MASK, mdio_reg),
194 &eqos->mac_regs->mdio_data);
197 writel(val, &eqos->mac_regs->mdio_address);
199 udelay(eqos->config->mdio_wait);
201 ret = eqos_mdio_wait_idle(eqos);
203 pr_err("MDIO read didn't complete\n");
207 val = readl(&eqos->mac_regs->mdio_data);
208 val &= EQOS_MAC_MDIO_DATA_GD_MASK;
210 debug("%s: val=%x\n", __func__, val);
215 static int eqos_mdio_write(struct mii_dev *bus, int mdio_addr, int mdio_devad,
216 int mdio_reg, u16 mdio_val)
218 struct eqos_priv *eqos = bus->priv;
223 debug("%s(dev=%p, addr=%x, reg=%d, val=%x):\n", __func__, eqos->dev,
224 mdio_addr, mdio_reg, mdio_val);
226 ret = eqos_mdio_wait_idle(eqos);
228 pr_err("MDIO not idle at entry\n");
232 v_addr = readl(&eqos->mac_regs->mdio_address);
233 v_addr &= EQOS_MAC_MDIO_ADDRESS_SKAP;
235 v_addr |= eqos_mdio_bitfield(eqos, mdio_addr, mdio_devad, mdio_reg) |
236 FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_GOC_MASK,
237 EQOS_MAC_MDIO_ADDRESS_GOC_WRITE);
240 if (v_addr & EQOS_MAC_MDIO_ADDRESS_C45E)
241 v_data |= FIELD_PREP(EQOS_MAC_MDIO_DATA_RA_MASK, mdio_reg);
243 writel(v_data, &eqos->mac_regs->mdio_data);
244 writel(v_addr, &eqos->mac_regs->mdio_address);
245 udelay(eqos->config->mdio_wait);
247 ret = eqos_mdio_wait_idle(eqos);
249 pr_err("MDIO read didn't complete\n");
256 static int eqos_start_clks_tegra186(struct udevice *dev)
259 struct eqos_priv *eqos = dev_get_priv(dev);
262 debug("%s(dev=%p):\n", __func__, dev);
264 ret = clk_enable(&eqos->clk_slave_bus);
266 pr_err("clk_enable(clk_slave_bus) failed: %d\n", ret);
270 ret = clk_enable(&eqos->clk_master_bus);
272 pr_err("clk_enable(clk_master_bus) failed: %d\n", ret);
273 goto err_disable_clk_slave_bus;
276 ret = clk_enable(&eqos->clk_rx);
278 pr_err("clk_enable(clk_rx) failed: %d\n", ret);
279 goto err_disable_clk_master_bus;
282 ret = clk_enable(&eqos->clk_ptp_ref);
284 pr_err("clk_enable(clk_ptp_ref) failed: %d\n", ret);
285 goto err_disable_clk_rx;
288 ret = clk_set_rate(&eqos->clk_ptp_ref, 125 * 1000 * 1000);
290 pr_err("clk_set_rate(clk_ptp_ref) failed: %d\n", ret);
291 goto err_disable_clk_ptp_ref;
294 ret = clk_enable(&eqos->clk_tx);
296 pr_err("clk_enable(clk_tx) failed: %d\n", ret);
297 goto err_disable_clk_ptp_ref;
301 debug("%s: OK\n", __func__);
305 err_disable_clk_ptp_ref:
306 clk_disable(&eqos->clk_ptp_ref);
308 clk_disable(&eqos->clk_rx);
309 err_disable_clk_master_bus:
310 clk_disable(&eqos->clk_master_bus);
311 err_disable_clk_slave_bus:
312 clk_disable(&eqos->clk_slave_bus);
314 debug("%s: FAILED: %d\n", __func__, ret);
319 static int eqos_stop_clks_tegra186(struct udevice *dev)
322 struct eqos_priv *eqos = dev_get_priv(dev);
324 debug("%s(dev=%p):\n", __func__, dev);
326 clk_disable(&eqos->clk_tx);
327 clk_disable(&eqos->clk_ptp_ref);
328 clk_disable(&eqos->clk_rx);
329 clk_disable(&eqos->clk_master_bus);
330 clk_disable(&eqos->clk_slave_bus);
333 debug("%s: OK\n", __func__);
337 static int eqos_start_resets_tegra186(struct udevice *dev)
339 struct eqos_priv *eqos = dev_get_priv(dev);
342 debug("%s(dev=%p):\n", __func__, dev);
344 ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 1);
346 pr_err("dm_gpio_set_value(phy_reset, assert) failed: %d\n", ret);
352 ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 0);
354 pr_err("dm_gpio_set_value(phy_reset, deassert) failed: %d\n", ret);
358 ret = reset_assert(&eqos->reset_ctl);
360 pr_err("reset_assert() failed: %d\n", ret);
366 ret = reset_deassert(&eqos->reset_ctl);
368 pr_err("reset_deassert() failed: %d\n", ret);
372 debug("%s: OK\n", __func__);
376 static int eqos_stop_resets_tegra186(struct udevice *dev)
378 struct eqos_priv *eqos = dev_get_priv(dev);
380 reset_assert(&eqos->reset_ctl);
381 dm_gpio_set_value(&eqos->phy_reset_gpio, 1);
386 static int eqos_calibrate_pads_tegra186(struct udevice *dev)
388 struct eqos_priv *eqos = dev_get_priv(dev);
391 debug("%s(dev=%p):\n", __func__, dev);
393 setbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl,
394 EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD);
398 setbits_le32(&eqos->tegra186_regs->auto_cal_config,
399 EQOS_AUTO_CAL_CONFIG_START | EQOS_AUTO_CAL_CONFIG_ENABLE);
401 ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status,
402 EQOS_AUTO_CAL_STATUS_ACTIVE, true, 10, false);
404 pr_err("calibrate didn't start\n");
408 ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status,
409 EQOS_AUTO_CAL_STATUS_ACTIVE, false, 10, false);
411 pr_err("calibrate didn't finish\n");
418 clrbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl,
419 EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD);
421 debug("%s: returns %d\n", __func__, ret);
426 static int eqos_disable_calibration_tegra186(struct udevice *dev)
428 struct eqos_priv *eqos = dev_get_priv(dev);
430 debug("%s(dev=%p):\n", __func__, dev);
432 clrbits_le32(&eqos->tegra186_regs->auto_cal_config,
433 EQOS_AUTO_CAL_CONFIG_ENABLE);
438 static ulong eqos_get_tick_clk_rate_tegra186(struct udevice *dev)
441 struct eqos_priv *eqos = dev_get_priv(dev);
443 return clk_get_rate(&eqos->clk_slave_bus);
449 static int eqos_set_full_duplex(struct udevice *dev)
451 struct eqos_priv *eqos = dev_get_priv(dev);
453 debug("%s(dev=%p):\n", __func__, dev);
455 setbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM);
460 static int eqos_set_half_duplex(struct udevice *dev)
462 struct eqos_priv *eqos = dev_get_priv(dev);
464 debug("%s(dev=%p):\n", __func__, dev);
466 clrbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM);
468 /* WAR: Flush TX queue when switching to half-duplex */
469 setbits_le32(&eqos->mtl_regs->txq0_operation_mode,
470 EQOS_MTL_TXQ0_OPERATION_MODE_FTQ);
475 static int eqos_set_gmii_speed(struct udevice *dev)
477 struct eqos_priv *eqos = dev_get_priv(dev);
479 debug("%s(dev=%p):\n", __func__, dev);
481 clrbits_le32(&eqos->mac_regs->configuration,
482 EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES);
487 static int eqos_set_mii_speed_100(struct udevice *dev)
489 struct eqos_priv *eqos = dev_get_priv(dev);
491 debug("%s(dev=%p):\n", __func__, dev);
493 setbits_le32(&eqos->mac_regs->configuration,
494 EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES);
499 static int eqos_set_mii_speed_10(struct udevice *dev)
501 struct eqos_priv *eqos = dev_get_priv(dev);
503 debug("%s(dev=%p):\n", __func__, dev);
505 clrsetbits_le32(&eqos->mac_regs->configuration,
506 EQOS_MAC_CONFIGURATION_FES, EQOS_MAC_CONFIGURATION_PS);
511 static int eqos_set_tx_clk_speed_tegra186(struct udevice *dev)
514 struct eqos_priv *eqos = dev_get_priv(dev);
518 debug("%s(dev=%p):\n", __func__, dev);
520 switch (eqos->phy->speed) {
522 rate = 125 * 1000 * 1000;
525 rate = 25 * 1000 * 1000;
528 rate = 2.5 * 1000 * 1000;
531 pr_err("invalid speed %d\n", eqos->phy->speed);
535 ret = clk_set_rate(&eqos->clk_tx, rate);
537 pr_err("clk_set_rate(tx_clk, %lu) failed: %d\n", rate, ret);
545 static int eqos_adjust_link(struct udevice *dev)
547 struct eqos_priv *eqos = dev_get_priv(dev);
551 debug("%s(dev=%p):\n", __func__, dev);
553 if (eqos->phy->duplex)
554 ret = eqos_set_full_duplex(dev);
556 ret = eqos_set_half_duplex(dev);
558 pr_err("eqos_set_*_duplex() failed: %d\n", ret);
562 switch (eqos->phy->speed) {
564 en_calibration = true;
565 ret = eqos_set_gmii_speed(dev);
568 en_calibration = true;
569 ret = eqos_set_mii_speed_100(dev);
572 en_calibration = false;
573 ret = eqos_set_mii_speed_10(dev);
576 pr_err("invalid speed %d\n", eqos->phy->speed);
580 pr_err("eqos_set_*mii_speed*() failed: %d\n", ret);
584 if (en_calibration) {
585 ret = eqos->config->ops->eqos_calibrate_pads(dev);
587 pr_err("eqos_calibrate_pads() failed: %d\n",
592 ret = eqos->config->ops->eqos_disable_calibration(dev);
594 pr_err("eqos_disable_calibration() failed: %d\n",
599 ret = eqos->config->ops->eqos_set_tx_clk_speed(dev);
601 pr_err("eqos_set_tx_clk_speed() failed: %d\n", ret);
608 static int eqos_write_hwaddr(struct udevice *dev)
610 struct eth_pdata *plat = dev_get_plat(dev);
611 struct eqos_priv *eqos = dev_get_priv(dev);
615 * This function may be called before start() or after stop(). At that
616 * time, on at least some configurations of the EQoS HW, all clocks to
617 * the EQoS HW block will be stopped, and a reset signal applied. If
618 * any register access is attempted in this state, bus timeouts or CPU
619 * hangs may occur. This check prevents that.
621 * A simple solution to this problem would be to not implement
622 * write_hwaddr(), since start() always writes the MAC address into HW
623 * anyway. However, it is desirable to implement write_hwaddr() to
624 * support the case of SW that runs subsequent to U-Boot which expects
625 * the MAC address to already be programmed into the EQoS registers,
626 * which must happen irrespective of whether the U-Boot user (or
627 * scripts) actually made use of the EQoS device, and hence
628 * irrespective of whether start() was ever called.
630 * Note that this requirement by subsequent SW is not valid for
631 * Tegra186, and is likely not valid for any non-PCI instantiation of
632 * the EQoS HW block. This function is implemented solely as
633 * future-proofing with the expectation the driver will eventually be
634 * ported to some system where the expectation above is true.
636 if (!eqos->config->reg_access_always_ok && !eqos->reg_access_ok)
639 /* Update the MAC address */
640 val = (plat->enetaddr[5] << 8) |
642 writel(val, &eqos->mac_regs->address0_high);
643 val = (plat->enetaddr[3] << 24) |
644 (plat->enetaddr[2] << 16) |
645 (plat->enetaddr[1] << 8) |
647 writel(val, &eqos->mac_regs->address0_low);
652 static int eqos_read_rom_hwaddr(struct udevice *dev)
654 struct eth_pdata *pdata = dev_get_plat(dev);
655 struct eqos_priv *eqos = dev_get_priv(dev);
658 ret = eqos->config->ops->eqos_get_enetaddr(dev);
662 return !is_valid_ethaddr(pdata->enetaddr);
665 static int eqos_get_phy_addr(struct eqos_priv *priv, struct udevice *dev)
667 struct ofnode_phandle_args phandle_args;
670 if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
672 debug("Failed to find phy-handle");
676 priv->phy_of_node = phandle_args.node;
678 reg = ofnode_read_u32_default(phandle_args.node, "reg", 0);
683 static int eqos_start(struct udevice *dev)
685 struct eqos_priv *eqos = dev_get_priv(dev);
688 u32 val, tx_fifo_sz, rx_fifo_sz, tqs, rqs, pbl;
693 debug("%s(dev=%p):\n", __func__, dev);
695 eqos->tx_desc_idx = 0;
696 eqos->rx_desc_idx = 0;
698 ret = eqos->config->ops->eqos_start_resets(dev);
700 pr_err("eqos_start_resets() failed: %d\n", ret);
706 eqos->reg_access_ok = true;
709 * Assert the SWR first, the actually reset the MAC and to latch in
710 * e.g. i.MX8M Plus GPR[1] content, which selects interface mode.
712 setbits_le32(&eqos->dma_regs->mode, EQOS_DMA_MODE_SWR);
714 ret = wait_for_bit_le32(&eqos->dma_regs->mode,
715 EQOS_DMA_MODE_SWR, false,
716 eqos->config->swr_wait, false);
718 pr_err("EQOS_DMA_MODE_SWR stuck\n");
719 goto err_stop_resets;
722 ret = eqos->config->ops->eqos_calibrate_pads(dev);
724 pr_err("eqos_calibrate_pads() failed: %d\n", ret);
725 goto err_stop_resets;
728 if (eqos->config->ops->eqos_get_tick_clk_rate) {
729 rate = eqos->config->ops->eqos_get_tick_clk_rate(dev);
731 val = (rate / 1000000) - 1;
732 writel(val, &eqos->mac_regs->us_tic_counter);
736 * if PHY was already connected and configured,
737 * don't need to reconnect/reconfigure again
743 if (IS_ENABLED(CONFIG_PHY_FIXED)) {
744 fixed_node = ofnode_find_subnode(dev_ofnode(dev),
746 if (ofnode_valid(fixed_node))
747 eqos->phy = fixed_phy_create(dev_ofnode(dev));
751 addr = eqos_get_phy_addr(eqos, dev);
752 eqos->phy = phy_connect(eqos->mii, addr, dev,
753 eqos->config->interface(dev));
757 pr_err("phy_connect() failed\n");
759 goto err_stop_resets;
762 if (eqos->max_speed) {
763 ret = phy_set_supported(eqos->phy, eqos->max_speed);
765 pr_err("phy_set_supported() failed: %d\n", ret);
766 goto err_shutdown_phy;
770 eqos->phy->node = eqos->phy_of_node;
771 ret = phy_config(eqos->phy);
773 pr_err("phy_config() failed: %d\n", ret);
774 goto err_shutdown_phy;
778 ret = phy_startup(eqos->phy);
780 pr_err("phy_startup() failed: %d\n", ret);
781 goto err_shutdown_phy;
784 if (!eqos->phy->link) {
787 goto err_shutdown_phy;
790 ret = eqos_adjust_link(dev);
792 pr_err("eqos_adjust_link() failed: %d\n", ret);
793 goto err_shutdown_phy;
798 /* Enable Store and Forward mode for TX */
799 /* Program Tx operating mode */
800 setbits_le32(&eqos->mtl_regs->txq0_operation_mode,
801 EQOS_MTL_TXQ0_OPERATION_MODE_TSF |
802 (EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_ENABLED <<
803 EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT));
805 /* Transmit Queue weight */
806 writel(0x10, &eqos->mtl_regs->txq0_quantum_weight);
808 /* Enable Store and Forward mode for RX, since no jumbo frame */
809 setbits_le32(&eqos->mtl_regs->rxq0_operation_mode,
810 EQOS_MTL_RXQ0_OPERATION_MODE_RSF);
812 /* Transmit/Receive queue fifo size; use all RAM for 1 queue */
813 val = readl(&eqos->mac_regs->hw_feature1);
814 tx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_SHIFT) &
815 EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_MASK;
816 rx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_SHIFT) &
817 EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_MASK;
819 /* r/tx_fifo_sz is encoded as log2(n / 128). Undo that by shifting */
820 tx_fifo_sz = 128 << tx_fifo_sz;
821 rx_fifo_sz = 128 << rx_fifo_sz;
823 /* Allow platform to override TX/RX fifo size */
824 if (eqos->tx_fifo_sz)
825 tx_fifo_sz = eqos->tx_fifo_sz;
826 if (eqos->rx_fifo_sz)
827 rx_fifo_sz = eqos->rx_fifo_sz;
829 /* r/tqs is encoded as (n / 256) - 1 */
830 tqs = tx_fifo_sz / 256 - 1;
831 rqs = rx_fifo_sz / 256 - 1;
833 clrsetbits_le32(&eqos->mtl_regs->txq0_operation_mode,
834 EQOS_MTL_TXQ0_OPERATION_MODE_TQS_MASK <<
835 EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT,
836 tqs << EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT);
837 clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode,
838 EQOS_MTL_RXQ0_OPERATION_MODE_RQS_MASK <<
839 EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT,
840 rqs << EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT);
842 /* Flow control used only if each channel gets 4KB or more FIFO */
843 if (rqs >= ((4096 / 256) - 1)) {
846 setbits_le32(&eqos->mtl_regs->rxq0_operation_mode,
847 EQOS_MTL_RXQ0_OPERATION_MODE_EHFC);
850 * Set Threshold for Activating Flow Contol space for min 2
851 * frames ie, (1500 * 1) = 1500 bytes.
853 * Set Threshold for Deactivating Flow Contol for space of
854 * min 1 frame (frame size 1500bytes) in receive fifo
856 if (rqs == ((4096 / 256) - 1)) {
858 * This violates the above formula because of FIFO size
859 * limit therefore overflow may occur inspite of this.
861 rfd = 0x3; /* Full-3K */
862 rfa = 0x1; /* Full-1.5K */
863 } else if (rqs == ((8192 / 256) - 1)) {
864 rfd = 0x6; /* Full-4K */
865 rfa = 0xa; /* Full-6K */
866 } else if (rqs == ((16384 / 256) - 1)) {
867 rfd = 0x6; /* Full-4K */
868 rfa = 0x12; /* Full-10K */
870 rfd = 0x6; /* Full-4K */
871 rfa = 0x1E; /* Full-16K */
874 clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode,
875 (EQOS_MTL_RXQ0_OPERATION_MODE_RFD_MASK <<
876 EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) |
877 (EQOS_MTL_RXQ0_OPERATION_MODE_RFA_MASK <<
878 EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT),
880 EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) |
882 EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT));
887 clrsetbits_le32(&eqos->mac_regs->rxq_ctrl0,
888 EQOS_MAC_RXQ_CTRL0_RXQ0EN_MASK <<
889 EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT,
890 eqos->config->config_mac <<
891 EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT);
893 /* Multicast and Broadcast Queue Enable */
894 setbits_le32(&eqos->mac_regs->unused_0a4,
896 /* enable promise mode */
897 setbits_le32(&eqos->mac_regs->unused_004[1],
900 /* Set TX flow control parameters */
902 setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl,
903 0xffff << EQOS_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT);
904 /* Assign priority for TX flow control */
905 clrbits_le32(&eqos->mac_regs->txq_prty_map0,
906 EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_MASK <<
907 EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_SHIFT);
908 /* Assign priority for RX flow control */
909 clrbits_le32(&eqos->mac_regs->rxq_ctrl2,
910 EQOS_MAC_RXQ_CTRL2_PSRQ0_MASK <<
911 EQOS_MAC_RXQ_CTRL2_PSRQ0_SHIFT);
912 /* Enable flow control */
913 setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl,
914 EQOS_MAC_Q0_TX_FLOW_CTRL_TFE);
915 setbits_le32(&eqos->mac_regs->rx_flow_ctrl,
916 EQOS_MAC_RX_FLOW_CTRL_RFE);
918 clrsetbits_le32(&eqos->mac_regs->configuration,
919 EQOS_MAC_CONFIGURATION_GPSLCE |
920 EQOS_MAC_CONFIGURATION_WD |
921 EQOS_MAC_CONFIGURATION_JD |
922 EQOS_MAC_CONFIGURATION_JE,
923 EQOS_MAC_CONFIGURATION_CST |
924 EQOS_MAC_CONFIGURATION_ACS);
926 eqos_write_hwaddr(dev);
930 /* Enable OSP mode */
931 setbits_le32(&eqos->dma_regs->ch0_tx_control,
932 EQOS_DMA_CH0_TX_CONTROL_OSP);
934 /* RX buffer size. Must be a multiple of bus width */
935 clrsetbits_le32(&eqos->dma_regs->ch0_rx_control,
936 EQOS_DMA_CH0_RX_CONTROL_RBSZ_MASK <<
937 EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT,
938 EQOS_MAX_PACKET_SIZE <<
939 EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT);
941 desc_pad = (eqos->desc_size - sizeof(struct eqos_desc)) /
942 eqos->config->axi_bus_width;
944 setbits_le32(&eqos->dma_regs->ch0_control,
945 EQOS_DMA_CH0_CONTROL_PBLX8 |
946 (desc_pad << EQOS_DMA_CH0_CONTROL_DSL_SHIFT));
949 * Burst length must be < 1/2 FIFO size.
950 * FIFO size in tqs is encoded as (n / 256) - 1.
951 * Each burst is n * 8 (PBLX8) * 16 (AXI width) == 128 bytes.
952 * Half of n * 256 is n * 128, so pbl == tqs, modulo the -1.
957 clrsetbits_le32(&eqos->dma_regs->ch0_tx_control,
958 EQOS_DMA_CH0_TX_CONTROL_TXPBL_MASK <<
959 EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT,
960 pbl << EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT);
962 clrsetbits_le32(&eqos->dma_regs->ch0_rx_control,
963 EQOS_DMA_CH0_RX_CONTROL_RXPBL_MASK <<
964 EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT,
965 8 << EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT);
967 /* DMA performance configuration */
968 val = (2 << EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT) |
969 EQOS_DMA_SYSBUS_MODE_EAME | EQOS_DMA_SYSBUS_MODE_BLEN16 |
970 EQOS_DMA_SYSBUS_MODE_BLEN8 | EQOS_DMA_SYSBUS_MODE_BLEN4;
971 writel(val, &eqos->dma_regs->sysbus_mode);
973 /* Set up descriptors */
975 memset(eqos->tx_descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_TX);
976 memset(eqos->rx_descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_RX);
978 for (i = 0; i < EQOS_DESCRIPTORS_TX; i++) {
979 struct eqos_desc *tx_desc = eqos_get_desc(eqos, i, false);
980 eqos->config->ops->eqos_flush_desc(tx_desc);
983 for (i = 0; i < EQOS_DESCRIPTORS_RX; i++) {
984 struct eqos_desc *rx_desc = eqos_get_desc(eqos, i, true);
986 addr64 = (ulong)(eqos->rx_dma_buf + (i * EQOS_MAX_PACKET_SIZE));
987 rx_desc->des0 = lower_32_bits(addr64);
988 rx_desc->des1 = upper_32_bits(addr64);
989 rx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_BUF1V;
991 eqos->config->ops->eqos_flush_desc(rx_desc);
992 eqos->config->ops->eqos_inval_buffer((void *)addr64, EQOS_MAX_PACKET_SIZE);
995 addr64 = (ulong)eqos_get_desc(eqos, 0, false);
996 writel(upper_32_bits(addr64), &eqos->dma_regs->ch0_txdesc_list_haddress);
997 writel(lower_32_bits(addr64), &eqos->dma_regs->ch0_txdesc_list_address);
998 writel(EQOS_DESCRIPTORS_TX - 1,
999 &eqos->dma_regs->ch0_txdesc_ring_length);
1001 addr64 = (ulong)eqos_get_desc(eqos, 0, true);
1002 writel(upper_32_bits(addr64), &eqos->dma_regs->ch0_rxdesc_list_haddress);
1003 writel(lower_32_bits(addr64), &eqos->dma_regs->ch0_rxdesc_list_address);
1004 writel(EQOS_DESCRIPTORS_RX - 1,
1005 &eqos->dma_regs->ch0_rxdesc_ring_length);
1007 /* Enable everything */
1008 setbits_le32(&eqos->dma_regs->ch0_tx_control,
1009 EQOS_DMA_CH0_TX_CONTROL_ST);
1010 setbits_le32(&eqos->dma_regs->ch0_rx_control,
1011 EQOS_DMA_CH0_RX_CONTROL_SR);
1012 setbits_le32(&eqos->mac_regs->configuration,
1013 EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE);
1015 /* TX tail pointer not written until we need to TX a packet */
1017 * Point RX tail pointer at last descriptor. Ideally, we'd point at the
1018 * first descriptor, implying all descriptors were available. However,
1019 * that's not distinguishable from none of the descriptors being
1022 last_rx_desc = (ulong)eqos_get_desc(eqos, EQOS_DESCRIPTORS_RX - 1, true);
1023 writel(last_rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer);
1025 eqos->started = true;
1027 debug("%s: OK\n", __func__);
1031 phy_shutdown(eqos->phy);
1033 eqos->config->ops->eqos_stop_resets(dev);
1035 pr_err("FAILED: %d\n", ret);
1039 static void eqos_stop(struct udevice *dev)
1041 struct eqos_priv *eqos = dev_get_priv(dev);
1044 debug("%s(dev=%p):\n", __func__, dev);
1048 eqos->started = false;
1049 eqos->reg_access_ok = false;
1051 /* Disable TX DMA */
1052 clrbits_le32(&eqos->dma_regs->ch0_tx_control,
1053 EQOS_DMA_CH0_TX_CONTROL_ST);
1055 /* Wait for TX all packets to drain out of MTL */
1056 for (i = 0; i < 1000000; i++) {
1057 u32 val = readl(&eqos->mtl_regs->txq0_debug);
1058 u32 trcsts = (val >> EQOS_MTL_TXQ0_DEBUG_TRCSTS_SHIFT) &
1059 EQOS_MTL_TXQ0_DEBUG_TRCSTS_MASK;
1060 u32 txqsts = val & EQOS_MTL_TXQ0_DEBUG_TXQSTS;
1061 if ((trcsts != 1) && (!txqsts))
1065 /* Turn off MAC TX and RX */
1066 clrbits_le32(&eqos->mac_regs->configuration,
1067 EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE);
1069 /* Wait for all RX packets to drain out of MTL */
1070 for (i = 0; i < 1000000; i++) {
1071 u32 val = readl(&eqos->mtl_regs->rxq0_debug);
1072 u32 prxq = (val >> EQOS_MTL_RXQ0_DEBUG_PRXQ_SHIFT) &
1073 EQOS_MTL_RXQ0_DEBUG_PRXQ_MASK;
1074 u32 rxqsts = (val >> EQOS_MTL_RXQ0_DEBUG_RXQSTS_SHIFT) &
1075 EQOS_MTL_RXQ0_DEBUG_RXQSTS_MASK;
1076 if ((!prxq) && (!rxqsts))
1080 /* Turn off RX DMA */
1081 clrbits_le32(&eqos->dma_regs->ch0_rx_control,
1082 EQOS_DMA_CH0_RX_CONTROL_SR);
1085 phy_shutdown(eqos->phy);
1087 eqos->config->ops->eqos_stop_resets(dev);
1089 debug("%s: OK\n", __func__);
1092 static int eqos_send(struct udevice *dev, void *packet, int length)
1094 struct eqos_priv *eqos = dev_get_priv(dev);
1095 struct eqos_desc *tx_desc;
1098 debug("%s(dev=%p, packet=%p, length=%d):\n", __func__, dev, packet,
1101 memcpy(eqos->tx_dma_buf, packet, length);
1102 eqos->config->ops->eqos_flush_buffer(eqos->tx_dma_buf, length);
1104 tx_desc = eqos_get_desc(eqos, eqos->tx_desc_idx, false);
1105 eqos->tx_desc_idx++;
1106 eqos->tx_desc_idx %= EQOS_DESCRIPTORS_TX;
1108 tx_desc->des0 = lower_32_bits((ulong)eqos->tx_dma_buf);
1109 tx_desc->des1 = upper_32_bits((ulong)eqos->tx_dma_buf);
1110 tx_desc->des2 = length;
1112 * Make sure that if HW sees the _OWN write below, it will see all the
1113 * writes to the rest of the descriptor too.
1116 tx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_FD | EQOS_DESC3_LD | length;
1117 eqos->config->ops->eqos_flush_desc(tx_desc);
1119 writel((ulong)eqos_get_desc(eqos, eqos->tx_desc_idx, false),
1120 &eqos->dma_regs->ch0_txdesc_tail_pointer);
1122 for (i = 0; i < 1000000; i++) {
1123 eqos->config->ops->eqos_inval_desc(tx_desc);
1124 if (!(readl(&tx_desc->des3) & EQOS_DESC3_OWN))
1129 debug("%s: TX timeout\n", __func__);
1134 static int eqos_recv(struct udevice *dev, int flags, uchar **packetp)
1136 struct eqos_priv *eqos = dev_get_priv(dev);
1137 struct eqos_desc *rx_desc;
1140 rx_desc = eqos_get_desc(eqos, eqos->rx_desc_idx, true);
1141 eqos->config->ops->eqos_inval_desc(rx_desc);
1142 if (rx_desc->des3 & EQOS_DESC3_OWN)
1145 debug("%s(dev=%p, flags=%x):\n", __func__, dev, flags);
1147 *packetp = eqos->rx_dma_buf +
1148 (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE);
1149 length = rx_desc->des3 & 0x7fff;
1150 debug("%s: *packetp=%p, length=%d\n", __func__, *packetp, length);
1152 eqos->config->ops->eqos_inval_buffer(*packetp, length);
1157 static int eqos_free_pkt(struct udevice *dev, uchar *packet, int length)
1159 struct eqos_priv *eqos = dev_get_priv(dev);
1160 u32 idx, idx_mask = eqos->desc_per_cacheline - 1;
1161 uchar *packet_expected;
1162 struct eqos_desc *rx_desc = NULL;
1164 debug("%s(packet=%p, length=%d)\n", __func__, packet, length);
1166 packet_expected = eqos->rx_dma_buf +
1167 (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE);
1168 if (packet != packet_expected) {
1169 debug("%s: Unexpected packet (expected %p)\n", __func__,
1174 eqos->config->ops->eqos_inval_buffer(packet, length);
1176 if ((eqos->rx_desc_idx & idx_mask) == idx_mask) {
1177 for (idx = eqos->rx_desc_idx - idx_mask;
1178 idx <= eqos->rx_desc_idx;
1182 rx_desc = eqos_get_desc(eqos, idx, true);
1186 eqos->config->ops->eqos_flush_desc(rx_desc);
1187 eqos->config->ops->eqos_inval_buffer(packet, length);
1188 addr64 = (ulong)(eqos->rx_dma_buf + (idx * EQOS_MAX_PACKET_SIZE));
1189 rx_desc->des0 = lower_32_bits(addr64);
1190 rx_desc->des1 = upper_32_bits(addr64);
1193 * Make sure that if HW sees the _OWN write below,
1194 * it will see all the writes to the rest of the
1198 rx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_BUF1V;
1199 eqos->config->ops->eqos_flush_desc(rx_desc);
1201 writel((ulong)rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer);
1204 eqos->rx_desc_idx++;
1205 eqos->rx_desc_idx %= EQOS_DESCRIPTORS_RX;
1210 static int eqos_probe_resources_core(struct udevice *dev)
1212 struct eqos_priv *eqos = dev_get_priv(dev);
1213 unsigned int desc_step;
1216 debug("%s(dev=%p):\n", __func__, dev);
1218 /* Maximum distance between neighboring descriptors, in Bytes. */
1219 desc_step = sizeof(struct eqos_desc) +
1220 EQOS_DMA_CH0_CONTROL_DSL_MASK * eqos->config->axi_bus_width;
1221 if (desc_step < ARCH_DMA_MINALIGN) {
1223 * The EQoS hardware implementation cannot place one descriptor
1224 * per cacheline, it is necessary to place multiple descriptors
1225 * per cacheline in memory and do cache management carefully.
1227 eqos->desc_size = BIT(fls(desc_step) - 1);
1229 eqos->desc_size = ALIGN(sizeof(struct eqos_desc),
1230 (unsigned int)ARCH_DMA_MINALIGN);
1232 eqos->desc_per_cacheline = ARCH_DMA_MINALIGN / eqos->desc_size;
1234 eqos->tx_descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_TX);
1235 if (!eqos->tx_descs) {
1236 debug("%s: eqos_alloc_descs(tx) failed\n", __func__);
1241 eqos->rx_descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_RX);
1242 if (!eqos->rx_descs) {
1243 debug("%s: eqos_alloc_descs(rx) failed\n", __func__);
1245 goto err_free_tx_descs;
1248 eqos->tx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_MAX_PACKET_SIZE);
1249 if (!eqos->tx_dma_buf) {
1250 debug("%s: memalign(tx_dma_buf) failed\n", __func__);
1252 goto err_free_descs;
1254 debug("%s: tx_dma_buf=%p\n", __func__, eqos->tx_dma_buf);
1256 eqos->rx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_RX_BUFFER_SIZE);
1257 if (!eqos->rx_dma_buf) {
1258 debug("%s: memalign(rx_dma_buf) failed\n", __func__);
1260 goto err_free_tx_dma_buf;
1262 debug("%s: rx_dma_buf=%p\n", __func__, eqos->rx_dma_buf);
1264 eqos->config->ops->eqos_inval_buffer(eqos->rx_dma_buf,
1265 EQOS_MAX_PACKET_SIZE * EQOS_DESCRIPTORS_RX);
1267 debug("%s: OK\n", __func__);
1270 err_free_tx_dma_buf:
1271 free(eqos->tx_dma_buf);
1273 eqos_free_descs(eqos->rx_descs);
1275 eqos_free_descs(eqos->tx_descs);
1278 debug("%s: returns %d\n", __func__, ret);
1282 static int eqos_remove_resources_core(struct udevice *dev)
1284 struct eqos_priv *eqos = dev_get_priv(dev);
1286 debug("%s(dev=%p):\n", __func__, dev);
1288 free(eqos->rx_dma_buf);
1289 free(eqos->tx_dma_buf);
1290 eqos_free_descs(eqos->rx_descs);
1291 eqos_free_descs(eqos->tx_descs);
1293 debug("%s: OK\n", __func__);
1297 static int eqos_probe_resources_tegra186(struct udevice *dev)
1299 struct eqos_priv *eqos = dev_get_priv(dev);
1302 debug("%s(dev=%p):\n", __func__, dev);
1304 ret = reset_get_by_name(dev, "eqos", &eqos->reset_ctl);
1306 pr_err("reset_get_by_name(rst) failed: %d\n", ret);
1310 ret = gpio_request_by_name(dev, "phy-reset-gpios", 0,
1311 &eqos->phy_reset_gpio,
1312 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
1314 pr_err("gpio_request_by_name(phy reset) failed: %d\n", ret);
1315 goto err_free_reset_eqos;
1318 ret = clk_get_by_name(dev, "slave_bus", &eqos->clk_slave_bus);
1320 pr_err("clk_get_by_name(slave_bus) failed: %d\n", ret);
1321 goto err_free_gpio_phy_reset;
1324 ret = clk_get_by_name(dev, "master_bus", &eqos->clk_master_bus);
1326 pr_err("clk_get_by_name(master_bus) failed: %d\n", ret);
1327 goto err_free_gpio_phy_reset;
1330 ret = clk_get_by_name(dev, "rx", &eqos->clk_rx);
1332 pr_err("clk_get_by_name(rx) failed: %d\n", ret);
1333 goto err_free_gpio_phy_reset;
1336 ret = clk_get_by_name(dev, "ptp_ref", &eqos->clk_ptp_ref);
1338 pr_err("clk_get_by_name(ptp_ref) failed: %d\n", ret);
1339 goto err_free_gpio_phy_reset;
1342 ret = clk_get_by_name(dev, "tx", &eqos->clk_tx);
1344 pr_err("clk_get_by_name(tx) failed: %d\n", ret);
1345 goto err_free_gpio_phy_reset;
1348 debug("%s: OK\n", __func__);
1351 err_free_gpio_phy_reset:
1352 dm_gpio_free(dev, &eqos->phy_reset_gpio);
1353 err_free_reset_eqos:
1354 reset_free(&eqos->reset_ctl);
1356 debug("%s: returns %d\n", __func__, ret);
1360 static phy_interface_t eqos_get_interface_tegra186(const struct udevice *dev)
1362 return PHY_INTERFACE_MODE_MII;
1365 static int eqos_remove_resources_tegra186(struct udevice *dev)
1367 struct eqos_priv *eqos = dev_get_priv(dev);
1369 debug("%s(dev=%p):\n", __func__, dev);
1371 dm_gpio_free(dev, &eqos->phy_reset_gpio);
1372 reset_free(&eqos->reset_ctl);
1374 debug("%s: OK\n", __func__);
1378 static int eqos_probe(struct udevice *dev)
1380 struct eqos_priv *eqos = dev_get_priv(dev);
1383 debug("%s(dev=%p):\n", __func__, dev);
1386 eqos->config = (void *)dev_get_driver_data(dev);
1388 eqos->regs = dev_read_addr(dev);
1389 if (eqos->regs == FDT_ADDR_T_NONE) {
1390 pr_err("dev_read_addr() failed\n");
1393 eqos->mac_regs = (void *)(eqos->regs + EQOS_MAC_REGS_BASE);
1394 eqos->mtl_regs = (void *)(eqos->regs + EQOS_MTL_REGS_BASE);
1395 eqos->dma_regs = (void *)(eqos->regs + EQOS_DMA_REGS_BASE);
1396 eqos->tegra186_regs = (void *)(eqos->regs + EQOS_TEGRA186_REGS_BASE);
1398 eqos->max_speed = dev_read_u32_default(dev, "max-speed", 0);
1400 ret = eqos_probe_resources_core(dev);
1402 pr_err("eqos_probe_resources_core() failed: %d\n", ret);
1406 ret = eqos->config->ops->eqos_probe_resources(dev);
1408 pr_err("eqos_probe_resources() failed: %d\n", ret);
1409 goto err_remove_resources_core;
1412 ret = eqos->config->ops->eqos_start_clks(dev);
1414 pr_err("eqos_start_clks() failed: %d\n", ret);
1415 goto err_remove_resources_tegra;
1418 #ifdef CONFIG_DM_ETH_PHY
1419 eqos->mii = eth_phy_get_mdio_bus(dev);
1422 eqos->mii = mdio_alloc();
1424 pr_err("mdio_alloc() failed\n");
1428 eqos->mii->read = eqos_mdio_read;
1429 eqos->mii->write = eqos_mdio_write;
1430 eqos->mii->priv = eqos;
1431 strcpy(eqos->mii->name, dev->name);
1433 ret = mdio_register(eqos->mii);
1435 pr_err("mdio_register() failed: %d\n", ret);
1440 #ifdef CONFIG_DM_ETH_PHY
1441 eth_phy_set_mdio_bus(dev, eqos->mii);
1444 debug("%s: OK\n", __func__);
1448 mdio_free(eqos->mii);
1450 eqos->config->ops->eqos_stop_clks(dev);
1451 err_remove_resources_tegra:
1452 eqos->config->ops->eqos_remove_resources(dev);
1453 err_remove_resources_core:
1454 eqos_remove_resources_core(dev);
1456 debug("%s: returns %d\n", __func__, ret);
1460 static int eqos_remove(struct udevice *dev)
1462 struct eqos_priv *eqos = dev_get_priv(dev);
1464 debug("%s(dev=%p):\n", __func__, dev);
1466 mdio_unregister(eqos->mii);
1467 mdio_free(eqos->mii);
1468 eqos->config->ops->eqos_stop_clks(dev);
1469 eqos->config->ops->eqos_remove_resources(dev);
1471 eqos_remove_resources_core(dev);
1473 debug("%s: OK\n", __func__);
1477 int eqos_null_ops(struct udevice *dev)
1482 static const struct eth_ops eqos_ops = {
1483 .start = eqos_start,
1487 .free_pkt = eqos_free_pkt,
1488 .write_hwaddr = eqos_write_hwaddr,
1489 .read_rom_hwaddr = eqos_read_rom_hwaddr,
1492 static struct eqos_ops eqos_tegra186_ops = {
1493 .eqos_inval_desc = eqos_inval_desc_generic,
1494 .eqos_flush_desc = eqos_flush_desc_generic,
1495 .eqos_inval_buffer = eqos_inval_buffer_tegra186,
1496 .eqos_flush_buffer = eqos_flush_buffer_tegra186,
1497 .eqos_probe_resources = eqos_probe_resources_tegra186,
1498 .eqos_remove_resources = eqos_remove_resources_tegra186,
1499 .eqos_stop_resets = eqos_stop_resets_tegra186,
1500 .eqos_start_resets = eqos_start_resets_tegra186,
1501 .eqos_stop_clks = eqos_stop_clks_tegra186,
1502 .eqos_start_clks = eqos_start_clks_tegra186,
1503 .eqos_calibrate_pads = eqos_calibrate_pads_tegra186,
1504 .eqos_disable_calibration = eqos_disable_calibration_tegra186,
1505 .eqos_set_tx_clk_speed = eqos_set_tx_clk_speed_tegra186,
1506 .eqos_get_enetaddr = eqos_null_ops,
1507 .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_tegra186
1510 static const struct eqos_config __maybe_unused eqos_tegra186_config = {
1511 .reg_access_always_ok = false,
1514 .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB,
1515 .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_20_35,
1516 .axi_bus_width = EQOS_AXI_WIDTH_128,
1517 .interface = eqos_get_interface_tegra186,
1518 .ops = &eqos_tegra186_ops
1521 static const struct udevice_id eqos_ids[] = {
1522 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_TEGRA186)
1524 .compatible = "nvidia,tegra186-eqos",
1525 .data = (ulong)&eqos_tegra186_config
1528 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_STM32)
1530 .compatible = "st,stm32mp13-dwmac",
1531 .data = (ulong)&eqos_stm32mp13_config
1534 .compatible = "st,stm32mp1-dwmac",
1535 .data = (ulong)&eqos_stm32mp15_config
1538 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_IMX)
1540 .compatible = "nxp,imx8mp-dwmac-eqos",
1541 .data = (ulong)&eqos_imx_config
1544 .compatible = "nxp,imx93-dwmac-eqos",
1545 .data = (ulong)&eqos_imx_config
1548 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_ROCKCHIP)
1550 .compatible = "rockchip,rk3568-gmac",
1551 .data = (ulong)&eqos_rockchip_config
1554 .compatible = "rockchip,rk3588-gmac",
1555 .data = (ulong)&eqos_rockchip_config
1558 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_QCOM)
1560 .compatible = "qcom,qcs404-ethqos",
1561 .data = (ulong)&eqos_qcom_config
1564 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_STARFIVE)
1566 .compatible = "starfive,jh7110-dwmac",
1567 .data = (ulong)&eqos_jh7110_config
1573 U_BOOT_DRIVER(eth_eqos) = {
1576 .of_match = of_match_ptr(eqos_ids),
1577 .probe = eqos_probe,
1578 .remove = eqos_remove,
1580 .priv_auto = sizeof(struct eqos_priv),
1581 .plat_auto = sizeof(struct eth_pdata),