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