Lines Matching refs:macb

144 static int macb_is_gem(struct macb_device *macb)  in macb_is_gem()  argument
146 return MACB_BFEXT(IDNUM, macb_readl(macb, MID)) == 0x2; in macb_is_gem()
157 static int gem_is_gigabit_capable(struct macb_device *macb) in gem_is_gigabit_capable() argument
163 return macb_is_gem(macb) && !cpu_is_sama5d2() && !cpu_is_sama5d4(); in gem_is_gigabit_capable()
166 static void macb_mdio_write(struct macb_device *macb, u8 reg, u16 value) in macb_mdio_write() argument
172 netctl = macb_readl(macb, NCR); in macb_mdio_write()
174 macb_writel(macb, NCR, netctl); in macb_mdio_write()
178 | MACB_BF(PHYA, macb->phy_addr) in macb_mdio_write()
182 macb_writel(macb, MAN, frame); in macb_mdio_write()
185 netstat = macb_readl(macb, NSR); in macb_mdio_write()
188 netctl = macb_readl(macb, NCR); in macb_mdio_write()
190 macb_writel(macb, NCR, netctl); in macb_mdio_write()
193 static u16 macb_mdio_read(struct macb_device *macb, u8 reg) in macb_mdio_read() argument
199 netctl = macb_readl(macb, NCR); in macb_mdio_read()
201 macb_writel(macb, NCR, netctl); in macb_mdio_read()
205 | MACB_BF(PHYA, macb->phy_addr) in macb_mdio_read()
208 macb_writel(macb, MAN, frame); in macb_mdio_read()
211 netstat = macb_readl(macb, NSR); in macb_mdio_read()
214 frame = macb_readl(macb, MAN); in macb_mdio_read()
216 netctl = macb_readl(macb, NCR); in macb_mdio_read()
218 macb_writel(macb, NCR, netctl); in macb_mdio_read()
235 struct macb_device *macb = dev_get_priv(dev); in macb_miiphy_read() local
238 struct macb_device *macb = to_macb(dev); in macb_miiphy_read() local
241 if (macb->phy_addr != phy_adr) in macb_miiphy_read()
245 value = macb_mdio_read(macb, reg); in macb_miiphy_read()
255 struct macb_device *macb = dev_get_priv(dev); in macb_miiphy_write() local
258 struct macb_device *macb = to_macb(dev); in macb_miiphy_write()
261 if (macb->phy_addr != phy_adr) in macb_miiphy_write()
265 macb_mdio_write(macb, reg, value); in macb_miiphy_write()
273 static inline void macb_invalidate_ring_desc(struct macb_device *macb, bool rx) in macb_invalidate_ring_desc() argument
276 invalidate_dcache_range(macb->rx_ring_dma, in macb_invalidate_ring_desc()
277 ALIGN(macb->rx_ring_dma + MACB_RX_DMA_DESC_SIZE, in macb_invalidate_ring_desc()
280 invalidate_dcache_range(macb->tx_ring_dma, in macb_invalidate_ring_desc()
281 ALIGN(macb->tx_ring_dma + MACB_TX_DMA_DESC_SIZE, in macb_invalidate_ring_desc()
285 static inline void macb_flush_ring_desc(struct macb_device *macb, bool rx) in macb_flush_ring_desc() argument
288 flush_dcache_range(macb->rx_ring_dma, macb->rx_ring_dma + in macb_flush_ring_desc()
291 flush_dcache_range(macb->tx_ring_dma, macb->tx_ring_dma + in macb_flush_ring_desc()
295 static inline void macb_flush_rx_buffer(struct macb_device *macb) in macb_flush_rx_buffer() argument
297 flush_dcache_range(macb->rx_buffer_dma, macb->rx_buffer_dma + in macb_flush_rx_buffer()
301 static inline void macb_invalidate_rx_buffer(struct macb_device *macb) in macb_invalidate_rx_buffer() argument
303 invalidate_dcache_range(macb->rx_buffer_dma, macb->rx_buffer_dma + in macb_invalidate_rx_buffer()
309 static int _macb_send(struct macb_device *macb, const char *name, void *packet, in _macb_send() argument
313 unsigned int tx_head = macb->tx_head; in _macb_send()
322 macb->tx_head = 0; in _macb_send()
324 macb->tx_head++; in _macb_send()
327 macb->tx_ring[tx_head].ctrl = ctrl; in _macb_send()
328 macb->tx_ring[tx_head].addr = paddr; in _macb_send()
330 macb_flush_ring_desc(macb, TX); in _macb_send()
333 macb_writel(macb, NCR, MACB_BIT(TE) | MACB_BIT(RE) | MACB_BIT(TSTART)); in _macb_send()
341 macb_invalidate_ring_desc(macb, TX); in _macb_send()
342 ctrl = macb->tx_ring[tx_head].ctrl; in _macb_send()
363 static void reclaim_rx_buffers(struct macb_device *macb, in reclaim_rx_buffers() argument
368 i = macb->rx_tail; in reclaim_rx_buffers()
370 macb_invalidate_ring_desc(macb, RX); in reclaim_rx_buffers()
372 macb->rx_ring[i].addr &= ~RXADDR_USED; in reclaim_rx_buffers()
379 macb->rx_ring[i].addr &= ~RXADDR_USED; in reclaim_rx_buffers()
384 macb_flush_ring_desc(macb, RX); in reclaim_rx_buffers()
385 macb->rx_tail = new_tail; in reclaim_rx_buffers()
388 static int _macb_recv(struct macb_device *macb, uchar **packetp) in _macb_recv() argument
390 unsigned int next_rx_tail = macb->next_rx_tail; in _macb_recv()
395 macb->wrapped = false; in _macb_recv()
397 macb_invalidate_ring_desc(macb, RX); in _macb_recv()
399 if (!(macb->rx_ring[next_rx_tail].addr & RXADDR_USED)) in _macb_recv()
402 status = macb->rx_ring[next_rx_tail].ctrl; in _macb_recv()
404 if (next_rx_tail != macb->rx_tail) in _macb_recv()
405 reclaim_rx_buffers(macb, next_rx_tail); in _macb_recv()
406 macb->wrapped = false; in _macb_recv()
410 buffer = macb->rx_buffer + 128 * macb->rx_tail; in _macb_recv()
413 macb_invalidate_rx_buffer(macb); in _macb_recv()
414 if (macb->wrapped) { in _macb_recv()
418 - macb->rx_tail); in _macb_recv()
423 macb->rx_buffer, taillen); in _macb_recv()
431 macb->next_rx_tail = next_rx_tail; in _macb_recv()
435 macb->wrapped = true; in _macb_recv()
443 static void macb_phy_reset(struct macb_device *macb, const char *name) in macb_phy_reset() argument
449 macb_mdio_write(macb, MII_ADVERTISE, adv); in macb_phy_reset()
451 macb_mdio_write(macb, MII_BMCR, (BMCR_ANENABLE in macb_phy_reset()
455 status = macb_mdio_read(macb, MII_BMSR); in macb_phy_reset()
468 static int macb_phy_find(struct macb_device *macb, const char *name) in macb_phy_find() argument
475 macb->phy_addr = i; in macb_phy_find()
476 phy_id = macb_mdio_read(macb, MII_PHYSID1); in macb_phy_find()
504 static int macb_phy_init(struct macb_device *macb, const char *name) in macb_phy_init()
508 struct macb_device *macb = dev_get_priv(dev); in macb_phy_init() local
518 ret = macb_phy_find(macb, name); in macb_phy_init()
523 phy_id = macb_mdio_read(macb, MII_PHYSID1); in macb_phy_init()
531 macb->phydev = phy_connect(macb->bus, macb->phy_addr, dev, in macb_phy_init()
532 macb->phy_interface); in macb_phy_init()
535 macb->phydev = phy_connect(macb->bus, macb->phy_addr, &macb->netdev, in macb_phy_init()
538 if (!macb->phydev) { in macb_phy_init()
543 phy_config(macb->phydev); in macb_phy_init()
546 status = macb_mdio_read(macb, MII_BMSR); in macb_phy_init()
549 macb_phy_reset(macb, name); in macb_phy_init()
552 status = macb_mdio_read(macb, MII_BMSR); in macb_phy_init()
566 if (gem_is_gigabit_capable(macb)) { in macb_phy_init()
567 lpa = macb_mdio_read(macb, MII_STAT1000); in macb_phy_init()
577 ncfgr = macb_readl(macb, NCFGR); in macb_phy_init()
584 macb_writel(macb, NCFGR, ncfgr); in macb_phy_init()
586 ret = macb_linkspd_cb(macb->regs, _1000BASET); in macb_phy_init()
595 adv = macb_mdio_read(macb, MII_ADVERTISE); in macb_phy_init()
596 lpa = macb_mdio_read(macb, MII_LPA); in macb_phy_init()
607 ncfgr = macb_readl(macb, NCFGR); in macb_phy_init()
611 ret = macb_linkspd_cb(macb->regs, _100BASET); in macb_phy_init()
613 ret = macb_linkspd_cb(macb->regs, _10BASET); in macb_phy_init()
621 macb_writel(macb, NCFGR, ncfgr); in macb_phy_init()
626 static int gmac_init_multi_queues(struct macb_device *macb) in gmac_init_multi_queues() argument
632 queue_mask = gem_readl(macb, DCFG6) & 0xff; in gmac_init_multi_queues()
639 macb->dummy_desc->ctrl = TXBUF_USED; in gmac_init_multi_queues()
640 macb->dummy_desc->addr = 0; in gmac_init_multi_queues()
641 flush_dcache_range(macb->dummy_desc_dma, macb->dummy_desc_dma + in gmac_init_multi_queues()
645 gem_writel_queue_TBQP(macb, macb->dummy_desc_dma, i - 1); in gmac_init_multi_queues()
653 static int _macb_init(struct macb_device *macb, const char *name) in _macb_init()
657 struct macb_device *macb = dev_get_priv(dev); in _macb_init() local
669 paddr = macb->rx_buffer_dma; in _macb_init()
673 macb->rx_ring[i].addr = paddr; in _macb_init()
674 macb->rx_ring[i].ctrl = 0; in _macb_init()
677 macb_flush_ring_desc(macb, RX); in _macb_init()
678 macb_flush_rx_buffer(macb); in _macb_init()
681 macb->tx_ring[i].addr = 0; in _macb_init()
683 macb->tx_ring[i].ctrl = TXBUF_USED | TXBUF_WRAP; in _macb_init()
685 macb->tx_ring[i].ctrl = TXBUF_USED; in _macb_init()
687 macb_flush_ring_desc(macb, TX); in _macb_init()
689 macb->rx_tail = 0; in _macb_init()
690 macb->tx_head = 0; in _macb_init()
691 macb->tx_tail = 0; in _macb_init()
692 macb->next_rx_tail = 0; in _macb_init()
695 macb_writel(macb, DMACFG, MACB_ZYNQ_GEM_DMACR_INIT); in _macb_init()
698 macb_writel(macb, RBQP, macb->rx_ring_dma); in _macb_init()
699 macb_writel(macb, TBQP, macb->tx_ring_dma); in _macb_init()
701 if (macb_is_gem(macb)) { in _macb_init()
703 gmac_init_multi_queues(macb); in _macb_init()
712 if ((macb->phy_interface == PHY_INTERFACE_MODE_RMII) || in _macb_init()
713 (macb->phy_interface == PHY_INTERFACE_MODE_RGMII)) in _macb_init()
714 gem_writel(macb, UR, GEM_BIT(RGMII)); in _macb_init()
716 gem_writel(macb, UR, 0); in _macb_init()
719 gem_writel(macb, UR, GEM_BIT(RGMII)); in _macb_init()
721 gem_writel(macb, UR, 0); in _macb_init()
728 if (macb->phy_interface == PHY_INTERFACE_MODE_RMII) { in _macb_init()
729 macb_writel(macb, USRIO, in _macb_init()
732 macb_writel(macb, USRIO, MACB_BIT(CLKEN)); in _macb_init()
735 if (macb->phy_interface == PHY_INTERFACE_MODE_RMII) in _macb_init()
736 macb_writel(macb, USRIO, 0); in _macb_init()
738 macb_writel(macb, USRIO, MACB_BIT(MII)); in _macb_init()
743 macb_writel(macb, USRIO, MACB_BIT(RMII) | MACB_BIT(CLKEN)); in _macb_init()
745 macb_writel(macb, USRIO, 0); in _macb_init()
749 macb_writel(macb, USRIO, MACB_BIT(CLKEN)); in _macb_init()
751 macb_writel(macb, USRIO, MACB_BIT(MII)); in _macb_init()
760 ret = macb_phy_init(macb, name); in _macb_init()
766 macb_writel(macb, NCR, MACB_BIT(TE) | MACB_BIT(RE)); in _macb_init()
771 static void _macb_halt(struct macb_device *macb) in _macb_halt() argument
776 ncr = macb_readl(macb, NCR); in _macb_halt()
778 macb_writel(macb, NCR, ncr); in _macb_halt()
781 tsr = macb_readl(macb, TSR); in _macb_halt()
785 macb_writel(macb, NCR, MACB_BIT(CLRSTAT)); in _macb_halt()
788 static int _macb_write_hwaddr(struct macb_device *macb, unsigned char *enetaddr) in _macb_write_hwaddr() argument
796 macb_writel(macb, SA1B, hwaddr_bottom); in _macb_write_hwaddr()
798 macb_writel(macb, SA1T, hwaddr_top); in _macb_write_hwaddr()
802 static u32 macb_mdc_clk_div(int id, struct macb_device *macb) in macb_mdc_clk_div() argument
806 unsigned long macb_hz = macb->pclk_rate; in macb_mdc_clk_div()
823 static u32 gem_mdc_clk_div(int id, struct macb_device *macb) in gem_mdc_clk_div() argument
828 unsigned long macb_hz = macb->pclk_rate; in gem_mdc_clk_div()
854 static u32 macb_dbw(struct macb_device *macb) in macb_dbw() argument
856 switch (GEM_BFEXT(DBWDEF, gem_readl(macb, DCFG1))) { in macb_dbw()
867 static void _macb_eth_initialize(struct macb_device *macb) in _macb_eth_initialize() argument
873 macb->rx_buffer = dma_alloc_coherent(MACB_RX_BUFFER_SIZE, in _macb_eth_initialize()
874 &macb->rx_buffer_dma); in _macb_eth_initialize()
875 macb->rx_ring = dma_alloc_coherent(MACB_RX_DMA_DESC_SIZE, in _macb_eth_initialize()
876 &macb->rx_ring_dma); in _macb_eth_initialize()
877 macb->tx_ring = dma_alloc_coherent(MACB_TX_DMA_DESC_SIZE, in _macb_eth_initialize()
878 &macb->tx_ring_dma); in _macb_eth_initialize()
879 macb->dummy_desc = dma_alloc_coherent(MACB_TX_DUMMY_DMA_DESC_SIZE, in _macb_eth_initialize()
880 &macb->dummy_desc_dma); in _macb_eth_initialize()
886 if (macb_is_gem(macb)) { in _macb_eth_initialize()
887 ncfgr = gem_mdc_clk_div(id, macb); in _macb_eth_initialize()
888 ncfgr |= macb_dbw(macb); in _macb_eth_initialize()
890 ncfgr = macb_mdc_clk_div(id, macb); in _macb_eth_initialize()
893 macb_writel(macb, NCFGR, ncfgr); in _macb_eth_initialize()
899 struct macb_device *macb = to_macb(netdev); in macb_send() local
901 return _macb_send(macb, netdev->name, packet, length); in macb_send()
906 struct macb_device *macb = to_macb(netdev); in macb_recv() local
910 macb->wrapped = false; in macb_recv()
912 macb->next_rx_tail = macb->rx_tail; in macb_recv()
913 length = _macb_recv(macb, &packet); in macb_recv()
916 reclaim_rx_buffers(macb, macb->next_rx_tail); in macb_recv()
925 struct macb_device *macb = to_macb(netdev); in macb_init() local
927 return _macb_init(macb, netdev->name); in macb_init()
932 struct macb_device *macb = to_macb(netdev); in macb_halt() local
934 return _macb_halt(macb); in macb_halt()
939 struct macb_device *macb = to_macb(netdev); in macb_write_hwaddr() local
941 return _macb_write_hwaddr(macb, netdev->enetaddr); in macb_write_hwaddr()
946 struct macb_device *macb; in macb_eth_initialize() local
949 macb = malloc(sizeof(struct macb_device)); in macb_eth_initialize()
950 if (!macb) { in macb_eth_initialize()
954 memset(macb, 0, sizeof(struct macb_device)); in macb_eth_initialize()
956 netdev = &macb->netdev; in macb_eth_initialize()
958 macb->regs = regs; in macb_eth_initialize()
959 macb->phy_addr = phy_addr; in macb_eth_initialize()
961 if (macb_is_gem(macb)) in macb_eth_initialize()
972 _macb_eth_initialize(macb); in macb_eth_initialize()
988 macb->bus = miiphy_get_dev_by_name(netdev->name); in macb_eth_initialize()
1003 struct macb_device *macb = dev_get_priv(dev); in macb_send() local
1005 return _macb_send(macb, dev->name, packet, length); in macb_send()
1010 struct macb_device *macb = dev_get_priv(dev); in macb_recv() local
1012 macb->next_rx_tail = macb->rx_tail; in macb_recv()
1013 macb->wrapped = false; in macb_recv()
1015 return _macb_recv(macb, packetp); in macb_recv()
1020 struct macb_device *macb = dev_get_priv(dev); in macb_free_pkt() local
1022 reclaim_rx_buffers(macb, macb->next_rx_tail); in macb_free_pkt()
1029 struct macb_device *macb = dev_get_priv(dev); in macb_stop() local
1031 _macb_halt(macb); in macb_stop()
1037 struct macb_device *macb = dev_get_priv(dev); in macb_write_hwaddr() local
1039 return _macb_write_hwaddr(macb, plat->enetaddr); in macb_write_hwaddr()
1054 struct macb_device *macb = dev_get_priv(dev); in macb_enable_clk() local
1077 macb->pclk_rate = clk_rate; in macb_enable_clk()
1086 struct macb_device *macb = dev_get_priv(dev); in macb_eth_probe() local
1093 macb->phy_interface = phy_get_interface_by_name(phy_mode); in macb_eth_probe()
1094 if (macb->phy_interface == -1) { in macb_eth_probe()
1099 macb->regs = (void *)pdata->iobase; in macb_eth_probe()
1107 _macb_eth_initialize(macb); in macb_eth_probe()
1110 macb->bus = mdio_alloc(); in macb_eth_probe()
1111 if (!macb->bus) in macb_eth_probe()
1113 strncpy(macb->bus->name, dev->name, MDIO_NAME_LEN); in macb_eth_probe()
1114 macb->bus->read = macb_miiphy_read; in macb_eth_probe()
1115 macb->bus->write = macb_miiphy_write; in macb_eth_probe()
1117 ret = mdio_register(macb->bus); in macb_eth_probe()
1120 macb->bus = miiphy_get_dev_by_name(dev->name); in macb_eth_probe()
1128 struct macb_device *macb = dev_get_priv(dev); in macb_eth_remove() local
1131 free(macb->phydev); in macb_eth_remove()
1133 mdio_unregister(macb->bus); in macb_eth_remove()
1134 mdio_free(macb->bus); in macb_eth_remove()