Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2005-2006 Atmel Corporation |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 4 | */ |
| 5 | #include <common.h> |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 6 | #include <clk.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 7 | #include <cpu_func.h> |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 10 | #include <linux/delay.h> |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 11 | |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 12 | /* |
| 13 | * The u-boot networking stack is a little weird. It seems like the |
| 14 | * networking core allocates receive buffers up front without any |
| 15 | * regard to the hardware that's supposed to actually receive those |
| 16 | * packets. |
| 17 | * |
| 18 | * The MACB receives packets into 128-byte receive buffers, so the |
| 19 | * buffers allocated by the core isn't very practical to use. We'll |
| 20 | * allocate our own, but we need one such buffer in case a packet |
| 21 | * wraps around the DMA ring so that we have to copy it. |
| 22 | * |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | * Therefore, define CONFIG_SYS_RX_ETH_BUFFER to 1 in the board-specific |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 24 | * configuration header. This way, the core allocates one RX buffer |
| 25 | * and one TX buffer, each of which can hold a ethernet packet of |
| 26 | * maximum size. |
| 27 | * |
| 28 | * For some reason, the networking core unconditionally specifies a |
| 29 | * 32-byte packet "alignment" (which really should be called |
| 30 | * "padding"). MACB shouldn't need that, but we'll refrain from any |
| 31 | * core modifications here... |
| 32 | */ |
| 33 | |
| 34 | #include <net.h> |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 35 | #ifndef CONFIG_DM_ETH |
Ben Warren | 2f2b6b6 | 2008-08-31 22:22:04 -0700 | [diff] [blame] | 36 | #include <netdev.h> |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 37 | #endif |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 38 | #include <malloc.h> |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 39 | #include <miiphy.h> |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 40 | |
| 41 | #include <linux/mii.h> |
| 42 | #include <asm/io.h> |
Masahiro Yamada | 6373a17 | 2020-02-14 16:40:19 +0900 | [diff] [blame] | 43 | #include <linux/dma-mapping.h> |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 44 | #include <asm/arch/clk.h> |
Masahiro Yamada | 64e4f7f | 2016-09-21 11:28:57 +0900 | [diff] [blame] | 45 | #include <linux/errno.h> |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 46 | |
| 47 | #include "macb.h" |
| 48 | |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 49 | DECLARE_GLOBAL_DATA_PTR; |
| 50 | |
Ramon Fried | 377d19d | 2019-07-14 18:25:14 +0300 | [diff] [blame] | 51 | /* |
| 52 | * These buffer sizes must be power of 2 and divisible |
| 53 | * by RX_BUFFER_MULTIPLE |
| 54 | */ |
| 55 | #define MACB_RX_BUFFER_SIZE 128 |
| 56 | #define GEM_RX_BUFFER_SIZE 2048 |
Ramon Fried | b40501f | 2019-07-16 22:04:36 +0300 | [diff] [blame] | 57 | #define RX_BUFFER_MULTIPLE 64 |
Ramon Fried | 377d19d | 2019-07-14 18:25:14 +0300 | [diff] [blame] | 58 | |
| 59 | #define MACB_RX_RING_SIZE 32 |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 60 | #define MACB_TX_RING_SIZE 16 |
Ramon Fried | 377d19d | 2019-07-14 18:25:14 +0300 | [diff] [blame] | 61 | |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 62 | #define MACB_TX_TIMEOUT 1000 |
| 63 | #define MACB_AUTONEG_TIMEOUT 5000000 |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 64 | |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 65 | #ifdef CONFIG_MACB_ZYNQ |
| 66 | /* INCR4 AHB bursts */ |
| 67 | #define MACB_ZYNQ_GEM_DMACR_BLENGTH 0x00000004 |
| 68 | /* Use full configured addressable space (8 Kb) */ |
| 69 | #define MACB_ZYNQ_GEM_DMACR_RXSIZE 0x00000300 |
| 70 | /* Use full configured addressable space (4 Kb) */ |
| 71 | #define MACB_ZYNQ_GEM_DMACR_TXSIZE 0x00000400 |
| 72 | /* Set RXBUF with use of 128 byte */ |
| 73 | #define MACB_ZYNQ_GEM_DMACR_RXBUF 0x00020000 |
| 74 | #define MACB_ZYNQ_GEM_DMACR_INIT \ |
| 75 | (MACB_ZYNQ_GEM_DMACR_BLENGTH | \ |
| 76 | MACB_ZYNQ_GEM_DMACR_RXSIZE | \ |
| 77 | MACB_ZYNQ_GEM_DMACR_TXSIZE | \ |
| 78 | MACB_ZYNQ_GEM_DMACR_RXBUF) |
| 79 | #endif |
| 80 | |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 81 | struct macb_dma_desc { |
| 82 | u32 addr; |
| 83 | u32 ctrl; |
| 84 | }; |
| 85 | |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 86 | struct macb_dma_desc_64 { |
| 87 | u32 addrh; |
| 88 | u32 unused; |
| 89 | }; |
| 90 | |
| 91 | #define HW_DMA_CAP_32B 0 |
| 92 | #define HW_DMA_CAP_64B 1 |
| 93 | |
| 94 | #define DMA_DESC_SIZE 16 |
| 95 | #define DMA_DESC_BYTES(n) ((n) * DMA_DESC_SIZE) |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 96 | #define MACB_TX_DMA_DESC_SIZE (DMA_DESC_BYTES(MACB_TX_RING_SIZE)) |
| 97 | #define MACB_RX_DMA_DESC_SIZE (DMA_DESC_BYTES(MACB_RX_RING_SIZE)) |
Wu, Josh | 012d68d | 2015-06-03 16:45:44 +0800 | [diff] [blame] | 98 | #define MACB_TX_DUMMY_DMA_DESC_SIZE (DMA_DESC_BYTES(1)) |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 99 | |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 100 | #define RXBUF_FRMLEN_MASK 0x00000fff |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 101 | #define TXBUF_FRMLEN_MASK 0x000007ff |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 102 | |
| 103 | struct macb_device { |
| 104 | void *regs; |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 105 | |
Anup Patel | a1818b1 | 2019-07-24 04:09:37 +0000 | [diff] [blame] | 106 | bool is_big_endian; |
| 107 | |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 108 | const struct macb_config *config; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 109 | |
| 110 | unsigned int rx_tail; |
| 111 | unsigned int tx_head; |
| 112 | unsigned int tx_tail; |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 113 | unsigned int next_rx_tail; |
| 114 | bool wrapped; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 115 | |
| 116 | void *rx_buffer; |
| 117 | void *tx_buffer; |
| 118 | struct macb_dma_desc *rx_ring; |
| 119 | struct macb_dma_desc *tx_ring; |
Ramon Fried | 377d19d | 2019-07-14 18:25:14 +0300 | [diff] [blame] | 120 | size_t rx_buffer_size; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 121 | |
| 122 | unsigned long rx_buffer_dma; |
| 123 | unsigned long rx_ring_dma; |
| 124 | unsigned long tx_ring_dma; |
| 125 | |
Wu, Josh | 012d68d | 2015-06-03 16:45:44 +0800 | [diff] [blame] | 126 | struct macb_dma_desc *dummy_desc; |
| 127 | unsigned long dummy_desc_dma; |
| 128 | |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 129 | const struct device *dev; |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 130 | #ifndef CONFIG_DM_ETH |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 131 | struct eth_device netdev; |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 132 | #endif |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 133 | unsigned short phy_addr; |
Bo Shen | 7d91deb | 2013-04-24 15:59:27 +0800 | [diff] [blame] | 134 | struct mii_dev *bus; |
Wenyou Yang | 44835ea | 2017-04-14 14:36:04 +0800 | [diff] [blame] | 135 | #ifdef CONFIG_PHYLIB |
| 136 | struct phy_device *phydev; |
| 137 | #endif |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 138 | |
| 139 | #ifdef CONFIG_DM_ETH |
Wenyou Yang | 1944936 | 2017-02-14 16:24:40 +0800 | [diff] [blame] | 140 | #ifdef CONFIG_CLK |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 141 | unsigned long pclk_rate; |
Wenyou Yang | 1944936 | 2017-02-14 16:24:40 +0800 | [diff] [blame] | 142 | #endif |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 143 | phy_interface_t phy_interface; |
| 144 | #endif |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 145 | }; |
Ramon Fried | 834040c | 2019-07-16 22:04:35 +0300 | [diff] [blame] | 146 | |
| 147 | struct macb_config { |
| 148 | unsigned int dma_burst_length; |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 149 | unsigned int hw_dma_cap; |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 150 | |
| 151 | int (*clk_init)(struct udevice *dev, ulong rate); |
Ramon Fried | 834040c | 2019-07-16 22:04:35 +0300 | [diff] [blame] | 152 | }; |
| 153 | |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 154 | #ifndef CONFIG_DM_ETH |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 155 | #define to_macb(_nd) container_of(_nd, struct macb_device, netdev) |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 156 | #endif |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 157 | |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 158 | static int macb_is_gem(struct macb_device *macb) |
| 159 | { |
Atish Patra | e1a8518 | 2019-02-25 08:14:42 +0000 | [diff] [blame] | 160 | return MACB_BFEXT(IDNUM, macb_readl(macb, MID)) >= 0x2; |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 161 | } |
| 162 | |
Gregory CLEMENT | f1a1e58 | 2015-12-16 14:50:34 +0100 | [diff] [blame] | 163 | #ifndef cpu_is_sama5d2 |
| 164 | #define cpu_is_sama5d2() 0 |
| 165 | #endif |
| 166 | |
| 167 | #ifndef cpu_is_sama5d4 |
| 168 | #define cpu_is_sama5d4() 0 |
| 169 | #endif |
| 170 | |
| 171 | static int gem_is_gigabit_capable(struct macb_device *macb) |
| 172 | { |
| 173 | /* |
Robert P. J. Day | 8c60f92 | 2016-05-04 04:47:31 -0400 | [diff] [blame] | 174 | * The GEM controllers embedded in SAMA5D2 and SAMA5D4 are |
Gregory CLEMENT | f1a1e58 | 2015-12-16 14:50:34 +0100 | [diff] [blame] | 175 | * configured to support only 10/100. |
| 176 | */ |
| 177 | return macb_is_gem(macb) && !cpu_is_sama5d2() && !cpu_is_sama5d4(); |
| 178 | } |
| 179 | |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 180 | static void macb_mdio_write(struct macb_device *macb, u8 phy_adr, u8 reg, |
| 181 | u16 value) |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 182 | { |
| 183 | unsigned long netctl; |
| 184 | unsigned long netstat; |
| 185 | unsigned long frame; |
| 186 | |
| 187 | netctl = macb_readl(macb, NCR); |
| 188 | netctl |= MACB_BIT(MPE); |
| 189 | macb_writel(macb, NCR, netctl); |
| 190 | |
| 191 | frame = (MACB_BF(SOF, 1) |
| 192 | | MACB_BF(RW, 1) |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 193 | | MACB_BF(PHYA, phy_adr) |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 194 | | MACB_BF(REGA, reg) |
| 195 | | MACB_BF(CODE, 2) |
| 196 | | MACB_BF(DATA, value)); |
| 197 | macb_writel(macb, MAN, frame); |
| 198 | |
| 199 | do { |
| 200 | netstat = macb_readl(macb, NSR); |
| 201 | } while (!(netstat & MACB_BIT(IDLE))); |
| 202 | |
| 203 | netctl = macb_readl(macb, NCR); |
| 204 | netctl &= ~MACB_BIT(MPE); |
| 205 | macb_writel(macb, NCR, netctl); |
| 206 | } |
| 207 | |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 208 | static u16 macb_mdio_read(struct macb_device *macb, u8 phy_adr, u8 reg) |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 209 | { |
| 210 | unsigned long netctl; |
| 211 | unsigned long netstat; |
| 212 | unsigned long frame; |
| 213 | |
| 214 | netctl = macb_readl(macb, NCR); |
| 215 | netctl |= MACB_BIT(MPE); |
| 216 | macb_writel(macb, NCR, netctl); |
| 217 | |
| 218 | frame = (MACB_BF(SOF, 1) |
| 219 | | MACB_BF(RW, 2) |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 220 | | MACB_BF(PHYA, phy_adr) |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 221 | | MACB_BF(REGA, reg) |
| 222 | | MACB_BF(CODE, 2)); |
| 223 | macb_writel(macb, MAN, frame); |
| 224 | |
| 225 | do { |
| 226 | netstat = macb_readl(macb, NSR); |
| 227 | } while (!(netstat & MACB_BIT(IDLE))); |
| 228 | |
| 229 | frame = macb_readl(macb, MAN); |
| 230 | |
| 231 | netctl = macb_readl(macb, NCR); |
| 232 | netctl &= ~MACB_BIT(MPE); |
| 233 | macb_writel(macb, NCR, netctl); |
| 234 | |
| 235 | return MACB_BFEXT(DATA, frame); |
| 236 | } |
| 237 | |
Joe Hershberger | 9e5742b | 2013-06-24 19:06:38 -0500 | [diff] [blame] | 238 | void __weak arch_get_mdio_control(const char *name) |
Shiraz Hashim | 77cdf0f | 2012-12-13 17:22:52 +0530 | [diff] [blame] | 239 | { |
| 240 | return; |
| 241 | } |
| 242 | |
Bo Shen | 7d91deb | 2013-04-24 15:59:27 +0800 | [diff] [blame] | 243 | #if defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB) |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 244 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 245 | int macb_miiphy_read(struct mii_dev *bus, int phy_adr, int devad, int reg) |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 246 | { |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 247 | u16 value = 0; |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 248 | #ifdef CONFIG_DM_ETH |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 249 | struct udevice *dev = eth_get_dev_by_name(bus->name); |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 250 | struct macb_device *macb = dev_get_priv(dev); |
| 251 | #else |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 252 | struct eth_device *dev = eth_get_dev_by_name(bus->name); |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 253 | struct macb_device *macb = to_macb(dev); |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 254 | #endif |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 255 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 256 | arch_get_mdio_control(bus->name); |
Josef Holzmayr | 017feb5 | 2019-10-02 21:22:52 +0200 | [diff] [blame] | 257 | value = macb_mdio_read(macb, phy_adr, reg); |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 258 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 259 | return value; |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 260 | } |
| 261 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 262 | int macb_miiphy_write(struct mii_dev *bus, int phy_adr, int devad, int reg, |
| 263 | u16 value) |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 264 | { |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 265 | #ifdef CONFIG_DM_ETH |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 266 | struct udevice *dev = eth_get_dev_by_name(bus->name); |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 267 | struct macb_device *macb = dev_get_priv(dev); |
| 268 | #else |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 269 | struct eth_device *dev = eth_get_dev_by_name(bus->name); |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 270 | struct macb_device *macb = to_macb(dev); |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 271 | #endif |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 272 | |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 273 | arch_get_mdio_control(bus->name); |
Josef Holzmayr | 017feb5 | 2019-10-02 21:22:52 +0200 | [diff] [blame] | 274 | macb_mdio_write(macb, phy_adr, reg, value); |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | #endif |
| 279 | |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 280 | #define RX 1 |
| 281 | #define TX 0 |
| 282 | static inline void macb_invalidate_ring_desc(struct macb_device *macb, bool rx) |
| 283 | { |
| 284 | if (rx) |
Heiko Schocher | 8353f9d | 2016-08-29 07:46:11 +0200 | [diff] [blame] | 285 | invalidate_dcache_range(macb->rx_ring_dma, |
| 286 | ALIGN(macb->rx_ring_dma + MACB_RX_DMA_DESC_SIZE, |
| 287 | PKTALIGN)); |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 288 | else |
Heiko Schocher | 8353f9d | 2016-08-29 07:46:11 +0200 | [diff] [blame] | 289 | invalidate_dcache_range(macb->tx_ring_dma, |
| 290 | ALIGN(macb->tx_ring_dma + MACB_TX_DMA_DESC_SIZE, |
| 291 | PKTALIGN)); |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | static inline void macb_flush_ring_desc(struct macb_device *macb, bool rx) |
| 295 | { |
| 296 | if (rx) |
| 297 | flush_dcache_range(macb->rx_ring_dma, macb->rx_ring_dma + |
Heiko Schocher | 8353f9d | 2016-08-29 07:46:11 +0200 | [diff] [blame] | 298 | ALIGN(MACB_RX_DMA_DESC_SIZE, PKTALIGN)); |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 299 | else |
| 300 | flush_dcache_range(macb->tx_ring_dma, macb->tx_ring_dma + |
Heiko Schocher | 8353f9d | 2016-08-29 07:46:11 +0200 | [diff] [blame] | 301 | ALIGN(MACB_TX_DMA_DESC_SIZE, PKTALIGN)); |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | static inline void macb_flush_rx_buffer(struct macb_device *macb) |
| 305 | { |
| 306 | flush_dcache_range(macb->rx_buffer_dma, macb->rx_buffer_dma + |
Stefan Roese | 7df65a5 | 2019-08-26 09:18:11 +0200 | [diff] [blame] | 307 | ALIGN(macb->rx_buffer_size * MACB_RX_RING_SIZE, |
| 308 | PKTALIGN)); |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | static inline void macb_invalidate_rx_buffer(struct macb_device *macb) |
| 312 | { |
| 313 | invalidate_dcache_range(macb->rx_buffer_dma, macb->rx_buffer_dma + |
Stefan Roese | 7df65a5 | 2019-08-26 09:18:11 +0200 | [diff] [blame] | 314 | ALIGN(macb->rx_buffer_size * MACB_RX_RING_SIZE, |
| 315 | PKTALIGN)); |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 316 | } |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 317 | |
Jon Loeliger | b1d408a | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 318 | #if defined(CONFIG_CMD_NET) |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 319 | |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 320 | static struct macb_dma_desc_64 *macb_64b_desc(struct macb_dma_desc *desc) |
| 321 | { |
| 322 | return (struct macb_dma_desc_64 *)((void *)desc |
| 323 | + sizeof(struct macb_dma_desc)); |
| 324 | } |
| 325 | |
| 326 | static void macb_set_addr(struct macb_device *macb, struct macb_dma_desc *desc, |
| 327 | ulong addr) |
| 328 | { |
| 329 | struct macb_dma_desc_64 *desc_64; |
| 330 | |
| 331 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) { |
| 332 | desc_64 = macb_64b_desc(desc); |
| 333 | desc_64->addrh = upper_32_bits(addr); |
| 334 | } |
| 335 | desc->addr = lower_32_bits(addr); |
| 336 | } |
| 337 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 338 | static int _macb_send(struct macb_device *macb, const char *name, void *packet, |
| 339 | int length) |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 340 | { |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 341 | unsigned long paddr, ctrl; |
| 342 | unsigned int tx_head = macb->tx_head; |
| 343 | int i; |
| 344 | |
| 345 | paddr = dma_map_single(packet, length, DMA_TO_DEVICE); |
| 346 | |
| 347 | ctrl = length & TXBUF_FRMLEN_MASK; |
Ramon Fried | 6402fb19 | 2019-07-16 22:04:33 +0300 | [diff] [blame] | 348 | ctrl |= MACB_BIT(TX_LAST); |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 349 | if (tx_head == (MACB_TX_RING_SIZE - 1)) { |
Ramon Fried | 6402fb19 | 2019-07-16 22:04:33 +0300 | [diff] [blame] | 350 | ctrl |= MACB_BIT(TX_WRAP); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 351 | macb->tx_head = 0; |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 352 | } else { |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 353 | macb->tx_head++; |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 354 | } |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 355 | |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 356 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) |
| 357 | tx_head = tx_head * 2; |
| 358 | |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 359 | macb->tx_ring[tx_head].ctrl = ctrl; |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 360 | macb_set_addr(macb, &macb->tx_ring[tx_head], paddr); |
| 361 | |
Haavard Skinnemoen | 996e147 | 2007-05-02 13:22:38 +0200 | [diff] [blame] | 362 | barrier(); |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 363 | macb_flush_ring_desc(macb, TX); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 364 | macb_writel(macb, NCR, MACB_BIT(TE) | MACB_BIT(RE) | MACB_BIT(TSTART)); |
| 365 | |
| 366 | /* |
| 367 | * I guess this is necessary because the networking core may |
| 368 | * re-use the transmit buffer as soon as we return... |
| 369 | */ |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 370 | for (i = 0; i <= MACB_TX_TIMEOUT; i++) { |
Haavard Skinnemoen | 996e147 | 2007-05-02 13:22:38 +0200 | [diff] [blame] | 371 | barrier(); |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 372 | macb_invalidate_ring_desc(macb, TX); |
Haavard Skinnemoen | 996e147 | 2007-05-02 13:22:38 +0200 | [diff] [blame] | 373 | ctrl = macb->tx_ring[tx_head].ctrl; |
Ramon Fried | 6402fb19 | 2019-07-16 22:04:33 +0300 | [diff] [blame] | 374 | if (ctrl & MACB_BIT(TX_USED)) |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 375 | break; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 376 | udelay(1); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 377 | } |
| 378 | |
Masahiro Yamada | 05a5dba | 2020-02-14 16:40:18 +0900 | [diff] [blame] | 379 | dma_unmap_single(paddr, length, DMA_TO_DEVICE); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 380 | |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 381 | if (i <= MACB_TX_TIMEOUT) { |
Ramon Fried | 6402fb19 | 2019-07-16 22:04:33 +0300 | [diff] [blame] | 382 | if (ctrl & MACB_BIT(TX_UNDERRUN)) |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 383 | printf("%s: TX underrun\n", name); |
Ramon Fried | 6402fb19 | 2019-07-16 22:04:33 +0300 | [diff] [blame] | 384 | if (ctrl & MACB_BIT(TX_BUF_EXHAUSTED)) |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 385 | printf("%s: TX buffers exhausted in mid frame\n", name); |
Haavard Skinnemoen | 996e147 | 2007-05-02 13:22:38 +0200 | [diff] [blame] | 386 | } else { |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 387 | printf("%s: TX timeout\n", name); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | /* No one cares anyway */ |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | static void reclaim_rx_buffers(struct macb_device *macb, |
| 395 | unsigned int new_tail) |
| 396 | { |
| 397 | unsigned int i; |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 398 | unsigned int count; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 399 | |
| 400 | i = macb->rx_tail; |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 401 | |
| 402 | macb_invalidate_ring_desc(macb, RX); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 403 | while (i > new_tail) { |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 404 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) |
| 405 | count = i * 2; |
| 406 | else |
| 407 | count = i; |
| 408 | macb->rx_ring[count].addr &= ~MACB_BIT(RX_USED); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 409 | i++; |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 410 | if (i > MACB_RX_RING_SIZE) |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 411 | i = 0; |
| 412 | } |
| 413 | |
| 414 | while (i < new_tail) { |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 415 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) |
| 416 | count = i * 2; |
| 417 | else |
| 418 | count = i; |
| 419 | macb->rx_ring[count].addr &= ~MACB_BIT(RX_USED); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 420 | i++; |
| 421 | } |
| 422 | |
Haavard Skinnemoen | 996e147 | 2007-05-02 13:22:38 +0200 | [diff] [blame] | 423 | barrier(); |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 424 | macb_flush_ring_desc(macb, RX); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 425 | macb->rx_tail = new_tail; |
| 426 | } |
| 427 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 428 | static int _macb_recv(struct macb_device *macb, uchar **packetp) |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 429 | { |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 430 | unsigned int next_rx_tail = macb->next_rx_tail; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 431 | void *buffer; |
| 432 | int length; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 433 | u32 status; |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 434 | u8 flag = false; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 435 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 436 | macb->wrapped = false; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 437 | for (;;) { |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 438 | macb_invalidate_ring_desc(macb, RX); |
| 439 | |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 440 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) |
| 441 | next_rx_tail = next_rx_tail * 2; |
| 442 | |
Ramon Fried | 6402fb19 | 2019-07-16 22:04:33 +0300 | [diff] [blame] | 443 | if (!(macb->rx_ring[next_rx_tail].addr & MACB_BIT(RX_USED))) |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 444 | return -EAGAIN; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 445 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 446 | status = macb->rx_ring[next_rx_tail].ctrl; |
Ramon Fried | 6402fb19 | 2019-07-16 22:04:33 +0300 | [diff] [blame] | 447 | if (status & MACB_BIT(RX_SOF)) { |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 448 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) { |
| 449 | next_rx_tail = next_rx_tail / 2; |
| 450 | flag = true; |
| 451 | } |
| 452 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 453 | if (next_rx_tail != macb->rx_tail) |
| 454 | reclaim_rx_buffers(macb, next_rx_tail); |
| 455 | macb->wrapped = false; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 456 | } |
| 457 | |
Ramon Fried | 6402fb19 | 2019-07-16 22:04:33 +0300 | [diff] [blame] | 458 | if (status & MACB_BIT(RX_EOF)) { |
Ramon Fried | 377d19d | 2019-07-14 18:25:14 +0300 | [diff] [blame] | 459 | buffer = macb->rx_buffer + |
| 460 | macb->rx_buffer_size * macb->rx_tail; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 461 | length = status & RXBUF_FRMLEN_MASK; |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 462 | |
| 463 | macb_invalidate_rx_buffer(macb); |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 464 | if (macb->wrapped) { |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 465 | unsigned int headlen, taillen; |
| 466 | |
Ramon Fried | 377d19d | 2019-07-14 18:25:14 +0300 | [diff] [blame] | 467 | headlen = macb->rx_buffer_size * |
| 468 | (MACB_RX_RING_SIZE - macb->rx_tail); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 469 | taillen = length - headlen; |
Joe Hershberger | 9f09a36 | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 470 | memcpy((void *)net_rx_packets[0], |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 471 | buffer, headlen); |
Joe Hershberger | 9f09a36 | 2015-04-08 01:41:06 -0500 | [diff] [blame] | 472 | memcpy((void *)net_rx_packets[0] + headlen, |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 473 | macb->rx_buffer, taillen); |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 474 | *packetp = (void *)net_rx_packets[0]; |
| 475 | } else { |
| 476 | *packetp = buffer; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 477 | } |
| 478 | |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 479 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) { |
| 480 | if (!flag) |
| 481 | next_rx_tail = next_rx_tail / 2; |
| 482 | } |
| 483 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 484 | if (++next_rx_tail >= MACB_RX_RING_SIZE) |
| 485 | next_rx_tail = 0; |
| 486 | macb->next_rx_tail = next_rx_tail; |
| 487 | return length; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 488 | } else { |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 489 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) { |
| 490 | if (!flag) |
| 491 | next_rx_tail = next_rx_tail / 2; |
| 492 | flag = false; |
| 493 | } |
| 494 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 495 | if (++next_rx_tail >= MACB_RX_RING_SIZE) { |
| 496 | macb->wrapped = true; |
| 497 | next_rx_tail = 0; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 498 | } |
| 499 | } |
Haavard Skinnemoen | 996e147 | 2007-05-02 13:22:38 +0200 | [diff] [blame] | 500 | barrier(); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 501 | } |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 502 | } |
| 503 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 504 | static void macb_phy_reset(struct macb_device *macb, const char *name) |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 505 | { |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 506 | int i; |
Haavard Skinnemoen | b3ad772 | 2007-05-02 13:31:53 +0200 | [diff] [blame] | 507 | u16 status, adv; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 508 | |
| 509 | adv = ADVERTISE_CSMA | ADVERTISE_ALL; |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 510 | macb_mdio_write(macb, macb->phy_addr, MII_ADVERTISE, adv); |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 511 | printf("%s: Starting autonegotiation...\n", name); |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 512 | macb_mdio_write(macb, macb->phy_addr, MII_BMCR, (BMCR_ANENABLE |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 513 | | BMCR_ANRESTART)); |
| 514 | |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 515 | for (i = 0; i < MACB_AUTONEG_TIMEOUT / 100; i++) { |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 516 | status = macb_mdio_read(macb, macb->phy_addr, MII_BMSR); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 517 | if (status & BMSR_ANEGCOMPLETE) |
| 518 | break; |
| 519 | udelay(100); |
| 520 | } |
| 521 | |
| 522 | if (status & BMSR_ANEGCOMPLETE) |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 523 | printf("%s: Autonegotiation complete\n", name); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 524 | else |
| 525 | printf("%s: Autonegotiation timed out (status=0x%04x)\n", |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 526 | name, status); |
Haavard Skinnemoen | b3ad772 | 2007-05-02 13:31:53 +0200 | [diff] [blame] | 527 | } |
| 528 | |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 529 | static int macb_phy_find(struct macb_device *macb, const char *name) |
Gunnar Rangoy | 6dd74f3 | 2009-01-23 12:56:31 +0100 | [diff] [blame] | 530 | { |
| 531 | int i; |
| 532 | u16 phy_id; |
| 533 | |
Padmarao Begari | 34394ba | 2021-01-15 08:20:37 +0530 | [diff] [blame^] | 534 | phy_id = macb_mdio_read(macb, macb->phy_addr, MII_PHYSID1); |
| 535 | if (phy_id != 0xffff) { |
| 536 | printf("%s: PHY present at %d\n", name, macb->phy_addr); |
| 537 | return 0; |
| 538 | } |
| 539 | |
Gunnar Rangoy | 6dd74f3 | 2009-01-23 12:56:31 +0100 | [diff] [blame] | 540 | /* Search for PHY... */ |
| 541 | for (i = 0; i < 32; i++) { |
| 542 | macb->phy_addr = i; |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 543 | phy_id = macb_mdio_read(macb, macb->phy_addr, MII_PHYSID1); |
Gunnar Rangoy | 6dd74f3 | 2009-01-23 12:56:31 +0100 | [diff] [blame] | 544 | if (phy_id != 0xffff) { |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 545 | printf("%s: PHY present at %d\n", name, i); |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 546 | return 0; |
Gunnar Rangoy | 6dd74f3 | 2009-01-23 12:56:31 +0100 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | |
| 550 | /* PHY isn't up to snuff */ |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 551 | printf("%s: PHY not found\n", name); |
Gunnar Rangoy | 6dd74f3 | 2009-01-23 12:56:31 +0100 | [diff] [blame] | 552 | |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 553 | return -ENODEV; |
| 554 | } |
| 555 | |
| 556 | /** |
| 557 | * macb_linkspd_cb - Linkspeed change callback function |
Bin Meng | cf82132 | 2019-05-22 00:09:45 -0700 | [diff] [blame] | 558 | * @dev/@regs: MACB udevice (DM version) or |
| 559 | * Base Register of MACB devices (non-DM version) |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 560 | * @speed: Linkspeed |
| 561 | * Returns 0 when operation success and negative errno number |
| 562 | * when operation failed. |
| 563 | */ |
Bin Meng | cf82132 | 2019-05-22 00:09:45 -0700 | [diff] [blame] | 564 | #ifdef CONFIG_DM_ETH |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 565 | static int macb_sifive_clk_init(struct udevice *dev, ulong rate) |
| 566 | { |
| 567 | fdt_addr_t addr; |
| 568 | void *gemgxl_regs; |
| 569 | |
| 570 | addr = dev_read_addr_index(dev, 1); |
| 571 | if (addr == FDT_ADDR_T_NONE) |
| 572 | return -ENODEV; |
| 573 | |
| 574 | gemgxl_regs = (void __iomem *)addr; |
| 575 | if (!gemgxl_regs) |
| 576 | return -ENODEV; |
| 577 | |
| 578 | /* |
| 579 | * SiFive GEMGXL TX clock operation mode: |
| 580 | * |
| 581 | * 0 = GMII mode. Use 125 MHz gemgxlclk from PRCI in TX logic |
| 582 | * and output clock on GMII output signal GTX_CLK |
| 583 | * 1 = MII mode. Use MII input signal TX_CLK in TX logic |
| 584 | */ |
| 585 | writel(rate != 125000000, gemgxl_regs); |
| 586 | return 0; |
| 587 | } |
| 588 | |
Bin Meng | cf82132 | 2019-05-22 00:09:45 -0700 | [diff] [blame] | 589 | int __weak macb_linkspd_cb(struct udevice *dev, unsigned int speed) |
| 590 | { |
Bin Meng | 12766ca | 2019-05-22 00:09:46 -0700 | [diff] [blame] | 591 | #ifdef CONFIG_CLK |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 592 | struct macb_device *macb = dev_get_priv(dev); |
Bin Meng | 12766ca | 2019-05-22 00:09:46 -0700 | [diff] [blame] | 593 | struct clk tx_clk; |
| 594 | ulong rate; |
| 595 | int ret; |
| 596 | |
Bin Meng | 12766ca | 2019-05-22 00:09:46 -0700 | [diff] [blame] | 597 | switch (speed) { |
| 598 | case _10BASET: |
| 599 | rate = 2500000; /* 2.5 MHz */ |
| 600 | break; |
| 601 | case _100BASET: |
| 602 | rate = 25000000; /* 25 MHz */ |
| 603 | break; |
| 604 | case _1000BASET: |
| 605 | rate = 125000000; /* 125 MHz */ |
| 606 | break; |
| 607 | default: |
| 608 | /* does not change anything */ |
| 609 | return 0; |
| 610 | } |
| 611 | |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 612 | if (macb->config->clk_init) |
| 613 | return macb->config->clk_init(dev, rate); |
| 614 | |
| 615 | /* |
| 616 | * "tx_clk" is an optional clock source for MACB. |
| 617 | * Ignore if it does not exist in DT. |
| 618 | */ |
| 619 | ret = clk_get_by_name(dev, "tx_clk", &tx_clk); |
| 620 | if (ret) |
| 621 | return 0; |
| 622 | |
Bin Meng | 12766ca | 2019-05-22 00:09:46 -0700 | [diff] [blame] | 623 | if (tx_clk.dev) { |
| 624 | ret = clk_set_rate(&tx_clk, rate); |
| 625 | if (ret) |
| 626 | return ret; |
| 627 | } |
| 628 | #endif |
| 629 | |
Bin Meng | cf82132 | 2019-05-22 00:09:45 -0700 | [diff] [blame] | 630 | return 0; |
| 631 | } |
| 632 | #else |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 633 | int __weak macb_linkspd_cb(void *regs, unsigned int speed) |
| 634 | { |
Gunnar Rangoy | 6dd74f3 | 2009-01-23 12:56:31 +0100 | [diff] [blame] | 635 | return 0; |
| 636 | } |
Bin Meng | cf82132 | 2019-05-22 00:09:45 -0700 | [diff] [blame] | 637 | #endif |
Gunnar Rangoy | 6dd74f3 | 2009-01-23 12:56:31 +0100 | [diff] [blame] | 638 | |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 639 | #ifdef CONFIG_DM_ETH |
| 640 | static int macb_phy_init(struct udevice *dev, const char *name) |
| 641 | #else |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 642 | static int macb_phy_init(struct macb_device *macb, const char *name) |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 643 | #endif |
Haavard Skinnemoen | b3ad772 | 2007-05-02 13:31:53 +0200 | [diff] [blame] | 644 | { |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 645 | #ifdef CONFIG_DM_ETH |
| 646 | struct macb_device *macb = dev_get_priv(dev); |
| 647 | #endif |
Haavard Skinnemoen | b3ad772 | 2007-05-02 13:31:53 +0200 | [diff] [blame] | 648 | u32 ncfgr; |
| 649 | u16 phy_id, status, adv, lpa; |
| 650 | int media, speed, duplex; |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 651 | int ret; |
Haavard Skinnemoen | b3ad772 | 2007-05-02 13:31:53 +0200 | [diff] [blame] | 652 | int i; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 653 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 654 | arch_get_mdio_control(name); |
Gunnar Rangoy | 6dd74f3 | 2009-01-23 12:56:31 +0100 | [diff] [blame] | 655 | /* Auto-detect phy_addr */ |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 656 | ret = macb_phy_find(macb, name); |
| 657 | if (ret) |
| 658 | return ret; |
Gunnar Rangoy | 6dd74f3 | 2009-01-23 12:56:31 +0100 | [diff] [blame] | 659 | |
Haavard Skinnemoen | b3ad772 | 2007-05-02 13:31:53 +0200 | [diff] [blame] | 660 | /* Check if the PHY is up to snuff... */ |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 661 | phy_id = macb_mdio_read(macb, macb->phy_addr, MII_PHYSID1); |
Haavard Skinnemoen | b3ad772 | 2007-05-02 13:31:53 +0200 | [diff] [blame] | 662 | if (phy_id == 0xffff) { |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 663 | printf("%s: No PHY present\n", name); |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 664 | return -ENODEV; |
Haavard Skinnemoen | b3ad772 | 2007-05-02 13:31:53 +0200 | [diff] [blame] | 665 | } |
| 666 | |
Bo Shen | 7d91deb | 2013-04-24 15:59:27 +0800 | [diff] [blame] | 667 | #ifdef CONFIG_PHYLIB |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 668 | #ifdef CONFIG_DM_ETH |
Wenyou Yang | 44835ea | 2017-04-14 14:36:04 +0800 | [diff] [blame] | 669 | macb->phydev = phy_connect(macb->bus, macb->phy_addr, dev, |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 670 | macb->phy_interface); |
| 671 | #else |
Bo Shen | e04fe55 | 2013-08-19 10:35:47 +0800 | [diff] [blame] | 672 | /* need to consider other phy interface mode */ |
Wenyou Yang | 44835ea | 2017-04-14 14:36:04 +0800 | [diff] [blame] | 673 | macb->phydev = phy_connect(macb->bus, macb->phy_addr, &macb->netdev, |
Bo Shen | e04fe55 | 2013-08-19 10:35:47 +0800 | [diff] [blame] | 674 | PHY_INTERFACE_MODE_RGMII); |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 675 | #endif |
Wenyou Yang | 44835ea | 2017-04-14 14:36:04 +0800 | [diff] [blame] | 676 | if (!macb->phydev) { |
Bo Shen | e04fe55 | 2013-08-19 10:35:47 +0800 | [diff] [blame] | 677 | printf("phy_connect failed\n"); |
| 678 | return -ENODEV; |
| 679 | } |
| 680 | |
Wenyou Yang | 44835ea | 2017-04-14 14:36:04 +0800 | [diff] [blame] | 681 | phy_config(macb->phydev); |
Bo Shen | 7d91deb | 2013-04-24 15:59:27 +0800 | [diff] [blame] | 682 | #endif |
| 683 | |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 684 | status = macb_mdio_read(macb, macb->phy_addr, MII_BMSR); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 685 | if (!(status & BMSR_LSTATUS)) { |
Haavard Skinnemoen | b3ad772 | 2007-05-02 13:31:53 +0200 | [diff] [blame] | 686 | /* Try to re-negotiate if we don't have link already. */ |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 687 | macb_phy_reset(macb, name); |
Haavard Skinnemoen | b3ad772 | 2007-05-02 13:31:53 +0200 | [diff] [blame] | 688 | |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 689 | for (i = 0; i < MACB_AUTONEG_TIMEOUT / 100; i++) { |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 690 | status = macb_mdio_read(macb, macb->phy_addr, MII_BMSR); |
Stefan Roese | 4029180 | 2019-03-27 11:20:19 +0100 | [diff] [blame] | 691 | if (status & BMSR_LSTATUS) { |
| 692 | /* |
| 693 | * Delay a bit after the link is established, |
| 694 | * so that the next xfer does not fail |
| 695 | */ |
| 696 | mdelay(10); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 697 | break; |
Stefan Roese | 4029180 | 2019-03-27 11:20:19 +0100 | [diff] [blame] | 698 | } |
Haavard Skinnemoen | b3ad772 | 2007-05-02 13:31:53 +0200 | [diff] [blame] | 699 | udelay(100); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 700 | } |
| 701 | } |
| 702 | |
| 703 | if (!(status & BMSR_LSTATUS)) { |
| 704 | printf("%s: link down (status: 0x%04x)\n", |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 705 | name, status); |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 706 | return -ENETDOWN; |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 707 | } |
| 708 | |
Gregory CLEMENT | f1a1e58 | 2015-12-16 14:50:34 +0100 | [diff] [blame] | 709 | /* First check for GMAC and that it is GiB capable */ |
| 710 | if (gem_is_gigabit_capable(macb)) { |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 711 | lpa = macb_mdio_read(macb, macb->phy_addr, MII_STAT1000); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 712 | |
Radu Pirea | 1676dfb | 2019-06-07 14:18:36 +0300 | [diff] [blame] | 713 | if (lpa & (LPA_1000FULL | LPA_1000HALF | LPA_1000XFULL | |
| 714 | LPA_1000XHALF)) { |
| 715 | duplex = ((lpa & (LPA_1000FULL | LPA_1000XFULL)) ? |
| 716 | 1 : 0); |
Andreas Bießmann | d43a89a | 2014-09-18 23:46:48 +0200 | [diff] [blame] | 717 | |
| 718 | printf("%s: link up, 1000Mbps %s-duplex (lpa: 0x%04x)\n", |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 719 | name, |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 720 | duplex ? "full" : "half", |
| 721 | lpa); |
| 722 | |
| 723 | ncfgr = macb_readl(macb, NCFGR); |
Andreas Bießmann | d43a89a | 2014-09-18 23:46:48 +0200 | [diff] [blame] | 724 | ncfgr &= ~(MACB_BIT(SPD) | MACB_BIT(FD)); |
| 725 | ncfgr |= GEM_BIT(GBE); |
| 726 | |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 727 | if (duplex) |
| 728 | ncfgr |= MACB_BIT(FD); |
Andreas Bießmann | d43a89a | 2014-09-18 23:46:48 +0200 | [diff] [blame] | 729 | |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 730 | macb_writel(macb, NCFGR, ncfgr); |
| 731 | |
Bin Meng | cf82132 | 2019-05-22 00:09:45 -0700 | [diff] [blame] | 732 | #ifdef CONFIG_DM_ETH |
| 733 | ret = macb_linkspd_cb(dev, _1000BASET); |
| 734 | #else |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 735 | ret = macb_linkspd_cb(macb->regs, _1000BASET); |
Bin Meng | cf82132 | 2019-05-22 00:09:45 -0700 | [diff] [blame] | 736 | #endif |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 737 | if (ret) |
| 738 | return ret; |
| 739 | |
| 740 | return 0; |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 741 | } |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 742 | } |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 743 | |
| 744 | /* fall back for EMAC checking */ |
Josef Holzmayr | 9fe1878 | 2019-10-02 21:22:51 +0200 | [diff] [blame] | 745 | adv = macb_mdio_read(macb, macb->phy_addr, MII_ADVERTISE); |
| 746 | lpa = macb_mdio_read(macb, macb->phy_addr, MII_LPA); |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 747 | media = mii_nway_result(lpa & adv); |
| 748 | speed = (media & (ADVERTISE_100FULL | ADVERTISE_100HALF) |
| 749 | ? 1 : 0); |
| 750 | duplex = (media & ADVERTISE_FULL) ? 1 : 0; |
| 751 | printf("%s: link up, %sMbps %s-duplex (lpa: 0x%04x)\n", |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 752 | name, |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 753 | speed ? "100" : "10", |
| 754 | duplex ? "full" : "half", |
| 755 | lpa); |
| 756 | |
| 757 | ncfgr = macb_readl(macb, NCFGR); |
Bo Shen | fe19ef3 | 2015-03-04 13:35:16 +0800 | [diff] [blame] | 758 | ncfgr &= ~(MACB_BIT(SPD) | MACB_BIT(FD) | GEM_BIT(GBE)); |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 759 | if (speed) { |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 760 | ncfgr |= MACB_BIT(SPD); |
Bin Meng | cf82132 | 2019-05-22 00:09:45 -0700 | [diff] [blame] | 761 | #ifdef CONFIG_DM_ETH |
| 762 | ret = macb_linkspd_cb(dev, _100BASET); |
| 763 | #else |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 764 | ret = macb_linkspd_cb(macb->regs, _100BASET); |
Bin Meng | cf82132 | 2019-05-22 00:09:45 -0700 | [diff] [blame] | 765 | #endif |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 766 | } else { |
Bin Meng | cf82132 | 2019-05-22 00:09:45 -0700 | [diff] [blame] | 767 | #ifdef CONFIG_DM_ETH |
| 768 | ret = macb_linkspd_cb(dev, _10BASET); |
| 769 | #else |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 770 | ret = macb_linkspd_cb(macb->regs, _10BASET); |
Bin Meng | cf82132 | 2019-05-22 00:09:45 -0700 | [diff] [blame] | 771 | #endif |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | if (ret) |
| 775 | return ret; |
| 776 | |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 777 | if (duplex) |
| 778 | ncfgr |= MACB_BIT(FD); |
| 779 | macb_writel(macb, NCFGR, ncfgr); |
| 780 | |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 781 | return 0; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 782 | } |
| 783 | |
Wu, Josh | 012d68d | 2015-06-03 16:45:44 +0800 | [diff] [blame] | 784 | static int gmac_init_multi_queues(struct macb_device *macb) |
| 785 | { |
| 786 | int i, num_queues = 1; |
| 787 | u32 queue_mask; |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 788 | unsigned long paddr; |
Wu, Josh | 012d68d | 2015-06-03 16:45:44 +0800 | [diff] [blame] | 789 | |
| 790 | /* bit 0 is never set but queue 0 always exists */ |
| 791 | queue_mask = gem_readl(macb, DCFG6) & 0xff; |
| 792 | queue_mask |= 0x1; |
| 793 | |
| 794 | for (i = 1; i < MACB_MAX_QUEUES; i++) |
| 795 | if (queue_mask & (1 << i)) |
| 796 | num_queues++; |
| 797 | |
Ramon Fried | 6402fb19 | 2019-07-16 22:04:33 +0300 | [diff] [blame] | 798 | macb->dummy_desc->ctrl = MACB_BIT(TX_USED); |
Wu, Josh | 012d68d | 2015-06-03 16:45:44 +0800 | [diff] [blame] | 799 | macb->dummy_desc->addr = 0; |
| 800 | flush_dcache_range(macb->dummy_desc_dma, macb->dummy_desc_dma + |
Heiko Schocher | 8353f9d | 2016-08-29 07:46:11 +0200 | [diff] [blame] | 801 | ALIGN(MACB_TX_DUMMY_DMA_DESC_SIZE, PKTALIGN)); |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 802 | paddr = macb->dummy_desc_dma; |
Wu, Josh | 012d68d | 2015-06-03 16:45:44 +0800 | [diff] [blame] | 803 | |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 804 | for (i = 1; i < num_queues; i++) { |
| 805 | gem_writel_queue_TBQP(macb, lower_32_bits(paddr), i - 1); |
| 806 | gem_writel_queue_RBQP(macb, lower_32_bits(paddr), i - 1); |
| 807 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) { |
| 808 | gem_writel_queue_TBQPH(macb, upper_32_bits(paddr), |
| 809 | i - 1); |
| 810 | gem_writel_queue_RBQPH(macb, upper_32_bits(paddr), |
| 811 | i - 1); |
| 812 | } |
| 813 | } |
Wu, Josh | 012d68d | 2015-06-03 16:45:44 +0800 | [diff] [blame] | 814 | return 0; |
| 815 | } |
| 816 | |
Ramon Fried | b40501f | 2019-07-16 22:04:36 +0300 | [diff] [blame] | 817 | static void gmac_configure_dma(struct macb_device *macb) |
| 818 | { |
| 819 | u32 buffer_size; |
| 820 | u32 dmacfg; |
| 821 | |
Ramon Fried | 377d19d | 2019-07-14 18:25:14 +0300 | [diff] [blame] | 822 | buffer_size = macb->rx_buffer_size / RX_BUFFER_MULTIPLE; |
Ramon Fried | b40501f | 2019-07-16 22:04:36 +0300 | [diff] [blame] | 823 | dmacfg = gem_readl(macb, DMACFG) & ~GEM_BF(RXBS, -1L); |
| 824 | dmacfg |= GEM_BF(RXBS, buffer_size); |
| 825 | |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 826 | if (macb->config->dma_burst_length) |
| 827 | dmacfg = GEM_BFINS(FBLDO, |
| 828 | macb->config->dma_burst_length, dmacfg); |
Ramon Fried | b40501f | 2019-07-16 22:04:36 +0300 | [diff] [blame] | 829 | |
| 830 | dmacfg |= GEM_BIT(TXPBMS) | GEM_BF(RXBMS, -1L); |
| 831 | dmacfg &= ~GEM_BIT(ENDIA_PKT); |
| 832 | |
Anup Patel | a1818b1 | 2019-07-24 04:09:37 +0000 | [diff] [blame] | 833 | if (macb->is_big_endian) |
Ramon Fried | b40501f | 2019-07-16 22:04:36 +0300 | [diff] [blame] | 834 | dmacfg |= GEM_BIT(ENDIA_DESC); /* CPU in big endian */ |
Anup Patel | a1818b1 | 2019-07-24 04:09:37 +0000 | [diff] [blame] | 835 | else |
| 836 | dmacfg &= ~GEM_BIT(ENDIA_DESC); |
Ramon Fried | b40501f | 2019-07-16 22:04:36 +0300 | [diff] [blame] | 837 | |
| 838 | dmacfg &= ~GEM_BIT(ADDR64); |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 839 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) |
| 840 | dmacfg |= GEM_BIT(ADDR64); |
| 841 | |
Ramon Fried | b40501f | 2019-07-16 22:04:36 +0300 | [diff] [blame] | 842 | gem_writel(macb, DMACFG, dmacfg); |
| 843 | } |
| 844 | |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 845 | #ifdef CONFIG_DM_ETH |
| 846 | static int _macb_init(struct udevice *dev, const char *name) |
| 847 | #else |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 848 | static int _macb_init(struct macb_device *macb, const char *name) |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 849 | #endif |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 850 | { |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 851 | #ifdef CONFIG_DM_ETH |
| 852 | struct macb_device *macb = dev_get_priv(dev); |
| 853 | #endif |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 854 | unsigned long paddr; |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 855 | int ret; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 856 | int i; |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 857 | int count; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 858 | |
| 859 | /* |
| 860 | * macb_halt should have been called at some point before now, |
| 861 | * so we'll assume the controller is idle. |
| 862 | */ |
| 863 | |
| 864 | /* initialize DMA descriptors */ |
| 865 | paddr = macb->rx_buffer_dma; |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 866 | for (i = 0; i < MACB_RX_RING_SIZE; i++) { |
| 867 | if (i == (MACB_RX_RING_SIZE - 1)) |
Ramon Fried | 6402fb19 | 2019-07-16 22:04:33 +0300 | [diff] [blame] | 868 | paddr |= MACB_BIT(RX_WRAP); |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 869 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) |
| 870 | count = i * 2; |
| 871 | else |
| 872 | count = i; |
| 873 | macb->rx_ring[count].ctrl = 0; |
| 874 | macb_set_addr(macb, &macb->rx_ring[count], paddr); |
Ramon Fried | 377d19d | 2019-07-14 18:25:14 +0300 | [diff] [blame] | 875 | paddr += macb->rx_buffer_size; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 876 | } |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 877 | macb_flush_ring_desc(macb, RX); |
| 878 | macb_flush_rx_buffer(macb); |
| 879 | |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 880 | for (i = 0; i < MACB_TX_RING_SIZE; i++) { |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 881 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) |
| 882 | count = i * 2; |
| 883 | else |
| 884 | count = i; |
| 885 | macb_set_addr(macb, &macb->tx_ring[count], 0); |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 886 | if (i == (MACB_TX_RING_SIZE - 1)) |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 887 | macb->tx_ring[count].ctrl = MACB_BIT(TX_USED) | |
Ramon Fried | 6402fb19 | 2019-07-16 22:04:33 +0300 | [diff] [blame] | 888 | MACB_BIT(TX_WRAP); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 889 | else |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 890 | macb->tx_ring[count].ctrl = MACB_BIT(TX_USED); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 891 | } |
Wu, Josh | 1805240 | 2014-05-27 16:31:05 +0800 | [diff] [blame] | 892 | macb_flush_ring_desc(macb, TX); |
| 893 | |
Andreas Bießmann | 1e86812 | 2014-05-26 22:55:18 +0200 | [diff] [blame] | 894 | macb->rx_tail = 0; |
| 895 | macb->tx_head = 0; |
| 896 | macb->tx_tail = 0; |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 897 | macb->next_rx_tail = 0; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 898 | |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 899 | #ifdef CONFIG_MACB_ZYNQ |
Michal Simek | fc91bdb | 2020-03-26 15:01:29 +0100 | [diff] [blame] | 900 | gem_writel(macb, DMACFG, MACB_ZYNQ_GEM_DMACR_INIT); |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 901 | #endif |
| 902 | |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 903 | macb_writel(macb, RBQP, lower_32_bits(macb->rx_ring_dma)); |
| 904 | macb_writel(macb, TBQP, lower_32_bits(macb->tx_ring_dma)); |
| 905 | if (macb->config->hw_dma_cap & HW_DMA_CAP_64B) { |
| 906 | macb_writel(macb, RBQPH, upper_32_bits(macb->rx_ring_dma)); |
| 907 | macb_writel(macb, TBQPH, upper_32_bits(macb->tx_ring_dma)); |
| 908 | } |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 909 | |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 910 | if (macb_is_gem(macb)) { |
Ramon Fried | b40501f | 2019-07-16 22:04:36 +0300 | [diff] [blame] | 911 | /* Initialize DMA properties */ |
| 912 | gmac_configure_dma(macb); |
Wu, Josh | 012d68d | 2015-06-03 16:45:44 +0800 | [diff] [blame] | 913 | /* Check the multi queue and initialize the queue for tx */ |
| 914 | gmac_init_multi_queues(macb); |
| 915 | |
Bo Shen | 4660b33 | 2014-11-10 15:24:01 +0800 | [diff] [blame] | 916 | /* |
| 917 | * When the GMAC IP with GE feature, this bit is used to |
| 918 | * select interface between RGMII and GMII. |
| 919 | * When the GMAC IP without GE feature, this bit is used |
| 920 | * to select interface between RMII and MII. |
| 921 | */ |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 922 | #ifdef CONFIG_DM_ETH |
Wenyou Yang | 5653dbc | 2017-04-20 11:13:13 +0800 | [diff] [blame] | 923 | if ((macb->phy_interface == PHY_INTERFACE_MODE_RMII) || |
| 924 | (macb->phy_interface == PHY_INTERFACE_MODE_RGMII)) |
Ramon Fried | 94e6bd8 | 2019-07-16 22:03:00 +0300 | [diff] [blame] | 925 | gem_writel(macb, USRIO, GEM_BIT(RGMII)); |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 926 | else |
Ramon Fried | 94e6bd8 | 2019-07-16 22:03:00 +0300 | [diff] [blame] | 927 | gem_writel(macb, USRIO, 0); |
Ramon Fried | 588a5b7 | 2019-07-16 22:04:34 +0300 | [diff] [blame] | 928 | |
| 929 | if (macb->phy_interface == PHY_INTERFACE_MODE_SGMII) { |
| 930 | unsigned int ncfgr = macb_readl(macb, NCFGR); |
| 931 | |
| 932 | ncfgr |= GEM_BIT(SGMIIEN) | GEM_BIT(PCSSEL); |
| 933 | macb_writel(macb, NCFGR, ncfgr); |
| 934 | } |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 935 | #else |
Bo Shen | 4660b33 | 2014-11-10 15:24:01 +0800 | [diff] [blame] | 936 | #if defined(CONFIG_RGMII) || defined(CONFIG_RMII) |
Ramon Fried | 94e6bd8 | 2019-07-16 22:03:00 +0300 | [diff] [blame] | 937 | gem_writel(macb, USRIO, GEM_BIT(RGMII)); |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 938 | #else |
Ramon Fried | 94e6bd8 | 2019-07-16 22:03:00 +0300 | [diff] [blame] | 939 | gem_writel(macb, USRIO, 0); |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 940 | #endif |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 941 | #endif |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 942 | } else { |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 943 | /* choose RMII or MII mode. This depends on the board */ |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 944 | #ifdef CONFIG_DM_ETH |
| 945 | #ifdef CONFIG_AT91FAMILY |
| 946 | if (macb->phy_interface == PHY_INTERFACE_MODE_RMII) { |
| 947 | macb_writel(macb, USRIO, |
| 948 | MACB_BIT(RMII) | MACB_BIT(CLKEN)); |
| 949 | } else { |
| 950 | macb_writel(macb, USRIO, MACB_BIT(CLKEN)); |
| 951 | } |
| 952 | #else |
| 953 | if (macb->phy_interface == PHY_INTERFACE_MODE_RMII) |
| 954 | macb_writel(macb, USRIO, 0); |
| 955 | else |
| 956 | macb_writel(macb, USRIO, MACB_BIT(MII)); |
| 957 | #endif |
| 958 | #else |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 959 | #ifdef CONFIG_RMII |
Bo Shen | cc29ce5 | 2013-04-24 15:59:26 +0800 | [diff] [blame] | 960 | #ifdef CONFIG_AT91FAMILY |
Stelian Pop | 87a8254 | 2008-01-03 21:15:56 +0000 | [diff] [blame] | 961 | macb_writel(macb, USRIO, MACB_BIT(RMII) | MACB_BIT(CLKEN)); |
| 962 | #else |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 963 | macb_writel(macb, USRIO, 0); |
Stelian Pop | 87a8254 | 2008-01-03 21:15:56 +0000 | [diff] [blame] | 964 | #endif |
| 965 | #else |
Bo Shen | cc29ce5 | 2013-04-24 15:59:26 +0800 | [diff] [blame] | 966 | #ifdef CONFIG_AT91FAMILY |
Stelian Pop | 87a8254 | 2008-01-03 21:15:56 +0000 | [diff] [blame] | 967 | macb_writel(macb, USRIO, MACB_BIT(CLKEN)); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 968 | #else |
| 969 | macb_writel(macb, USRIO, MACB_BIT(MII)); |
| 970 | #endif |
Stelian Pop | 87a8254 | 2008-01-03 21:15:56 +0000 | [diff] [blame] | 971 | #endif /* CONFIG_RMII */ |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 972 | #endif |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 973 | } |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 974 | |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 975 | #ifdef CONFIG_DM_ETH |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 976 | ret = macb_phy_init(dev, name); |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 977 | #else |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 978 | ret = macb_phy_init(macb, name); |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 979 | #endif |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 980 | if (ret) |
| 981 | return ret; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 982 | |
| 983 | /* Enable TX and RX */ |
| 984 | macb_writel(macb, NCR, MACB_BIT(TE) | MACB_BIT(RE)); |
| 985 | |
Ben Warren | de9fcb5 | 2008-01-09 18:15:53 -0500 | [diff] [blame] | 986 | return 0; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 987 | } |
| 988 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 989 | static void _macb_halt(struct macb_device *macb) |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 990 | { |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 991 | u32 ncr, tsr; |
| 992 | |
| 993 | /* Halt the controller and wait for any ongoing transmission to end. */ |
| 994 | ncr = macb_readl(macb, NCR); |
| 995 | ncr |= MACB_BIT(THALT); |
| 996 | macb_writel(macb, NCR, ncr); |
| 997 | |
| 998 | do { |
| 999 | tsr = macb_readl(macb, TSR); |
| 1000 | } while (tsr & MACB_BIT(TGO)); |
| 1001 | |
| 1002 | /* Disable TX and RX, and clear statistics */ |
| 1003 | macb_writel(macb, NCR, MACB_BIT(CLRSTAT)); |
| 1004 | } |
| 1005 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 1006 | static int _macb_write_hwaddr(struct macb_device *macb, unsigned char *enetaddr) |
Ben Warren | 33f8431 | 2010-06-01 11:55:42 -0700 | [diff] [blame] | 1007 | { |
Ben Warren | 33f8431 | 2010-06-01 11:55:42 -0700 | [diff] [blame] | 1008 | u32 hwaddr_bottom; |
| 1009 | u16 hwaddr_top; |
| 1010 | |
| 1011 | /* set hardware address */ |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 1012 | hwaddr_bottom = enetaddr[0] | enetaddr[1] << 8 | |
| 1013 | enetaddr[2] << 16 | enetaddr[3] << 24; |
Ben Warren | 33f8431 | 2010-06-01 11:55:42 -0700 | [diff] [blame] | 1014 | macb_writel(macb, SA1B, hwaddr_bottom); |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 1015 | hwaddr_top = enetaddr[4] | enetaddr[5] << 8; |
Ben Warren | 33f8431 | 2010-06-01 11:55:42 -0700 | [diff] [blame] | 1016 | macb_writel(macb, SA1T, hwaddr_top); |
| 1017 | return 0; |
| 1018 | } |
| 1019 | |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 1020 | static u32 macb_mdc_clk_div(int id, struct macb_device *macb) |
| 1021 | { |
| 1022 | u32 config; |
Wenyou Yang | 1944936 | 2017-02-14 16:24:40 +0800 | [diff] [blame] | 1023 | #if defined(CONFIG_DM_ETH) && defined(CONFIG_CLK) |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1024 | unsigned long macb_hz = macb->pclk_rate; |
| 1025 | #else |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 1026 | unsigned long macb_hz = get_macb_pclk_rate(id); |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1027 | #endif |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 1028 | |
| 1029 | if (macb_hz < 20000000) |
| 1030 | config = MACB_BF(CLK, MACB_CLK_DIV8); |
| 1031 | else if (macb_hz < 40000000) |
| 1032 | config = MACB_BF(CLK, MACB_CLK_DIV16); |
| 1033 | else if (macb_hz < 80000000) |
| 1034 | config = MACB_BF(CLK, MACB_CLK_DIV32); |
| 1035 | else |
| 1036 | config = MACB_BF(CLK, MACB_CLK_DIV64); |
| 1037 | |
| 1038 | return config; |
| 1039 | } |
| 1040 | |
| 1041 | static u32 gem_mdc_clk_div(int id, struct macb_device *macb) |
| 1042 | { |
| 1043 | u32 config; |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1044 | |
Wenyou Yang | 1944936 | 2017-02-14 16:24:40 +0800 | [diff] [blame] | 1045 | #if defined(CONFIG_DM_ETH) && defined(CONFIG_CLK) |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1046 | unsigned long macb_hz = macb->pclk_rate; |
| 1047 | #else |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 1048 | unsigned long macb_hz = get_macb_pclk_rate(id); |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1049 | #endif |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 1050 | |
| 1051 | if (macb_hz < 20000000) |
| 1052 | config = GEM_BF(CLK, GEM_CLK_DIV8); |
| 1053 | else if (macb_hz < 40000000) |
| 1054 | config = GEM_BF(CLK, GEM_CLK_DIV16); |
| 1055 | else if (macb_hz < 80000000) |
| 1056 | config = GEM_BF(CLK, GEM_CLK_DIV32); |
| 1057 | else if (macb_hz < 120000000) |
| 1058 | config = GEM_BF(CLK, GEM_CLK_DIV48); |
| 1059 | else if (macb_hz < 160000000) |
| 1060 | config = GEM_BF(CLK, GEM_CLK_DIV64); |
Ramon Fried | b1b9b4f | 2019-07-16 22:04:32 +0300 | [diff] [blame] | 1061 | else if (macb_hz < 240000000) |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 1062 | config = GEM_BF(CLK, GEM_CLK_DIV96); |
Ramon Fried | b1b9b4f | 2019-07-16 22:04:32 +0300 | [diff] [blame] | 1063 | else if (macb_hz < 320000000) |
| 1064 | config = GEM_BF(CLK, GEM_CLK_DIV128); |
| 1065 | else |
| 1066 | config = GEM_BF(CLK, GEM_CLK_DIV224); |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 1067 | |
| 1068 | return config; |
| 1069 | } |
| 1070 | |
Bo Shen | 0e6624a | 2013-09-18 15:07:44 +0800 | [diff] [blame] | 1071 | /* |
| 1072 | * Get the DMA bus width field of the network configuration register that we |
| 1073 | * should program. We find the width from decoding the design configuration |
| 1074 | * register to find the maximum supported data bus width. |
| 1075 | */ |
| 1076 | static u32 macb_dbw(struct macb_device *macb) |
| 1077 | { |
| 1078 | switch (GEM_BFEXT(DBWDEF, gem_readl(macb, DCFG1))) { |
| 1079 | case 4: |
| 1080 | return GEM_BF(DBW, GEM_DBW128); |
| 1081 | case 2: |
| 1082 | return GEM_BF(DBW, GEM_DBW64); |
| 1083 | case 1: |
| 1084 | default: |
| 1085 | return GEM_BF(DBW, GEM_DBW32); |
| 1086 | } |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | static void _macb_eth_initialize(struct macb_device *macb) |
| 1090 | { |
| 1091 | int id = 0; /* This is not used by functions we call */ |
| 1092 | u32 ncfgr; |
| 1093 | |
Ramon Fried | 377d19d | 2019-07-14 18:25:14 +0300 | [diff] [blame] | 1094 | if (macb_is_gem(macb)) |
| 1095 | macb->rx_buffer_size = GEM_RX_BUFFER_SIZE; |
| 1096 | else |
| 1097 | macb->rx_buffer_size = MACB_RX_BUFFER_SIZE; |
| 1098 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 1099 | /* TODO: we need check the rx/tx_ring_dma is dcache line aligned */ |
Ramon Fried | 377d19d | 2019-07-14 18:25:14 +0300 | [diff] [blame] | 1100 | macb->rx_buffer = dma_alloc_coherent(macb->rx_buffer_size * |
| 1101 | MACB_RX_RING_SIZE, |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 1102 | &macb->rx_buffer_dma); |
| 1103 | macb->rx_ring = dma_alloc_coherent(MACB_RX_DMA_DESC_SIZE, |
| 1104 | &macb->rx_ring_dma); |
| 1105 | macb->tx_ring = dma_alloc_coherent(MACB_TX_DMA_DESC_SIZE, |
| 1106 | &macb->tx_ring_dma); |
| 1107 | macb->dummy_desc = dma_alloc_coherent(MACB_TX_DUMMY_DMA_DESC_SIZE, |
| 1108 | &macb->dummy_desc_dma); |
| 1109 | |
| 1110 | /* |
| 1111 | * Do some basic initialization so that we at least can talk |
| 1112 | * to the PHY |
| 1113 | */ |
| 1114 | if (macb_is_gem(macb)) { |
| 1115 | ncfgr = gem_mdc_clk_div(id, macb); |
| 1116 | ncfgr |= macb_dbw(macb); |
| 1117 | } else { |
| 1118 | ncfgr = macb_mdc_clk_div(id, macb); |
| 1119 | } |
| 1120 | |
| 1121 | macb_writel(macb, NCFGR, ncfgr); |
| 1122 | } |
| 1123 | |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1124 | #ifndef CONFIG_DM_ETH |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 1125 | static int macb_send(struct eth_device *netdev, void *packet, int length) |
| 1126 | { |
| 1127 | struct macb_device *macb = to_macb(netdev); |
| 1128 | |
| 1129 | return _macb_send(macb, netdev->name, packet, length); |
Bo Shen | 0e6624a | 2013-09-18 15:07:44 +0800 | [diff] [blame] | 1130 | } |
| 1131 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 1132 | static int macb_recv(struct eth_device *netdev) |
| 1133 | { |
| 1134 | struct macb_device *macb = to_macb(netdev); |
| 1135 | uchar *packet; |
| 1136 | int length; |
| 1137 | |
| 1138 | macb->wrapped = false; |
| 1139 | for (;;) { |
| 1140 | macb->next_rx_tail = macb->rx_tail; |
| 1141 | length = _macb_recv(macb, &packet); |
| 1142 | if (length >= 0) { |
| 1143 | net_process_received_packet(packet, length); |
| 1144 | reclaim_rx_buffers(macb, macb->next_rx_tail); |
Heinrich Schuchardt | 6c4aae9 | 2018-03-18 11:32:53 +0100 | [diff] [blame] | 1145 | } else { |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 1146 | return length; |
| 1147 | } |
| 1148 | } |
| 1149 | } |
| 1150 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 1151 | static int macb_init(struct eth_device *netdev, struct bd_info *bd) |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 1152 | { |
| 1153 | struct macb_device *macb = to_macb(netdev); |
| 1154 | |
| 1155 | return _macb_init(macb, netdev->name); |
| 1156 | } |
| 1157 | |
| 1158 | static void macb_halt(struct eth_device *netdev) |
| 1159 | { |
| 1160 | struct macb_device *macb = to_macb(netdev); |
| 1161 | |
| 1162 | return _macb_halt(macb); |
| 1163 | } |
| 1164 | |
| 1165 | static int macb_write_hwaddr(struct eth_device *netdev) |
| 1166 | { |
| 1167 | struct macb_device *macb = to_macb(netdev); |
| 1168 | |
| 1169 | return _macb_write_hwaddr(macb, netdev->enetaddr); |
| 1170 | } |
| 1171 | |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 1172 | int macb_eth_initialize(int id, void *regs, unsigned int phy_addr) |
| 1173 | { |
| 1174 | struct macb_device *macb; |
| 1175 | struct eth_device *netdev; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 1176 | |
| 1177 | macb = malloc(sizeof(struct macb_device)); |
| 1178 | if (!macb) { |
| 1179 | printf("Error: Failed to allocate memory for MACB%d\n", id); |
| 1180 | return -1; |
| 1181 | } |
| 1182 | memset(macb, 0, sizeof(struct macb_device)); |
| 1183 | |
| 1184 | netdev = &macb->netdev; |
| 1185 | |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 1186 | macb->regs = regs; |
| 1187 | macb->phy_addr = phy_addr; |
| 1188 | |
Bo Shen | 6f7d7d9 | 2013-04-24 15:59:28 +0800 | [diff] [blame] | 1189 | if (macb_is_gem(macb)) |
| 1190 | sprintf(netdev->name, "gmac%d", id); |
| 1191 | else |
| 1192 | sprintf(netdev->name, "macb%d", id); |
| 1193 | |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 1194 | netdev->init = macb_init; |
| 1195 | netdev->halt = macb_halt; |
| 1196 | netdev->send = macb_send; |
| 1197 | netdev->recv = macb_recv; |
Ben Warren | 33f8431 | 2010-06-01 11:55:42 -0700 | [diff] [blame] | 1198 | netdev->write_hwaddr = macb_write_hwaddr; |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 1199 | |
Simon Glass | 5ad2751 | 2016-05-05 07:28:09 -0600 | [diff] [blame] | 1200 | _macb_eth_initialize(macb); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 1201 | |
| 1202 | eth_register(netdev); |
| 1203 | |
Bo Shen | 7d91deb | 2013-04-24 15:59:27 +0800 | [diff] [blame] | 1204 | #if defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB) |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 1205 | int retval; |
| 1206 | struct mii_dev *mdiodev = mdio_alloc(); |
| 1207 | if (!mdiodev) |
| 1208 | return -ENOMEM; |
| 1209 | strncpy(mdiodev->name, netdev->name, MDIO_NAME_LEN); |
| 1210 | mdiodev->read = macb_miiphy_read; |
| 1211 | mdiodev->write = macb_miiphy_write; |
| 1212 | |
| 1213 | retval = mdio_register(mdiodev); |
| 1214 | if (retval < 0) |
| 1215 | return retval; |
Bo Shen | 7d91deb | 2013-04-24 15:59:27 +0800 | [diff] [blame] | 1216 | macb->bus = miiphy_get_dev_by_name(netdev->name); |
Semih Hazar | 790088e | 2009-12-17 15:07:15 +0200 | [diff] [blame] | 1217 | #endif |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1218 | return 0; |
| 1219 | } |
| 1220 | #endif /* !CONFIG_DM_ETH */ |
| 1221 | |
| 1222 | #ifdef CONFIG_DM_ETH |
| 1223 | |
| 1224 | static int macb_start(struct udevice *dev) |
| 1225 | { |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 1226 | return _macb_init(dev, dev->name); |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | static int macb_send(struct udevice *dev, void *packet, int length) |
| 1230 | { |
| 1231 | struct macb_device *macb = dev_get_priv(dev); |
| 1232 | |
| 1233 | return _macb_send(macb, dev->name, packet, length); |
| 1234 | } |
| 1235 | |
| 1236 | static int macb_recv(struct udevice *dev, int flags, uchar **packetp) |
| 1237 | { |
| 1238 | struct macb_device *macb = dev_get_priv(dev); |
| 1239 | |
| 1240 | macb->next_rx_tail = macb->rx_tail; |
| 1241 | macb->wrapped = false; |
| 1242 | |
| 1243 | return _macb_recv(macb, packetp); |
| 1244 | } |
| 1245 | |
| 1246 | static int macb_free_pkt(struct udevice *dev, uchar *packet, int length) |
| 1247 | { |
| 1248 | struct macb_device *macb = dev_get_priv(dev); |
| 1249 | |
| 1250 | reclaim_rx_buffers(macb, macb->next_rx_tail); |
| 1251 | |
| 1252 | return 0; |
| 1253 | } |
| 1254 | |
| 1255 | static void macb_stop(struct udevice *dev) |
| 1256 | { |
| 1257 | struct macb_device *macb = dev_get_priv(dev); |
| 1258 | |
| 1259 | _macb_halt(macb); |
| 1260 | } |
| 1261 | |
| 1262 | static int macb_write_hwaddr(struct udevice *dev) |
| 1263 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 1264 | struct eth_pdata *plat = dev_get_plat(dev); |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1265 | struct macb_device *macb = dev_get_priv(dev); |
| 1266 | |
| 1267 | return _macb_write_hwaddr(macb, plat->enetaddr); |
| 1268 | } |
| 1269 | |
| 1270 | static const struct eth_ops macb_eth_ops = { |
| 1271 | .start = macb_start, |
| 1272 | .send = macb_send, |
| 1273 | .recv = macb_recv, |
| 1274 | .stop = macb_stop, |
| 1275 | .free_pkt = macb_free_pkt, |
| 1276 | .write_hwaddr = macb_write_hwaddr, |
| 1277 | }; |
| 1278 | |
Wenyou Yang | 1944936 | 2017-02-14 16:24:40 +0800 | [diff] [blame] | 1279 | #ifdef CONFIG_CLK |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1280 | static int macb_enable_clk(struct udevice *dev) |
| 1281 | { |
| 1282 | struct macb_device *macb = dev_get_priv(dev); |
| 1283 | struct clk clk; |
| 1284 | ulong clk_rate; |
| 1285 | int ret; |
| 1286 | |
| 1287 | ret = clk_get_by_index(dev, 0, &clk); |
| 1288 | if (ret) |
| 1289 | return -EINVAL; |
| 1290 | |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 1291 | /* |
Anup Patel | 51b51f8 | 2019-02-25 08:14:36 +0000 | [diff] [blame] | 1292 | * If clock driver didn't support enable or disable then |
| 1293 | * we get -ENOSYS from clk_enable(). To handle this, we |
| 1294 | * don't fail for ret == -ENOSYS. |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 1295 | */ |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1296 | ret = clk_enable(&clk); |
Anup Patel | 51b51f8 | 2019-02-25 08:14:36 +0000 | [diff] [blame] | 1297 | if (ret && ret != -ENOSYS) |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1298 | return ret; |
| 1299 | |
| 1300 | clk_rate = clk_get_rate(&clk); |
| 1301 | if (!clk_rate) |
| 1302 | return -EINVAL; |
| 1303 | |
| 1304 | macb->pclk_rate = clk_rate; |
| 1305 | |
| 1306 | return 0; |
| 1307 | } |
Wenyou Yang | 1944936 | 2017-02-14 16:24:40 +0800 | [diff] [blame] | 1308 | #endif |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1309 | |
Ramon Fried | 834040c | 2019-07-16 22:04:35 +0300 | [diff] [blame] | 1310 | static const struct macb_config default_gem_config = { |
| 1311 | .dma_burst_length = 16, |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 1312 | .hw_dma_cap = HW_DMA_CAP_32B, |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 1313 | .clk_init = NULL, |
Ramon Fried | 834040c | 2019-07-16 22:04:35 +0300 | [diff] [blame] | 1314 | }; |
| 1315 | |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1316 | static int macb_eth_probe(struct udevice *dev) |
| 1317 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 1318 | struct eth_pdata *pdata = dev_get_plat(dev); |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1319 | struct macb_device *macb = dev_get_priv(dev); |
Padmarao Begari | 34394ba | 2021-01-15 08:20:37 +0530 | [diff] [blame^] | 1320 | struct ofnode_phandle_args phandle_args; |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 1321 | const char *phy_mode; |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 1322 | int ret; |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 1323 | |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 1324 | phy_mode = dev_read_prop(dev, "phy-mode", NULL); |
| 1325 | |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 1326 | if (phy_mode) |
| 1327 | macb->phy_interface = phy_get_interface_by_name(phy_mode); |
| 1328 | if (macb->phy_interface == -1) { |
| 1329 | debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); |
| 1330 | return -EINVAL; |
| 1331 | } |
Wenyou Yang | 7b81185 | 2016-05-17 13:11:35 +0800 | [diff] [blame] | 1332 | |
Padmarao Begari | 34394ba | 2021-01-15 08:20:37 +0530 | [diff] [blame^] | 1333 | /* Read phyaddr from DT */ |
| 1334 | if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, |
| 1335 | &phandle_args)) |
| 1336 | macb->phy_addr = ofnode_read_u32_default(phandle_args.node, |
| 1337 | "reg", -1); |
| 1338 | |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1339 | macb->regs = (void *)pdata->iobase; |
| 1340 | |
Anup Patel | a1818b1 | 2019-07-24 04:09:37 +0000 | [diff] [blame] | 1341 | macb->is_big_endian = (cpu_to_be32(0x12345678) == 0x12345678); |
| 1342 | |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 1343 | macb->config = (struct macb_config *)dev_get_driver_data(dev); |
| 1344 | if (!macb->config) |
| 1345 | macb->config = &default_gem_config; |
Ramon Fried | 834040c | 2019-07-16 22:04:35 +0300 | [diff] [blame] | 1346 | |
Wenyou Yang | 1944936 | 2017-02-14 16:24:40 +0800 | [diff] [blame] | 1347 | #ifdef CONFIG_CLK |
Wenyou Yang | 44835ea | 2017-04-14 14:36:04 +0800 | [diff] [blame] | 1348 | ret = macb_enable_clk(dev); |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1349 | if (ret) |
| 1350 | return ret; |
Wenyou Yang | 1944936 | 2017-02-14 16:24:40 +0800 | [diff] [blame] | 1351 | #endif |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1352 | |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1353 | _macb_eth_initialize(macb); |
Wenyou Yang | 3d8d348 | 2016-11-02 10:06:56 +0800 | [diff] [blame] | 1354 | |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1355 | #if defined(CONFIG_CMD_MII) || defined(CONFIG_PHYLIB) |
Wenyou Yang | 44835ea | 2017-04-14 14:36:04 +0800 | [diff] [blame] | 1356 | macb->bus = mdio_alloc(); |
| 1357 | if (!macb->bus) |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 1358 | return -ENOMEM; |
Wenyou Yang | 44835ea | 2017-04-14 14:36:04 +0800 | [diff] [blame] | 1359 | strncpy(macb->bus->name, dev->name, MDIO_NAME_LEN); |
| 1360 | macb->bus->read = macb_miiphy_read; |
| 1361 | macb->bus->write = macb_miiphy_write; |
Joe Hershberger | 1fbcbed | 2016-08-08 11:28:38 -0500 | [diff] [blame] | 1362 | |
Wenyou Yang | 44835ea | 2017-04-14 14:36:04 +0800 | [diff] [blame] | 1363 | ret = mdio_register(macb->bus); |
| 1364 | if (ret < 0) |
| 1365 | return ret; |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1366 | macb->bus = miiphy_get_dev_by_name(dev->name); |
| 1367 | #endif |
Wenyou Yang | 44835ea | 2017-04-14 14:36:04 +0800 | [diff] [blame] | 1368 | |
| 1369 | return 0; |
| 1370 | } |
| 1371 | |
| 1372 | static int macb_eth_remove(struct udevice *dev) |
| 1373 | { |
| 1374 | struct macb_device *macb = dev_get_priv(dev); |
| 1375 | |
| 1376 | #ifdef CONFIG_PHYLIB |
| 1377 | free(macb->phydev); |
| 1378 | #endif |
| 1379 | mdio_unregister(macb->bus); |
| 1380 | mdio_free(macb->bus); |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1381 | |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 1382 | return 0; |
| 1383 | } |
| 1384 | |
| 1385 | /** |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 1386 | * macb_late_eth_of_to_plat |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 1387 | * @dev: udevice struct |
| 1388 | * Returns 0 when operation success and negative errno number |
| 1389 | * when operation failed. |
| 1390 | */ |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 1391 | int __weak macb_late_eth_of_to_plat(struct udevice *dev) |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 1392 | { |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1393 | return 0; |
| 1394 | } |
| 1395 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 1396 | static int macb_eth_of_to_plat(struct udevice *dev) |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1397 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 1398 | struct eth_pdata *pdata = dev_get_plat(dev); |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1399 | |
Ramon Fried | bf15d2f | 2018-12-27 19:58:42 +0200 | [diff] [blame] | 1400 | pdata->iobase = (phys_addr_t)dev_remap_addr(dev); |
| 1401 | if (!pdata->iobase) |
| 1402 | return -EINVAL; |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 1403 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 1404 | return macb_late_eth_of_to_plat(dev); |
Haavard Skinnemoen | 51c8f24 | 2006-01-20 10:03:34 +0100 | [diff] [blame] | 1405 | } |
| 1406 | |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 1407 | static const struct macb_config microchip_config = { |
| 1408 | .dma_burst_length = 16, |
| 1409 | .hw_dma_cap = HW_DMA_CAP_64B, |
| 1410 | .clk_init = NULL, |
| 1411 | }; |
| 1412 | |
Ramon Fried | 834040c | 2019-07-16 22:04:35 +0300 | [diff] [blame] | 1413 | static const struct macb_config sama5d4_config = { |
| 1414 | .dma_burst_length = 4, |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 1415 | .hw_dma_cap = HW_DMA_CAP_32B, |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 1416 | .clk_init = NULL, |
| 1417 | }; |
| 1418 | |
| 1419 | static const struct macb_config sifive_config = { |
| 1420 | .dma_burst_length = 16, |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 1421 | .hw_dma_cap = HW_DMA_CAP_32B, |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 1422 | .clk_init = macb_sifive_clk_init, |
Ramon Fried | 834040c | 2019-07-16 22:04:35 +0300 | [diff] [blame] | 1423 | }; |
| 1424 | |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1425 | static const struct udevice_id macb_eth_ids[] = { |
| 1426 | { .compatible = "cdns,macb" }, |
Wenyou Yang | 8f15540 | 2017-04-14 14:36:05 +0800 | [diff] [blame] | 1427 | { .compatible = "cdns,at91sam9260-macb" }, |
Nicolas Ferre | 9115f57 | 2019-09-27 13:08:32 +0000 | [diff] [blame] | 1428 | { .compatible = "cdns,sam9x60-macb" }, |
Wenyou Yang | 8f15540 | 2017-04-14 14:36:05 +0800 | [diff] [blame] | 1429 | { .compatible = "atmel,sama5d2-gem" }, |
| 1430 | { .compatible = "atmel,sama5d3-gem" }, |
Ramon Fried | 834040c | 2019-07-16 22:04:35 +0300 | [diff] [blame] | 1431 | { .compatible = "atmel,sama5d4-gem", .data = (ulong)&sama5d4_config }, |
Wilson Lee | 41d6d1e | 2017-08-22 20:25:07 -0700 | [diff] [blame] | 1432 | { .compatible = "cdns,zynq-gem" }, |
Anup Patel | 88799a6 | 2019-07-24 04:09:32 +0000 | [diff] [blame] | 1433 | { .compatible = "sifive,fu540-c000-gem", |
| 1434 | .data = (ulong)&sifive_config }, |
Padmarao Begari | 7a2c496 | 2021-01-15 08:20:36 +0530 | [diff] [blame] | 1435 | { .compatible = "microchip,mpfs-mss-gem", |
| 1436 | .data = (ulong)µchip_config }, |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1437 | { } |
| 1438 | }; |
| 1439 | |
| 1440 | U_BOOT_DRIVER(eth_macb) = { |
| 1441 | .name = "eth_macb", |
| 1442 | .id = UCLASS_ETH, |
| 1443 | .of_match = macb_eth_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 1444 | .of_to_plat = macb_eth_of_to_plat, |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1445 | .probe = macb_eth_probe, |
Wenyou Yang | 44835ea | 2017-04-14 14:36:04 +0800 | [diff] [blame] | 1446 | .remove = macb_eth_remove, |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1447 | .ops = &macb_eth_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 1448 | .priv_auto = sizeof(struct macb_device), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1449 | .plat_auto = sizeof(struct eth_pdata), |
Simon Glass | 75c5d18 | 2016-05-05 07:28:11 -0600 | [diff] [blame] | 1450 | }; |
| 1451 | #endif |
| 1452 | |
Jon Loeliger | b1d408a | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 1453 | #endif |