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
35 #include <dm/device_compat.h>
47 #include <asm/cache.h>
50 #ifdef CONFIG_ARCH_IMX8M
51 #include <asm/arch/clock.h>
52 #include <asm/mach-imx/sys_proto.h>
54 #include <linux/bitfield.h>
55 #include <linux/delay.h>
56 #include <linux/printk.h>
58 #include "dwc_eth_qos.h"
61 * TX and RX descriptors are 16 bytes. This causes problems with the cache
62 * maintenance on CPUs where the cache-line size exceeds the size of these
63 * descriptors. What will happen is that when the driver receives a packet
64 * it will be immediately requeued for the hardware to reuse. The CPU will
65 * therefore need to flush the cache-line containing the descriptor, which
66 * will cause all other descriptors in the same cache-line to be flushed
67 * along with it. If one of those descriptors had been written to by the
68 * device those changes (and the associated packet) will be lost.
70 * To work around this, we make use of non-cached memory if available. If
71 * descriptors are mapped uncached there's no need to manually flush them
74 * Note that this only applies to descriptors. The packet data buffers do
75 * not have the same constraints since they are 1536 bytes large, so they
76 * are unlikely to share cache-lines.
78 static void *eqos_alloc_descs(struct eqos_priv *eqos, unsigned int num)
80 return memalign(ARCH_DMA_MINALIGN, num * eqos->desc_size);
83 static void eqos_free_descs(void *descs)
88 static struct eqos_desc *eqos_get_desc(struct eqos_priv *eqos,
89 unsigned int num, bool rx)
91 return (rx ? eqos->rx_descs : eqos->tx_descs) +
92 (num * eqos->desc_size);
95 void eqos_inval_desc_generic(void *desc)
97 unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1);
98 unsigned long end = ALIGN(start + sizeof(struct eqos_desc),
101 invalidate_dcache_range(start, end);
104 void eqos_flush_desc_generic(void *desc)
106 unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1);
107 unsigned long end = ALIGN(start + sizeof(struct eqos_desc),
110 flush_dcache_range(start, end);
113 static void eqos_inval_buffer_tegra186(void *buf, size_t size)
115 unsigned long start = (unsigned long)buf & ~(ARCH_DMA_MINALIGN - 1);
116 unsigned long end = ALIGN(start + size, ARCH_DMA_MINALIGN);
118 invalidate_dcache_range(start, end);
121 void eqos_inval_buffer_generic(void *buf, size_t size)
123 unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN);
124 unsigned long end = roundup((unsigned long)buf + size,
127 invalidate_dcache_range(start, end);
130 static void eqos_flush_buffer_tegra186(void *buf, size_t size)
132 flush_cache((unsigned long)buf, size);
135 void eqos_flush_buffer_generic(void *buf, size_t size)
137 unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN);
138 unsigned long end = roundup((unsigned long)buf + size,
141 flush_dcache_range(start, end);
144 static int eqos_mdio_wait_idle(struct eqos_priv *eqos)
146 return wait_for_bit_le32(&eqos->mac_regs->mdio_address,
147 EQOS_MAC_MDIO_ADDRESS_GB, false,
151 /* Bitmask common for mdio_read and mdio_write */
152 #define EQOS_MDIO_BITFIELD(pa, rda, cr) \
153 FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_PA_MASK, pa) | \
154 FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_RDA_MASK, rda) | \
155 FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_CR_MASK, cr) | \
156 EQOS_MAC_MDIO_ADDRESS_GB
158 static u32 eqos_mdio_bitfield(struct eqos_priv *eqos, int addr, int devad, int reg)
160 int cr = eqos->config->config_mac_mdio;
161 bool c22 = devad == MDIO_DEVAD_NONE ? true : false;
164 return EQOS_MDIO_BITFIELD(addr, reg, cr);
166 return EQOS_MDIO_BITFIELD(addr, devad, cr) |
167 EQOS_MAC_MDIO_ADDRESS_C45E;
170 static int eqos_mdio_read(struct mii_dev *bus, int mdio_addr, int mdio_devad,
173 struct eqos_priv *eqos = bus->priv;
177 debug("%s(dev=%p, addr=%x, reg=%d):\n", __func__, eqos->dev, mdio_addr,
180 ret = eqos_mdio_wait_idle(eqos);
182 pr_err("MDIO not idle at entry\n");
186 val = readl(&eqos->mac_regs->mdio_address);
187 val &= EQOS_MAC_MDIO_ADDRESS_SKAP;
189 val |= eqos_mdio_bitfield(eqos, mdio_addr, mdio_devad, mdio_reg) |
190 FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_GOC_MASK,
191 EQOS_MAC_MDIO_ADDRESS_GOC_READ);
193 if (val & EQOS_MAC_MDIO_ADDRESS_C45E) {
194 writel(FIELD_PREP(EQOS_MAC_MDIO_DATA_RA_MASK, mdio_reg),
195 &eqos->mac_regs->mdio_data);
198 writel(val, &eqos->mac_regs->mdio_address);
200 udelay(eqos->config->mdio_wait);
202 ret = eqos_mdio_wait_idle(eqos);
204 pr_err("MDIO read didn't complete\n");
208 val = readl(&eqos->mac_regs->mdio_data);
209 val &= EQOS_MAC_MDIO_DATA_GD_MASK;
211 debug("%s: val=%x\n", __func__, val);
216 static int eqos_mdio_write(struct mii_dev *bus, int mdio_addr, int mdio_devad,
217 int mdio_reg, u16 mdio_val)
219 struct eqos_priv *eqos = bus->priv;
224 debug("%s(dev=%p, addr=%x, reg=%d, val=%x):\n", __func__, eqos->dev,
225 mdio_addr, mdio_reg, mdio_val);
227 ret = eqos_mdio_wait_idle(eqos);
229 pr_err("MDIO not idle at entry\n");
233 v_addr = readl(&eqos->mac_regs->mdio_address);
234 v_addr &= EQOS_MAC_MDIO_ADDRESS_SKAP;
236 v_addr |= eqos_mdio_bitfield(eqos, mdio_addr, mdio_devad, mdio_reg) |
237 FIELD_PREP(EQOS_MAC_MDIO_ADDRESS_GOC_MASK,
238 EQOS_MAC_MDIO_ADDRESS_GOC_WRITE);
241 if (v_addr & EQOS_MAC_MDIO_ADDRESS_C45E)
242 v_data |= FIELD_PREP(EQOS_MAC_MDIO_DATA_RA_MASK, mdio_reg);
244 writel(v_data, &eqos->mac_regs->mdio_data);
245 writel(v_addr, &eqos->mac_regs->mdio_address);
246 udelay(eqos->config->mdio_wait);
248 ret = eqos_mdio_wait_idle(eqos);
250 pr_err("MDIO read didn't complete\n");
257 static int eqos_start_clks_tegra186(struct udevice *dev)
260 struct eqos_priv *eqos = dev_get_priv(dev);
263 debug("%s(dev=%p):\n", __func__, dev);
265 ret = clk_enable(&eqos->clk_slave_bus);
267 pr_err("clk_enable(clk_slave_bus) failed: %d\n", ret);
271 ret = clk_enable(&eqos->clk_master_bus);
273 pr_err("clk_enable(clk_master_bus) failed: %d\n", ret);
274 goto err_disable_clk_slave_bus;
277 ret = clk_enable(&eqos->clk_rx);
279 pr_err("clk_enable(clk_rx) failed: %d\n", ret);
280 goto err_disable_clk_master_bus;
283 ret = clk_enable(&eqos->clk_ptp_ref);
285 pr_err("clk_enable(clk_ptp_ref) failed: %d\n", ret);
286 goto err_disable_clk_rx;
289 ret = clk_set_rate(&eqos->clk_ptp_ref, 125 * 1000 * 1000);
291 pr_err("clk_set_rate(clk_ptp_ref) failed: %d\n", ret);
292 goto err_disable_clk_ptp_ref;
295 ret = clk_enable(&eqos->clk_tx);
297 pr_err("clk_enable(clk_tx) failed: %d\n", ret);
298 goto err_disable_clk_ptp_ref;
302 debug("%s: OK\n", __func__);
306 err_disable_clk_ptp_ref:
307 clk_disable(&eqos->clk_ptp_ref);
309 clk_disable(&eqos->clk_rx);
310 err_disable_clk_master_bus:
311 clk_disable(&eqos->clk_master_bus);
312 err_disable_clk_slave_bus:
313 clk_disable(&eqos->clk_slave_bus);
315 debug("%s: FAILED: %d\n", __func__, ret);
320 static int eqos_stop_clks_tegra186(struct udevice *dev)
323 struct eqos_priv *eqos = dev_get_priv(dev);
325 debug("%s(dev=%p):\n", __func__, dev);
327 clk_disable(&eqos->clk_tx);
328 clk_disable(&eqos->clk_ptp_ref);
329 clk_disable(&eqos->clk_rx);
330 clk_disable(&eqos->clk_master_bus);
331 clk_disable(&eqos->clk_slave_bus);
334 debug("%s: OK\n", __func__);
338 static int eqos_start_resets_tegra186(struct udevice *dev)
340 struct eqos_priv *eqos = dev_get_priv(dev);
343 debug("%s(dev=%p):\n", __func__, dev);
345 ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 1);
347 pr_err("dm_gpio_set_value(phy_reset, assert) failed: %d\n", ret);
353 ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 0);
355 pr_err("dm_gpio_set_value(phy_reset, deassert) failed: %d\n", ret);
359 ret = reset_assert(&eqos->reset_ctl);
361 pr_err("reset_assert() failed: %d\n", ret);
367 ret = reset_deassert(&eqos->reset_ctl);
369 pr_err("reset_deassert() failed: %d\n", ret);
373 debug("%s: OK\n", __func__);
377 static int eqos_stop_resets_tegra186(struct udevice *dev)
379 struct eqos_priv *eqos = dev_get_priv(dev);
381 reset_assert(&eqos->reset_ctl);
382 dm_gpio_set_value(&eqos->phy_reset_gpio, 1);
387 static int eqos_calibrate_pads_tegra186(struct udevice *dev)
389 struct eqos_priv *eqos = dev_get_priv(dev);
392 debug("%s(dev=%p):\n", __func__, dev);
394 setbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl,
395 EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD);
399 setbits_le32(&eqos->tegra186_regs->auto_cal_config,
400 EQOS_AUTO_CAL_CONFIG_START | EQOS_AUTO_CAL_CONFIG_ENABLE);
402 ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status,
403 EQOS_AUTO_CAL_STATUS_ACTIVE, true, 10, false);
405 pr_err("calibrate didn't start\n");
409 ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status,
410 EQOS_AUTO_CAL_STATUS_ACTIVE, false, 10, false);
412 pr_err("calibrate didn't finish\n");
419 clrbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl,
420 EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD);
422 debug("%s: returns %d\n", __func__, ret);
427 static int eqos_disable_calibration_tegra186(struct udevice *dev)
429 struct eqos_priv *eqos = dev_get_priv(dev);
431 debug("%s(dev=%p):\n", __func__, dev);
433 clrbits_le32(&eqos->tegra186_regs->auto_cal_config,
434 EQOS_AUTO_CAL_CONFIG_ENABLE);
439 static ulong eqos_get_tick_clk_rate_tegra186(struct udevice *dev)
442 struct eqos_priv *eqos = dev_get_priv(dev);
444 return clk_get_rate(&eqos->clk_slave_bus);
450 static int eqos_set_full_duplex(struct udevice *dev)
452 struct eqos_priv *eqos = dev_get_priv(dev);
454 debug("%s(dev=%p):\n", __func__, dev);
456 setbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM);
461 static int eqos_set_half_duplex(struct udevice *dev)
463 struct eqos_priv *eqos = dev_get_priv(dev);
465 debug("%s(dev=%p):\n", __func__, dev);
467 clrbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM);
469 /* WAR: Flush TX queue when switching to half-duplex */
470 setbits_le32(&eqos->mtl_regs->txq0_operation_mode,
471 EQOS_MTL_TXQ0_OPERATION_MODE_FTQ);
476 static int eqos_set_gmii_speed(struct udevice *dev)
478 struct eqos_priv *eqos = dev_get_priv(dev);
480 debug("%s(dev=%p):\n", __func__, dev);
482 clrbits_le32(&eqos->mac_regs->configuration,
483 EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES);
488 static int eqos_set_mii_speed_100(struct udevice *dev)
490 struct eqos_priv *eqos = dev_get_priv(dev);
492 debug("%s(dev=%p):\n", __func__, dev);
494 setbits_le32(&eqos->mac_regs->configuration,
495 EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES);
500 static int eqos_set_mii_speed_10(struct udevice *dev)
502 struct eqos_priv *eqos = dev_get_priv(dev);
504 debug("%s(dev=%p):\n", __func__, dev);
506 clrsetbits_le32(&eqos->mac_regs->configuration,
507 EQOS_MAC_CONFIGURATION_FES, EQOS_MAC_CONFIGURATION_PS);
512 static int eqos_set_tx_clk_speed_tegra186(struct udevice *dev)
515 struct eqos_priv *eqos = dev_get_priv(dev);
519 debug("%s(dev=%p):\n", __func__, dev);
521 switch (eqos->phy->speed) {
523 rate = 125 * 1000 * 1000;
526 rate = 25 * 1000 * 1000;
529 rate = 2.5 * 1000 * 1000;
532 pr_err("invalid speed %d\n", eqos->phy->speed);
536 ret = clk_set_rate(&eqos->clk_tx, rate);
538 pr_err("clk_set_rate(tx_clk, %lu) failed: %d\n", rate, ret);
546 static int eqos_adjust_link(struct udevice *dev)
548 struct eqos_priv *eqos = dev_get_priv(dev);
552 debug("%s(dev=%p):\n", __func__, dev);
554 if (eqos->phy->duplex)
555 ret = eqos_set_full_duplex(dev);
557 ret = eqos_set_half_duplex(dev);
559 pr_err("eqos_set_*_duplex() failed: %d\n", ret);
563 switch (eqos->phy->speed) {
565 en_calibration = true;
566 ret = eqos_set_gmii_speed(dev);
569 en_calibration = true;
570 ret = eqos_set_mii_speed_100(dev);
573 en_calibration = false;
574 ret = eqos_set_mii_speed_10(dev);
577 pr_err("invalid speed %d\n", eqos->phy->speed);
581 pr_err("eqos_set_*mii_speed*() failed: %d\n", ret);
585 if (en_calibration) {
586 ret = eqos->config->ops->eqos_calibrate_pads(dev);
588 pr_err("eqos_calibrate_pads() failed: %d\n",
593 ret = eqos->config->ops->eqos_disable_calibration(dev);
595 pr_err("eqos_disable_calibration() failed: %d\n",
600 ret = eqos->config->ops->eqos_set_tx_clk_speed(dev);
602 pr_err("eqos_set_tx_clk_speed() failed: %d\n", ret);
609 static int eqos_write_hwaddr(struct udevice *dev)
611 struct eth_pdata *plat = dev_get_plat(dev);
612 struct eqos_priv *eqos = dev_get_priv(dev);
616 * This function may be called before start() or after stop(). At that
617 * time, on at least some configurations of the EQoS HW, all clocks to
618 * the EQoS HW block will be stopped, and a reset signal applied. If
619 * any register access is attempted in this state, bus timeouts or CPU
620 * hangs may occur. This check prevents that.
622 * A simple solution to this problem would be to not implement
623 * write_hwaddr(), since start() always writes the MAC address into HW
624 * anyway. However, it is desirable to implement write_hwaddr() to
625 * support the case of SW that runs subsequent to U-Boot which expects
626 * the MAC address to already be programmed into the EQoS registers,
627 * which must happen irrespective of whether the U-Boot user (or
628 * scripts) actually made use of the EQoS device, and hence
629 * irrespective of whether start() was ever called.
631 * Note that this requirement by subsequent SW is not valid for
632 * Tegra186, and is likely not valid for any non-PCI instantiation of
633 * the EQoS HW block. This function is implemented solely as
634 * future-proofing with the expectation the driver will eventually be
635 * ported to some system where the expectation above is true.
637 if (!eqos->config->reg_access_always_ok && !eqos->reg_access_ok)
640 /* Update the MAC address */
641 val = (plat->enetaddr[5] << 8) |
643 writel(val, &eqos->mac_regs->address0_high);
644 val = (plat->enetaddr[3] << 24) |
645 (plat->enetaddr[2] << 16) |
646 (plat->enetaddr[1] << 8) |
648 writel(val, &eqos->mac_regs->address0_low);
653 static int eqos_read_rom_hwaddr(struct udevice *dev)
655 struct eth_pdata *pdata = dev_get_plat(dev);
656 struct eqos_priv *eqos = dev_get_priv(dev);
659 ret = eqos->config->ops->eqos_get_enetaddr(dev);
663 return !is_valid_ethaddr(pdata->enetaddr);
666 static int eqos_get_phy_addr(struct eqos_priv *priv, struct udevice *dev)
668 struct ofnode_phandle_args phandle_args;
671 if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
673 debug("Failed to find phy-handle");
677 priv->phy_of_node = phandle_args.node;
679 reg = ofnode_read_u32_default(phandle_args.node, "reg", 0);
684 static int eqos_start(struct udevice *dev)
686 struct eqos_priv *eqos = dev_get_priv(dev);
689 u32 val, tx_fifo_sz, rx_fifo_sz, tqs, rqs, pbl;
694 debug("%s(dev=%p):\n", __func__, dev);
696 eqos->tx_desc_idx = 0;
697 eqos->rx_desc_idx = 0;
699 ret = eqos->config->ops->eqos_start_resets(dev);
701 pr_err("eqos_start_resets() failed: %d\n", ret);
707 eqos->reg_access_ok = true;
710 * Assert the SWR first, the actually reset the MAC and to latch in
711 * e.g. i.MX8M Plus GPR[1] content, which selects interface mode.
713 setbits_le32(&eqos->dma_regs->mode, EQOS_DMA_MODE_SWR);
715 ret = wait_for_bit_le32(&eqos->dma_regs->mode,
716 EQOS_DMA_MODE_SWR, false,
717 eqos->config->swr_wait, false);
719 pr_err("EQOS_DMA_MODE_SWR stuck\n");
720 goto err_stop_resets;
723 ret = eqos->config->ops->eqos_calibrate_pads(dev);
725 pr_err("eqos_calibrate_pads() failed: %d\n", ret);
726 goto err_stop_resets;
729 if (eqos->config->ops->eqos_get_tick_clk_rate) {
730 rate = eqos->config->ops->eqos_get_tick_clk_rate(dev);
732 val = (rate / 1000000) - 1;
733 writel(val, &eqos->mac_regs->us_tic_counter);
737 * if PHY was already connected and configured,
738 * don't need to reconnect/reconfigure again
744 if (IS_ENABLED(CONFIG_PHY_FIXED)) {
745 fixed_node = ofnode_find_subnode(dev_ofnode(dev),
747 if (ofnode_valid(fixed_node))
748 eqos->phy = fixed_phy_create(dev_ofnode(dev));
752 addr = eqos_get_phy_addr(eqos, dev);
753 eqos->phy = phy_connect(eqos->mii, addr, dev,
754 eqos->config->interface(dev));
758 pr_err("phy_connect() failed\n");
760 goto err_stop_resets;
763 if (eqos->max_speed) {
764 ret = phy_set_supported(eqos->phy, eqos->max_speed);
766 pr_err("phy_set_supported() failed: %d\n", ret);
767 goto err_shutdown_phy;
771 eqos->phy->node = eqos->phy_of_node;
772 ret = phy_config(eqos->phy);
774 pr_err("phy_config() failed: %d\n", ret);
775 goto err_shutdown_phy;
779 ret = phy_startup(eqos->phy);
781 pr_err("phy_startup() failed: %d\n", ret);
782 goto err_shutdown_phy;
785 if (!eqos->phy->link) {
788 goto err_shutdown_phy;
791 ret = eqos_adjust_link(dev);
793 pr_err("eqos_adjust_link() failed: %d\n", ret);
794 goto err_shutdown_phy;
799 /* Enable Store and Forward mode for TX */
800 /* Program Tx operating mode */
801 setbits_le32(&eqos->mtl_regs->txq0_operation_mode,
802 EQOS_MTL_TXQ0_OPERATION_MODE_TSF |
803 (EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_ENABLED <<
804 EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT));
806 /* Transmit Queue weight */
807 writel(0x10, &eqos->mtl_regs->txq0_quantum_weight);
809 /* Enable Store and Forward mode for RX, since no jumbo frame */
810 setbits_le32(&eqos->mtl_regs->rxq0_operation_mode,
811 EQOS_MTL_RXQ0_OPERATION_MODE_RSF);
813 /* Transmit/Receive queue fifo size; use all RAM for 1 queue */
814 val = readl(&eqos->mac_regs->hw_feature1);
815 tx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_SHIFT) &
816 EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_MASK;
817 rx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_SHIFT) &
818 EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_MASK;
820 /* r/tx_fifo_sz is encoded as log2(n / 128). Undo that by shifting */
821 tx_fifo_sz = 128 << tx_fifo_sz;
822 rx_fifo_sz = 128 << rx_fifo_sz;
824 /* Allow platform to override TX/RX fifo size */
825 if (eqos->tx_fifo_sz)
826 tx_fifo_sz = eqos->tx_fifo_sz;
827 if (eqos->rx_fifo_sz)
828 rx_fifo_sz = eqos->rx_fifo_sz;
830 /* r/tqs is encoded as (n / 256) - 1 */
831 tqs = tx_fifo_sz / 256 - 1;
832 rqs = rx_fifo_sz / 256 - 1;
834 clrsetbits_le32(&eqos->mtl_regs->txq0_operation_mode,
835 EQOS_MTL_TXQ0_OPERATION_MODE_TQS_MASK <<
836 EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT,
837 tqs << EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT);
838 clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode,
839 EQOS_MTL_RXQ0_OPERATION_MODE_RQS_MASK <<
840 EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT,
841 rqs << EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT);
843 /* Flow control used only if each channel gets 4KB or more FIFO */
844 if (rqs >= ((4096 / 256) - 1)) {
847 setbits_le32(&eqos->mtl_regs->rxq0_operation_mode,
848 EQOS_MTL_RXQ0_OPERATION_MODE_EHFC);
851 * Set Threshold for Activating Flow Contol space for min 2
852 * frames ie, (1500 * 1) = 1500 bytes.
854 * Set Threshold for Deactivating Flow Contol for space of
855 * min 1 frame (frame size 1500bytes) in receive fifo
857 if (rqs == ((4096 / 256) - 1)) {
859 * This violates the above formula because of FIFO size
860 * limit therefore overflow may occur inspite of this.
862 rfd = 0x3; /* Full-3K */
863 rfa = 0x1; /* Full-1.5K */
864 } else if (rqs == ((8192 / 256) - 1)) {
865 rfd = 0x6; /* Full-4K */
866 rfa = 0xa; /* Full-6K */
867 } else if (rqs == ((16384 / 256) - 1)) {
868 rfd = 0x6; /* Full-4K */
869 rfa = 0x12; /* Full-10K */
871 rfd = 0x6; /* Full-4K */
872 rfa = 0x1E; /* Full-16K */
875 clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode,
876 (EQOS_MTL_RXQ0_OPERATION_MODE_RFD_MASK <<
877 EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) |
878 (EQOS_MTL_RXQ0_OPERATION_MODE_RFA_MASK <<
879 EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT),
881 EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) |
883 EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT));
888 clrsetbits_le32(&eqos->mac_regs->rxq_ctrl0,
889 EQOS_MAC_RXQ_CTRL0_RXQ0EN_MASK <<
890 EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT,
891 eqos->config->config_mac <<
892 EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT);
894 /* Multicast and Broadcast Queue Enable */
895 setbits_le32(&eqos->mac_regs->unused_0a4,
897 /* enable promise mode */
898 setbits_le32(&eqos->mac_regs->unused_004[1],
901 /* Set TX flow control parameters */
903 setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl,
904 0xffff << EQOS_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT);
905 /* Assign priority for TX flow control */
906 clrbits_le32(&eqos->mac_regs->txq_prty_map0,
907 EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_MASK <<
908 EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_SHIFT);
909 /* Assign priority for RX flow control */
910 clrbits_le32(&eqos->mac_regs->rxq_ctrl2,
911 EQOS_MAC_RXQ_CTRL2_PSRQ0_MASK <<
912 EQOS_MAC_RXQ_CTRL2_PSRQ0_SHIFT);
913 /* Enable flow control */
914 setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl,
915 EQOS_MAC_Q0_TX_FLOW_CTRL_TFE);
916 setbits_le32(&eqos->mac_regs->rx_flow_ctrl,
917 EQOS_MAC_RX_FLOW_CTRL_RFE);
919 clrsetbits_le32(&eqos->mac_regs->configuration,
920 EQOS_MAC_CONFIGURATION_GPSLCE |
921 EQOS_MAC_CONFIGURATION_WD |
922 EQOS_MAC_CONFIGURATION_JD |
923 EQOS_MAC_CONFIGURATION_JE,
924 EQOS_MAC_CONFIGURATION_CST |
925 EQOS_MAC_CONFIGURATION_ACS);
927 eqos_write_hwaddr(dev);
931 /* Enable OSP mode */
932 setbits_le32(&eqos->dma_regs->ch0_tx_control,
933 EQOS_DMA_CH0_TX_CONTROL_OSP);
935 /* RX buffer size. Must be a multiple of bus width */
936 clrsetbits_le32(&eqos->dma_regs->ch0_rx_control,
937 EQOS_DMA_CH0_RX_CONTROL_RBSZ_MASK <<
938 EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT,
939 EQOS_MAX_PACKET_SIZE <<
940 EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT);
942 desc_pad = (eqos->desc_size - sizeof(struct eqos_desc)) /
943 eqos->config->axi_bus_width;
945 setbits_le32(&eqos->dma_regs->ch0_control,
946 EQOS_DMA_CH0_CONTROL_PBLX8 |
947 (desc_pad << EQOS_DMA_CH0_CONTROL_DSL_SHIFT));
950 * Burst length must be < 1/2 FIFO size.
951 * FIFO size in tqs is encoded as (n / 256) - 1.
952 * Each burst is n * 8 (PBLX8) * 16 (AXI width) == 128 bytes.
953 * Half of n * 256 is n * 128, so pbl == tqs, modulo the -1.
958 clrsetbits_le32(&eqos->dma_regs->ch0_tx_control,
959 EQOS_DMA_CH0_TX_CONTROL_TXPBL_MASK <<
960 EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT,
961 pbl << EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT);
963 clrsetbits_le32(&eqos->dma_regs->ch0_rx_control,
964 EQOS_DMA_CH0_RX_CONTROL_RXPBL_MASK <<
965 EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT,
966 8 << EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT);
968 /* DMA performance configuration */
969 val = (2 << EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT) |
970 EQOS_DMA_SYSBUS_MODE_EAME | EQOS_DMA_SYSBUS_MODE_BLEN16 |
971 EQOS_DMA_SYSBUS_MODE_BLEN8 | EQOS_DMA_SYSBUS_MODE_BLEN4;
972 writel(val, &eqos->dma_regs->sysbus_mode);
974 /* Set up descriptors */
976 memset(eqos->tx_descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_TX);
977 memset(eqos->rx_descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_RX);
979 for (i = 0; i < EQOS_DESCRIPTORS_TX; i++) {
980 struct eqos_desc *tx_desc = eqos_get_desc(eqos, i, false);
981 eqos->config->ops->eqos_flush_desc(tx_desc);
984 for (i = 0; i < EQOS_DESCRIPTORS_RX; i++) {
985 struct eqos_desc *rx_desc = eqos_get_desc(eqos, i, true);
987 addr64 = (ulong)(eqos->rx_dma_buf + (i * EQOS_MAX_PACKET_SIZE));
988 rx_desc->des0 = lower_32_bits(addr64);
989 rx_desc->des1 = upper_32_bits(addr64);
990 rx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_BUF1V;
992 eqos->config->ops->eqos_flush_desc(rx_desc);
993 eqos->config->ops->eqos_inval_buffer((void *)addr64, EQOS_MAX_PACKET_SIZE);
996 addr64 = (ulong)eqos_get_desc(eqos, 0, false);
997 writel(upper_32_bits(addr64), &eqos->dma_regs->ch0_txdesc_list_haddress);
998 writel(lower_32_bits(addr64), &eqos->dma_regs->ch0_txdesc_list_address);
999 writel(EQOS_DESCRIPTORS_TX - 1,
1000 &eqos->dma_regs->ch0_txdesc_ring_length);
1002 addr64 = (ulong)eqos_get_desc(eqos, 0, true);
1003 writel(upper_32_bits(addr64), &eqos->dma_regs->ch0_rxdesc_list_haddress);
1004 writel(lower_32_bits(addr64), &eqos->dma_regs->ch0_rxdesc_list_address);
1005 writel(EQOS_DESCRIPTORS_RX - 1,
1006 &eqos->dma_regs->ch0_rxdesc_ring_length);
1008 /* Enable everything */
1009 setbits_le32(&eqos->dma_regs->ch0_tx_control,
1010 EQOS_DMA_CH0_TX_CONTROL_ST);
1011 setbits_le32(&eqos->dma_regs->ch0_rx_control,
1012 EQOS_DMA_CH0_RX_CONTROL_SR);
1013 setbits_le32(&eqos->mac_regs->configuration,
1014 EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE);
1016 /* TX tail pointer not written until we need to TX a packet */
1018 * Point RX tail pointer at last descriptor. Ideally, we'd point at the
1019 * first descriptor, implying all descriptors were available. However,
1020 * that's not distinguishable from none of the descriptors being
1023 last_rx_desc = (ulong)eqos_get_desc(eqos, EQOS_DESCRIPTORS_RX - 1, true);
1024 writel(last_rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer);
1026 eqos->started = true;
1028 debug("%s: OK\n", __func__);
1032 phy_shutdown(eqos->phy);
1034 eqos->config->ops->eqos_stop_resets(dev);
1036 pr_err("FAILED: %d\n", ret);
1040 static void eqos_stop(struct udevice *dev)
1042 struct eqos_priv *eqos = dev_get_priv(dev);
1045 debug("%s(dev=%p):\n", __func__, dev);
1049 eqos->started = false;
1050 eqos->reg_access_ok = false;
1052 /* Disable TX DMA */
1053 clrbits_le32(&eqos->dma_regs->ch0_tx_control,
1054 EQOS_DMA_CH0_TX_CONTROL_ST);
1056 /* Wait for TX all packets to drain out of MTL */
1057 for (i = 0; i < 1000000; i++) {
1058 u32 val = readl(&eqos->mtl_regs->txq0_debug);
1059 u32 trcsts = (val >> EQOS_MTL_TXQ0_DEBUG_TRCSTS_SHIFT) &
1060 EQOS_MTL_TXQ0_DEBUG_TRCSTS_MASK;
1061 u32 txqsts = val & EQOS_MTL_TXQ0_DEBUG_TXQSTS;
1062 if ((trcsts != 1) && (!txqsts))
1066 /* Turn off MAC TX and RX */
1067 clrbits_le32(&eqos->mac_regs->configuration,
1068 EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE);
1070 /* Wait for all RX packets to drain out of MTL */
1071 for (i = 0; i < 1000000; i++) {
1072 u32 val = readl(&eqos->mtl_regs->rxq0_debug);
1073 u32 prxq = (val >> EQOS_MTL_RXQ0_DEBUG_PRXQ_SHIFT) &
1074 EQOS_MTL_RXQ0_DEBUG_PRXQ_MASK;
1075 u32 rxqsts = (val >> EQOS_MTL_RXQ0_DEBUG_RXQSTS_SHIFT) &
1076 EQOS_MTL_RXQ0_DEBUG_RXQSTS_MASK;
1077 if ((!prxq) && (!rxqsts))
1081 /* Turn off RX DMA */
1082 clrbits_le32(&eqos->dma_regs->ch0_rx_control,
1083 EQOS_DMA_CH0_RX_CONTROL_SR);
1086 phy_shutdown(eqos->phy);
1088 eqos->config->ops->eqos_stop_resets(dev);
1090 debug("%s: OK\n", __func__);
1093 static int eqos_send(struct udevice *dev, void *packet, int length)
1095 struct eqos_priv *eqos = dev_get_priv(dev);
1096 struct eqos_desc *tx_desc;
1099 debug("%s(dev=%p, packet=%p, length=%d):\n", __func__, dev, packet,
1102 memcpy(eqos->tx_dma_buf, packet, length);
1103 eqos->config->ops->eqos_flush_buffer(eqos->tx_dma_buf, length);
1105 tx_desc = eqos_get_desc(eqos, eqos->tx_desc_idx, false);
1106 eqos->tx_desc_idx++;
1107 eqos->tx_desc_idx %= EQOS_DESCRIPTORS_TX;
1109 tx_desc->des0 = lower_32_bits((ulong)eqos->tx_dma_buf);
1110 tx_desc->des1 = upper_32_bits((ulong)eqos->tx_dma_buf);
1111 tx_desc->des2 = length;
1113 * Make sure that if HW sees the _OWN write below, it will see all the
1114 * writes to the rest of the descriptor too.
1117 tx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_FD | EQOS_DESC3_LD | length;
1118 eqos->config->ops->eqos_flush_desc(tx_desc);
1120 writel((ulong)eqos_get_desc(eqos, eqos->tx_desc_idx, false),
1121 &eqos->dma_regs->ch0_txdesc_tail_pointer);
1123 for (i = 0; i < 1000000; i++) {
1124 eqos->config->ops->eqos_inval_desc(tx_desc);
1125 if (!(readl(&tx_desc->des3) & EQOS_DESC3_OWN))
1130 debug("%s: TX timeout\n", __func__);
1135 static int eqos_recv(struct udevice *dev, int flags, uchar **packetp)
1137 struct eqos_priv *eqos = dev_get_priv(dev);
1138 struct eqos_desc *rx_desc;
1141 rx_desc = eqos_get_desc(eqos, eqos->rx_desc_idx, true);
1142 eqos->config->ops->eqos_inval_desc(rx_desc);
1143 if (rx_desc->des3 & EQOS_DESC3_OWN)
1146 debug("%s(dev=%p, flags=%x):\n", __func__, dev, flags);
1148 *packetp = eqos->rx_dma_buf +
1149 (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE);
1150 length = rx_desc->des3 & 0x7fff;
1151 debug("%s: *packetp=%p, length=%d\n", __func__, *packetp, length);
1153 eqos->config->ops->eqos_inval_buffer(*packetp, length);
1158 static int eqos_free_pkt(struct udevice *dev, uchar *packet, int length)
1160 struct eqos_priv *eqos = dev_get_priv(dev);
1161 u32 idx, idx_mask = eqos->desc_per_cacheline - 1;
1162 uchar *packet_expected;
1163 struct eqos_desc *rx_desc = NULL;
1165 debug("%s(packet=%p, length=%d)\n", __func__, packet, length);
1167 packet_expected = eqos->rx_dma_buf +
1168 (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE);
1169 if (packet != packet_expected) {
1170 debug("%s: Unexpected packet (expected %p)\n", __func__,
1175 eqos->config->ops->eqos_inval_buffer(packet, length);
1177 if ((eqos->rx_desc_idx & idx_mask) == idx_mask) {
1178 for (idx = eqos->rx_desc_idx - idx_mask;
1179 idx <= eqos->rx_desc_idx;
1183 rx_desc = eqos_get_desc(eqos, idx, true);
1187 eqos->config->ops->eqos_flush_desc(rx_desc);
1188 eqos->config->ops->eqos_inval_buffer(packet, length);
1189 addr64 = (ulong)(eqos->rx_dma_buf + (idx * EQOS_MAX_PACKET_SIZE));
1190 rx_desc->des0 = lower_32_bits(addr64);
1191 rx_desc->des1 = upper_32_bits(addr64);
1194 * Make sure that if HW sees the _OWN write below,
1195 * it will see all the writes to the rest of the
1199 rx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_BUF1V;
1200 eqos->config->ops->eqos_flush_desc(rx_desc);
1202 writel((ulong)rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer);
1205 eqos->rx_desc_idx++;
1206 eqos->rx_desc_idx %= EQOS_DESCRIPTORS_RX;
1211 static int eqos_probe_resources_core(struct udevice *dev)
1213 struct eqos_priv *eqos = dev_get_priv(dev);
1214 unsigned int desc_step;
1217 debug("%s(dev=%p):\n", __func__, dev);
1219 /* Maximum distance between neighboring descriptors, in Bytes. */
1220 desc_step = sizeof(struct eqos_desc) +
1221 EQOS_DMA_CH0_CONTROL_DSL_MASK * eqos->config->axi_bus_width;
1222 if (desc_step < ARCH_DMA_MINALIGN) {
1224 * The EQoS hardware implementation cannot place one descriptor
1225 * per cacheline, it is necessary to place multiple descriptors
1226 * per cacheline in memory and do cache management carefully.
1228 eqos->desc_size = BIT(fls(desc_step) - 1);
1230 eqos->desc_size = ALIGN(sizeof(struct eqos_desc),
1231 (unsigned int)ARCH_DMA_MINALIGN);
1233 eqos->desc_per_cacheline = ARCH_DMA_MINALIGN / eqos->desc_size;
1235 eqos->tx_descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_TX);
1236 if (!eqos->tx_descs) {
1237 debug("%s: eqos_alloc_descs(tx) failed\n", __func__);
1242 eqos->rx_descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_RX);
1243 if (!eqos->rx_descs) {
1244 debug("%s: eqos_alloc_descs(rx) failed\n", __func__);
1246 goto err_free_tx_descs;
1249 eqos->tx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_MAX_PACKET_SIZE);
1250 if (!eqos->tx_dma_buf) {
1251 debug("%s: memalign(tx_dma_buf) failed\n", __func__);
1253 goto err_free_descs;
1255 debug("%s: tx_dma_buf=%p\n", __func__, eqos->tx_dma_buf);
1257 eqos->rx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_RX_BUFFER_SIZE);
1258 if (!eqos->rx_dma_buf) {
1259 debug("%s: memalign(rx_dma_buf) failed\n", __func__);
1261 goto err_free_tx_dma_buf;
1263 debug("%s: rx_dma_buf=%p\n", __func__, eqos->rx_dma_buf);
1265 eqos->config->ops->eqos_inval_buffer(eqos->rx_dma_buf,
1266 EQOS_MAX_PACKET_SIZE * EQOS_DESCRIPTORS_RX);
1268 debug("%s: OK\n", __func__);
1271 err_free_tx_dma_buf:
1272 free(eqos->tx_dma_buf);
1274 eqos_free_descs(eqos->rx_descs);
1276 eqos_free_descs(eqos->tx_descs);
1279 debug("%s: returns %d\n", __func__, ret);
1283 static int eqos_remove_resources_core(struct udevice *dev)
1285 struct eqos_priv *eqos = dev_get_priv(dev);
1287 debug("%s(dev=%p):\n", __func__, dev);
1289 free(eqos->rx_dma_buf);
1290 free(eqos->tx_dma_buf);
1291 eqos_free_descs(eqos->rx_descs);
1292 eqos_free_descs(eqos->tx_descs);
1294 debug("%s: OK\n", __func__);
1298 static int eqos_probe_resources_tegra186(struct udevice *dev)
1300 struct eqos_priv *eqos = dev_get_priv(dev);
1303 debug("%s(dev=%p):\n", __func__, dev);
1305 ret = eqos_get_base_addr_dt(dev);
1307 pr_err("eqos_get_base_addr_dt failed: %d\n", ret);
1310 eqos->tegra186_regs = (void *)(eqos->regs + EQOS_TEGRA186_REGS_BASE);
1312 ret = reset_get_by_name(dev, "eqos", &eqos->reset_ctl);
1314 pr_err("reset_get_by_name(rst) failed: %d\n", ret);
1318 ret = gpio_request_by_name(dev, "phy-reset-gpios", 0,
1319 &eqos->phy_reset_gpio,
1320 GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
1322 pr_err("gpio_request_by_name(phy reset) failed: %d\n", ret);
1323 goto err_free_reset_eqos;
1326 ret = clk_get_by_name(dev, "slave_bus", &eqos->clk_slave_bus);
1328 pr_err("clk_get_by_name(slave_bus) failed: %d\n", ret);
1329 goto err_free_gpio_phy_reset;
1332 ret = clk_get_by_name(dev, "master_bus", &eqos->clk_master_bus);
1334 pr_err("clk_get_by_name(master_bus) failed: %d\n", ret);
1335 goto err_free_gpio_phy_reset;
1338 ret = clk_get_by_name(dev, "rx", &eqos->clk_rx);
1340 pr_err("clk_get_by_name(rx) failed: %d\n", ret);
1341 goto err_free_gpio_phy_reset;
1344 ret = clk_get_by_name(dev, "ptp_ref", &eqos->clk_ptp_ref);
1346 pr_err("clk_get_by_name(ptp_ref) failed: %d\n", ret);
1347 goto err_free_gpio_phy_reset;
1350 ret = clk_get_by_name(dev, "tx", &eqos->clk_tx);
1352 pr_err("clk_get_by_name(tx) failed: %d\n", ret);
1353 goto err_free_gpio_phy_reset;
1356 debug("%s: OK\n", __func__);
1359 err_free_gpio_phy_reset:
1360 dm_gpio_free(dev, &eqos->phy_reset_gpio);
1361 err_free_reset_eqos:
1362 reset_free(&eqos->reset_ctl);
1364 debug("%s: returns %d\n", __func__, ret);
1368 static phy_interface_t eqos_get_interface_tegra186(const struct udevice *dev)
1370 return PHY_INTERFACE_MODE_MII;
1373 static int eqos_remove_resources_tegra186(struct udevice *dev)
1375 struct eqos_priv *eqos = dev_get_priv(dev);
1377 debug("%s(dev=%p):\n", __func__, dev);
1379 dm_gpio_free(dev, &eqos->phy_reset_gpio);
1380 reset_free(&eqos->reset_ctl);
1382 debug("%s: OK\n", __func__);
1386 static int eqos_bind(struct udevice *dev)
1389 const size_t name_sz = 16;
1392 /* Device name defaults to DT node name. */
1393 if (ofnode_valid(dev_ofnode(dev)))
1396 /* Assign unique names in case there is no DT node. */
1397 snprintf(name, name_sz, "eth_eqos#%d", dev_num++);
1398 return device_set_name(dev, name);
1402 * Get driver data based on the device tree. Boards not using a device tree can
1403 * overwrite this function.
1405 __weak void *eqos_get_driver_data(struct udevice *dev)
1407 return (void *)dev_get_driver_data(dev);
1410 static fdt_addr_t eqos_get_base_addr_common(struct udevice *dev, fdt_addr_t addr)
1412 struct eqos_priv *eqos = dev_get_priv(dev);
1414 if (addr == FDT_ADDR_T_NONE) {
1415 #if CONFIG_IS_ENABLED(FDT_64BIT)
1416 dev_err(dev, "addr=0x%llx is invalid.\n", addr);
1418 dev_err(dev, "addr=0x%x is invalid.\n", addr);
1424 eqos->mac_regs = (void *)(addr + EQOS_MAC_REGS_BASE);
1425 eqos->mtl_regs = (void *)(addr + EQOS_MTL_REGS_BASE);
1426 eqos->dma_regs = (void *)(addr + EQOS_DMA_REGS_BASE);
1431 int eqos_get_base_addr_dt(struct udevice *dev)
1433 fdt_addr_t addr = dev_read_addr(dev);
1434 return eqos_get_base_addr_common(dev, addr);
1437 int eqos_get_base_addr_pci(struct udevice *dev)
1442 paddr = dm_pci_map_bar(dev, PCI_BASE_ADDRESS_0, 0, 0, PCI_REGION_TYPE,
1444 addr = paddr ? (fdt_addr_t)paddr : FDT_ADDR_T_NONE;
1446 return eqos_get_base_addr_common(dev, addr);
1449 static int eqos_probe(struct udevice *dev)
1451 struct eqos_priv *eqos = dev_get_priv(dev);
1454 debug("%s(dev=%p):\n", __func__, dev);
1458 eqos->config = eqos_get_driver_data(dev);
1459 if (!eqos->config) {
1460 pr_err("Failed to get driver data.\n");
1464 eqos->max_speed = dev_read_u32_default(dev, "max-speed", 0);
1466 ret = eqos_probe_resources_core(dev);
1468 pr_err("eqos_probe_resources_core() failed: %d\n", ret);
1472 ret = eqos->config->ops->eqos_probe_resources(dev);
1474 pr_err("eqos_probe_resources() failed: %d\n", ret);
1475 goto err_remove_resources_core;
1478 ret = eqos->config->ops->eqos_start_clks(dev);
1480 pr_err("eqos_start_clks() failed: %d\n", ret);
1481 goto err_remove_resources_tegra;
1484 #ifdef CONFIG_DM_ETH_PHY
1485 eqos->mii = eth_phy_get_mdio_bus(dev);
1488 eqos->mii = mdio_alloc();
1490 pr_err("mdio_alloc() failed\n");
1494 eqos->mii->read = eqos_mdio_read;
1495 eqos->mii->write = eqos_mdio_write;
1496 eqos->mii->priv = eqos;
1497 strcpy(eqos->mii->name, dev->name);
1499 ret = mdio_register(eqos->mii);
1501 pr_err("mdio_register() failed: %d\n", ret);
1506 #ifdef CONFIG_DM_ETH_PHY
1507 eth_phy_set_mdio_bus(dev, eqos->mii);
1510 debug("%s: OK\n", __func__);
1514 mdio_free(eqos->mii);
1516 eqos->config->ops->eqos_stop_clks(dev);
1517 err_remove_resources_tegra:
1518 eqos->config->ops->eqos_remove_resources(dev);
1519 err_remove_resources_core:
1520 eqos_remove_resources_core(dev);
1522 debug("%s: returns %d\n", __func__, ret);
1526 static int eqos_remove(struct udevice *dev)
1528 struct eqos_priv *eqos = dev_get_priv(dev);
1530 debug("%s(dev=%p):\n", __func__, dev);
1532 mdio_unregister(eqos->mii);
1533 mdio_free(eqos->mii);
1534 eqos->config->ops->eqos_stop_clks(dev);
1535 eqos->config->ops->eqos_remove_resources(dev);
1537 eqos_remove_resources_core(dev);
1539 debug("%s: OK\n", __func__);
1543 int eqos_null_ops(struct udevice *dev)
1548 static const struct eth_ops eqos_ops = {
1549 .start = eqos_start,
1553 .free_pkt = eqos_free_pkt,
1554 .write_hwaddr = eqos_write_hwaddr,
1555 .read_rom_hwaddr = eqos_read_rom_hwaddr,
1558 static struct eqos_ops eqos_tegra186_ops = {
1559 .eqos_inval_desc = eqos_inval_desc_generic,
1560 .eqos_flush_desc = eqos_flush_desc_generic,
1561 .eqos_inval_buffer = eqos_inval_buffer_tegra186,
1562 .eqos_flush_buffer = eqos_flush_buffer_tegra186,
1563 .eqos_probe_resources = eqos_probe_resources_tegra186,
1564 .eqos_remove_resources = eqos_remove_resources_tegra186,
1565 .eqos_stop_resets = eqos_stop_resets_tegra186,
1566 .eqos_start_resets = eqos_start_resets_tegra186,
1567 .eqos_stop_clks = eqos_stop_clks_tegra186,
1568 .eqos_start_clks = eqos_start_clks_tegra186,
1569 .eqos_calibrate_pads = eqos_calibrate_pads_tegra186,
1570 .eqos_disable_calibration = eqos_disable_calibration_tegra186,
1571 .eqos_set_tx_clk_speed = eqos_set_tx_clk_speed_tegra186,
1572 .eqos_get_enetaddr = eqos_null_ops,
1573 .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_tegra186
1576 static const struct eqos_config __maybe_unused eqos_tegra186_config = {
1577 .reg_access_always_ok = false,
1580 .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB,
1581 .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_20_35,
1582 .axi_bus_width = EQOS_AXI_WIDTH_128,
1583 .interface = eqos_get_interface_tegra186,
1584 .ops = &eqos_tegra186_ops
1587 static const struct udevice_id eqos_ids[] = {
1588 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_TEGRA186)
1590 .compatible = "nvidia,tegra186-eqos",
1591 .data = (ulong)&eqos_tegra186_config
1594 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_STM32)
1596 .compatible = "st,stm32mp13-dwmac",
1597 .data = (ulong)&eqos_stm32mp13_config
1600 .compatible = "st,stm32mp1-dwmac",
1601 .data = (ulong)&eqos_stm32mp15_config
1604 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_IMX)
1606 .compatible = "nxp,imx8mp-dwmac-eqos",
1607 .data = (ulong)&eqos_imx_config
1610 .compatible = "nxp,imx93-dwmac-eqos",
1611 .data = (ulong)&eqos_imx_config
1614 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_ROCKCHIP)
1616 .compatible = "rockchip,rk3568-gmac",
1617 .data = (ulong)&eqos_rockchip_config
1620 .compatible = "rockchip,rk3588-gmac",
1621 .data = (ulong)&eqos_rockchip_config
1624 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_QCOM)
1626 .compatible = "qcom,qcs404-ethqos",
1627 .data = (ulong)&eqos_qcom_config
1630 #if IS_ENABLED(CONFIG_DWC_ETH_QOS_STARFIVE)
1632 .compatible = "starfive,jh7110-dwmac",
1633 .data = (ulong)&eqos_jh7110_config
1639 U_BOOT_DRIVER(eth_eqos) = {
1642 .of_match = of_match_ptr(eqos_ids),
1644 .probe = eqos_probe,
1645 .remove = eqos_remove,
1647 .priv_auto = sizeof(struct eqos_priv),
1648 .plat_auto = sizeof(struct eth_pdata),