Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016, NVIDIA CORPORATION. |
| 4 | * |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 5 | * Portions based on U-Boot's rtl8169.c. |
| 6 | */ |
| 7 | |
| 8 | /* |
| 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. |
| 12 | * |
| 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 |
| 20 | * field. |
| 21 | * |
| 22 | * The following configurations are currently supported: |
| 23 | * tegra186: |
| 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. |
| 28 | */ |
Patrick Delaunay | cafaa30 | 2020-09-09 18:30:06 +0200 | [diff] [blame] | 29 | |
Patrick Delaunay | b547f4b | 2021-07-20 20:15:29 +0200 | [diff] [blame] | 30 | #define LOG_CATEGORY UCLASS_ETH |
| 31 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 32 | #include <common.h> |
| 33 | #include <clk.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 34 | #include <cpu_func.h> |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 35 | #include <dm.h> |
| 36 | #include <errno.h> |
Patrick Delaunay | 8a3b69d | 2022-06-30 11:09:41 +0200 | [diff] [blame] | 37 | #include <eth_phy.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 38 | #include <log.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 39 | #include <malloc.h> |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 40 | #include <memalign.h> |
| 41 | #include <miiphy.h> |
| 42 | #include <net.h> |
| 43 | #include <netdev.h> |
| 44 | #include <phy.h> |
| 45 | #include <reset.h> |
| 46 | #include <wait_bit.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 47 | #include <asm/cache.h> |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 48 | #include <asm/gpio.h> |
| 49 | #include <asm/io.h> |
Fugang Duan | 0e9d239 | 2020-05-03 22:41:18 +0800 | [diff] [blame] | 50 | #ifdef CONFIG_ARCH_IMX8M |
| 51 | #include <asm/arch/clock.h> |
| 52 | #include <asm/mach-imx/sys_proto.h> |
| 53 | #endif |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 54 | #include <linux/delay.h> |
Simon Glass | 1e94b46 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 55 | #include <linux/printk.h> |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 56 | |
Peng Fan | 149e80f | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 57 | #include "dwc_eth_qos.h" |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 58 | |
| 59 | /* |
| 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. |
| 68 | * |
| 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 |
| 71 | * or invalidate them. |
| 72 | * |
| 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. |
| 76 | */ |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 77 | static void *eqos_alloc_descs(struct eqos_priv *eqos, unsigned int num) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 78 | { |
Marek Vasut | e9d3fc7 | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 79 | return memalign(ARCH_DMA_MINALIGN, num * eqos->desc_size); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static void eqos_free_descs(void *descs) |
| 83 | { |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 84 | free(descs); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 85 | } |
| 86 | |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 87 | static struct eqos_desc *eqos_get_desc(struct eqos_priv *eqos, |
| 88 | unsigned int num, bool rx) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 89 | { |
Marek Vasut | f94d008 | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 90 | return (rx ? eqos->rx_descs : eqos->tx_descs) + |
| 91 | (num * eqos->desc_size); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 92 | } |
| 93 | |
Peng Fan | 149e80f | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 94 | void eqos_inval_desc_generic(void *desc) |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 95 | { |
Marek Vasut | e9d3fc7 | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 96 | unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1); |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 97 | unsigned long end = ALIGN(start + sizeof(struct eqos_desc), |
| 98 | ARCH_DMA_MINALIGN); |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 99 | |
| 100 | invalidate_dcache_range(start, end); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 101 | } |
| 102 | |
Peng Fan | 149e80f | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 103 | void eqos_flush_desc_generic(void *desc) |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 104 | { |
Marek Vasut | e9d3fc7 | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 105 | unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1); |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 106 | unsigned long end = ALIGN(start + sizeof(struct eqos_desc), |
| 107 | ARCH_DMA_MINALIGN); |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 108 | |
| 109 | flush_dcache_range(start, end); |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Marek Vasut | ac19125 | 2023-03-06 15:53:45 +0100 | [diff] [blame] | 112 | static void eqos_inval_buffer_tegra186(void *buf, size_t size) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 113 | { |
| 114 | unsigned long start = (unsigned long)buf & ~(ARCH_DMA_MINALIGN - 1); |
| 115 | unsigned long end = ALIGN(start + size, ARCH_DMA_MINALIGN); |
| 116 | |
| 117 | invalidate_dcache_range(start, end); |
| 118 | } |
| 119 | |
Peng Fan | 149e80f | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 120 | void eqos_inval_buffer_generic(void *buf, size_t size) |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 121 | { |
| 122 | unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN); |
| 123 | unsigned long end = roundup((unsigned long)buf + size, |
| 124 | ARCH_DMA_MINALIGN); |
| 125 | |
| 126 | invalidate_dcache_range(start, end); |
| 127 | } |
| 128 | |
| 129 | static void eqos_flush_buffer_tegra186(void *buf, size_t size) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 130 | { |
| 131 | flush_cache((unsigned long)buf, size); |
| 132 | } |
| 133 | |
Peng Fan | 149e80f | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 134 | void eqos_flush_buffer_generic(void *buf, size_t size) |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 135 | { |
| 136 | unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN); |
| 137 | unsigned long end = roundup((unsigned long)buf + size, |
| 138 | ARCH_DMA_MINALIGN); |
| 139 | |
| 140 | flush_dcache_range(start, end); |
| 141 | } |
| 142 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 143 | static int eqos_mdio_wait_idle(struct eqos_priv *eqos) |
| 144 | { |
Ălvaro FernĂĄndez Rojas | 4826350 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 145 | return wait_for_bit_le32(&eqos->mac_regs->mdio_address, |
| 146 | EQOS_MAC_MDIO_ADDRESS_GB, false, |
| 147 | 1000000, true); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | static int eqos_mdio_read(struct mii_dev *bus, int mdio_addr, int mdio_devad, |
| 151 | int mdio_reg) |
| 152 | { |
| 153 | struct eqos_priv *eqos = bus->priv; |
| 154 | u32 val; |
| 155 | int ret; |
| 156 | |
| 157 | debug("%s(dev=%p, addr=%x, reg=%d):\n", __func__, eqos->dev, mdio_addr, |
| 158 | mdio_reg); |
| 159 | |
| 160 | ret = eqos_mdio_wait_idle(eqos); |
| 161 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 162 | pr_err("MDIO not idle at entry"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | val = readl(&eqos->mac_regs->mdio_address); |
| 167 | val &= EQOS_MAC_MDIO_ADDRESS_SKAP | |
| 168 | EQOS_MAC_MDIO_ADDRESS_C45E; |
| 169 | val |= (mdio_addr << EQOS_MAC_MDIO_ADDRESS_PA_SHIFT) | |
| 170 | (mdio_reg << EQOS_MAC_MDIO_ADDRESS_RDA_SHIFT) | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 171 | (eqos->config->config_mac_mdio << |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 172 | EQOS_MAC_MDIO_ADDRESS_CR_SHIFT) | |
| 173 | (EQOS_MAC_MDIO_ADDRESS_GOC_READ << |
| 174 | EQOS_MAC_MDIO_ADDRESS_GOC_SHIFT) | |
| 175 | EQOS_MAC_MDIO_ADDRESS_GB; |
| 176 | writel(val, &eqos->mac_regs->mdio_address); |
| 177 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 178 | udelay(eqos->config->mdio_wait); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 179 | |
| 180 | ret = eqos_mdio_wait_idle(eqos); |
| 181 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 182 | pr_err("MDIO read didn't complete"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | val = readl(&eqos->mac_regs->mdio_data); |
| 187 | val &= EQOS_MAC_MDIO_DATA_GD_MASK; |
| 188 | |
| 189 | debug("%s: val=%x\n", __func__, val); |
| 190 | |
| 191 | return val; |
| 192 | } |
| 193 | |
| 194 | static int eqos_mdio_write(struct mii_dev *bus, int mdio_addr, int mdio_devad, |
| 195 | int mdio_reg, u16 mdio_val) |
| 196 | { |
| 197 | struct eqos_priv *eqos = bus->priv; |
| 198 | u32 val; |
| 199 | int ret; |
| 200 | |
| 201 | debug("%s(dev=%p, addr=%x, reg=%d, val=%x):\n", __func__, eqos->dev, |
| 202 | mdio_addr, mdio_reg, mdio_val); |
| 203 | |
| 204 | ret = eqos_mdio_wait_idle(eqos); |
| 205 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 206 | pr_err("MDIO not idle at entry"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 207 | return ret; |
| 208 | } |
| 209 | |
| 210 | writel(mdio_val, &eqos->mac_regs->mdio_data); |
| 211 | |
| 212 | val = readl(&eqos->mac_regs->mdio_address); |
| 213 | val &= EQOS_MAC_MDIO_ADDRESS_SKAP | |
| 214 | EQOS_MAC_MDIO_ADDRESS_C45E; |
| 215 | val |= (mdio_addr << EQOS_MAC_MDIO_ADDRESS_PA_SHIFT) | |
| 216 | (mdio_reg << EQOS_MAC_MDIO_ADDRESS_RDA_SHIFT) | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 217 | (eqos->config->config_mac_mdio << |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 218 | EQOS_MAC_MDIO_ADDRESS_CR_SHIFT) | |
| 219 | (EQOS_MAC_MDIO_ADDRESS_GOC_WRITE << |
| 220 | EQOS_MAC_MDIO_ADDRESS_GOC_SHIFT) | |
| 221 | EQOS_MAC_MDIO_ADDRESS_GB; |
| 222 | writel(val, &eqos->mac_regs->mdio_address); |
| 223 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 224 | udelay(eqos->config->mdio_wait); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 225 | |
| 226 | ret = eqos_mdio_wait_idle(eqos); |
| 227 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 228 | pr_err("MDIO read didn't complete"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 229 | return ret; |
| 230 | } |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static int eqos_start_clks_tegra186(struct udevice *dev) |
| 236 | { |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 237 | #ifdef CONFIG_CLK |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 238 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 239 | int ret; |
| 240 | |
| 241 | debug("%s(dev=%p):\n", __func__, dev); |
| 242 | |
| 243 | ret = clk_enable(&eqos->clk_slave_bus); |
| 244 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 245 | pr_err("clk_enable(clk_slave_bus) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 246 | goto err; |
| 247 | } |
| 248 | |
| 249 | ret = clk_enable(&eqos->clk_master_bus); |
| 250 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 251 | pr_err("clk_enable(clk_master_bus) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 252 | goto err_disable_clk_slave_bus; |
| 253 | } |
| 254 | |
| 255 | ret = clk_enable(&eqos->clk_rx); |
| 256 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 257 | pr_err("clk_enable(clk_rx) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 258 | goto err_disable_clk_master_bus; |
| 259 | } |
| 260 | |
| 261 | ret = clk_enable(&eqos->clk_ptp_ref); |
| 262 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 263 | pr_err("clk_enable(clk_ptp_ref) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 264 | goto err_disable_clk_rx; |
| 265 | } |
| 266 | |
| 267 | ret = clk_set_rate(&eqos->clk_ptp_ref, 125 * 1000 * 1000); |
| 268 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 269 | pr_err("clk_set_rate(clk_ptp_ref) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 270 | goto err_disable_clk_ptp_ref; |
| 271 | } |
| 272 | |
| 273 | ret = clk_enable(&eqos->clk_tx); |
| 274 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 275 | pr_err("clk_enable(clk_tx) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 276 | goto err_disable_clk_ptp_ref; |
| 277 | } |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 278 | #endif |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 279 | |
| 280 | debug("%s: OK\n", __func__); |
| 281 | return 0; |
| 282 | |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 283 | #ifdef CONFIG_CLK |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 284 | err_disable_clk_ptp_ref: |
| 285 | clk_disable(&eqos->clk_ptp_ref); |
| 286 | err_disable_clk_rx: |
| 287 | clk_disable(&eqos->clk_rx); |
| 288 | err_disable_clk_master_bus: |
| 289 | clk_disable(&eqos->clk_master_bus); |
| 290 | err_disable_clk_slave_bus: |
| 291 | clk_disable(&eqos->clk_slave_bus); |
| 292 | err: |
| 293 | debug("%s: FAILED: %d\n", __func__, ret); |
| 294 | return ret; |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 295 | #endif |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 296 | } |
| 297 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 298 | static int eqos_start_clks_stm32(struct udevice *dev) |
| 299 | { |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 300 | #ifdef CONFIG_CLK |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 301 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 302 | int ret; |
| 303 | |
| 304 | debug("%s(dev=%p):\n", __func__, dev); |
| 305 | |
| 306 | ret = clk_enable(&eqos->clk_master_bus); |
| 307 | if (ret < 0) { |
| 308 | pr_err("clk_enable(clk_master_bus) failed: %d", ret); |
| 309 | goto err; |
| 310 | } |
| 311 | |
| 312 | ret = clk_enable(&eqos->clk_rx); |
| 313 | if (ret < 0) { |
| 314 | pr_err("clk_enable(clk_rx) failed: %d", ret); |
| 315 | goto err_disable_clk_master_bus; |
| 316 | } |
| 317 | |
| 318 | ret = clk_enable(&eqos->clk_tx); |
| 319 | if (ret < 0) { |
| 320 | pr_err("clk_enable(clk_tx) failed: %d", ret); |
| 321 | goto err_disable_clk_rx; |
| 322 | } |
| 323 | |
Daniil Stas | 07292f8 | 2021-05-23 22:24:48 +0000 | [diff] [blame] | 324 | if (clk_valid(&eqos->clk_ck) && !eqos->clk_ck_enabled) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 325 | ret = clk_enable(&eqos->clk_ck); |
| 326 | if (ret < 0) { |
| 327 | pr_err("clk_enable(clk_ck) failed: %d", ret); |
| 328 | goto err_disable_clk_tx; |
| 329 | } |
Daniil Stas | 07292f8 | 2021-05-23 22:24:48 +0000 | [diff] [blame] | 330 | eqos->clk_ck_enabled = true; |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 331 | } |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 332 | #endif |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 333 | |
| 334 | debug("%s: OK\n", __func__); |
| 335 | return 0; |
| 336 | |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 337 | #ifdef CONFIG_CLK |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 338 | err_disable_clk_tx: |
| 339 | clk_disable(&eqos->clk_tx); |
| 340 | err_disable_clk_rx: |
| 341 | clk_disable(&eqos->clk_rx); |
| 342 | err_disable_clk_master_bus: |
| 343 | clk_disable(&eqos->clk_master_bus); |
| 344 | err: |
| 345 | debug("%s: FAILED: %d\n", __func__, ret); |
| 346 | return ret; |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 347 | #endif |
| 348 | } |
| 349 | |
Patrick Delaunay | c6a0df2 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 350 | static int eqos_stop_clks_tegra186(struct udevice *dev) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 351 | { |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 352 | #ifdef CONFIG_CLK |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 353 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 354 | |
| 355 | debug("%s(dev=%p):\n", __func__, dev); |
| 356 | |
| 357 | clk_disable(&eqos->clk_tx); |
| 358 | clk_disable(&eqos->clk_ptp_ref); |
| 359 | clk_disable(&eqos->clk_rx); |
| 360 | clk_disable(&eqos->clk_master_bus); |
| 361 | clk_disable(&eqos->clk_slave_bus); |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 362 | #endif |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 363 | |
| 364 | debug("%s: OK\n", __func__); |
Patrick Delaunay | c6a0df2 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 365 | return 0; |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 366 | } |
| 367 | |
Patrick Delaunay | c6a0df2 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 368 | static int eqos_stop_clks_stm32(struct udevice *dev) |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 369 | { |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 370 | #ifdef CONFIG_CLK |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 371 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 372 | |
| 373 | debug("%s(dev=%p):\n", __func__, dev); |
| 374 | |
| 375 | clk_disable(&eqos->clk_tx); |
| 376 | clk_disable(&eqos->clk_rx); |
| 377 | clk_disable(&eqos->clk_master_bus); |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 378 | #endif |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 379 | |
| 380 | debug("%s: OK\n", __func__); |
Patrick Delaunay | c6a0df2 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 381 | return 0; |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 382 | } |
| 383 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 384 | static int eqos_start_resets_tegra186(struct udevice *dev) |
| 385 | { |
| 386 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 387 | int ret; |
| 388 | |
| 389 | debug("%s(dev=%p):\n", __func__, dev); |
| 390 | |
| 391 | ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 1); |
| 392 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 393 | pr_err("dm_gpio_set_value(phy_reset, assert) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 394 | return ret; |
| 395 | } |
| 396 | |
| 397 | udelay(2); |
| 398 | |
| 399 | ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 0); |
| 400 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 401 | pr_err("dm_gpio_set_value(phy_reset, deassert) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 402 | return ret; |
| 403 | } |
| 404 | |
| 405 | ret = reset_assert(&eqos->reset_ctl); |
| 406 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 407 | pr_err("reset_assert() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 408 | return ret; |
| 409 | } |
| 410 | |
| 411 | udelay(2); |
| 412 | |
| 413 | ret = reset_deassert(&eqos->reset_ctl); |
| 414 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 415 | pr_err("reset_deassert() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | debug("%s: OK\n", __func__); |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | static int eqos_stop_resets_tegra186(struct udevice *dev) |
| 424 | { |
| 425 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 426 | |
| 427 | reset_assert(&eqos->reset_ctl); |
| 428 | dm_gpio_set_value(&eqos->phy_reset_gpio, 1); |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | static int eqos_calibrate_pads_tegra186(struct udevice *dev) |
| 434 | { |
| 435 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 436 | int ret; |
| 437 | |
| 438 | debug("%s(dev=%p):\n", __func__, dev); |
| 439 | |
| 440 | setbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl, |
| 441 | EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD); |
| 442 | |
| 443 | udelay(1); |
| 444 | |
| 445 | setbits_le32(&eqos->tegra186_regs->auto_cal_config, |
| 446 | EQOS_AUTO_CAL_CONFIG_START | EQOS_AUTO_CAL_CONFIG_ENABLE); |
| 447 | |
Ălvaro FernĂĄndez Rojas | 4826350 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 448 | ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status, |
| 449 | EQOS_AUTO_CAL_STATUS_ACTIVE, true, 10, false); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 450 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 451 | pr_err("calibrate didn't start"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 452 | goto failed; |
| 453 | } |
| 454 | |
Ălvaro FernĂĄndez Rojas | 4826350 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 455 | ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status, |
| 456 | EQOS_AUTO_CAL_STATUS_ACTIVE, false, 10, false); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 457 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 458 | pr_err("calibrate didn't finish"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 459 | goto failed; |
| 460 | } |
| 461 | |
| 462 | ret = 0; |
| 463 | |
| 464 | failed: |
| 465 | clrbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl, |
| 466 | EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD); |
| 467 | |
| 468 | debug("%s: returns %d\n", __func__, ret); |
| 469 | |
| 470 | return ret; |
| 471 | } |
| 472 | |
| 473 | static int eqos_disable_calibration_tegra186(struct udevice *dev) |
| 474 | { |
| 475 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 476 | |
| 477 | debug("%s(dev=%p):\n", __func__, dev); |
| 478 | |
| 479 | clrbits_le32(&eqos->tegra186_regs->auto_cal_config, |
| 480 | EQOS_AUTO_CAL_CONFIG_ENABLE); |
| 481 | |
| 482 | return 0; |
| 483 | } |
| 484 | |
| 485 | static ulong eqos_get_tick_clk_rate_tegra186(struct udevice *dev) |
| 486 | { |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 487 | #ifdef CONFIG_CLK |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 488 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 489 | |
| 490 | return clk_get_rate(&eqos->clk_slave_bus); |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 491 | #else |
| 492 | return 0; |
| 493 | #endif |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 494 | } |
| 495 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 496 | static ulong eqos_get_tick_clk_rate_stm32(struct udevice *dev) |
| 497 | { |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 498 | #ifdef CONFIG_CLK |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 499 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 500 | |
| 501 | return clk_get_rate(&eqos->clk_master_bus); |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 502 | #else |
| 503 | return 0; |
| 504 | #endif |
| 505 | } |
| 506 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 507 | static int eqos_set_full_duplex(struct udevice *dev) |
| 508 | { |
| 509 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 510 | |
| 511 | debug("%s(dev=%p):\n", __func__, dev); |
| 512 | |
| 513 | setbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM); |
| 514 | |
| 515 | return 0; |
| 516 | } |
| 517 | |
| 518 | static int eqos_set_half_duplex(struct udevice *dev) |
| 519 | { |
| 520 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 521 | |
| 522 | debug("%s(dev=%p):\n", __func__, dev); |
| 523 | |
| 524 | clrbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM); |
| 525 | |
| 526 | /* WAR: Flush TX queue when switching to half-duplex */ |
| 527 | setbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 528 | EQOS_MTL_TXQ0_OPERATION_MODE_FTQ); |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | static int eqos_set_gmii_speed(struct udevice *dev) |
| 534 | { |
| 535 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 536 | |
| 537 | debug("%s(dev=%p):\n", __func__, dev); |
| 538 | |
| 539 | clrbits_le32(&eqos->mac_regs->configuration, |
| 540 | EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES); |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
| 545 | static int eqos_set_mii_speed_100(struct udevice *dev) |
| 546 | { |
| 547 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 548 | |
| 549 | debug("%s(dev=%p):\n", __func__, dev); |
| 550 | |
| 551 | setbits_le32(&eqos->mac_regs->configuration, |
| 552 | EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES); |
| 553 | |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | static int eqos_set_mii_speed_10(struct udevice *dev) |
| 558 | { |
| 559 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 560 | |
| 561 | debug("%s(dev=%p):\n", __func__, dev); |
| 562 | |
| 563 | clrsetbits_le32(&eqos->mac_regs->configuration, |
| 564 | EQOS_MAC_CONFIGURATION_FES, EQOS_MAC_CONFIGURATION_PS); |
| 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
| 569 | static int eqos_set_tx_clk_speed_tegra186(struct udevice *dev) |
| 570 | { |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 571 | #ifdef CONFIG_CLK |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 572 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 573 | ulong rate; |
| 574 | int ret; |
| 575 | |
| 576 | debug("%s(dev=%p):\n", __func__, dev); |
| 577 | |
| 578 | switch (eqos->phy->speed) { |
| 579 | case SPEED_1000: |
| 580 | rate = 125 * 1000 * 1000; |
| 581 | break; |
| 582 | case SPEED_100: |
| 583 | rate = 25 * 1000 * 1000; |
| 584 | break; |
| 585 | case SPEED_10: |
| 586 | rate = 2.5 * 1000 * 1000; |
| 587 | break; |
| 588 | default: |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 589 | pr_err("invalid speed %d", eqos->phy->speed); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 590 | return -EINVAL; |
| 591 | } |
| 592 | |
| 593 | ret = clk_set_rate(&eqos->clk_tx, rate); |
| 594 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 595 | pr_err("clk_set_rate(tx_clk, %lu) failed: %d", rate, ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 596 | return ret; |
| 597 | } |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 598 | #endif |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 599 | |
| 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | static int eqos_adjust_link(struct udevice *dev) |
| 604 | { |
| 605 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 606 | int ret; |
| 607 | bool en_calibration; |
| 608 | |
| 609 | debug("%s(dev=%p):\n", __func__, dev); |
| 610 | |
| 611 | if (eqos->phy->duplex) |
| 612 | ret = eqos_set_full_duplex(dev); |
| 613 | else |
| 614 | ret = eqos_set_half_duplex(dev); |
| 615 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 616 | pr_err("eqos_set_*_duplex() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 617 | return ret; |
| 618 | } |
| 619 | |
| 620 | switch (eqos->phy->speed) { |
| 621 | case SPEED_1000: |
| 622 | en_calibration = true; |
| 623 | ret = eqos_set_gmii_speed(dev); |
| 624 | break; |
| 625 | case SPEED_100: |
| 626 | en_calibration = true; |
| 627 | ret = eqos_set_mii_speed_100(dev); |
| 628 | break; |
| 629 | case SPEED_10: |
| 630 | en_calibration = false; |
| 631 | ret = eqos_set_mii_speed_10(dev); |
| 632 | break; |
| 633 | default: |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 634 | pr_err("invalid speed %d", eqos->phy->speed); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 635 | return -EINVAL; |
| 636 | } |
| 637 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 638 | pr_err("eqos_set_*mii_speed*() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 639 | return ret; |
| 640 | } |
| 641 | |
| 642 | if (en_calibration) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 643 | ret = eqos->config->ops->eqos_calibrate_pads(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 644 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 645 | pr_err("eqos_calibrate_pads() failed: %d", |
| 646 | ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 647 | return ret; |
| 648 | } |
| 649 | } else { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 650 | ret = eqos->config->ops->eqos_disable_calibration(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 651 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 652 | pr_err("eqos_disable_calibration() failed: %d", |
| 653 | ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 654 | return ret; |
| 655 | } |
| 656 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 657 | ret = eqos->config->ops->eqos_set_tx_clk_speed(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 658 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 659 | pr_err("eqos_set_tx_clk_speed() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 660 | return ret; |
| 661 | } |
| 662 | |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | static int eqos_write_hwaddr(struct udevice *dev) |
| 667 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 668 | struct eth_pdata *plat = dev_get_plat(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 669 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 670 | uint32_t val; |
| 671 | |
| 672 | /* |
| 673 | * This function may be called before start() or after stop(). At that |
| 674 | * time, on at least some configurations of the EQoS HW, all clocks to |
| 675 | * the EQoS HW block will be stopped, and a reset signal applied. If |
| 676 | * any register access is attempted in this state, bus timeouts or CPU |
| 677 | * hangs may occur. This check prevents that. |
| 678 | * |
| 679 | * A simple solution to this problem would be to not implement |
| 680 | * write_hwaddr(), since start() always writes the MAC address into HW |
| 681 | * anyway. However, it is desirable to implement write_hwaddr() to |
| 682 | * support the case of SW that runs subsequent to U-Boot which expects |
| 683 | * the MAC address to already be programmed into the EQoS registers, |
| 684 | * which must happen irrespective of whether the U-Boot user (or |
| 685 | * scripts) actually made use of the EQoS device, and hence |
| 686 | * irrespective of whether start() was ever called. |
| 687 | * |
| 688 | * Note that this requirement by subsequent SW is not valid for |
| 689 | * Tegra186, and is likely not valid for any non-PCI instantiation of |
| 690 | * the EQoS HW block. This function is implemented solely as |
| 691 | * future-proofing with the expectation the driver will eventually be |
| 692 | * ported to some system where the expectation above is true. |
| 693 | */ |
| 694 | if (!eqos->config->reg_access_always_ok && !eqos->reg_access_ok) |
| 695 | return 0; |
| 696 | |
| 697 | /* Update the MAC address */ |
| 698 | val = (plat->enetaddr[5] << 8) | |
| 699 | (plat->enetaddr[4]); |
| 700 | writel(val, &eqos->mac_regs->address0_high); |
| 701 | val = (plat->enetaddr[3] << 24) | |
| 702 | (plat->enetaddr[2] << 16) | |
| 703 | (plat->enetaddr[1] << 8) | |
| 704 | (plat->enetaddr[0]); |
| 705 | writel(val, &eqos->mac_regs->address0_low); |
| 706 | |
| 707 | return 0; |
| 708 | } |
| 709 | |
Ye Li | 580fab4 | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 710 | static int eqos_read_rom_hwaddr(struct udevice *dev) |
| 711 | { |
Simon Glass | c69cda2 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 712 | struct eth_pdata *pdata = dev_get_plat(dev); |
Peng Fan | a624251 | 2022-07-26 16:41:17 +0800 | [diff] [blame] | 713 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 714 | int ret; |
Ye Li | 580fab4 | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 715 | |
Peng Fan | a624251 | 2022-07-26 16:41:17 +0800 | [diff] [blame] | 716 | ret = eqos->config->ops->eqos_get_enetaddr(dev); |
| 717 | if (ret < 0) |
| 718 | return ret; |
| 719 | |
Ye Li | 580fab4 | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 720 | return !is_valid_ethaddr(pdata->enetaddr); |
| 721 | } |
| 722 | |
Ye Li | a6acf95 | 2022-07-26 16:41:16 +0800 | [diff] [blame] | 723 | static int eqos_get_phy_addr(struct eqos_priv *priv, struct udevice *dev) |
| 724 | { |
| 725 | struct ofnode_phandle_args phandle_args; |
| 726 | int reg; |
| 727 | |
| 728 | if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, |
| 729 | &phandle_args)) { |
| 730 | debug("Failed to find phy-handle"); |
| 731 | return -ENODEV; |
| 732 | } |
| 733 | |
| 734 | priv->phy_of_node = phandle_args.node; |
| 735 | |
| 736 | reg = ofnode_read_u32_default(phandle_args.node, "reg", 0); |
| 737 | |
| 738 | return reg; |
| 739 | } |
| 740 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 741 | static int eqos_start(struct udevice *dev) |
| 742 | { |
| 743 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 744 | int ret, i; |
| 745 | ulong rate; |
| 746 | u32 val, tx_fifo_sz, rx_fifo_sz, tqs, rqs, pbl; |
| 747 | ulong last_rx_desc; |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 748 | ulong desc_pad; |
Ley Foon Tan | 5d260d0 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 749 | ulong addr64; |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 750 | |
| 751 | debug("%s(dev=%p):\n", __func__, dev); |
| 752 | |
| 753 | eqos->tx_desc_idx = 0; |
| 754 | eqos->rx_desc_idx = 0; |
| 755 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 756 | ret = eqos->config->ops->eqos_start_resets(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 757 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 758 | pr_err("eqos_start_resets() failed: %d", ret); |
Marek Vasut | 3fbd17a | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 759 | goto err; |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | udelay(10); |
| 763 | |
| 764 | eqos->reg_access_ok = true; |
| 765 | |
Marek Vasut | a79de08 | 2023-03-06 15:53:46 +0100 | [diff] [blame] | 766 | /* |
| 767 | * Assert the SWR first, the actually reset the MAC and to latch in |
| 768 | * e.g. i.MX8M Plus GPR[1] content, which selects interface mode. |
| 769 | */ |
| 770 | setbits_le32(&eqos->dma_regs->mode, EQOS_DMA_MODE_SWR); |
| 771 | |
Ălvaro FernĂĄndez Rojas | 4826350 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 772 | ret = wait_for_bit_le32(&eqos->dma_regs->mode, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 773 | EQOS_DMA_MODE_SWR, false, |
| 774 | eqos->config->swr_wait, false); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 775 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 776 | pr_err("EQOS_DMA_MODE_SWR stuck"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 777 | goto err_stop_resets; |
| 778 | } |
| 779 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 780 | ret = eqos->config->ops->eqos_calibrate_pads(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 781 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 782 | pr_err("eqos_calibrate_pads() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 783 | goto err_stop_resets; |
| 784 | } |
| 785 | |
Sumit Garg | 9d53f33 | 2023-02-01 19:28:53 +0530 | [diff] [blame] | 786 | if (eqos->config->ops->eqos_get_tick_clk_rate) { |
| 787 | rate = eqos->config->ops->eqos_get_tick_clk_rate(dev); |
| 788 | |
| 789 | val = (rate / 1000000) - 1; |
| 790 | writel(val, &eqos->mac_regs->us_tic_counter); |
| 791 | } |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 792 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 793 | /* |
| 794 | * if PHY was already connected and configured, |
| 795 | * don't need to reconnect/reconfigure again |
| 796 | */ |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 797 | if (!eqos->phy) { |
Ye Li | 6a895d0 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 798 | int addr = -1; |
Elmar Psilog | 96d58ec | 2023-02-20 16:03:15 +0100 | [diff] [blame] | 799 | ofnode fixed_node; |
| 800 | |
| 801 | if (IS_ENABLED(CONFIG_PHY_FIXED)) { |
| 802 | fixed_node = ofnode_find_subnode(dev_ofnode(dev), |
| 803 | "fixed-link"); |
| 804 | if (ofnode_valid(fixed_node)) |
| 805 | eqos->phy = fixed_phy_create(dev_ofnode(dev)); |
| 806 | } |
| 807 | |
| 808 | if (!eqos->phy) { |
| 809 | addr = eqos_get_phy_addr(eqos, dev); |
| 810 | eqos->phy = phy_connect(eqos->mii, addr, dev, |
| 811 | eqos->config->interface(dev)); |
| 812 | } |
| 813 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 814 | if (!eqos->phy) { |
| 815 | pr_err("phy_connect() failed"); |
Jonas Karlman | ded6014 | 2023-10-01 19:17:17 +0000 | [diff] [blame] | 816 | ret = -ENODEV; |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 817 | goto err_stop_resets; |
| 818 | } |
Patrick Delaunay | 4f60a51 | 2020-03-18 10:50:16 +0100 | [diff] [blame] | 819 | |
| 820 | if (eqos->max_speed) { |
| 821 | ret = phy_set_supported(eqos->phy, eqos->max_speed); |
| 822 | if (ret) { |
| 823 | pr_err("phy_set_supported() failed: %d", ret); |
| 824 | goto err_shutdown_phy; |
| 825 | } |
| 826 | } |
| 827 | |
Ye Li | a6acf95 | 2022-07-26 16:41:16 +0800 | [diff] [blame] | 828 | eqos->phy->node = eqos->phy_of_node; |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 829 | ret = phy_config(eqos->phy); |
| 830 | if (ret < 0) { |
| 831 | pr_err("phy_config() failed: %d", ret); |
| 832 | goto err_shutdown_phy; |
| 833 | } |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 834 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 835 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 836 | ret = phy_startup(eqos->phy); |
| 837 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 838 | pr_err("phy_startup() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 839 | goto err_shutdown_phy; |
| 840 | } |
| 841 | |
| 842 | if (!eqos->phy->link) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 843 | pr_err("No link"); |
Jonas Karlman | ded6014 | 2023-10-01 19:17:17 +0000 | [diff] [blame] | 844 | ret = -EAGAIN; |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 845 | goto err_shutdown_phy; |
| 846 | } |
| 847 | |
| 848 | ret = eqos_adjust_link(dev); |
| 849 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 850 | pr_err("eqos_adjust_link() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 851 | goto err_shutdown_phy; |
| 852 | } |
| 853 | |
| 854 | /* Configure MTL */ |
| 855 | |
| 856 | /* Enable Store and Forward mode for TX */ |
| 857 | /* Program Tx operating mode */ |
| 858 | setbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 859 | EQOS_MTL_TXQ0_OPERATION_MODE_TSF | |
| 860 | (EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_ENABLED << |
| 861 | EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT)); |
| 862 | |
| 863 | /* Transmit Queue weight */ |
| 864 | writel(0x10, &eqos->mtl_regs->txq0_quantum_weight); |
| 865 | |
| 866 | /* Enable Store and Forward mode for RX, since no jumbo frame */ |
| 867 | setbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
Daniil Stas | f024e0b | 2021-05-30 13:34:09 +0000 | [diff] [blame] | 868 | EQOS_MTL_RXQ0_OPERATION_MODE_RSF); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 869 | |
| 870 | /* Transmit/Receive queue fifo size; use all RAM for 1 queue */ |
| 871 | val = readl(&eqos->mac_regs->hw_feature1); |
| 872 | tx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_SHIFT) & |
| 873 | EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_MASK; |
| 874 | rx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_SHIFT) & |
| 875 | EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_MASK; |
| 876 | |
Sumit Garg | a962b7c | 2023-02-01 19:28:54 +0530 | [diff] [blame] | 877 | /* r/tx_fifo_sz is encoded as log2(n / 128). Undo that by shifting */ |
| 878 | tx_fifo_sz = 128 << tx_fifo_sz; |
| 879 | rx_fifo_sz = 128 << rx_fifo_sz; |
| 880 | |
| 881 | /* Allow platform to override TX/RX fifo size */ |
| 882 | if (eqos->tx_fifo_sz) |
| 883 | tx_fifo_sz = eqos->tx_fifo_sz; |
| 884 | if (eqos->rx_fifo_sz) |
| 885 | rx_fifo_sz = eqos->rx_fifo_sz; |
| 886 | |
| 887 | /* r/tqs is encoded as (n / 256) - 1 */ |
| 888 | tqs = tx_fifo_sz / 256 - 1; |
| 889 | rqs = rx_fifo_sz / 256 - 1; |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 890 | |
| 891 | clrsetbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 892 | EQOS_MTL_TXQ0_OPERATION_MODE_TQS_MASK << |
| 893 | EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT, |
| 894 | tqs << EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT); |
| 895 | clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 896 | EQOS_MTL_RXQ0_OPERATION_MODE_RQS_MASK << |
| 897 | EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT, |
| 898 | rqs << EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT); |
| 899 | |
| 900 | /* Flow control used only if each channel gets 4KB or more FIFO */ |
| 901 | if (rqs >= ((4096 / 256) - 1)) { |
| 902 | u32 rfd, rfa; |
| 903 | |
| 904 | setbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 905 | EQOS_MTL_RXQ0_OPERATION_MODE_EHFC); |
| 906 | |
| 907 | /* |
| 908 | * Set Threshold for Activating Flow Contol space for min 2 |
| 909 | * frames ie, (1500 * 1) = 1500 bytes. |
| 910 | * |
| 911 | * Set Threshold for Deactivating Flow Contol for space of |
| 912 | * min 1 frame (frame size 1500bytes) in receive fifo |
| 913 | */ |
| 914 | if (rqs == ((4096 / 256) - 1)) { |
| 915 | /* |
| 916 | * This violates the above formula because of FIFO size |
| 917 | * limit therefore overflow may occur inspite of this. |
| 918 | */ |
| 919 | rfd = 0x3; /* Full-3K */ |
| 920 | rfa = 0x1; /* Full-1.5K */ |
| 921 | } else if (rqs == ((8192 / 256) - 1)) { |
| 922 | rfd = 0x6; /* Full-4K */ |
| 923 | rfa = 0xa; /* Full-6K */ |
| 924 | } else if (rqs == ((16384 / 256) - 1)) { |
| 925 | rfd = 0x6; /* Full-4K */ |
| 926 | rfa = 0x12; /* Full-10K */ |
| 927 | } else { |
| 928 | rfd = 0x6; /* Full-4K */ |
| 929 | rfa = 0x1E; /* Full-16K */ |
| 930 | } |
| 931 | |
| 932 | clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 933 | (EQOS_MTL_RXQ0_OPERATION_MODE_RFD_MASK << |
| 934 | EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) | |
| 935 | (EQOS_MTL_RXQ0_OPERATION_MODE_RFA_MASK << |
| 936 | EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT), |
| 937 | (rfd << |
| 938 | EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) | |
| 939 | (rfa << |
| 940 | EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT)); |
| 941 | } |
| 942 | |
| 943 | /* Configure MAC */ |
| 944 | |
| 945 | clrsetbits_le32(&eqos->mac_regs->rxq_ctrl0, |
| 946 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_MASK << |
| 947 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 948 | eqos->config->config_mac << |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 949 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT); |
| 950 | |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 951 | /* Multicast and Broadcast Queue Enable */ |
| 952 | setbits_le32(&eqos->mac_regs->unused_0a4, |
| 953 | 0x00100000); |
| 954 | /* enable promise mode */ |
| 955 | setbits_le32(&eqos->mac_regs->unused_004[1], |
| 956 | 0x1); |
| 957 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 958 | /* Set TX flow control parameters */ |
| 959 | /* Set Pause Time */ |
| 960 | setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl, |
| 961 | 0xffff << EQOS_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT); |
| 962 | /* Assign priority for TX flow control */ |
| 963 | clrbits_le32(&eqos->mac_regs->txq_prty_map0, |
| 964 | EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_MASK << |
| 965 | EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_SHIFT); |
| 966 | /* Assign priority for RX flow control */ |
| 967 | clrbits_le32(&eqos->mac_regs->rxq_ctrl2, |
| 968 | EQOS_MAC_RXQ_CTRL2_PSRQ0_MASK << |
| 969 | EQOS_MAC_RXQ_CTRL2_PSRQ0_SHIFT); |
| 970 | /* Enable flow control */ |
| 971 | setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl, |
| 972 | EQOS_MAC_Q0_TX_FLOW_CTRL_TFE); |
| 973 | setbits_le32(&eqos->mac_regs->rx_flow_ctrl, |
| 974 | EQOS_MAC_RX_FLOW_CTRL_RFE); |
| 975 | |
| 976 | clrsetbits_le32(&eqos->mac_regs->configuration, |
| 977 | EQOS_MAC_CONFIGURATION_GPSLCE | |
| 978 | EQOS_MAC_CONFIGURATION_WD | |
| 979 | EQOS_MAC_CONFIGURATION_JD | |
| 980 | EQOS_MAC_CONFIGURATION_JE, |
| 981 | EQOS_MAC_CONFIGURATION_CST | |
| 982 | EQOS_MAC_CONFIGURATION_ACS); |
| 983 | |
| 984 | eqos_write_hwaddr(dev); |
| 985 | |
| 986 | /* Configure DMA */ |
| 987 | |
| 988 | /* Enable OSP mode */ |
| 989 | setbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 990 | EQOS_DMA_CH0_TX_CONTROL_OSP); |
| 991 | |
| 992 | /* RX buffer size. Must be a multiple of bus width */ |
| 993 | clrsetbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 994 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_MASK << |
| 995 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT, |
| 996 | EQOS_MAX_PACKET_SIZE << |
| 997 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT); |
| 998 | |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 999 | desc_pad = (eqos->desc_size - sizeof(struct eqos_desc)) / |
| 1000 | eqos->config->axi_bus_width; |
| 1001 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1002 | setbits_le32(&eqos->dma_regs->ch0_control, |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1003 | EQOS_DMA_CH0_CONTROL_PBLX8 | |
| 1004 | (desc_pad << EQOS_DMA_CH0_CONTROL_DSL_SHIFT)); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1005 | |
| 1006 | /* |
| 1007 | * Burst length must be < 1/2 FIFO size. |
| 1008 | * FIFO size in tqs is encoded as (n / 256) - 1. |
| 1009 | * Each burst is n * 8 (PBLX8) * 16 (AXI width) == 128 bytes. |
| 1010 | * Half of n * 256 is n * 128, so pbl == tqs, modulo the -1. |
| 1011 | */ |
| 1012 | pbl = tqs + 1; |
| 1013 | if (pbl > 32) |
| 1014 | pbl = 32; |
| 1015 | clrsetbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1016 | EQOS_DMA_CH0_TX_CONTROL_TXPBL_MASK << |
| 1017 | EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT, |
| 1018 | pbl << EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT); |
| 1019 | |
| 1020 | clrsetbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1021 | EQOS_DMA_CH0_RX_CONTROL_RXPBL_MASK << |
| 1022 | EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT, |
| 1023 | 8 << EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT); |
| 1024 | |
| 1025 | /* DMA performance configuration */ |
| 1026 | val = (2 << EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT) | |
| 1027 | EQOS_DMA_SYSBUS_MODE_EAME | EQOS_DMA_SYSBUS_MODE_BLEN16 | |
| 1028 | EQOS_DMA_SYSBUS_MODE_BLEN8 | EQOS_DMA_SYSBUS_MODE_BLEN4; |
| 1029 | writel(val, &eqos->dma_regs->sysbus_mode); |
| 1030 | |
| 1031 | /* Set up descriptors */ |
| 1032 | |
Marek Vasut | f94d008 | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 1033 | memset(eqos->tx_descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_TX); |
| 1034 | memset(eqos->rx_descs, 0, eqos->desc_size * EQOS_DESCRIPTORS_RX); |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1035 | |
| 1036 | for (i = 0; i < EQOS_DESCRIPTORS_TX; i++) { |
| 1037 | struct eqos_desc *tx_desc = eqos_get_desc(eqos, i, false); |
| 1038 | eqos->config->ops->eqos_flush_desc(tx_desc); |
| 1039 | } |
| 1040 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1041 | for (i = 0; i < EQOS_DESCRIPTORS_RX; i++) { |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1042 | struct eqos_desc *rx_desc = eqos_get_desc(eqos, i, true); |
Ley Foon Tan | 5d260d0 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1043 | |
| 1044 | addr64 = (ulong)(eqos->rx_dma_buf + (i * EQOS_MAX_PACKET_SIZE)); |
| 1045 | rx_desc->des0 = lower_32_bits(addr64); |
| 1046 | rx_desc->des1 = upper_32_bits(addr64); |
Marek Vasut | 4332d80 | 2020-03-23 02:02:57 +0100 | [diff] [blame] | 1047 | rx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_BUF1V; |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1048 | mb(); |
Marek Vasut | dd90c2e | 2020-03-23 02:09:01 +0100 | [diff] [blame] | 1049 | eqos->config->ops->eqos_flush_desc(rx_desc); |
Ley Foon Tan | 5d260d0 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1050 | eqos->config->ops->eqos_inval_buffer((void *)addr64, EQOS_MAX_PACKET_SIZE); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1051 | } |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1052 | |
Ley Foon Tan | 5d260d0 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1053 | addr64 = (ulong)eqos_get_desc(eqos, 0, false); |
| 1054 | writel(upper_32_bits(addr64), &eqos->dma_regs->ch0_txdesc_list_haddress); |
| 1055 | writel(lower_32_bits(addr64), &eqos->dma_regs->ch0_txdesc_list_address); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1056 | writel(EQOS_DESCRIPTORS_TX - 1, |
| 1057 | &eqos->dma_regs->ch0_txdesc_ring_length); |
| 1058 | |
Ley Foon Tan | 5d260d0 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1059 | addr64 = (ulong)eqos_get_desc(eqos, 0, true); |
| 1060 | writel(upper_32_bits(addr64), &eqos->dma_regs->ch0_rxdesc_list_haddress); |
| 1061 | writel(lower_32_bits(addr64), &eqos->dma_regs->ch0_rxdesc_list_address); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1062 | writel(EQOS_DESCRIPTORS_RX - 1, |
| 1063 | &eqos->dma_regs->ch0_rxdesc_ring_length); |
| 1064 | |
| 1065 | /* Enable everything */ |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1066 | setbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1067 | EQOS_DMA_CH0_TX_CONTROL_ST); |
| 1068 | setbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1069 | EQOS_DMA_CH0_RX_CONTROL_SR); |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1070 | setbits_le32(&eqos->mac_regs->configuration, |
| 1071 | EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1072 | |
| 1073 | /* TX tail pointer not written until we need to TX a packet */ |
| 1074 | /* |
| 1075 | * Point RX tail pointer at last descriptor. Ideally, we'd point at the |
| 1076 | * first descriptor, implying all descriptors were available. However, |
| 1077 | * that's not distinguishable from none of the descriptors being |
| 1078 | * available. |
| 1079 | */ |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1080 | last_rx_desc = (ulong)eqos_get_desc(eqos, EQOS_DESCRIPTORS_RX - 1, true); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1081 | writel(last_rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer); |
| 1082 | |
| 1083 | eqos->started = true; |
| 1084 | |
| 1085 | debug("%s: OK\n", __func__); |
| 1086 | return 0; |
| 1087 | |
| 1088 | err_shutdown_phy: |
| 1089 | phy_shutdown(eqos->phy); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1090 | err_stop_resets: |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1091 | eqos->config->ops->eqos_stop_resets(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1092 | err: |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1093 | pr_err("FAILED: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1094 | return ret; |
| 1095 | } |
| 1096 | |
Patrick Delaunay | 50d86e5 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1097 | static void eqos_stop(struct udevice *dev) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1098 | { |
| 1099 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1100 | int i; |
| 1101 | |
| 1102 | debug("%s(dev=%p):\n", __func__, dev); |
| 1103 | |
| 1104 | if (!eqos->started) |
| 1105 | return; |
| 1106 | eqos->started = false; |
| 1107 | eqos->reg_access_ok = false; |
| 1108 | |
| 1109 | /* Disable TX DMA */ |
| 1110 | clrbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1111 | EQOS_DMA_CH0_TX_CONTROL_ST); |
| 1112 | |
| 1113 | /* Wait for TX all packets to drain out of MTL */ |
| 1114 | for (i = 0; i < 1000000; i++) { |
| 1115 | u32 val = readl(&eqos->mtl_regs->txq0_debug); |
| 1116 | u32 trcsts = (val >> EQOS_MTL_TXQ0_DEBUG_TRCSTS_SHIFT) & |
| 1117 | EQOS_MTL_TXQ0_DEBUG_TRCSTS_MASK; |
| 1118 | u32 txqsts = val & EQOS_MTL_TXQ0_DEBUG_TXQSTS; |
| 1119 | if ((trcsts != 1) && (!txqsts)) |
| 1120 | break; |
| 1121 | } |
| 1122 | |
| 1123 | /* Turn off MAC TX and RX */ |
| 1124 | clrbits_le32(&eqos->mac_regs->configuration, |
| 1125 | EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE); |
| 1126 | |
| 1127 | /* Wait for all RX packets to drain out of MTL */ |
| 1128 | for (i = 0; i < 1000000; i++) { |
| 1129 | u32 val = readl(&eqos->mtl_regs->rxq0_debug); |
| 1130 | u32 prxq = (val >> EQOS_MTL_RXQ0_DEBUG_PRXQ_SHIFT) & |
| 1131 | EQOS_MTL_RXQ0_DEBUG_PRXQ_MASK; |
| 1132 | u32 rxqsts = (val >> EQOS_MTL_RXQ0_DEBUG_RXQSTS_SHIFT) & |
| 1133 | EQOS_MTL_RXQ0_DEBUG_RXQSTS_MASK; |
| 1134 | if ((!prxq) && (!rxqsts)) |
| 1135 | break; |
| 1136 | } |
| 1137 | |
| 1138 | /* Turn off RX DMA */ |
| 1139 | clrbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1140 | EQOS_DMA_CH0_RX_CONTROL_SR); |
| 1141 | |
| 1142 | if (eqos->phy) { |
| 1143 | phy_shutdown(eqos->phy); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1144 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1145 | eqos->config->ops->eqos_stop_resets(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1146 | |
| 1147 | debug("%s: OK\n", __func__); |
| 1148 | } |
| 1149 | |
Patrick Delaunay | 50d86e5 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1150 | static int eqos_send(struct udevice *dev, void *packet, int length) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1151 | { |
| 1152 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1153 | struct eqos_desc *tx_desc; |
| 1154 | int i; |
| 1155 | |
| 1156 | debug("%s(dev=%p, packet=%p, length=%d):\n", __func__, dev, packet, |
| 1157 | length); |
| 1158 | |
| 1159 | memcpy(eqos->tx_dma_buf, packet, length); |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1160 | eqos->config->ops->eqos_flush_buffer(eqos->tx_dma_buf, length); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1161 | |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1162 | tx_desc = eqos_get_desc(eqos, eqos->tx_desc_idx, false); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1163 | eqos->tx_desc_idx++; |
| 1164 | eqos->tx_desc_idx %= EQOS_DESCRIPTORS_TX; |
| 1165 | |
Ley Foon Tan | 5d260d0 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1166 | tx_desc->des0 = lower_32_bits((ulong)eqos->tx_dma_buf); |
| 1167 | tx_desc->des1 = upper_32_bits((ulong)eqos->tx_dma_buf); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1168 | tx_desc->des2 = length; |
| 1169 | /* |
| 1170 | * Make sure that if HW sees the _OWN write below, it will see all the |
| 1171 | * writes to the rest of the descriptor too. |
| 1172 | */ |
| 1173 | mb(); |
| 1174 | tx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_FD | EQOS_DESC3_LD | length; |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1175 | eqos->config->ops->eqos_flush_desc(tx_desc); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1176 | |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1177 | writel((ulong)eqos_get_desc(eqos, eqos->tx_desc_idx, false), |
Marek Vasut | 83858d8 | 2020-03-23 02:03:50 +0100 | [diff] [blame] | 1178 | &eqos->dma_regs->ch0_txdesc_tail_pointer); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1179 | |
| 1180 | for (i = 0; i < 1000000; i++) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1181 | eqos->config->ops->eqos_inval_desc(tx_desc); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1182 | if (!(readl(&tx_desc->des3) & EQOS_DESC3_OWN)) |
| 1183 | return 0; |
| 1184 | udelay(1); |
| 1185 | } |
| 1186 | |
| 1187 | debug("%s: TX timeout\n", __func__); |
| 1188 | |
| 1189 | return -ETIMEDOUT; |
| 1190 | } |
| 1191 | |
Patrick Delaunay | 50d86e5 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1192 | static int eqos_recv(struct udevice *dev, int flags, uchar **packetp) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1193 | { |
| 1194 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1195 | struct eqos_desc *rx_desc; |
| 1196 | int length; |
| 1197 | |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1198 | rx_desc = eqos_get_desc(eqos, eqos->rx_desc_idx, true); |
Marek Vasut | 738ee27 | 2020-03-23 02:09:21 +0100 | [diff] [blame] | 1199 | eqos->config->ops->eqos_inval_desc(rx_desc); |
Jonas Karlman | 95446f4 | 2023-10-01 19:17:18 +0000 | [diff] [blame] | 1200 | if (rx_desc->des3 & EQOS_DESC3_OWN) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1201 | return -EAGAIN; |
Jonas Karlman | 95446f4 | 2023-10-01 19:17:18 +0000 | [diff] [blame] | 1202 | |
| 1203 | debug("%s(dev=%p, flags=%x):\n", __func__, dev, flags); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1204 | |
| 1205 | *packetp = eqos->rx_dma_buf + |
| 1206 | (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE); |
| 1207 | length = rx_desc->des3 & 0x7fff; |
| 1208 | debug("%s: *packetp=%p, length=%d\n", __func__, *packetp, length); |
| 1209 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1210 | eqos->config->ops->eqos_inval_buffer(*packetp, length); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1211 | |
| 1212 | return length; |
| 1213 | } |
| 1214 | |
Patrick Delaunay | 50d86e5 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1215 | static int eqos_free_pkt(struct udevice *dev, uchar *packet, int length) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1216 | { |
| 1217 | struct eqos_priv *eqos = dev_get_priv(dev); |
Marek Vasut | e9d3fc7 | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1218 | u32 idx, idx_mask = eqos->desc_per_cacheline - 1; |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1219 | uchar *packet_expected; |
| 1220 | struct eqos_desc *rx_desc; |
| 1221 | |
| 1222 | debug("%s(packet=%p, length=%d)\n", __func__, packet, length); |
| 1223 | |
| 1224 | packet_expected = eqos->rx_dma_buf + |
| 1225 | (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE); |
| 1226 | if (packet != packet_expected) { |
| 1227 | debug("%s: Unexpected packet (expected %p)\n", __func__, |
| 1228 | packet_expected); |
| 1229 | return -EINVAL; |
| 1230 | } |
| 1231 | |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1232 | eqos->config->ops->eqos_inval_buffer(packet, length); |
| 1233 | |
Marek Vasut | e9d3fc7 | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1234 | if ((eqos->rx_desc_idx & idx_mask) == idx_mask) { |
| 1235 | for (idx = eqos->rx_desc_idx - idx_mask; |
| 1236 | idx <= eqos->rx_desc_idx; |
| 1237 | idx++) { |
Ley Foon Tan | 5d260d0 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1238 | ulong addr64; |
| 1239 | |
Marek Vasut | e9d3fc7 | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1240 | rx_desc = eqos_get_desc(eqos, idx, true); |
| 1241 | rx_desc->des0 = 0; |
Ley Foon Tan | 5d260d0 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1242 | rx_desc->des1 = 0; |
Marek Vasut | e9d3fc7 | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1243 | mb(); |
| 1244 | eqos->config->ops->eqos_flush_desc(rx_desc); |
| 1245 | eqos->config->ops->eqos_inval_buffer(packet, length); |
Ley Foon Tan | 5d260d0 | 2022-12-09 14:33:14 +0800 | [diff] [blame] | 1246 | addr64 = (ulong)(eqos->rx_dma_buf + (idx * EQOS_MAX_PACKET_SIZE)); |
| 1247 | rx_desc->des0 = lower_32_bits(addr64); |
| 1248 | rx_desc->des1 = upper_32_bits(addr64); |
Marek Vasut | e9d3fc7 | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1249 | rx_desc->des2 = 0; |
| 1250 | /* |
| 1251 | * Make sure that if HW sees the _OWN write below, |
| 1252 | * it will see all the writes to the rest of the |
| 1253 | * descriptor too. |
| 1254 | */ |
| 1255 | mb(); |
| 1256 | rx_desc->des3 = EQOS_DESC3_OWN | EQOS_DESC3_BUF1V; |
| 1257 | eqos->config->ops->eqos_flush_desc(rx_desc); |
| 1258 | } |
| 1259 | writel((ulong)rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer); |
| 1260 | } |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1261 | |
| 1262 | eqos->rx_desc_idx++; |
| 1263 | eqos->rx_desc_idx %= EQOS_DESCRIPTORS_RX; |
| 1264 | |
| 1265 | return 0; |
| 1266 | } |
| 1267 | |
| 1268 | static int eqos_probe_resources_core(struct udevice *dev) |
| 1269 | { |
| 1270 | struct eqos_priv *eqos = dev_get_priv(dev); |
Marek Vasut | e9d3fc7 | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1271 | unsigned int desc_step; |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1272 | int ret; |
| 1273 | |
| 1274 | debug("%s(dev=%p):\n", __func__, dev); |
| 1275 | |
Marek Vasut | e9d3fc7 | 2022-10-09 17:51:46 +0200 | [diff] [blame] | 1276 | /* Maximum distance between neighboring descriptors, in Bytes. */ |
| 1277 | desc_step = sizeof(struct eqos_desc) + |
| 1278 | EQOS_DMA_CH0_CONTROL_DSL_MASK * eqos->config->axi_bus_width; |
| 1279 | if (desc_step < ARCH_DMA_MINALIGN) { |
| 1280 | /* |
| 1281 | * The EQoS hardware implementation cannot place one descriptor |
| 1282 | * per cacheline, it is necessary to place multiple descriptors |
| 1283 | * per cacheline in memory and do cache management carefully. |
| 1284 | */ |
| 1285 | eqos->desc_size = BIT(fls(desc_step) - 1); |
| 1286 | } else { |
| 1287 | eqos->desc_size = ALIGN(sizeof(struct eqos_desc), |
| 1288 | (unsigned int)ARCH_DMA_MINALIGN); |
| 1289 | } |
| 1290 | eqos->desc_per_cacheline = ARCH_DMA_MINALIGN / eqos->desc_size; |
Marek Vasut | f94d008 | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 1291 | |
| 1292 | eqos->tx_descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_TX); |
| 1293 | if (!eqos->tx_descs) { |
| 1294 | debug("%s: eqos_alloc_descs(tx) failed\n", __func__); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1295 | ret = -ENOMEM; |
| 1296 | goto err; |
| 1297 | } |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1298 | |
Marek Vasut | f94d008 | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 1299 | eqos->rx_descs = eqos_alloc_descs(eqos, EQOS_DESCRIPTORS_RX); |
| 1300 | if (!eqos->rx_descs) { |
| 1301 | debug("%s: eqos_alloc_descs(rx) failed\n", __func__); |
| 1302 | ret = -ENOMEM; |
| 1303 | goto err_free_tx_descs; |
| 1304 | } |
| 1305 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1306 | eqos->tx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_MAX_PACKET_SIZE); |
| 1307 | if (!eqos->tx_dma_buf) { |
| 1308 | debug("%s: memalign(tx_dma_buf) failed\n", __func__); |
| 1309 | ret = -ENOMEM; |
| 1310 | goto err_free_descs; |
| 1311 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1312 | debug("%s: tx_dma_buf=%p\n", __func__, eqos->tx_dma_buf); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1313 | |
| 1314 | eqos->rx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_RX_BUFFER_SIZE); |
| 1315 | if (!eqos->rx_dma_buf) { |
| 1316 | debug("%s: memalign(rx_dma_buf) failed\n", __func__); |
| 1317 | ret = -ENOMEM; |
| 1318 | goto err_free_tx_dma_buf; |
| 1319 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1320 | debug("%s: rx_dma_buf=%p\n", __func__, eqos->rx_dma_buf); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1321 | |
Marek Vasut | a83ca0c | 2020-03-23 02:09:55 +0100 | [diff] [blame] | 1322 | eqos->config->ops->eqos_inval_buffer(eqos->rx_dma_buf, |
| 1323 | EQOS_MAX_PACKET_SIZE * EQOS_DESCRIPTORS_RX); |
| 1324 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1325 | debug("%s: OK\n", __func__); |
| 1326 | return 0; |
| 1327 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1328 | err_free_tx_dma_buf: |
| 1329 | free(eqos->tx_dma_buf); |
| 1330 | err_free_descs: |
Marek Vasut | f94d008 | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 1331 | eqos_free_descs(eqos->rx_descs); |
| 1332 | err_free_tx_descs: |
| 1333 | eqos_free_descs(eqos->tx_descs); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1334 | err: |
| 1335 | |
| 1336 | debug("%s: returns %d\n", __func__, ret); |
| 1337 | return ret; |
| 1338 | } |
| 1339 | |
| 1340 | static int eqos_remove_resources_core(struct udevice *dev) |
| 1341 | { |
| 1342 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1343 | |
| 1344 | debug("%s(dev=%p):\n", __func__, dev); |
| 1345 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1346 | free(eqos->rx_dma_buf); |
| 1347 | free(eqos->tx_dma_buf); |
Marek Vasut | f94d008 | 2022-10-09 17:51:45 +0200 | [diff] [blame] | 1348 | eqos_free_descs(eqos->rx_descs); |
| 1349 | eqos_free_descs(eqos->tx_descs); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1350 | |
| 1351 | debug("%s: OK\n", __func__); |
| 1352 | return 0; |
| 1353 | } |
| 1354 | |
| 1355 | static int eqos_probe_resources_tegra186(struct udevice *dev) |
| 1356 | { |
| 1357 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1358 | int ret; |
| 1359 | |
| 1360 | debug("%s(dev=%p):\n", __func__, dev); |
| 1361 | |
| 1362 | ret = reset_get_by_name(dev, "eqos", &eqos->reset_ctl); |
| 1363 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1364 | pr_err("reset_get_by_name(rst) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1365 | return ret; |
| 1366 | } |
| 1367 | |
| 1368 | ret = gpio_request_by_name(dev, "phy-reset-gpios", 0, |
| 1369 | &eqos->phy_reset_gpio, |
| 1370 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 1371 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1372 | pr_err("gpio_request_by_name(phy reset) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1373 | goto err_free_reset_eqos; |
| 1374 | } |
| 1375 | |
| 1376 | ret = clk_get_by_name(dev, "slave_bus", &eqos->clk_slave_bus); |
| 1377 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1378 | pr_err("clk_get_by_name(slave_bus) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1379 | goto err_free_gpio_phy_reset; |
| 1380 | } |
| 1381 | |
| 1382 | ret = clk_get_by_name(dev, "master_bus", &eqos->clk_master_bus); |
| 1383 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1384 | pr_err("clk_get_by_name(master_bus) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1385 | goto err_free_clk_slave_bus; |
| 1386 | } |
| 1387 | |
| 1388 | ret = clk_get_by_name(dev, "rx", &eqos->clk_rx); |
| 1389 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1390 | pr_err("clk_get_by_name(rx) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1391 | goto err_free_clk_master_bus; |
| 1392 | } |
| 1393 | |
| 1394 | ret = clk_get_by_name(dev, "ptp_ref", &eqos->clk_ptp_ref); |
| 1395 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1396 | pr_err("clk_get_by_name(ptp_ref) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1397 | goto err_free_clk_rx; |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | ret = clk_get_by_name(dev, "tx", &eqos->clk_tx); |
| 1401 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1402 | pr_err("clk_get_by_name(tx) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1403 | goto err_free_clk_ptp_ref; |
| 1404 | } |
| 1405 | |
| 1406 | debug("%s: OK\n", __func__); |
| 1407 | return 0; |
| 1408 | |
| 1409 | err_free_clk_ptp_ref: |
| 1410 | clk_free(&eqos->clk_ptp_ref); |
| 1411 | err_free_clk_rx: |
| 1412 | clk_free(&eqos->clk_rx); |
| 1413 | err_free_clk_master_bus: |
| 1414 | clk_free(&eqos->clk_master_bus); |
| 1415 | err_free_clk_slave_bus: |
| 1416 | clk_free(&eqos->clk_slave_bus); |
| 1417 | err_free_gpio_phy_reset: |
| 1418 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1419 | err_free_reset_eqos: |
| 1420 | reset_free(&eqos->reset_ctl); |
| 1421 | |
| 1422 | debug("%s: returns %d\n", __func__, ret); |
| 1423 | return ret; |
| 1424 | } |
| 1425 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1426 | static int eqos_probe_resources_stm32(struct udevice *dev) |
| 1427 | { |
| 1428 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1429 | int ret; |
| 1430 | phy_interface_t interface; |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1431 | |
| 1432 | debug("%s(dev=%p):\n", __func__, dev); |
| 1433 | |
| 1434 | interface = eqos->config->interface(dev); |
| 1435 | |
Marek BehĂșn | ffb0f6f | 2022-04-07 00:33:03 +0200 | [diff] [blame] | 1436 | if (interface == PHY_INTERFACE_MODE_NA) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1437 | pr_err("Invalid PHY interface\n"); |
| 1438 | return -EINVAL; |
| 1439 | } |
| 1440 | |
Patrick Delaunay | 53e3d52 | 2019-08-01 11:29:03 +0200 | [diff] [blame] | 1441 | ret = board_interface_eth_init(dev, interface); |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1442 | if (ret) |
| 1443 | return -EINVAL; |
| 1444 | |
| 1445 | ret = clk_get_by_name(dev, "stmmaceth", &eqos->clk_master_bus); |
| 1446 | if (ret) { |
| 1447 | pr_err("clk_get_by_name(master_bus) failed: %d", ret); |
| 1448 | goto err_probe; |
| 1449 | } |
| 1450 | |
| 1451 | ret = clk_get_by_name(dev, "mac-clk-rx", &eqos->clk_rx); |
| 1452 | if (ret) { |
| 1453 | pr_err("clk_get_by_name(rx) failed: %d", ret); |
| 1454 | goto err_free_clk_master_bus; |
| 1455 | } |
| 1456 | |
| 1457 | ret = clk_get_by_name(dev, "mac-clk-tx", &eqos->clk_tx); |
| 1458 | if (ret) { |
| 1459 | pr_err("clk_get_by_name(tx) failed: %d", ret); |
| 1460 | goto err_free_clk_rx; |
| 1461 | } |
| 1462 | |
| 1463 | /* Get ETH_CLK clocks (optional) */ |
| 1464 | ret = clk_get_by_name(dev, "eth-ck", &eqos->clk_ck); |
| 1465 | if (ret) |
| 1466 | pr_warn("No phy clock provided %d", ret); |
| 1467 | |
| 1468 | debug("%s: OK\n", __func__); |
| 1469 | return 0; |
| 1470 | |
| 1471 | err_free_clk_rx: |
| 1472 | clk_free(&eqos->clk_rx); |
| 1473 | err_free_clk_master_bus: |
| 1474 | clk_free(&eqos->clk_master_bus); |
| 1475 | err_probe: |
| 1476 | |
| 1477 | debug("%s: returns %d\n", __func__, ret); |
| 1478 | return ret; |
| 1479 | } |
| 1480 | |
Marek BehĂșn | 123ca11 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1481 | static phy_interface_t eqos_get_interface_tegra186(const struct udevice *dev) |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1482 | { |
| 1483 | return PHY_INTERFACE_MODE_MII; |
| 1484 | } |
| 1485 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1486 | static int eqos_remove_resources_tegra186(struct udevice *dev) |
| 1487 | { |
| 1488 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1489 | |
| 1490 | debug("%s(dev=%p):\n", __func__, dev); |
| 1491 | |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1492 | #ifdef CONFIG_CLK |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1493 | clk_free(&eqos->clk_tx); |
| 1494 | clk_free(&eqos->clk_ptp_ref); |
| 1495 | clk_free(&eqos->clk_rx); |
| 1496 | clk_free(&eqos->clk_slave_bus); |
| 1497 | clk_free(&eqos->clk_master_bus); |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1498 | #endif |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1499 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1500 | reset_free(&eqos->reset_ctl); |
| 1501 | |
| 1502 | debug("%s: OK\n", __func__); |
| 1503 | return 0; |
| 1504 | } |
| 1505 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1506 | static int eqos_remove_resources_stm32(struct udevice *dev) |
| 1507 | { |
Marek Vasut | 2e0bade | 2023-03-06 15:53:44 +0100 | [diff] [blame] | 1508 | struct eqos_priv * __maybe_unused eqos = dev_get_priv(dev); |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1509 | |
| 1510 | debug("%s(dev=%p):\n", __func__, dev); |
| 1511 | |
Peng Fan | 00fcfa8 | 2022-07-26 16:41:13 +0800 | [diff] [blame] | 1512 | #ifdef CONFIG_CLK |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1513 | clk_free(&eqos->clk_tx); |
| 1514 | clk_free(&eqos->clk_rx); |
| 1515 | clk_free(&eqos->clk_master_bus); |
| 1516 | if (clk_valid(&eqos->clk_ck)) |
| 1517 | clk_free(&eqos->clk_ck); |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1518 | #endif |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1519 | |
| 1520 | debug("%s: OK\n", __func__); |
| 1521 | return 0; |
| 1522 | } |
| 1523 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1524 | static int eqos_probe(struct udevice *dev) |
| 1525 | { |
| 1526 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1527 | int ret; |
| 1528 | |
| 1529 | debug("%s(dev=%p):\n", __func__, dev); |
| 1530 | |
| 1531 | eqos->dev = dev; |
| 1532 | eqos->config = (void *)dev_get_driver_data(dev); |
| 1533 | |
Masahiro Yamada | 2548493 | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 1534 | eqos->regs = dev_read_addr(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1535 | if (eqos->regs == FDT_ADDR_T_NONE) { |
Masahiro Yamada | 2548493 | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 1536 | pr_err("dev_read_addr() failed"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1537 | return -ENODEV; |
| 1538 | } |
| 1539 | eqos->mac_regs = (void *)(eqos->regs + EQOS_MAC_REGS_BASE); |
| 1540 | eqos->mtl_regs = (void *)(eqos->regs + EQOS_MTL_REGS_BASE); |
| 1541 | eqos->dma_regs = (void *)(eqos->regs + EQOS_DMA_REGS_BASE); |
| 1542 | eqos->tegra186_regs = (void *)(eqos->regs + EQOS_TEGRA186_REGS_BASE); |
| 1543 | |
Rasmus Villemoes | 0c999ce | 2022-05-11 16:58:41 +0200 | [diff] [blame] | 1544 | eqos->max_speed = dev_read_u32_default(dev, "max-speed", 0); |
| 1545 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1546 | ret = eqos_probe_resources_core(dev); |
| 1547 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1548 | pr_err("eqos_probe_resources_core() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1549 | return ret; |
| 1550 | } |
| 1551 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1552 | ret = eqos->config->ops->eqos_probe_resources(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1553 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1554 | pr_err("eqos_probe_resources() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1555 | goto err_remove_resources_core; |
| 1556 | } |
| 1557 | |
Marek Vasut | 3fbd17a | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1558 | ret = eqos->config->ops->eqos_start_clks(dev); |
| 1559 | if (ret < 0) { |
| 1560 | pr_err("eqos_start_clks() failed: %d", ret); |
| 1561 | goto err_remove_resources_tegra; |
| 1562 | } |
| 1563 | |
Ye Li | 6a895d0 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1564 | #ifdef CONFIG_DM_ETH_PHY |
| 1565 | eqos->mii = eth_phy_get_mdio_bus(dev); |
| 1566 | #endif |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1567 | if (!eqos->mii) { |
Ye Li | 6a895d0 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1568 | eqos->mii = mdio_alloc(); |
| 1569 | if (!eqos->mii) { |
| 1570 | pr_err("mdio_alloc() failed"); |
| 1571 | ret = -ENOMEM; |
Marek Vasut | 3fbd17a | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1572 | goto err_stop_clks; |
Ye Li | 6a895d0 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1573 | } |
| 1574 | eqos->mii->read = eqos_mdio_read; |
| 1575 | eqos->mii->write = eqos_mdio_write; |
| 1576 | eqos->mii->priv = eqos; |
| 1577 | strcpy(eqos->mii->name, dev->name); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1578 | |
Ye Li | 6a895d0 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1579 | ret = mdio_register(eqos->mii); |
| 1580 | if (ret < 0) { |
| 1581 | pr_err("mdio_register() failed: %d", ret); |
| 1582 | goto err_free_mdio; |
| 1583 | } |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1584 | } |
| 1585 | |
Ye Li | 6a895d0 | 2020-05-03 22:41:15 +0800 | [diff] [blame] | 1586 | #ifdef CONFIG_DM_ETH_PHY |
| 1587 | eth_phy_set_mdio_bus(dev, eqos->mii); |
| 1588 | #endif |
| 1589 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1590 | debug("%s: OK\n", __func__); |
| 1591 | return 0; |
| 1592 | |
| 1593 | err_free_mdio: |
| 1594 | mdio_free(eqos->mii); |
Marek Vasut | 3fbd17a | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1595 | err_stop_clks: |
| 1596 | eqos->config->ops->eqos_stop_clks(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1597 | err_remove_resources_tegra: |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1598 | eqos->config->ops->eqos_remove_resources(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1599 | err_remove_resources_core: |
| 1600 | eqos_remove_resources_core(dev); |
| 1601 | |
| 1602 | debug("%s: returns %d\n", __func__, ret); |
| 1603 | return ret; |
| 1604 | } |
| 1605 | |
| 1606 | static int eqos_remove(struct udevice *dev) |
| 1607 | { |
| 1608 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1609 | |
| 1610 | debug("%s(dev=%p):\n", __func__, dev); |
| 1611 | |
| 1612 | mdio_unregister(eqos->mii); |
| 1613 | mdio_free(eqos->mii); |
Marek Vasut | 3fbd17a | 2021-11-13 03:23:52 +0100 | [diff] [blame] | 1614 | eqos->config->ops->eqos_stop_clks(dev); |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1615 | eqos->config->ops->eqos_remove_resources(dev); |
| 1616 | |
Rasmus Villemoes | 4a7c9db | 2022-05-11 16:12:50 +0200 | [diff] [blame] | 1617 | eqos_remove_resources_core(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1618 | |
| 1619 | debug("%s: OK\n", __func__); |
| 1620 | return 0; |
| 1621 | } |
| 1622 | |
Peng Fan | 149e80f | 2022-07-26 16:41:14 +0800 | [diff] [blame] | 1623 | int eqos_null_ops(struct udevice *dev) |
Patrick Delaunay | c6a0df2 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1624 | { |
| 1625 | return 0; |
| 1626 | } |
| 1627 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1628 | static const struct eth_ops eqos_ops = { |
| 1629 | .start = eqos_start, |
| 1630 | .stop = eqos_stop, |
| 1631 | .send = eqos_send, |
| 1632 | .recv = eqos_recv, |
| 1633 | .free_pkt = eqos_free_pkt, |
| 1634 | .write_hwaddr = eqos_write_hwaddr, |
Ye Li | 580fab4 | 2020-05-03 22:41:20 +0800 | [diff] [blame] | 1635 | .read_rom_hwaddr = eqos_read_rom_hwaddr, |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1636 | }; |
| 1637 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1638 | static struct eqos_ops eqos_tegra186_ops = { |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1639 | .eqos_inval_desc = eqos_inval_desc_generic, |
| 1640 | .eqos_flush_desc = eqos_flush_desc_generic, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1641 | .eqos_inval_buffer = eqos_inval_buffer_tegra186, |
| 1642 | .eqos_flush_buffer = eqos_flush_buffer_tegra186, |
| 1643 | .eqos_probe_resources = eqos_probe_resources_tegra186, |
| 1644 | .eqos_remove_resources = eqos_remove_resources_tegra186, |
| 1645 | .eqos_stop_resets = eqos_stop_resets_tegra186, |
| 1646 | .eqos_start_resets = eqos_start_resets_tegra186, |
| 1647 | .eqos_stop_clks = eqos_stop_clks_tegra186, |
| 1648 | .eqos_start_clks = eqos_start_clks_tegra186, |
| 1649 | .eqos_calibrate_pads = eqos_calibrate_pads_tegra186, |
| 1650 | .eqos_disable_calibration = eqos_disable_calibration_tegra186, |
| 1651 | .eqos_set_tx_clk_speed = eqos_set_tx_clk_speed_tegra186, |
Patrice Chotard | acce23b | 2022-08-02 10:55:25 +0200 | [diff] [blame] | 1652 | .eqos_get_enetaddr = eqos_null_ops, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1653 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_tegra186 |
| 1654 | }; |
| 1655 | |
Patrick Delaunay | a08f2f7 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1656 | static const struct eqos_config __maybe_unused eqos_tegra186_config = { |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1657 | .reg_access_always_ok = false, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1658 | .mdio_wait = 10, |
| 1659 | .swr_wait = 10, |
| 1660 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB, |
| 1661 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_20_35, |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1662 | .axi_bus_width = EQOS_AXI_WIDTH_128, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1663 | .interface = eqos_get_interface_tegra186, |
| 1664 | .ops = &eqos_tegra186_ops |
| 1665 | }; |
| 1666 | |
| 1667 | static struct eqos_ops eqos_stm32_ops = { |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1668 | .eqos_inval_desc = eqos_inval_desc_generic, |
| 1669 | .eqos_flush_desc = eqos_flush_desc_generic, |
| 1670 | .eqos_inval_buffer = eqos_inval_buffer_generic, |
| 1671 | .eqos_flush_buffer = eqos_flush_buffer_generic, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1672 | .eqos_probe_resources = eqos_probe_resources_stm32, |
| 1673 | .eqos_remove_resources = eqos_remove_resources_stm32, |
Patrick Delaunay | c6a0df2 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1674 | .eqos_stop_resets = eqos_null_ops, |
| 1675 | .eqos_start_resets = eqos_null_ops, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1676 | .eqos_stop_clks = eqos_stop_clks_stm32, |
| 1677 | .eqos_start_clks = eqos_start_clks_stm32, |
Patrick Delaunay | c6a0df2 | 2021-07-20 20:09:56 +0200 | [diff] [blame] | 1678 | .eqos_calibrate_pads = eqos_null_ops, |
| 1679 | .eqos_disable_calibration = eqos_null_ops, |
| 1680 | .eqos_set_tx_clk_speed = eqos_null_ops, |
Patrice Chotard | 5bd4f31 | 2022-08-02 10:55:26 +0200 | [diff] [blame] | 1681 | .eqos_get_enetaddr = eqos_null_ops, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1682 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_stm32 |
| 1683 | }; |
| 1684 | |
Patrick Delaunay | a08f2f7 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1685 | static const struct eqos_config __maybe_unused eqos_stm32_config = { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1686 | .reg_access_always_ok = false, |
| 1687 | .mdio_wait = 10000, |
| 1688 | .swr_wait = 50, |
| 1689 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV, |
| 1690 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, |
Marek Vasut | 6f1e668 | 2021-01-07 11:12:16 +0100 | [diff] [blame] | 1691 | .axi_bus_width = EQOS_AXI_WIDTH_64, |
Marek BehĂșn | 123ca11 | 2022-04-07 00:33:01 +0200 | [diff] [blame] | 1692 | .interface = dev_read_phy_mode, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1693 | .ops = &eqos_stm32_ops |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1694 | }; |
| 1695 | |
| 1696 | static const struct udevice_id eqos_ids[] = { |
Patrick Delaunay | a08f2f7 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1697 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_TEGRA186) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1698 | { |
| 1699 | .compatible = "nvidia,tegra186-eqos", |
| 1700 | .data = (ulong)&eqos_tegra186_config |
| 1701 | }, |
Patrick Delaunay | a08f2f7 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1702 | #endif |
| 1703 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_STM32) |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1704 | { |
Patrick Delaunay | a718a5d | 2020-05-14 15:00:23 +0200 | [diff] [blame] | 1705 | .compatible = "st,stm32mp1-dwmac", |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1706 | .data = (ulong)&eqos_stm32_config |
| 1707 | }, |
Patrick Delaunay | a08f2f7 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1708 | #endif |
| 1709 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_IMX) |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1710 | { |
Marek Vasut | 3fa3f23 | 2022-02-26 04:36:37 +0100 | [diff] [blame] | 1711 | .compatible = "nxp,imx8mp-dwmac-eqos", |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1712 | .data = (ulong)&eqos_imx_config |
| 1713 | }, |
Patrick Delaunay | a08f2f7 | 2020-06-08 11:27:19 +0200 | [diff] [blame] | 1714 | #endif |
Jonas Karlman | 8e76ff6 | 2023-10-01 19:17:19 +0000 | [diff] [blame] | 1715 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_ROCKCHIP) |
| 1716 | { |
| 1717 | .compatible = "rockchip,rk3568-gmac", |
| 1718 | .data = (ulong)&eqos_rockchip_config |
| 1719 | }, |
Jonas Karlman | 01b8ed4 | 2023-10-01 19:17:20 +0000 | [diff] [blame] | 1720 | { |
| 1721 | .compatible = "rockchip,rk3588-gmac", |
| 1722 | .data = (ulong)&eqos_rockchip_config |
| 1723 | }, |
Jonas Karlman | 8e76ff6 | 2023-10-01 19:17:19 +0000 | [diff] [blame] | 1724 | #endif |
Sumit Garg | d382025 | 2023-02-01 19:28:55 +0530 | [diff] [blame] | 1725 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_QCOM) |
| 1726 | { |
| 1727 | .compatible = "qcom,qcs404-ethqos", |
| 1728 | .data = (ulong)&eqos_qcom_config |
| 1729 | }, |
| 1730 | #endif |
Yanhong Wang | 736733b | 2023-06-15 17:36:43 +0800 | [diff] [blame] | 1731 | #if IS_ENABLED(CONFIG_DWC_ETH_QOS_STARFIVE) |
| 1732 | { |
| 1733 | .compatible = "starfive,jh7110-dwmac", |
| 1734 | .data = (ulong)&eqos_jh7110_config |
| 1735 | }, |
| 1736 | #endif |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1737 | { } |
| 1738 | }; |
| 1739 | |
| 1740 | U_BOOT_DRIVER(eth_eqos) = { |
| 1741 | .name = "eth_eqos", |
| 1742 | .id = UCLASS_ETH, |
Fugang Duan | 3a97da1 | 2020-05-03 22:41:17 +0800 | [diff] [blame] | 1743 | .of_match = of_match_ptr(eqos_ids), |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1744 | .probe = eqos_probe, |
| 1745 | .remove = eqos_remove, |
| 1746 | .ops = &eqos_ops, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 1747 | .priv_auto = sizeof(struct eqos_priv), |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1748 | .plat_auto = sizeof(struct eth_pdata), |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1749 | }; |