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 | */ |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 29 | #include <common.h> |
| 30 | #include <clk.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 31 | #include <cpu_func.h> |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 32 | #include <dm.h> |
| 33 | #include <errno.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 34 | #include <malloc.h> |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 35 | #include <memalign.h> |
| 36 | #include <miiphy.h> |
| 37 | #include <net.h> |
| 38 | #include <netdev.h> |
| 39 | #include <phy.h> |
| 40 | #include <reset.h> |
| 41 | #include <wait_bit.h> |
| 42 | #include <asm/gpio.h> |
| 43 | #include <asm/io.h> |
| 44 | |
| 45 | /* Core registers */ |
| 46 | |
| 47 | #define EQOS_MAC_REGS_BASE 0x000 |
| 48 | struct eqos_mac_regs { |
| 49 | uint32_t configuration; /* 0x000 */ |
| 50 | uint32_t unused_004[(0x070 - 0x004) / 4]; /* 0x004 */ |
| 51 | uint32_t q0_tx_flow_ctrl; /* 0x070 */ |
| 52 | uint32_t unused_070[(0x090 - 0x074) / 4]; /* 0x074 */ |
| 53 | uint32_t rx_flow_ctrl; /* 0x090 */ |
| 54 | uint32_t unused_094; /* 0x094 */ |
| 55 | uint32_t txq_prty_map0; /* 0x098 */ |
| 56 | uint32_t unused_09c; /* 0x09c */ |
| 57 | uint32_t rxq_ctrl0; /* 0x0a0 */ |
| 58 | uint32_t unused_0a4; /* 0x0a4 */ |
| 59 | uint32_t rxq_ctrl2; /* 0x0a8 */ |
| 60 | uint32_t unused_0ac[(0x0dc - 0x0ac) / 4]; /* 0x0ac */ |
| 61 | uint32_t us_tic_counter; /* 0x0dc */ |
| 62 | uint32_t unused_0e0[(0x11c - 0x0e0) / 4]; /* 0x0e0 */ |
| 63 | uint32_t hw_feature0; /* 0x11c */ |
| 64 | uint32_t hw_feature1; /* 0x120 */ |
| 65 | uint32_t hw_feature2; /* 0x124 */ |
| 66 | uint32_t unused_128[(0x200 - 0x128) / 4]; /* 0x128 */ |
| 67 | uint32_t mdio_address; /* 0x200 */ |
| 68 | uint32_t mdio_data; /* 0x204 */ |
| 69 | uint32_t unused_208[(0x300 - 0x208) / 4]; /* 0x208 */ |
| 70 | uint32_t address0_high; /* 0x300 */ |
| 71 | uint32_t address0_low; /* 0x304 */ |
| 72 | }; |
| 73 | |
| 74 | #define EQOS_MAC_CONFIGURATION_GPSLCE BIT(23) |
| 75 | #define EQOS_MAC_CONFIGURATION_CST BIT(21) |
| 76 | #define EQOS_MAC_CONFIGURATION_ACS BIT(20) |
| 77 | #define EQOS_MAC_CONFIGURATION_WD BIT(19) |
| 78 | #define EQOS_MAC_CONFIGURATION_JD BIT(17) |
| 79 | #define EQOS_MAC_CONFIGURATION_JE BIT(16) |
| 80 | #define EQOS_MAC_CONFIGURATION_PS BIT(15) |
| 81 | #define EQOS_MAC_CONFIGURATION_FES BIT(14) |
| 82 | #define EQOS_MAC_CONFIGURATION_DM BIT(13) |
| 83 | #define EQOS_MAC_CONFIGURATION_TE BIT(1) |
| 84 | #define EQOS_MAC_CONFIGURATION_RE BIT(0) |
| 85 | |
| 86 | #define EQOS_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT 16 |
| 87 | #define EQOS_MAC_Q0_TX_FLOW_CTRL_PT_MASK 0xffff |
| 88 | #define EQOS_MAC_Q0_TX_FLOW_CTRL_TFE BIT(1) |
| 89 | |
| 90 | #define EQOS_MAC_RX_FLOW_CTRL_RFE BIT(0) |
| 91 | |
| 92 | #define EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_SHIFT 0 |
| 93 | #define EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_MASK 0xff |
| 94 | |
| 95 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT 0 |
| 96 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_MASK 3 |
| 97 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_NOT_ENABLED 0 |
| 98 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB 2 |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 99 | #define EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV 1 |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 100 | |
| 101 | #define EQOS_MAC_RXQ_CTRL2_PSRQ0_SHIFT 0 |
| 102 | #define EQOS_MAC_RXQ_CTRL2_PSRQ0_MASK 0xff |
| 103 | |
| 104 | #define EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_SHIFT 6 |
| 105 | #define EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_MASK 0x1f |
| 106 | #define EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_SHIFT 0 |
| 107 | #define EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_MASK 0x1f |
| 108 | |
| 109 | #define EQOS_MAC_MDIO_ADDRESS_PA_SHIFT 21 |
| 110 | #define EQOS_MAC_MDIO_ADDRESS_RDA_SHIFT 16 |
| 111 | #define EQOS_MAC_MDIO_ADDRESS_CR_SHIFT 8 |
| 112 | #define EQOS_MAC_MDIO_ADDRESS_CR_20_35 2 |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 113 | #define EQOS_MAC_MDIO_ADDRESS_CR_250_300 5 |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 114 | #define EQOS_MAC_MDIO_ADDRESS_SKAP BIT(4) |
| 115 | #define EQOS_MAC_MDIO_ADDRESS_GOC_SHIFT 2 |
| 116 | #define EQOS_MAC_MDIO_ADDRESS_GOC_READ 3 |
| 117 | #define EQOS_MAC_MDIO_ADDRESS_GOC_WRITE 1 |
| 118 | #define EQOS_MAC_MDIO_ADDRESS_C45E BIT(1) |
| 119 | #define EQOS_MAC_MDIO_ADDRESS_GB BIT(0) |
| 120 | |
| 121 | #define EQOS_MAC_MDIO_DATA_GD_MASK 0xffff |
| 122 | |
| 123 | #define EQOS_MTL_REGS_BASE 0xd00 |
| 124 | struct eqos_mtl_regs { |
| 125 | uint32_t txq0_operation_mode; /* 0xd00 */ |
| 126 | uint32_t unused_d04; /* 0xd04 */ |
| 127 | uint32_t txq0_debug; /* 0xd08 */ |
| 128 | uint32_t unused_d0c[(0xd18 - 0xd0c) / 4]; /* 0xd0c */ |
| 129 | uint32_t txq0_quantum_weight; /* 0xd18 */ |
| 130 | uint32_t unused_d1c[(0xd30 - 0xd1c) / 4]; /* 0xd1c */ |
| 131 | uint32_t rxq0_operation_mode; /* 0xd30 */ |
| 132 | uint32_t unused_d34; /* 0xd34 */ |
| 133 | uint32_t rxq0_debug; /* 0xd38 */ |
| 134 | }; |
| 135 | |
| 136 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT 16 |
| 137 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TQS_MASK 0x1ff |
| 138 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT 2 |
| 139 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_MASK 3 |
| 140 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_ENABLED 2 |
| 141 | #define EQOS_MTL_TXQ0_OPERATION_MODE_TSF BIT(1) |
| 142 | #define EQOS_MTL_TXQ0_OPERATION_MODE_FTQ BIT(0) |
| 143 | |
| 144 | #define EQOS_MTL_TXQ0_DEBUG_TXQSTS BIT(4) |
| 145 | #define EQOS_MTL_TXQ0_DEBUG_TRCSTS_SHIFT 1 |
| 146 | #define EQOS_MTL_TXQ0_DEBUG_TRCSTS_MASK 3 |
| 147 | |
| 148 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT 20 |
| 149 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RQS_MASK 0x3ff |
| 150 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT 14 |
| 151 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFD_MASK 0x3f |
| 152 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT 8 |
| 153 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RFA_MASK 0x3f |
| 154 | #define EQOS_MTL_RXQ0_OPERATION_MODE_EHFC BIT(7) |
| 155 | #define EQOS_MTL_RXQ0_OPERATION_MODE_RSF BIT(5) |
| 156 | |
| 157 | #define EQOS_MTL_RXQ0_DEBUG_PRXQ_SHIFT 16 |
| 158 | #define EQOS_MTL_RXQ0_DEBUG_PRXQ_MASK 0x7fff |
| 159 | #define EQOS_MTL_RXQ0_DEBUG_RXQSTS_SHIFT 4 |
| 160 | #define EQOS_MTL_RXQ0_DEBUG_RXQSTS_MASK 3 |
| 161 | |
| 162 | #define EQOS_DMA_REGS_BASE 0x1000 |
| 163 | struct eqos_dma_regs { |
| 164 | uint32_t mode; /* 0x1000 */ |
| 165 | uint32_t sysbus_mode; /* 0x1004 */ |
| 166 | uint32_t unused_1008[(0x1100 - 0x1008) / 4]; /* 0x1008 */ |
| 167 | uint32_t ch0_control; /* 0x1100 */ |
| 168 | uint32_t ch0_tx_control; /* 0x1104 */ |
| 169 | uint32_t ch0_rx_control; /* 0x1108 */ |
| 170 | uint32_t unused_110c; /* 0x110c */ |
| 171 | uint32_t ch0_txdesc_list_haddress; /* 0x1110 */ |
| 172 | uint32_t ch0_txdesc_list_address; /* 0x1114 */ |
| 173 | uint32_t ch0_rxdesc_list_haddress; /* 0x1118 */ |
| 174 | uint32_t ch0_rxdesc_list_address; /* 0x111c */ |
| 175 | uint32_t ch0_txdesc_tail_pointer; /* 0x1120 */ |
| 176 | uint32_t unused_1124; /* 0x1124 */ |
| 177 | uint32_t ch0_rxdesc_tail_pointer; /* 0x1128 */ |
| 178 | uint32_t ch0_txdesc_ring_length; /* 0x112c */ |
| 179 | uint32_t ch0_rxdesc_ring_length; /* 0x1130 */ |
| 180 | }; |
| 181 | |
| 182 | #define EQOS_DMA_MODE_SWR BIT(0) |
| 183 | |
| 184 | #define EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT 16 |
| 185 | #define EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_MASK 0xf |
| 186 | #define EQOS_DMA_SYSBUS_MODE_EAME BIT(11) |
| 187 | #define EQOS_DMA_SYSBUS_MODE_BLEN16 BIT(3) |
| 188 | #define EQOS_DMA_SYSBUS_MODE_BLEN8 BIT(2) |
| 189 | #define EQOS_DMA_SYSBUS_MODE_BLEN4 BIT(1) |
| 190 | |
| 191 | #define EQOS_DMA_CH0_CONTROL_PBLX8 BIT(16) |
| 192 | |
| 193 | #define EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT 16 |
| 194 | #define EQOS_DMA_CH0_TX_CONTROL_TXPBL_MASK 0x3f |
| 195 | #define EQOS_DMA_CH0_TX_CONTROL_OSP BIT(4) |
| 196 | #define EQOS_DMA_CH0_TX_CONTROL_ST BIT(0) |
| 197 | |
| 198 | #define EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT 16 |
| 199 | #define EQOS_DMA_CH0_RX_CONTROL_RXPBL_MASK 0x3f |
| 200 | #define EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT 1 |
| 201 | #define EQOS_DMA_CH0_RX_CONTROL_RBSZ_MASK 0x3fff |
| 202 | #define EQOS_DMA_CH0_RX_CONTROL_SR BIT(0) |
| 203 | |
| 204 | /* These registers are Tegra186-specific */ |
| 205 | #define EQOS_TEGRA186_REGS_BASE 0x8800 |
| 206 | struct eqos_tegra186_regs { |
| 207 | uint32_t sdmemcomppadctrl; /* 0x8800 */ |
| 208 | uint32_t auto_cal_config; /* 0x8804 */ |
| 209 | uint32_t unused_8808; /* 0x8808 */ |
| 210 | uint32_t auto_cal_status; /* 0x880c */ |
| 211 | }; |
| 212 | |
| 213 | #define EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD BIT(31) |
| 214 | |
| 215 | #define EQOS_AUTO_CAL_CONFIG_START BIT(31) |
| 216 | #define EQOS_AUTO_CAL_CONFIG_ENABLE BIT(29) |
| 217 | |
| 218 | #define EQOS_AUTO_CAL_STATUS_ACTIVE BIT(31) |
| 219 | |
| 220 | /* Descriptors */ |
| 221 | |
| 222 | #define EQOS_DESCRIPTOR_WORDS 4 |
| 223 | #define EQOS_DESCRIPTOR_SIZE (EQOS_DESCRIPTOR_WORDS * 4) |
| 224 | /* We assume ARCH_DMA_MINALIGN >= 16; 16 is the EQOS HW minimum */ |
| 225 | #define EQOS_DESCRIPTOR_ALIGN ARCH_DMA_MINALIGN |
| 226 | #define EQOS_DESCRIPTORS_TX 4 |
| 227 | #define EQOS_DESCRIPTORS_RX 4 |
| 228 | #define EQOS_DESCRIPTORS_NUM (EQOS_DESCRIPTORS_TX + EQOS_DESCRIPTORS_RX) |
| 229 | #define EQOS_DESCRIPTORS_SIZE ALIGN(EQOS_DESCRIPTORS_NUM * \ |
| 230 | EQOS_DESCRIPTOR_SIZE, ARCH_DMA_MINALIGN) |
| 231 | #define EQOS_BUFFER_ALIGN ARCH_DMA_MINALIGN |
| 232 | #define EQOS_MAX_PACKET_SIZE ALIGN(1568, ARCH_DMA_MINALIGN) |
| 233 | #define EQOS_RX_BUFFER_SIZE (EQOS_DESCRIPTORS_RX * EQOS_MAX_PACKET_SIZE) |
| 234 | |
| 235 | /* |
| 236 | * Warn if the cache-line size is larger than the descriptor size. In such |
| 237 | * cases the driver will likely fail because the CPU needs to flush the cache |
| 238 | * when requeuing RX buffers, therefore descriptors written by the hardware |
| 239 | * may be discarded. Architectures with full IO coherence, such as x86, do not |
| 240 | * experience this issue, and hence are excluded from this condition. |
| 241 | * |
| 242 | * This can be fixed by defining CONFIG_SYS_NONCACHED_MEMORY which will cause |
| 243 | * the driver to allocate descriptors from a pool of non-cached memory. |
| 244 | */ |
| 245 | #if EQOS_DESCRIPTOR_SIZE < ARCH_DMA_MINALIGN |
| 246 | #if !defined(CONFIG_SYS_NONCACHED_MEMORY) && \ |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 247 | !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) && !defined(CONFIG_X86) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 248 | #warning Cache line size is larger than descriptor size |
| 249 | #endif |
| 250 | #endif |
| 251 | |
| 252 | struct eqos_desc { |
| 253 | u32 des0; |
| 254 | u32 des1; |
| 255 | u32 des2; |
| 256 | u32 des3; |
| 257 | }; |
| 258 | |
| 259 | #define EQOS_DESC3_OWN BIT(31) |
| 260 | #define EQOS_DESC3_FD BIT(29) |
| 261 | #define EQOS_DESC3_LD BIT(28) |
| 262 | #define EQOS_DESC3_BUF1V BIT(24) |
| 263 | |
| 264 | struct eqos_config { |
| 265 | bool reg_access_always_ok; |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 266 | int mdio_wait; |
| 267 | int swr_wait; |
| 268 | int config_mac; |
| 269 | int config_mac_mdio; |
| 270 | phy_interface_t (*interface)(struct udevice *dev); |
| 271 | struct eqos_ops *ops; |
| 272 | }; |
| 273 | |
| 274 | struct eqos_ops { |
| 275 | void (*eqos_inval_desc)(void *desc); |
| 276 | void (*eqos_flush_desc)(void *desc); |
| 277 | void (*eqos_inval_buffer)(void *buf, size_t size); |
| 278 | void (*eqos_flush_buffer)(void *buf, size_t size); |
| 279 | int (*eqos_probe_resources)(struct udevice *dev); |
| 280 | int (*eqos_remove_resources)(struct udevice *dev); |
| 281 | int (*eqos_stop_resets)(struct udevice *dev); |
| 282 | int (*eqos_start_resets)(struct udevice *dev); |
| 283 | void (*eqos_stop_clks)(struct udevice *dev); |
| 284 | int (*eqos_start_clks)(struct udevice *dev); |
| 285 | int (*eqos_calibrate_pads)(struct udevice *dev); |
| 286 | int (*eqos_disable_calibration)(struct udevice *dev); |
| 287 | int (*eqos_set_tx_clk_speed)(struct udevice *dev); |
| 288 | ulong (*eqos_get_tick_clk_rate)(struct udevice *dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | struct eqos_priv { |
| 292 | struct udevice *dev; |
| 293 | const struct eqos_config *config; |
| 294 | fdt_addr_t regs; |
| 295 | struct eqos_mac_regs *mac_regs; |
| 296 | struct eqos_mtl_regs *mtl_regs; |
| 297 | struct eqos_dma_regs *dma_regs; |
| 298 | struct eqos_tegra186_regs *tegra186_regs; |
| 299 | struct reset_ctl reset_ctl; |
| 300 | struct gpio_desc phy_reset_gpio; |
| 301 | struct clk clk_master_bus; |
| 302 | struct clk clk_rx; |
| 303 | struct clk clk_ptp_ref; |
| 304 | struct clk clk_tx; |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 305 | struct clk clk_ck; |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 306 | struct clk clk_slave_bus; |
| 307 | struct mii_dev *mii; |
| 308 | struct phy_device *phy; |
| 309 | void *descs; |
| 310 | struct eqos_desc *tx_descs; |
| 311 | struct eqos_desc *rx_descs; |
| 312 | int tx_desc_idx, rx_desc_idx; |
| 313 | void *tx_dma_buf; |
| 314 | void *rx_dma_buf; |
| 315 | void *rx_pkt; |
| 316 | bool started; |
| 317 | bool reg_access_ok; |
| 318 | }; |
| 319 | |
| 320 | /* |
| 321 | * TX and RX descriptors are 16 bytes. This causes problems with the cache |
| 322 | * maintenance on CPUs where the cache-line size exceeds the size of these |
| 323 | * descriptors. What will happen is that when the driver receives a packet |
| 324 | * it will be immediately requeued for the hardware to reuse. The CPU will |
| 325 | * therefore need to flush the cache-line containing the descriptor, which |
| 326 | * will cause all other descriptors in the same cache-line to be flushed |
| 327 | * along with it. If one of those descriptors had been written to by the |
| 328 | * device those changes (and the associated packet) will be lost. |
| 329 | * |
| 330 | * To work around this, we make use of non-cached memory if available. If |
| 331 | * descriptors are mapped uncached there's no need to manually flush them |
| 332 | * or invalidate them. |
| 333 | * |
| 334 | * Note that this only applies to descriptors. The packet data buffers do |
| 335 | * not have the same constraints since they are 1536 bytes large, so they |
| 336 | * are unlikely to share cache-lines. |
| 337 | */ |
| 338 | static void *eqos_alloc_descs(unsigned int num) |
| 339 | { |
| 340 | #ifdef CONFIG_SYS_NONCACHED_MEMORY |
| 341 | return (void *)noncached_alloc(EQOS_DESCRIPTORS_SIZE, |
| 342 | EQOS_DESCRIPTOR_ALIGN); |
| 343 | #else |
| 344 | return memalign(EQOS_DESCRIPTOR_ALIGN, EQOS_DESCRIPTORS_SIZE); |
| 345 | #endif |
| 346 | } |
| 347 | |
| 348 | static void eqos_free_descs(void *descs) |
| 349 | { |
| 350 | #ifdef CONFIG_SYS_NONCACHED_MEMORY |
| 351 | /* FIXME: noncached_alloc() has no opposite */ |
| 352 | #else |
| 353 | free(descs); |
| 354 | #endif |
| 355 | } |
| 356 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 357 | static void eqos_inval_desc_tegra186(void *desc) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 358 | { |
| 359 | #ifndef CONFIG_SYS_NONCACHED_MEMORY |
| 360 | unsigned long start = (unsigned long)desc & ~(ARCH_DMA_MINALIGN - 1); |
| 361 | unsigned long end = ALIGN(start + EQOS_DESCRIPTOR_SIZE, |
| 362 | ARCH_DMA_MINALIGN); |
| 363 | |
| 364 | invalidate_dcache_range(start, end); |
| 365 | #endif |
| 366 | } |
| 367 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 368 | static void eqos_inval_desc_stm32(void *desc) |
| 369 | { |
| 370 | #ifndef CONFIG_SYS_NONCACHED_MEMORY |
| 371 | unsigned long start = rounddown((unsigned long)desc, ARCH_DMA_MINALIGN); |
| 372 | unsigned long end = roundup((unsigned long)desc + EQOS_DESCRIPTOR_SIZE, |
| 373 | ARCH_DMA_MINALIGN); |
| 374 | |
| 375 | invalidate_dcache_range(start, end); |
| 376 | #endif |
| 377 | } |
| 378 | |
| 379 | static void eqos_flush_desc_tegra186(void *desc) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 380 | { |
| 381 | #ifndef CONFIG_SYS_NONCACHED_MEMORY |
| 382 | flush_cache((unsigned long)desc, EQOS_DESCRIPTOR_SIZE); |
| 383 | #endif |
| 384 | } |
| 385 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 386 | static void eqos_flush_desc_stm32(void *desc) |
| 387 | { |
| 388 | #ifndef CONFIG_SYS_NONCACHED_MEMORY |
| 389 | unsigned long start = rounddown((unsigned long)desc, ARCH_DMA_MINALIGN); |
| 390 | unsigned long end = roundup((unsigned long)desc + EQOS_DESCRIPTOR_SIZE, |
| 391 | ARCH_DMA_MINALIGN); |
| 392 | |
| 393 | flush_dcache_range(start, end); |
| 394 | #endif |
| 395 | } |
| 396 | |
| 397 | static void eqos_inval_buffer_tegra186(void *buf, size_t size) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 398 | { |
| 399 | unsigned long start = (unsigned long)buf & ~(ARCH_DMA_MINALIGN - 1); |
| 400 | unsigned long end = ALIGN(start + size, ARCH_DMA_MINALIGN); |
| 401 | |
| 402 | invalidate_dcache_range(start, end); |
| 403 | } |
| 404 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 405 | static void eqos_inval_buffer_stm32(void *buf, size_t size) |
| 406 | { |
| 407 | unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN); |
| 408 | unsigned long end = roundup((unsigned long)buf + size, |
| 409 | ARCH_DMA_MINALIGN); |
| 410 | |
| 411 | invalidate_dcache_range(start, end); |
| 412 | } |
| 413 | |
| 414 | static void eqos_flush_buffer_tegra186(void *buf, size_t size) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 415 | { |
| 416 | flush_cache((unsigned long)buf, size); |
| 417 | } |
| 418 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 419 | static void eqos_flush_buffer_stm32(void *buf, size_t size) |
| 420 | { |
| 421 | unsigned long start = rounddown((unsigned long)buf, ARCH_DMA_MINALIGN); |
| 422 | unsigned long end = roundup((unsigned long)buf + size, |
| 423 | ARCH_DMA_MINALIGN); |
| 424 | |
| 425 | flush_dcache_range(start, end); |
| 426 | } |
| 427 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 428 | static int eqos_mdio_wait_idle(struct eqos_priv *eqos) |
| 429 | { |
Álvaro Fernández Rojas | 4826350 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 430 | return wait_for_bit_le32(&eqos->mac_regs->mdio_address, |
| 431 | EQOS_MAC_MDIO_ADDRESS_GB, false, |
| 432 | 1000000, true); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | static int eqos_mdio_read(struct mii_dev *bus, int mdio_addr, int mdio_devad, |
| 436 | int mdio_reg) |
| 437 | { |
| 438 | struct eqos_priv *eqos = bus->priv; |
| 439 | u32 val; |
| 440 | int ret; |
| 441 | |
| 442 | debug("%s(dev=%p, addr=%x, reg=%d):\n", __func__, eqos->dev, mdio_addr, |
| 443 | mdio_reg); |
| 444 | |
| 445 | ret = eqos_mdio_wait_idle(eqos); |
| 446 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 447 | pr_err("MDIO not idle at entry"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 448 | return ret; |
| 449 | } |
| 450 | |
| 451 | val = readl(&eqos->mac_regs->mdio_address); |
| 452 | val &= EQOS_MAC_MDIO_ADDRESS_SKAP | |
| 453 | EQOS_MAC_MDIO_ADDRESS_C45E; |
| 454 | val |= (mdio_addr << EQOS_MAC_MDIO_ADDRESS_PA_SHIFT) | |
| 455 | (mdio_reg << EQOS_MAC_MDIO_ADDRESS_RDA_SHIFT) | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 456 | (eqos->config->config_mac_mdio << |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 457 | EQOS_MAC_MDIO_ADDRESS_CR_SHIFT) | |
| 458 | (EQOS_MAC_MDIO_ADDRESS_GOC_READ << |
| 459 | EQOS_MAC_MDIO_ADDRESS_GOC_SHIFT) | |
| 460 | EQOS_MAC_MDIO_ADDRESS_GB; |
| 461 | writel(val, &eqos->mac_regs->mdio_address); |
| 462 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 463 | udelay(eqos->config->mdio_wait); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 464 | |
| 465 | ret = eqos_mdio_wait_idle(eqos); |
| 466 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 467 | pr_err("MDIO read didn't complete"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 468 | return ret; |
| 469 | } |
| 470 | |
| 471 | val = readl(&eqos->mac_regs->mdio_data); |
| 472 | val &= EQOS_MAC_MDIO_DATA_GD_MASK; |
| 473 | |
| 474 | debug("%s: val=%x\n", __func__, val); |
| 475 | |
| 476 | return val; |
| 477 | } |
| 478 | |
| 479 | static int eqos_mdio_write(struct mii_dev *bus, int mdio_addr, int mdio_devad, |
| 480 | int mdio_reg, u16 mdio_val) |
| 481 | { |
| 482 | struct eqos_priv *eqos = bus->priv; |
| 483 | u32 val; |
| 484 | int ret; |
| 485 | |
| 486 | debug("%s(dev=%p, addr=%x, reg=%d, val=%x):\n", __func__, eqos->dev, |
| 487 | mdio_addr, mdio_reg, mdio_val); |
| 488 | |
| 489 | ret = eqos_mdio_wait_idle(eqos); |
| 490 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 491 | pr_err("MDIO not idle at entry"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 492 | return ret; |
| 493 | } |
| 494 | |
| 495 | writel(mdio_val, &eqos->mac_regs->mdio_data); |
| 496 | |
| 497 | val = readl(&eqos->mac_regs->mdio_address); |
| 498 | val &= EQOS_MAC_MDIO_ADDRESS_SKAP | |
| 499 | EQOS_MAC_MDIO_ADDRESS_C45E; |
| 500 | val |= (mdio_addr << EQOS_MAC_MDIO_ADDRESS_PA_SHIFT) | |
| 501 | (mdio_reg << EQOS_MAC_MDIO_ADDRESS_RDA_SHIFT) | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 502 | (eqos->config->config_mac_mdio << |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 503 | EQOS_MAC_MDIO_ADDRESS_CR_SHIFT) | |
| 504 | (EQOS_MAC_MDIO_ADDRESS_GOC_WRITE << |
| 505 | EQOS_MAC_MDIO_ADDRESS_GOC_SHIFT) | |
| 506 | EQOS_MAC_MDIO_ADDRESS_GB; |
| 507 | writel(val, &eqos->mac_regs->mdio_address); |
| 508 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 509 | udelay(eqos->config->mdio_wait); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 510 | |
| 511 | ret = eqos_mdio_wait_idle(eqos); |
| 512 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 513 | pr_err("MDIO read didn't complete"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 514 | return ret; |
| 515 | } |
| 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | static int eqos_start_clks_tegra186(struct udevice *dev) |
| 521 | { |
| 522 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 523 | int ret; |
| 524 | |
| 525 | debug("%s(dev=%p):\n", __func__, dev); |
| 526 | |
| 527 | ret = clk_enable(&eqos->clk_slave_bus); |
| 528 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 529 | pr_err("clk_enable(clk_slave_bus) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 530 | goto err; |
| 531 | } |
| 532 | |
| 533 | ret = clk_enable(&eqos->clk_master_bus); |
| 534 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 535 | pr_err("clk_enable(clk_master_bus) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 536 | goto err_disable_clk_slave_bus; |
| 537 | } |
| 538 | |
| 539 | ret = clk_enable(&eqos->clk_rx); |
| 540 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 541 | pr_err("clk_enable(clk_rx) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 542 | goto err_disable_clk_master_bus; |
| 543 | } |
| 544 | |
| 545 | ret = clk_enable(&eqos->clk_ptp_ref); |
| 546 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 547 | pr_err("clk_enable(clk_ptp_ref) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 548 | goto err_disable_clk_rx; |
| 549 | } |
| 550 | |
| 551 | ret = clk_set_rate(&eqos->clk_ptp_ref, 125 * 1000 * 1000); |
| 552 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 553 | pr_err("clk_set_rate(clk_ptp_ref) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 554 | goto err_disable_clk_ptp_ref; |
| 555 | } |
| 556 | |
| 557 | ret = clk_enable(&eqos->clk_tx); |
| 558 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 559 | pr_err("clk_enable(clk_tx) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 560 | goto err_disable_clk_ptp_ref; |
| 561 | } |
| 562 | |
| 563 | debug("%s: OK\n", __func__); |
| 564 | return 0; |
| 565 | |
| 566 | err_disable_clk_ptp_ref: |
| 567 | clk_disable(&eqos->clk_ptp_ref); |
| 568 | err_disable_clk_rx: |
| 569 | clk_disable(&eqos->clk_rx); |
| 570 | err_disable_clk_master_bus: |
| 571 | clk_disable(&eqos->clk_master_bus); |
| 572 | err_disable_clk_slave_bus: |
| 573 | clk_disable(&eqos->clk_slave_bus); |
| 574 | err: |
| 575 | debug("%s: FAILED: %d\n", __func__, ret); |
| 576 | return ret; |
| 577 | } |
| 578 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 579 | static int eqos_start_clks_stm32(struct udevice *dev) |
| 580 | { |
| 581 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 582 | int ret; |
| 583 | |
| 584 | debug("%s(dev=%p):\n", __func__, dev); |
| 585 | |
| 586 | ret = clk_enable(&eqos->clk_master_bus); |
| 587 | if (ret < 0) { |
| 588 | pr_err("clk_enable(clk_master_bus) failed: %d", ret); |
| 589 | goto err; |
| 590 | } |
| 591 | |
| 592 | ret = clk_enable(&eqos->clk_rx); |
| 593 | if (ret < 0) { |
| 594 | pr_err("clk_enable(clk_rx) failed: %d", ret); |
| 595 | goto err_disable_clk_master_bus; |
| 596 | } |
| 597 | |
| 598 | ret = clk_enable(&eqos->clk_tx); |
| 599 | if (ret < 0) { |
| 600 | pr_err("clk_enable(clk_tx) failed: %d", ret); |
| 601 | goto err_disable_clk_rx; |
| 602 | } |
| 603 | |
| 604 | if (clk_valid(&eqos->clk_ck)) { |
| 605 | ret = clk_enable(&eqos->clk_ck); |
| 606 | if (ret < 0) { |
| 607 | pr_err("clk_enable(clk_ck) failed: %d", ret); |
| 608 | goto err_disable_clk_tx; |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | debug("%s: OK\n", __func__); |
| 613 | return 0; |
| 614 | |
| 615 | err_disable_clk_tx: |
| 616 | clk_disable(&eqos->clk_tx); |
| 617 | err_disable_clk_rx: |
| 618 | clk_disable(&eqos->clk_rx); |
| 619 | err_disable_clk_master_bus: |
| 620 | clk_disable(&eqos->clk_master_bus); |
| 621 | err: |
| 622 | debug("%s: FAILED: %d\n", __func__, ret); |
| 623 | return ret; |
| 624 | } |
| 625 | |
Patrick Delaunay | 50d86e5 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 626 | static void eqos_stop_clks_tegra186(struct udevice *dev) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 627 | { |
| 628 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 629 | |
| 630 | debug("%s(dev=%p):\n", __func__, dev); |
| 631 | |
| 632 | clk_disable(&eqos->clk_tx); |
| 633 | clk_disable(&eqos->clk_ptp_ref); |
| 634 | clk_disable(&eqos->clk_rx); |
| 635 | clk_disable(&eqos->clk_master_bus); |
| 636 | clk_disable(&eqos->clk_slave_bus); |
| 637 | |
| 638 | debug("%s: OK\n", __func__); |
| 639 | } |
| 640 | |
Patrick Delaunay | 50d86e5 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 641 | static void eqos_stop_clks_stm32(struct udevice *dev) |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 642 | { |
| 643 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 644 | |
| 645 | debug("%s(dev=%p):\n", __func__, dev); |
| 646 | |
| 647 | clk_disable(&eqos->clk_tx); |
| 648 | clk_disable(&eqos->clk_rx); |
| 649 | clk_disable(&eqos->clk_master_bus); |
| 650 | if (clk_valid(&eqos->clk_ck)) |
| 651 | clk_disable(&eqos->clk_ck); |
| 652 | |
| 653 | debug("%s: OK\n", __func__); |
| 654 | } |
| 655 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 656 | static int eqos_start_resets_tegra186(struct udevice *dev) |
| 657 | { |
| 658 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 659 | int ret; |
| 660 | |
| 661 | debug("%s(dev=%p):\n", __func__, dev); |
| 662 | |
| 663 | ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 1); |
| 664 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 665 | pr_err("dm_gpio_set_value(phy_reset, assert) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 666 | return ret; |
| 667 | } |
| 668 | |
| 669 | udelay(2); |
| 670 | |
| 671 | ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 0); |
| 672 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 673 | pr_err("dm_gpio_set_value(phy_reset, deassert) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 674 | return ret; |
| 675 | } |
| 676 | |
| 677 | ret = reset_assert(&eqos->reset_ctl); |
| 678 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 679 | pr_err("reset_assert() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 680 | return ret; |
| 681 | } |
| 682 | |
| 683 | udelay(2); |
| 684 | |
| 685 | ret = reset_deassert(&eqos->reset_ctl); |
| 686 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 687 | pr_err("reset_deassert() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 688 | return ret; |
| 689 | } |
| 690 | |
| 691 | debug("%s: OK\n", __func__); |
| 692 | return 0; |
| 693 | } |
| 694 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 695 | static int eqos_start_resets_stm32(struct udevice *dev) |
| 696 | { |
Christophe Roullier | 5177b31 | 2020-03-18 10:50:15 +0100 | [diff] [blame^] | 697 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 698 | int ret; |
| 699 | |
| 700 | debug("%s(dev=%p):\n", __func__, dev); |
| 701 | if (dm_gpio_is_valid(&eqos->phy_reset_gpio)) { |
| 702 | ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 1); |
| 703 | if (ret < 0) { |
| 704 | pr_err("dm_gpio_set_value(phy_reset, assert) failed: %d", |
| 705 | ret); |
| 706 | return ret; |
| 707 | } |
| 708 | |
| 709 | udelay(2); |
| 710 | |
| 711 | ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 0); |
| 712 | if (ret < 0) { |
| 713 | pr_err("dm_gpio_set_value(phy_reset, deassert) failed: %d", |
| 714 | ret); |
| 715 | return ret; |
| 716 | } |
| 717 | } |
| 718 | debug("%s: OK\n", __func__); |
| 719 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 720 | return 0; |
| 721 | } |
| 722 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 723 | static int eqos_stop_resets_tegra186(struct udevice *dev) |
| 724 | { |
| 725 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 726 | |
| 727 | reset_assert(&eqos->reset_ctl); |
| 728 | dm_gpio_set_value(&eqos->phy_reset_gpio, 1); |
| 729 | |
| 730 | return 0; |
| 731 | } |
| 732 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 733 | static int eqos_stop_resets_stm32(struct udevice *dev) |
| 734 | { |
Christophe Roullier | 5177b31 | 2020-03-18 10:50:15 +0100 | [diff] [blame^] | 735 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 736 | int ret; |
| 737 | |
| 738 | if (dm_gpio_is_valid(&eqos->phy_reset_gpio)) { |
| 739 | ret = dm_gpio_set_value(&eqos->phy_reset_gpio, 1); |
| 740 | if (ret < 0) { |
| 741 | pr_err("dm_gpio_set_value(phy_reset, assert) failed: %d", |
| 742 | ret); |
| 743 | return ret; |
| 744 | } |
| 745 | } |
| 746 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 747 | return 0; |
| 748 | } |
| 749 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 750 | static int eqos_calibrate_pads_tegra186(struct udevice *dev) |
| 751 | { |
| 752 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 753 | int ret; |
| 754 | |
| 755 | debug("%s(dev=%p):\n", __func__, dev); |
| 756 | |
| 757 | setbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl, |
| 758 | EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD); |
| 759 | |
| 760 | udelay(1); |
| 761 | |
| 762 | setbits_le32(&eqos->tegra186_regs->auto_cal_config, |
| 763 | EQOS_AUTO_CAL_CONFIG_START | EQOS_AUTO_CAL_CONFIG_ENABLE); |
| 764 | |
Álvaro Fernández Rojas | 4826350 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 765 | ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status, |
| 766 | EQOS_AUTO_CAL_STATUS_ACTIVE, true, 10, false); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 767 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 768 | pr_err("calibrate didn't start"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 769 | goto failed; |
| 770 | } |
| 771 | |
Álvaro Fernández Rojas | 4826350 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 772 | ret = wait_for_bit_le32(&eqos->tegra186_regs->auto_cal_status, |
| 773 | EQOS_AUTO_CAL_STATUS_ACTIVE, false, 10, false); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 774 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 775 | pr_err("calibrate didn't finish"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 776 | goto failed; |
| 777 | } |
| 778 | |
| 779 | ret = 0; |
| 780 | |
| 781 | failed: |
| 782 | clrbits_le32(&eqos->tegra186_regs->sdmemcomppadctrl, |
| 783 | EQOS_SDMEMCOMPPADCTRL_PAD_E_INPUT_OR_E_PWRD); |
| 784 | |
| 785 | debug("%s: returns %d\n", __func__, ret); |
| 786 | |
| 787 | return ret; |
| 788 | } |
| 789 | |
| 790 | static int eqos_disable_calibration_tegra186(struct udevice *dev) |
| 791 | { |
| 792 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 793 | |
| 794 | debug("%s(dev=%p):\n", __func__, dev); |
| 795 | |
| 796 | clrbits_le32(&eqos->tegra186_regs->auto_cal_config, |
| 797 | EQOS_AUTO_CAL_CONFIG_ENABLE); |
| 798 | |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | static ulong eqos_get_tick_clk_rate_tegra186(struct udevice *dev) |
| 803 | { |
| 804 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 805 | |
| 806 | return clk_get_rate(&eqos->clk_slave_bus); |
| 807 | } |
| 808 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 809 | static ulong eqos_get_tick_clk_rate_stm32(struct udevice *dev) |
| 810 | { |
| 811 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 812 | |
| 813 | return clk_get_rate(&eqos->clk_master_bus); |
| 814 | } |
| 815 | |
| 816 | static int eqos_calibrate_pads_stm32(struct udevice *dev) |
| 817 | { |
| 818 | return 0; |
| 819 | } |
| 820 | |
| 821 | static int eqos_disable_calibration_stm32(struct udevice *dev) |
| 822 | { |
| 823 | return 0; |
| 824 | } |
| 825 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 826 | static int eqos_set_full_duplex(struct udevice *dev) |
| 827 | { |
| 828 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 829 | |
| 830 | debug("%s(dev=%p):\n", __func__, dev); |
| 831 | |
| 832 | setbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM); |
| 833 | |
| 834 | return 0; |
| 835 | } |
| 836 | |
| 837 | static int eqos_set_half_duplex(struct udevice *dev) |
| 838 | { |
| 839 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 840 | |
| 841 | debug("%s(dev=%p):\n", __func__, dev); |
| 842 | |
| 843 | clrbits_le32(&eqos->mac_regs->configuration, EQOS_MAC_CONFIGURATION_DM); |
| 844 | |
| 845 | /* WAR: Flush TX queue when switching to half-duplex */ |
| 846 | setbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 847 | EQOS_MTL_TXQ0_OPERATION_MODE_FTQ); |
| 848 | |
| 849 | return 0; |
| 850 | } |
| 851 | |
| 852 | static int eqos_set_gmii_speed(struct udevice *dev) |
| 853 | { |
| 854 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 855 | |
| 856 | debug("%s(dev=%p):\n", __func__, dev); |
| 857 | |
| 858 | clrbits_le32(&eqos->mac_regs->configuration, |
| 859 | EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES); |
| 860 | |
| 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | static int eqos_set_mii_speed_100(struct udevice *dev) |
| 865 | { |
| 866 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 867 | |
| 868 | debug("%s(dev=%p):\n", __func__, dev); |
| 869 | |
| 870 | setbits_le32(&eqos->mac_regs->configuration, |
| 871 | EQOS_MAC_CONFIGURATION_PS | EQOS_MAC_CONFIGURATION_FES); |
| 872 | |
| 873 | return 0; |
| 874 | } |
| 875 | |
| 876 | static int eqos_set_mii_speed_10(struct udevice *dev) |
| 877 | { |
| 878 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 879 | |
| 880 | debug("%s(dev=%p):\n", __func__, dev); |
| 881 | |
| 882 | clrsetbits_le32(&eqos->mac_regs->configuration, |
| 883 | EQOS_MAC_CONFIGURATION_FES, EQOS_MAC_CONFIGURATION_PS); |
| 884 | |
| 885 | return 0; |
| 886 | } |
| 887 | |
| 888 | static int eqos_set_tx_clk_speed_tegra186(struct udevice *dev) |
| 889 | { |
| 890 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 891 | ulong rate; |
| 892 | int ret; |
| 893 | |
| 894 | debug("%s(dev=%p):\n", __func__, dev); |
| 895 | |
| 896 | switch (eqos->phy->speed) { |
| 897 | case SPEED_1000: |
| 898 | rate = 125 * 1000 * 1000; |
| 899 | break; |
| 900 | case SPEED_100: |
| 901 | rate = 25 * 1000 * 1000; |
| 902 | break; |
| 903 | case SPEED_10: |
| 904 | rate = 2.5 * 1000 * 1000; |
| 905 | break; |
| 906 | default: |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 907 | pr_err("invalid speed %d", eqos->phy->speed); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 908 | return -EINVAL; |
| 909 | } |
| 910 | |
| 911 | ret = clk_set_rate(&eqos->clk_tx, rate); |
| 912 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 913 | pr_err("clk_set_rate(tx_clk, %lu) failed: %d", rate, ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 914 | return ret; |
| 915 | } |
| 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 920 | static int eqos_set_tx_clk_speed_stm32(struct udevice *dev) |
| 921 | { |
| 922 | return 0; |
| 923 | } |
| 924 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 925 | static int eqos_adjust_link(struct udevice *dev) |
| 926 | { |
| 927 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 928 | int ret; |
| 929 | bool en_calibration; |
| 930 | |
| 931 | debug("%s(dev=%p):\n", __func__, dev); |
| 932 | |
| 933 | if (eqos->phy->duplex) |
| 934 | ret = eqos_set_full_duplex(dev); |
| 935 | else |
| 936 | ret = eqos_set_half_duplex(dev); |
| 937 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 938 | pr_err("eqos_set_*_duplex() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 939 | return ret; |
| 940 | } |
| 941 | |
| 942 | switch (eqos->phy->speed) { |
| 943 | case SPEED_1000: |
| 944 | en_calibration = true; |
| 945 | ret = eqos_set_gmii_speed(dev); |
| 946 | break; |
| 947 | case SPEED_100: |
| 948 | en_calibration = true; |
| 949 | ret = eqos_set_mii_speed_100(dev); |
| 950 | break; |
| 951 | case SPEED_10: |
| 952 | en_calibration = false; |
| 953 | ret = eqos_set_mii_speed_10(dev); |
| 954 | break; |
| 955 | default: |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 956 | pr_err("invalid speed %d", eqos->phy->speed); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 957 | return -EINVAL; |
| 958 | } |
| 959 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 960 | pr_err("eqos_set_*mii_speed*() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 961 | return ret; |
| 962 | } |
| 963 | |
| 964 | if (en_calibration) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 965 | ret = eqos->config->ops->eqos_calibrate_pads(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 966 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 967 | pr_err("eqos_calibrate_pads() failed: %d", |
| 968 | ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 969 | return ret; |
| 970 | } |
| 971 | } else { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 972 | ret = eqos->config->ops->eqos_disable_calibration(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 973 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 974 | pr_err("eqos_disable_calibration() failed: %d", |
| 975 | ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 976 | return ret; |
| 977 | } |
| 978 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 979 | ret = eqos->config->ops->eqos_set_tx_clk_speed(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 980 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 981 | pr_err("eqos_set_tx_clk_speed() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 982 | return ret; |
| 983 | } |
| 984 | |
| 985 | return 0; |
| 986 | } |
| 987 | |
| 988 | static int eqos_write_hwaddr(struct udevice *dev) |
| 989 | { |
| 990 | struct eth_pdata *plat = dev_get_platdata(dev); |
| 991 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 992 | uint32_t val; |
| 993 | |
| 994 | /* |
| 995 | * This function may be called before start() or after stop(). At that |
| 996 | * time, on at least some configurations of the EQoS HW, all clocks to |
| 997 | * the EQoS HW block will be stopped, and a reset signal applied. If |
| 998 | * any register access is attempted in this state, bus timeouts or CPU |
| 999 | * hangs may occur. This check prevents that. |
| 1000 | * |
| 1001 | * A simple solution to this problem would be to not implement |
| 1002 | * write_hwaddr(), since start() always writes the MAC address into HW |
| 1003 | * anyway. However, it is desirable to implement write_hwaddr() to |
| 1004 | * support the case of SW that runs subsequent to U-Boot which expects |
| 1005 | * the MAC address to already be programmed into the EQoS registers, |
| 1006 | * which must happen irrespective of whether the U-Boot user (or |
| 1007 | * scripts) actually made use of the EQoS device, and hence |
| 1008 | * irrespective of whether start() was ever called. |
| 1009 | * |
| 1010 | * Note that this requirement by subsequent SW is not valid for |
| 1011 | * Tegra186, and is likely not valid for any non-PCI instantiation of |
| 1012 | * the EQoS HW block. This function is implemented solely as |
| 1013 | * future-proofing with the expectation the driver will eventually be |
| 1014 | * ported to some system where the expectation above is true. |
| 1015 | */ |
| 1016 | if (!eqos->config->reg_access_always_ok && !eqos->reg_access_ok) |
| 1017 | return 0; |
| 1018 | |
| 1019 | /* Update the MAC address */ |
| 1020 | val = (plat->enetaddr[5] << 8) | |
| 1021 | (plat->enetaddr[4]); |
| 1022 | writel(val, &eqos->mac_regs->address0_high); |
| 1023 | val = (plat->enetaddr[3] << 24) | |
| 1024 | (plat->enetaddr[2] << 16) | |
| 1025 | (plat->enetaddr[1] << 8) | |
| 1026 | (plat->enetaddr[0]); |
| 1027 | writel(val, &eqos->mac_regs->address0_low); |
| 1028 | |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | static int eqos_start(struct udevice *dev) |
| 1033 | { |
| 1034 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1035 | int ret, i; |
| 1036 | ulong rate; |
| 1037 | u32 val, tx_fifo_sz, rx_fifo_sz, tqs, rqs, pbl; |
| 1038 | ulong last_rx_desc; |
| 1039 | |
| 1040 | debug("%s(dev=%p):\n", __func__, dev); |
| 1041 | |
| 1042 | eqos->tx_desc_idx = 0; |
| 1043 | eqos->rx_desc_idx = 0; |
| 1044 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1045 | ret = eqos->config->ops->eqos_start_clks(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1046 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1047 | pr_err("eqos_start_clks() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1048 | goto err; |
| 1049 | } |
| 1050 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1051 | ret = eqos->config->ops->eqos_start_resets(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1052 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1053 | pr_err("eqos_start_resets() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1054 | goto err_stop_clks; |
| 1055 | } |
| 1056 | |
| 1057 | udelay(10); |
| 1058 | |
| 1059 | eqos->reg_access_ok = true; |
| 1060 | |
Álvaro Fernández Rojas | 4826350 | 2018-01-23 17:14:55 +0100 | [diff] [blame] | 1061 | ret = wait_for_bit_le32(&eqos->dma_regs->mode, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1062 | EQOS_DMA_MODE_SWR, false, |
| 1063 | eqos->config->swr_wait, false); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1064 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1065 | pr_err("EQOS_DMA_MODE_SWR stuck"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1066 | goto err_stop_resets; |
| 1067 | } |
| 1068 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1069 | ret = eqos->config->ops->eqos_calibrate_pads(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1070 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1071 | pr_err("eqos_calibrate_pads() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1072 | goto err_stop_resets; |
| 1073 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1074 | rate = eqos->config->ops->eqos_get_tick_clk_rate(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1075 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1076 | val = (rate / 1000000) - 1; |
| 1077 | writel(val, &eqos->mac_regs->us_tic_counter); |
| 1078 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1079 | /* |
| 1080 | * if PHY was already connected and configured, |
| 1081 | * don't need to reconnect/reconfigure again |
| 1082 | */ |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1083 | if (!eqos->phy) { |
Marek Vasut | a9447c0 | 2019-12-18 07:48:50 +0100 | [diff] [blame] | 1084 | eqos->phy = phy_connect(eqos->mii, -1, dev, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1085 | eqos->config->interface(dev)); |
| 1086 | if (!eqos->phy) { |
| 1087 | pr_err("phy_connect() failed"); |
| 1088 | goto err_stop_resets; |
| 1089 | } |
| 1090 | ret = phy_config(eqos->phy); |
| 1091 | if (ret < 0) { |
| 1092 | pr_err("phy_config() failed: %d", ret); |
| 1093 | goto err_shutdown_phy; |
| 1094 | } |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1095 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1096 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1097 | ret = phy_startup(eqos->phy); |
| 1098 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1099 | pr_err("phy_startup() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1100 | goto err_shutdown_phy; |
| 1101 | } |
| 1102 | |
| 1103 | if (!eqos->phy->link) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1104 | pr_err("No link"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1105 | goto err_shutdown_phy; |
| 1106 | } |
| 1107 | |
| 1108 | ret = eqos_adjust_link(dev); |
| 1109 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1110 | pr_err("eqos_adjust_link() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1111 | goto err_shutdown_phy; |
| 1112 | } |
| 1113 | |
| 1114 | /* Configure MTL */ |
| 1115 | |
| 1116 | /* Enable Store and Forward mode for TX */ |
| 1117 | /* Program Tx operating mode */ |
| 1118 | setbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 1119 | EQOS_MTL_TXQ0_OPERATION_MODE_TSF | |
| 1120 | (EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_ENABLED << |
| 1121 | EQOS_MTL_TXQ0_OPERATION_MODE_TXQEN_SHIFT)); |
| 1122 | |
| 1123 | /* Transmit Queue weight */ |
| 1124 | writel(0x10, &eqos->mtl_regs->txq0_quantum_weight); |
| 1125 | |
| 1126 | /* Enable Store and Forward mode for RX, since no jumbo frame */ |
| 1127 | setbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 1128 | EQOS_MTL_RXQ0_OPERATION_MODE_RSF); |
| 1129 | |
| 1130 | /* Transmit/Receive queue fifo size; use all RAM for 1 queue */ |
| 1131 | val = readl(&eqos->mac_regs->hw_feature1); |
| 1132 | tx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_SHIFT) & |
| 1133 | EQOS_MAC_HW_FEATURE1_TXFIFOSIZE_MASK; |
| 1134 | rx_fifo_sz = (val >> EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_SHIFT) & |
| 1135 | EQOS_MAC_HW_FEATURE1_RXFIFOSIZE_MASK; |
| 1136 | |
| 1137 | /* |
| 1138 | * r/tx_fifo_sz is encoded as log2(n / 128). Undo that by shifting. |
| 1139 | * r/tqs is encoded as (n / 256) - 1. |
| 1140 | */ |
| 1141 | tqs = (128 << tx_fifo_sz) / 256 - 1; |
| 1142 | rqs = (128 << rx_fifo_sz) / 256 - 1; |
| 1143 | |
| 1144 | clrsetbits_le32(&eqos->mtl_regs->txq0_operation_mode, |
| 1145 | EQOS_MTL_TXQ0_OPERATION_MODE_TQS_MASK << |
| 1146 | EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT, |
| 1147 | tqs << EQOS_MTL_TXQ0_OPERATION_MODE_TQS_SHIFT); |
| 1148 | clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 1149 | EQOS_MTL_RXQ0_OPERATION_MODE_RQS_MASK << |
| 1150 | EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT, |
| 1151 | rqs << EQOS_MTL_RXQ0_OPERATION_MODE_RQS_SHIFT); |
| 1152 | |
| 1153 | /* Flow control used only if each channel gets 4KB or more FIFO */ |
| 1154 | if (rqs >= ((4096 / 256) - 1)) { |
| 1155 | u32 rfd, rfa; |
| 1156 | |
| 1157 | setbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 1158 | EQOS_MTL_RXQ0_OPERATION_MODE_EHFC); |
| 1159 | |
| 1160 | /* |
| 1161 | * Set Threshold for Activating Flow Contol space for min 2 |
| 1162 | * frames ie, (1500 * 1) = 1500 bytes. |
| 1163 | * |
| 1164 | * Set Threshold for Deactivating Flow Contol for space of |
| 1165 | * min 1 frame (frame size 1500bytes) in receive fifo |
| 1166 | */ |
| 1167 | if (rqs == ((4096 / 256) - 1)) { |
| 1168 | /* |
| 1169 | * This violates the above formula because of FIFO size |
| 1170 | * limit therefore overflow may occur inspite of this. |
| 1171 | */ |
| 1172 | rfd = 0x3; /* Full-3K */ |
| 1173 | rfa = 0x1; /* Full-1.5K */ |
| 1174 | } else if (rqs == ((8192 / 256) - 1)) { |
| 1175 | rfd = 0x6; /* Full-4K */ |
| 1176 | rfa = 0xa; /* Full-6K */ |
| 1177 | } else if (rqs == ((16384 / 256) - 1)) { |
| 1178 | rfd = 0x6; /* Full-4K */ |
| 1179 | rfa = 0x12; /* Full-10K */ |
| 1180 | } else { |
| 1181 | rfd = 0x6; /* Full-4K */ |
| 1182 | rfa = 0x1E; /* Full-16K */ |
| 1183 | } |
| 1184 | |
| 1185 | clrsetbits_le32(&eqos->mtl_regs->rxq0_operation_mode, |
| 1186 | (EQOS_MTL_RXQ0_OPERATION_MODE_RFD_MASK << |
| 1187 | EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) | |
| 1188 | (EQOS_MTL_RXQ0_OPERATION_MODE_RFA_MASK << |
| 1189 | EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT), |
| 1190 | (rfd << |
| 1191 | EQOS_MTL_RXQ0_OPERATION_MODE_RFD_SHIFT) | |
| 1192 | (rfa << |
| 1193 | EQOS_MTL_RXQ0_OPERATION_MODE_RFA_SHIFT)); |
| 1194 | } |
| 1195 | |
| 1196 | /* Configure MAC */ |
| 1197 | |
| 1198 | clrsetbits_le32(&eqos->mac_regs->rxq_ctrl0, |
| 1199 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_MASK << |
| 1200 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1201 | eqos->config->config_mac << |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1202 | EQOS_MAC_RXQ_CTRL0_RXQ0EN_SHIFT); |
| 1203 | |
| 1204 | /* Set TX flow control parameters */ |
| 1205 | /* Set Pause Time */ |
| 1206 | setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl, |
| 1207 | 0xffff << EQOS_MAC_Q0_TX_FLOW_CTRL_PT_SHIFT); |
| 1208 | /* Assign priority for TX flow control */ |
| 1209 | clrbits_le32(&eqos->mac_regs->txq_prty_map0, |
| 1210 | EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_MASK << |
| 1211 | EQOS_MAC_TXQ_PRTY_MAP0_PSTQ0_SHIFT); |
| 1212 | /* Assign priority for RX flow control */ |
| 1213 | clrbits_le32(&eqos->mac_regs->rxq_ctrl2, |
| 1214 | EQOS_MAC_RXQ_CTRL2_PSRQ0_MASK << |
| 1215 | EQOS_MAC_RXQ_CTRL2_PSRQ0_SHIFT); |
| 1216 | /* Enable flow control */ |
| 1217 | setbits_le32(&eqos->mac_regs->q0_tx_flow_ctrl, |
| 1218 | EQOS_MAC_Q0_TX_FLOW_CTRL_TFE); |
| 1219 | setbits_le32(&eqos->mac_regs->rx_flow_ctrl, |
| 1220 | EQOS_MAC_RX_FLOW_CTRL_RFE); |
| 1221 | |
| 1222 | clrsetbits_le32(&eqos->mac_regs->configuration, |
| 1223 | EQOS_MAC_CONFIGURATION_GPSLCE | |
| 1224 | EQOS_MAC_CONFIGURATION_WD | |
| 1225 | EQOS_MAC_CONFIGURATION_JD | |
| 1226 | EQOS_MAC_CONFIGURATION_JE, |
| 1227 | EQOS_MAC_CONFIGURATION_CST | |
| 1228 | EQOS_MAC_CONFIGURATION_ACS); |
| 1229 | |
| 1230 | eqos_write_hwaddr(dev); |
| 1231 | |
| 1232 | /* Configure DMA */ |
| 1233 | |
| 1234 | /* Enable OSP mode */ |
| 1235 | setbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1236 | EQOS_DMA_CH0_TX_CONTROL_OSP); |
| 1237 | |
| 1238 | /* RX buffer size. Must be a multiple of bus width */ |
| 1239 | clrsetbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1240 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_MASK << |
| 1241 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT, |
| 1242 | EQOS_MAX_PACKET_SIZE << |
| 1243 | EQOS_DMA_CH0_RX_CONTROL_RBSZ_SHIFT); |
| 1244 | |
| 1245 | setbits_le32(&eqos->dma_regs->ch0_control, |
| 1246 | EQOS_DMA_CH0_CONTROL_PBLX8); |
| 1247 | |
| 1248 | /* |
| 1249 | * Burst length must be < 1/2 FIFO size. |
| 1250 | * FIFO size in tqs is encoded as (n / 256) - 1. |
| 1251 | * Each burst is n * 8 (PBLX8) * 16 (AXI width) == 128 bytes. |
| 1252 | * Half of n * 256 is n * 128, so pbl == tqs, modulo the -1. |
| 1253 | */ |
| 1254 | pbl = tqs + 1; |
| 1255 | if (pbl > 32) |
| 1256 | pbl = 32; |
| 1257 | clrsetbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1258 | EQOS_DMA_CH0_TX_CONTROL_TXPBL_MASK << |
| 1259 | EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT, |
| 1260 | pbl << EQOS_DMA_CH0_TX_CONTROL_TXPBL_SHIFT); |
| 1261 | |
| 1262 | clrsetbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1263 | EQOS_DMA_CH0_RX_CONTROL_RXPBL_MASK << |
| 1264 | EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT, |
| 1265 | 8 << EQOS_DMA_CH0_RX_CONTROL_RXPBL_SHIFT); |
| 1266 | |
| 1267 | /* DMA performance configuration */ |
| 1268 | val = (2 << EQOS_DMA_SYSBUS_MODE_RD_OSR_LMT_SHIFT) | |
| 1269 | EQOS_DMA_SYSBUS_MODE_EAME | EQOS_DMA_SYSBUS_MODE_BLEN16 | |
| 1270 | EQOS_DMA_SYSBUS_MODE_BLEN8 | EQOS_DMA_SYSBUS_MODE_BLEN4; |
| 1271 | writel(val, &eqos->dma_regs->sysbus_mode); |
| 1272 | |
| 1273 | /* Set up descriptors */ |
| 1274 | |
| 1275 | memset(eqos->descs, 0, EQOS_DESCRIPTORS_SIZE); |
| 1276 | for (i = 0; i < EQOS_DESCRIPTORS_RX; i++) { |
| 1277 | struct eqos_desc *rx_desc = &(eqos->rx_descs[i]); |
| 1278 | rx_desc->des0 = (u32)(ulong)(eqos->rx_dma_buf + |
| 1279 | (i * EQOS_MAX_PACKET_SIZE)); |
| 1280 | rx_desc->des3 |= EQOS_DESC3_OWN | EQOS_DESC3_BUF1V; |
| 1281 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1282 | eqos->config->ops->eqos_flush_desc(eqos->descs); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1283 | |
| 1284 | writel(0, &eqos->dma_regs->ch0_txdesc_list_haddress); |
| 1285 | writel((ulong)eqos->tx_descs, &eqos->dma_regs->ch0_txdesc_list_address); |
| 1286 | writel(EQOS_DESCRIPTORS_TX - 1, |
| 1287 | &eqos->dma_regs->ch0_txdesc_ring_length); |
| 1288 | |
| 1289 | writel(0, &eqos->dma_regs->ch0_rxdesc_list_haddress); |
| 1290 | writel((ulong)eqos->rx_descs, &eqos->dma_regs->ch0_rxdesc_list_address); |
| 1291 | writel(EQOS_DESCRIPTORS_RX - 1, |
| 1292 | &eqos->dma_regs->ch0_rxdesc_ring_length); |
| 1293 | |
| 1294 | /* Enable everything */ |
| 1295 | |
| 1296 | setbits_le32(&eqos->mac_regs->configuration, |
| 1297 | EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE); |
| 1298 | |
| 1299 | setbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1300 | EQOS_DMA_CH0_TX_CONTROL_ST); |
| 1301 | setbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1302 | EQOS_DMA_CH0_RX_CONTROL_SR); |
| 1303 | |
| 1304 | /* TX tail pointer not written until we need to TX a packet */ |
| 1305 | /* |
| 1306 | * Point RX tail pointer at last descriptor. Ideally, we'd point at the |
| 1307 | * first descriptor, implying all descriptors were available. However, |
| 1308 | * that's not distinguishable from none of the descriptors being |
| 1309 | * available. |
| 1310 | */ |
| 1311 | last_rx_desc = (ulong)&(eqos->rx_descs[(EQOS_DESCRIPTORS_RX - 1)]); |
| 1312 | writel(last_rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer); |
| 1313 | |
| 1314 | eqos->started = true; |
| 1315 | |
| 1316 | debug("%s: OK\n", __func__); |
| 1317 | return 0; |
| 1318 | |
| 1319 | err_shutdown_phy: |
| 1320 | phy_shutdown(eqos->phy); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1321 | err_stop_resets: |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1322 | eqos->config->ops->eqos_stop_resets(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1323 | err_stop_clks: |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1324 | eqos->config->ops->eqos_stop_clks(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1325 | err: |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1326 | pr_err("FAILED: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1327 | return ret; |
| 1328 | } |
| 1329 | |
Patrick Delaunay | 50d86e5 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1330 | static void eqos_stop(struct udevice *dev) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1331 | { |
| 1332 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1333 | int i; |
| 1334 | |
| 1335 | debug("%s(dev=%p):\n", __func__, dev); |
| 1336 | |
| 1337 | if (!eqos->started) |
| 1338 | return; |
| 1339 | eqos->started = false; |
| 1340 | eqos->reg_access_ok = false; |
| 1341 | |
| 1342 | /* Disable TX DMA */ |
| 1343 | clrbits_le32(&eqos->dma_regs->ch0_tx_control, |
| 1344 | EQOS_DMA_CH0_TX_CONTROL_ST); |
| 1345 | |
| 1346 | /* Wait for TX all packets to drain out of MTL */ |
| 1347 | for (i = 0; i < 1000000; i++) { |
| 1348 | u32 val = readl(&eqos->mtl_regs->txq0_debug); |
| 1349 | u32 trcsts = (val >> EQOS_MTL_TXQ0_DEBUG_TRCSTS_SHIFT) & |
| 1350 | EQOS_MTL_TXQ0_DEBUG_TRCSTS_MASK; |
| 1351 | u32 txqsts = val & EQOS_MTL_TXQ0_DEBUG_TXQSTS; |
| 1352 | if ((trcsts != 1) && (!txqsts)) |
| 1353 | break; |
| 1354 | } |
| 1355 | |
| 1356 | /* Turn off MAC TX and RX */ |
| 1357 | clrbits_le32(&eqos->mac_regs->configuration, |
| 1358 | EQOS_MAC_CONFIGURATION_TE | EQOS_MAC_CONFIGURATION_RE); |
| 1359 | |
| 1360 | /* Wait for all RX packets to drain out of MTL */ |
| 1361 | for (i = 0; i < 1000000; i++) { |
| 1362 | u32 val = readl(&eqos->mtl_regs->rxq0_debug); |
| 1363 | u32 prxq = (val >> EQOS_MTL_RXQ0_DEBUG_PRXQ_SHIFT) & |
| 1364 | EQOS_MTL_RXQ0_DEBUG_PRXQ_MASK; |
| 1365 | u32 rxqsts = (val >> EQOS_MTL_RXQ0_DEBUG_RXQSTS_SHIFT) & |
| 1366 | EQOS_MTL_RXQ0_DEBUG_RXQSTS_MASK; |
| 1367 | if ((!prxq) && (!rxqsts)) |
| 1368 | break; |
| 1369 | } |
| 1370 | |
| 1371 | /* Turn off RX DMA */ |
| 1372 | clrbits_le32(&eqos->dma_regs->ch0_rx_control, |
| 1373 | EQOS_DMA_CH0_RX_CONTROL_SR); |
| 1374 | |
| 1375 | if (eqos->phy) { |
| 1376 | phy_shutdown(eqos->phy); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1377 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1378 | eqos->config->ops->eqos_stop_resets(dev); |
| 1379 | eqos->config->ops->eqos_stop_clks(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1380 | |
| 1381 | debug("%s: OK\n", __func__); |
| 1382 | } |
| 1383 | |
Patrick Delaunay | 50d86e5 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1384 | static int eqos_send(struct udevice *dev, void *packet, int length) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1385 | { |
| 1386 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1387 | struct eqos_desc *tx_desc; |
| 1388 | int i; |
| 1389 | |
| 1390 | debug("%s(dev=%p, packet=%p, length=%d):\n", __func__, dev, packet, |
| 1391 | length); |
| 1392 | |
| 1393 | memcpy(eqos->tx_dma_buf, packet, length); |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1394 | eqos->config->ops->eqos_flush_buffer(eqos->tx_dma_buf, length); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1395 | |
| 1396 | tx_desc = &(eqos->tx_descs[eqos->tx_desc_idx]); |
| 1397 | eqos->tx_desc_idx++; |
| 1398 | eqos->tx_desc_idx %= EQOS_DESCRIPTORS_TX; |
| 1399 | |
| 1400 | tx_desc->des0 = (ulong)eqos->tx_dma_buf; |
| 1401 | tx_desc->des1 = 0; |
| 1402 | tx_desc->des2 = length; |
| 1403 | /* |
| 1404 | * Make sure that if HW sees the _OWN write below, it will see all the |
| 1405 | * writes to the rest of the descriptor too. |
| 1406 | */ |
| 1407 | mb(); |
| 1408 | 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] | 1409 | eqos->config->ops->eqos_flush_desc(tx_desc); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1410 | |
| 1411 | writel((ulong)(tx_desc + 1), &eqos->dma_regs->ch0_txdesc_tail_pointer); |
| 1412 | |
| 1413 | for (i = 0; i < 1000000; i++) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1414 | eqos->config->ops->eqos_inval_desc(tx_desc); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1415 | if (!(readl(&tx_desc->des3) & EQOS_DESC3_OWN)) |
| 1416 | return 0; |
| 1417 | udelay(1); |
| 1418 | } |
| 1419 | |
| 1420 | debug("%s: TX timeout\n", __func__); |
| 1421 | |
| 1422 | return -ETIMEDOUT; |
| 1423 | } |
| 1424 | |
Patrick Delaunay | 50d86e5 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1425 | static int eqos_recv(struct udevice *dev, int flags, uchar **packetp) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1426 | { |
| 1427 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1428 | struct eqos_desc *rx_desc; |
| 1429 | int length; |
| 1430 | |
| 1431 | debug("%s(dev=%p, flags=%x):\n", __func__, dev, flags); |
| 1432 | |
| 1433 | rx_desc = &(eqos->rx_descs[eqos->rx_desc_idx]); |
| 1434 | if (rx_desc->des3 & EQOS_DESC3_OWN) { |
| 1435 | debug("%s: RX packet not available\n", __func__); |
| 1436 | return -EAGAIN; |
| 1437 | } |
| 1438 | |
| 1439 | *packetp = eqos->rx_dma_buf + |
| 1440 | (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE); |
| 1441 | length = rx_desc->des3 & 0x7fff; |
| 1442 | debug("%s: *packetp=%p, length=%d\n", __func__, *packetp, length); |
| 1443 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1444 | eqos->config->ops->eqos_inval_buffer(*packetp, length); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1445 | |
| 1446 | return length; |
| 1447 | } |
| 1448 | |
Patrick Delaunay | 50d86e5 | 2019-08-01 11:29:02 +0200 | [diff] [blame] | 1449 | static int eqos_free_pkt(struct udevice *dev, uchar *packet, int length) |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1450 | { |
| 1451 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1452 | uchar *packet_expected; |
| 1453 | struct eqos_desc *rx_desc; |
| 1454 | |
| 1455 | debug("%s(packet=%p, length=%d)\n", __func__, packet, length); |
| 1456 | |
| 1457 | packet_expected = eqos->rx_dma_buf + |
| 1458 | (eqos->rx_desc_idx * EQOS_MAX_PACKET_SIZE); |
| 1459 | if (packet != packet_expected) { |
| 1460 | debug("%s: Unexpected packet (expected %p)\n", __func__, |
| 1461 | packet_expected); |
| 1462 | return -EINVAL; |
| 1463 | } |
| 1464 | |
| 1465 | rx_desc = &(eqos->rx_descs[eqos->rx_desc_idx]); |
| 1466 | rx_desc->des0 = (u32)(ulong)packet; |
| 1467 | rx_desc->des1 = 0; |
| 1468 | rx_desc->des2 = 0; |
| 1469 | /* |
| 1470 | * Make sure that if HW sees the _OWN write below, it will see all the |
| 1471 | * writes to the rest of the descriptor too. |
| 1472 | */ |
| 1473 | mb(); |
| 1474 | rx_desc->des3 |= EQOS_DESC3_OWN | EQOS_DESC3_BUF1V; |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1475 | eqos->config->ops->eqos_flush_desc(rx_desc); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1476 | |
| 1477 | writel((ulong)rx_desc, &eqos->dma_regs->ch0_rxdesc_tail_pointer); |
| 1478 | |
| 1479 | eqos->rx_desc_idx++; |
| 1480 | eqos->rx_desc_idx %= EQOS_DESCRIPTORS_RX; |
| 1481 | |
| 1482 | return 0; |
| 1483 | } |
| 1484 | |
| 1485 | static int eqos_probe_resources_core(struct udevice *dev) |
| 1486 | { |
| 1487 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1488 | int ret; |
| 1489 | |
| 1490 | debug("%s(dev=%p):\n", __func__, dev); |
| 1491 | |
| 1492 | eqos->descs = eqos_alloc_descs(EQOS_DESCRIPTORS_TX + |
| 1493 | EQOS_DESCRIPTORS_RX); |
| 1494 | if (!eqos->descs) { |
| 1495 | debug("%s: eqos_alloc_descs() failed\n", __func__); |
| 1496 | ret = -ENOMEM; |
| 1497 | goto err; |
| 1498 | } |
| 1499 | eqos->tx_descs = (struct eqos_desc *)eqos->descs; |
| 1500 | eqos->rx_descs = (eqos->tx_descs + EQOS_DESCRIPTORS_TX); |
| 1501 | debug("%s: tx_descs=%p, rx_descs=%p\n", __func__, eqos->tx_descs, |
| 1502 | eqos->rx_descs); |
| 1503 | |
| 1504 | eqos->tx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_MAX_PACKET_SIZE); |
| 1505 | if (!eqos->tx_dma_buf) { |
| 1506 | debug("%s: memalign(tx_dma_buf) failed\n", __func__); |
| 1507 | ret = -ENOMEM; |
| 1508 | goto err_free_descs; |
| 1509 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1510 | debug("%s: tx_dma_buf=%p\n", __func__, eqos->tx_dma_buf); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1511 | |
| 1512 | eqos->rx_dma_buf = memalign(EQOS_BUFFER_ALIGN, EQOS_RX_BUFFER_SIZE); |
| 1513 | if (!eqos->rx_dma_buf) { |
| 1514 | debug("%s: memalign(rx_dma_buf) failed\n", __func__); |
| 1515 | ret = -ENOMEM; |
| 1516 | goto err_free_tx_dma_buf; |
| 1517 | } |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1518 | debug("%s: rx_dma_buf=%p\n", __func__, eqos->rx_dma_buf); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1519 | |
| 1520 | eqos->rx_pkt = malloc(EQOS_MAX_PACKET_SIZE); |
| 1521 | if (!eqos->rx_pkt) { |
| 1522 | debug("%s: malloc(rx_pkt) failed\n", __func__); |
| 1523 | ret = -ENOMEM; |
| 1524 | goto err_free_rx_dma_buf; |
| 1525 | } |
| 1526 | debug("%s: rx_pkt=%p\n", __func__, eqos->rx_pkt); |
| 1527 | |
| 1528 | debug("%s: OK\n", __func__); |
| 1529 | return 0; |
| 1530 | |
| 1531 | err_free_rx_dma_buf: |
| 1532 | free(eqos->rx_dma_buf); |
| 1533 | err_free_tx_dma_buf: |
| 1534 | free(eqos->tx_dma_buf); |
| 1535 | err_free_descs: |
| 1536 | eqos_free_descs(eqos->descs); |
| 1537 | err: |
| 1538 | |
| 1539 | debug("%s: returns %d\n", __func__, ret); |
| 1540 | return ret; |
| 1541 | } |
| 1542 | |
| 1543 | static int eqos_remove_resources_core(struct udevice *dev) |
| 1544 | { |
| 1545 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1546 | |
| 1547 | debug("%s(dev=%p):\n", __func__, dev); |
| 1548 | |
| 1549 | free(eqos->rx_pkt); |
| 1550 | free(eqos->rx_dma_buf); |
| 1551 | free(eqos->tx_dma_buf); |
| 1552 | eqos_free_descs(eqos->descs); |
| 1553 | |
| 1554 | debug("%s: OK\n", __func__); |
| 1555 | return 0; |
| 1556 | } |
| 1557 | |
| 1558 | static int eqos_probe_resources_tegra186(struct udevice *dev) |
| 1559 | { |
| 1560 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1561 | int ret; |
| 1562 | |
| 1563 | debug("%s(dev=%p):\n", __func__, dev); |
| 1564 | |
| 1565 | ret = reset_get_by_name(dev, "eqos", &eqos->reset_ctl); |
| 1566 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1567 | pr_err("reset_get_by_name(rst) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1568 | return ret; |
| 1569 | } |
| 1570 | |
| 1571 | ret = gpio_request_by_name(dev, "phy-reset-gpios", 0, |
| 1572 | &eqos->phy_reset_gpio, |
| 1573 | GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); |
| 1574 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1575 | pr_err("gpio_request_by_name(phy reset) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1576 | goto err_free_reset_eqos; |
| 1577 | } |
| 1578 | |
| 1579 | ret = clk_get_by_name(dev, "slave_bus", &eqos->clk_slave_bus); |
| 1580 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1581 | pr_err("clk_get_by_name(slave_bus) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1582 | goto err_free_gpio_phy_reset; |
| 1583 | } |
| 1584 | |
| 1585 | ret = clk_get_by_name(dev, "master_bus", &eqos->clk_master_bus); |
| 1586 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1587 | pr_err("clk_get_by_name(master_bus) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1588 | goto err_free_clk_slave_bus; |
| 1589 | } |
| 1590 | |
| 1591 | ret = clk_get_by_name(dev, "rx", &eqos->clk_rx); |
| 1592 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1593 | pr_err("clk_get_by_name(rx) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1594 | goto err_free_clk_master_bus; |
| 1595 | } |
| 1596 | |
| 1597 | ret = clk_get_by_name(dev, "ptp_ref", &eqos->clk_ptp_ref); |
| 1598 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1599 | pr_err("clk_get_by_name(ptp_ref) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1600 | goto err_free_clk_rx; |
| 1601 | return ret; |
| 1602 | } |
| 1603 | |
| 1604 | ret = clk_get_by_name(dev, "tx", &eqos->clk_tx); |
| 1605 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1606 | pr_err("clk_get_by_name(tx) failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1607 | goto err_free_clk_ptp_ref; |
| 1608 | } |
| 1609 | |
| 1610 | debug("%s: OK\n", __func__); |
| 1611 | return 0; |
| 1612 | |
| 1613 | err_free_clk_ptp_ref: |
| 1614 | clk_free(&eqos->clk_ptp_ref); |
| 1615 | err_free_clk_rx: |
| 1616 | clk_free(&eqos->clk_rx); |
| 1617 | err_free_clk_master_bus: |
| 1618 | clk_free(&eqos->clk_master_bus); |
| 1619 | err_free_clk_slave_bus: |
| 1620 | clk_free(&eqos->clk_slave_bus); |
| 1621 | err_free_gpio_phy_reset: |
| 1622 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1623 | err_free_reset_eqos: |
| 1624 | reset_free(&eqos->reset_ctl); |
| 1625 | |
| 1626 | debug("%s: returns %d\n", __func__, ret); |
| 1627 | return ret; |
| 1628 | } |
| 1629 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1630 | /* board-specific Ethernet Interface initializations. */ |
Patrick Delaunay | 53e3d52 | 2019-08-01 11:29:03 +0200 | [diff] [blame] | 1631 | __weak int board_interface_eth_init(struct udevice *dev, |
| 1632 | phy_interface_t interface_type) |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1633 | { |
| 1634 | return 0; |
| 1635 | } |
| 1636 | |
| 1637 | static int eqos_probe_resources_stm32(struct udevice *dev) |
| 1638 | { |
| 1639 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1640 | int ret; |
| 1641 | phy_interface_t interface; |
Christophe Roullier | 5177b31 | 2020-03-18 10:50:15 +0100 | [diff] [blame^] | 1642 | struct ofnode_phandle_args phandle_args; |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1643 | |
| 1644 | debug("%s(dev=%p):\n", __func__, dev); |
| 1645 | |
| 1646 | interface = eqos->config->interface(dev); |
| 1647 | |
| 1648 | if (interface == PHY_INTERFACE_MODE_NONE) { |
| 1649 | pr_err("Invalid PHY interface\n"); |
| 1650 | return -EINVAL; |
| 1651 | } |
| 1652 | |
Patrick Delaunay | 53e3d52 | 2019-08-01 11:29:03 +0200 | [diff] [blame] | 1653 | ret = board_interface_eth_init(dev, interface); |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1654 | if (ret) |
| 1655 | return -EINVAL; |
| 1656 | |
| 1657 | ret = clk_get_by_name(dev, "stmmaceth", &eqos->clk_master_bus); |
| 1658 | if (ret) { |
| 1659 | pr_err("clk_get_by_name(master_bus) failed: %d", ret); |
| 1660 | goto err_probe; |
| 1661 | } |
| 1662 | |
| 1663 | ret = clk_get_by_name(dev, "mac-clk-rx", &eqos->clk_rx); |
| 1664 | if (ret) { |
| 1665 | pr_err("clk_get_by_name(rx) failed: %d", ret); |
| 1666 | goto err_free_clk_master_bus; |
| 1667 | } |
| 1668 | |
| 1669 | ret = clk_get_by_name(dev, "mac-clk-tx", &eqos->clk_tx); |
| 1670 | if (ret) { |
| 1671 | pr_err("clk_get_by_name(tx) failed: %d", ret); |
| 1672 | goto err_free_clk_rx; |
| 1673 | } |
| 1674 | |
| 1675 | /* Get ETH_CLK clocks (optional) */ |
| 1676 | ret = clk_get_by_name(dev, "eth-ck", &eqos->clk_ck); |
| 1677 | if (ret) |
| 1678 | pr_warn("No phy clock provided %d", ret); |
| 1679 | |
Christophe Roullier | 5177b31 | 2020-03-18 10:50:15 +0100 | [diff] [blame^] | 1680 | ret = dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, |
| 1681 | &phandle_args); |
| 1682 | if (!ret) { |
| 1683 | /* search "reset-gpios" in phy node */ |
| 1684 | ret = gpio_request_by_name_nodev(phandle_args.node, |
| 1685 | "reset-gpios", 0, |
| 1686 | &eqos->phy_reset_gpio, |
| 1687 | GPIOD_IS_OUT | |
| 1688 | GPIOD_IS_OUT_ACTIVE); |
| 1689 | if (ret) |
| 1690 | pr_warn("gpio_request_by_name(phy reset) not provided %d", |
| 1691 | ret); |
| 1692 | } |
| 1693 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1694 | debug("%s: OK\n", __func__); |
| 1695 | return 0; |
| 1696 | |
| 1697 | err_free_clk_rx: |
| 1698 | clk_free(&eqos->clk_rx); |
| 1699 | err_free_clk_master_bus: |
| 1700 | clk_free(&eqos->clk_master_bus); |
| 1701 | err_probe: |
| 1702 | |
| 1703 | debug("%s: returns %d\n", __func__, ret); |
| 1704 | return ret; |
| 1705 | } |
| 1706 | |
| 1707 | static phy_interface_t eqos_get_interface_stm32(struct udevice *dev) |
| 1708 | { |
| 1709 | const char *phy_mode; |
| 1710 | phy_interface_t interface = PHY_INTERFACE_MODE_NONE; |
| 1711 | |
| 1712 | debug("%s(dev=%p):\n", __func__, dev); |
| 1713 | |
| 1714 | phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", |
| 1715 | NULL); |
| 1716 | if (phy_mode) |
| 1717 | interface = phy_get_interface_by_name(phy_mode); |
| 1718 | |
| 1719 | return interface; |
| 1720 | } |
| 1721 | |
| 1722 | static phy_interface_t eqos_get_interface_tegra186(struct udevice *dev) |
| 1723 | { |
| 1724 | return PHY_INTERFACE_MODE_MII; |
| 1725 | } |
| 1726 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1727 | static int eqos_remove_resources_tegra186(struct udevice *dev) |
| 1728 | { |
| 1729 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1730 | |
| 1731 | debug("%s(dev=%p):\n", __func__, dev); |
| 1732 | |
| 1733 | clk_free(&eqos->clk_tx); |
| 1734 | clk_free(&eqos->clk_ptp_ref); |
| 1735 | clk_free(&eqos->clk_rx); |
| 1736 | clk_free(&eqos->clk_slave_bus); |
| 1737 | clk_free(&eqos->clk_master_bus); |
| 1738 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1739 | reset_free(&eqos->reset_ctl); |
| 1740 | |
| 1741 | debug("%s: OK\n", __func__); |
| 1742 | return 0; |
| 1743 | } |
| 1744 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1745 | static int eqos_remove_resources_stm32(struct udevice *dev) |
| 1746 | { |
| 1747 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1748 | |
| 1749 | debug("%s(dev=%p):\n", __func__, dev); |
| 1750 | |
| 1751 | clk_free(&eqos->clk_tx); |
| 1752 | clk_free(&eqos->clk_rx); |
| 1753 | clk_free(&eqos->clk_master_bus); |
| 1754 | if (clk_valid(&eqos->clk_ck)) |
| 1755 | clk_free(&eqos->clk_ck); |
| 1756 | |
Christophe Roullier | 5177b31 | 2020-03-18 10:50:15 +0100 | [diff] [blame^] | 1757 | if (dm_gpio_is_valid(&eqos->phy_reset_gpio)) |
| 1758 | dm_gpio_free(dev, &eqos->phy_reset_gpio); |
| 1759 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1760 | debug("%s: OK\n", __func__); |
| 1761 | return 0; |
| 1762 | } |
| 1763 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1764 | static int eqos_probe(struct udevice *dev) |
| 1765 | { |
| 1766 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1767 | int ret; |
| 1768 | |
| 1769 | debug("%s(dev=%p):\n", __func__, dev); |
| 1770 | |
| 1771 | eqos->dev = dev; |
| 1772 | eqos->config = (void *)dev_get_driver_data(dev); |
| 1773 | |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 1774 | eqos->regs = devfdt_get_addr(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1775 | if (eqos->regs == FDT_ADDR_T_NONE) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1776 | pr_err("devfdt_get_addr() failed"); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1777 | return -ENODEV; |
| 1778 | } |
| 1779 | eqos->mac_regs = (void *)(eqos->regs + EQOS_MAC_REGS_BASE); |
| 1780 | eqos->mtl_regs = (void *)(eqos->regs + EQOS_MTL_REGS_BASE); |
| 1781 | eqos->dma_regs = (void *)(eqos->regs + EQOS_DMA_REGS_BASE); |
| 1782 | eqos->tegra186_regs = (void *)(eqos->regs + EQOS_TEGRA186_REGS_BASE); |
| 1783 | |
| 1784 | ret = eqos_probe_resources_core(dev); |
| 1785 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1786 | pr_err("eqos_probe_resources_core() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1787 | return ret; |
| 1788 | } |
| 1789 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1790 | ret = eqos->config->ops->eqos_probe_resources(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1791 | if (ret < 0) { |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1792 | pr_err("eqos_probe_resources() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1793 | goto err_remove_resources_core; |
| 1794 | } |
| 1795 | |
| 1796 | eqos->mii = mdio_alloc(); |
| 1797 | if (!eqos->mii) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1798 | pr_err("mdio_alloc() failed"); |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1799 | ret = -ENOMEM; |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1800 | goto err_remove_resources_tegra; |
| 1801 | } |
| 1802 | eqos->mii->read = eqos_mdio_read; |
| 1803 | eqos->mii->write = eqos_mdio_write; |
| 1804 | eqos->mii->priv = eqos; |
| 1805 | strcpy(eqos->mii->name, dev->name); |
| 1806 | |
| 1807 | ret = mdio_register(eqos->mii); |
| 1808 | if (ret < 0) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 1809 | pr_err("mdio_register() failed: %d", ret); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1810 | goto err_free_mdio; |
| 1811 | } |
| 1812 | |
| 1813 | debug("%s: OK\n", __func__); |
| 1814 | return 0; |
| 1815 | |
| 1816 | err_free_mdio: |
| 1817 | mdio_free(eqos->mii); |
| 1818 | err_remove_resources_tegra: |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1819 | eqos->config->ops->eqos_remove_resources(dev); |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1820 | err_remove_resources_core: |
| 1821 | eqos_remove_resources_core(dev); |
| 1822 | |
| 1823 | debug("%s: returns %d\n", __func__, ret); |
| 1824 | return ret; |
| 1825 | } |
| 1826 | |
| 1827 | static int eqos_remove(struct udevice *dev) |
| 1828 | { |
| 1829 | struct eqos_priv *eqos = dev_get_priv(dev); |
| 1830 | |
| 1831 | debug("%s(dev=%p):\n", __func__, dev); |
| 1832 | |
| 1833 | mdio_unregister(eqos->mii); |
| 1834 | mdio_free(eqos->mii); |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1835 | eqos->config->ops->eqos_remove_resources(dev); |
| 1836 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1837 | eqos_probe_resources_core(dev); |
| 1838 | |
| 1839 | debug("%s: OK\n", __func__); |
| 1840 | return 0; |
| 1841 | } |
| 1842 | |
| 1843 | static const struct eth_ops eqos_ops = { |
| 1844 | .start = eqos_start, |
| 1845 | .stop = eqos_stop, |
| 1846 | .send = eqos_send, |
| 1847 | .recv = eqos_recv, |
| 1848 | .free_pkt = eqos_free_pkt, |
| 1849 | .write_hwaddr = eqos_write_hwaddr, |
| 1850 | }; |
| 1851 | |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1852 | static struct eqos_ops eqos_tegra186_ops = { |
| 1853 | .eqos_inval_desc = eqos_inval_desc_tegra186, |
| 1854 | .eqos_flush_desc = eqos_flush_desc_tegra186, |
| 1855 | .eqos_inval_buffer = eqos_inval_buffer_tegra186, |
| 1856 | .eqos_flush_buffer = eqos_flush_buffer_tegra186, |
| 1857 | .eqos_probe_resources = eqos_probe_resources_tegra186, |
| 1858 | .eqos_remove_resources = eqos_remove_resources_tegra186, |
| 1859 | .eqos_stop_resets = eqos_stop_resets_tegra186, |
| 1860 | .eqos_start_resets = eqos_start_resets_tegra186, |
| 1861 | .eqos_stop_clks = eqos_stop_clks_tegra186, |
| 1862 | .eqos_start_clks = eqos_start_clks_tegra186, |
| 1863 | .eqos_calibrate_pads = eqos_calibrate_pads_tegra186, |
| 1864 | .eqos_disable_calibration = eqos_disable_calibration_tegra186, |
| 1865 | .eqos_set_tx_clk_speed = eqos_set_tx_clk_speed_tegra186, |
| 1866 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_tegra186 |
| 1867 | }; |
| 1868 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1869 | static const struct eqos_config eqos_tegra186_config = { |
| 1870 | .reg_access_always_ok = false, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1871 | .mdio_wait = 10, |
| 1872 | .swr_wait = 10, |
| 1873 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB, |
| 1874 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_20_35, |
| 1875 | .interface = eqos_get_interface_tegra186, |
| 1876 | .ops = &eqos_tegra186_ops |
| 1877 | }; |
| 1878 | |
| 1879 | static struct eqos_ops eqos_stm32_ops = { |
| 1880 | .eqos_inval_desc = eqos_inval_desc_stm32, |
| 1881 | .eqos_flush_desc = eqos_flush_desc_stm32, |
| 1882 | .eqos_inval_buffer = eqos_inval_buffer_stm32, |
| 1883 | .eqos_flush_buffer = eqos_flush_buffer_stm32, |
| 1884 | .eqos_probe_resources = eqos_probe_resources_stm32, |
| 1885 | .eqos_remove_resources = eqos_remove_resources_stm32, |
| 1886 | .eqos_stop_resets = eqos_stop_resets_stm32, |
| 1887 | .eqos_start_resets = eqos_start_resets_stm32, |
| 1888 | .eqos_stop_clks = eqos_stop_clks_stm32, |
| 1889 | .eqos_start_clks = eqos_start_clks_stm32, |
| 1890 | .eqos_calibrate_pads = eqos_calibrate_pads_stm32, |
| 1891 | .eqos_disable_calibration = eqos_disable_calibration_stm32, |
| 1892 | .eqos_set_tx_clk_speed = eqos_set_tx_clk_speed_stm32, |
| 1893 | .eqos_get_tick_clk_rate = eqos_get_tick_clk_rate_stm32 |
| 1894 | }; |
| 1895 | |
| 1896 | static const struct eqos_config eqos_stm32_config = { |
| 1897 | .reg_access_always_ok = false, |
| 1898 | .mdio_wait = 10000, |
| 1899 | .swr_wait = 50, |
| 1900 | .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV, |
| 1901 | .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, |
| 1902 | .interface = eqos_get_interface_stm32, |
| 1903 | .ops = &eqos_stm32_ops |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1904 | }; |
| 1905 | |
| 1906 | static const struct udevice_id eqos_ids[] = { |
| 1907 | { |
| 1908 | .compatible = "nvidia,tegra186-eqos", |
| 1909 | .data = (ulong)&eqos_tegra186_config |
| 1910 | }, |
Christophe Roullier | ac2d4ef | 2019-05-17 15:08:44 +0200 | [diff] [blame] | 1911 | { |
| 1912 | .compatible = "snps,dwmac-4.20a", |
| 1913 | .data = (ulong)&eqos_stm32_config |
| 1914 | }, |
| 1915 | |
Stephen Warren | ba4dfef | 2016-10-21 14:46:47 -0600 | [diff] [blame] | 1916 | { } |
| 1917 | }; |
| 1918 | |
| 1919 | U_BOOT_DRIVER(eth_eqos) = { |
| 1920 | .name = "eth_eqos", |
| 1921 | .id = UCLASS_ETH, |
| 1922 | .of_match = eqos_ids, |
| 1923 | .probe = eqos_probe, |
| 1924 | .remove = eqos_remove, |
| 1925 | .ops = &eqos_ops, |
| 1926 | .priv_auto_alloc_size = sizeof(struct eqos_priv), |
| 1927 | .platdata_auto_alloc_size = sizeof(struct eth_pdata), |
| 1928 | }; |