Lines Matching refs:gmacdev
57 synopGMACdevice *gmacdev; member
72 static void mdio_write(synopGMACdevice *gmacdev, uint32_t addr, uint32_t reg, int data) in mdio_write() argument
74 synopGMAC_write_phy_reg((u32 *)gmacdev->MacBase, addr, reg, data); in mdio_write()
77 static int mdio_read(synopGMACdevice *gmacdev, uint32_t addr, uint32_t reg) in mdio_read() argument
81 synopGMAC_read_phy_reg((u32 *)gmacdev->MacBase, addr, reg, &data); in mdio_read()
85 static int numaker_eth_link_ok(synopGMACdevice *gmacdev) in numaker_eth_link_ok() argument
88 mdio_read(gmacdev, eth_phy_addr, MII_BMSR); in numaker_eth_link_ok()
89 if (mdio_read(gmacdev, eth_phy_addr, MII_BMSR) & BMSR_LSTATUS) { in numaker_eth_link_ok()
95 static int reset_phy(synopGMACdevice *gmacdev) in reset_phy() argument
101 mdio_write(gmacdev, eth_phy_addr, MII_BMCR, BMCR_RESET); in reset_phy()
104 ret = WAIT_FOR(!(mdio_read(gmacdev, eth_phy_addr, MII_BMCR) & BMCR_RESET), in reset_phy()
111 LOG_INF("PHY ID 1:0x%x", mdio_read(gmacdev, eth_phy_addr, MII_PHYSID1)); in reset_phy()
112 LOG_INF("PHY ID 2:0x%x", mdio_read(gmacdev, eth_phy_addr, MII_PHYSID2)); in reset_phy()
114 ret = WAIT_FOR(numaker_eth_link_ok(gmacdev), delay_us, k_msleep(1)); in reset_phy()
116 gmacdev->LinkState = LINKUP; in reset_phy()
119 gmacdev->LinkState = LINKDOWN; in reset_phy()
124 mdio_write(gmacdev, eth_phy_addr, MII_ADVERTISE, NUMAKER_MII_CONFIG); in reset_phy()
125 reg = mdio_read(gmacdev, eth_phy_addr, MII_BMCR); in reset_phy()
126 mdio_write(gmacdev, eth_phy_addr, MII_BMCR, reg | BMCR_ANRESTART); in reset_phy()
128 ret = WAIT_FOR((mdio_read(gmacdev, eth_phy_addr, MII_BMSR) & in reset_phy()
133 synopGMAC_set_full_duplex(gmacdev); in reset_phy()
138 reg = mdio_read(gmacdev, eth_phy_addr, MII_LPA); in reset_phy()
141 gmacdev->DuplexMode = FULLDUPLEX; in reset_phy()
142 gmacdev->Speed = SPEED100; in reset_phy()
143 synopGMAC_set_full_duplex(gmacdev); in reset_phy()
147 gmacdev->DuplexMode = HALFDUPLEX; in reset_phy()
148 gmacdev->Speed = SPEED100; in reset_phy()
149 synopGMAC_set_half_duplex(gmacdev); in reset_phy()
153 gmacdev->DuplexMode = FULLDUPLEX; in reset_phy()
154 gmacdev->Speed = SPEED10; in reset_phy()
155 synopGMAC_set_full_duplex(gmacdev); in reset_phy()
159 gmacdev->DuplexMode = HALFDUPLEX; in reset_phy()
160 gmacdev->Speed = SPEED10; in reset_phy()
161 synopGMAC_set_half_duplex(gmacdev); in reset_phy()
212 static void m_numaker_gmacdev_enable(synopGMACdevice *gmacdev) in m_numaker_gmacdev_enable() argument
215 synopGMAC_clear_interrupt(gmacdev); in m_numaker_gmacdev_enable()
218 synopGMAC_enable_interrupt(gmacdev, DmaIntEnable); in m_numaker_gmacdev_enable()
219 synopGMAC_enable_dma_rx(gmacdev); in m_numaker_gmacdev_enable()
220 synopGMAC_enable_dma_tx(gmacdev); in m_numaker_gmacdev_enable()
222 synopGMAC_tx_enable(gmacdev); in m_numaker_gmacdev_enable()
223 synopGMAC_rx_enable(gmacdev); in m_numaker_gmacdev_enable()
226 static int m_numaker_gmacdev_init(synopGMACdevice *gmacdev, uint8_t *mac_addr, uint32_t gmac_base) in m_numaker_gmacdev_init() argument
239 synopGMAC_attach(gmacdev, gmac_base + MACBASE, gmac_base + DMABASE, DEFAULT_PHY_BASE); in m_numaker_gmacdev_init()
240 synopGMAC_disable_interrupt_all(gmacdev); in m_numaker_gmacdev_init()
243 synopGMAC_reset(gmacdev); in m_numaker_gmacdev_init()
244 gmacdev->Intf = NUMAKER_GMAC_INTF; in m_numaker_gmacdev_init()
245 synopGMAC_read_version(gmacdev); in m_numaker_gmacdev_init()
248 synopGMAC_set_mdc_clk_div(gmacdev, GmiiCsrClk5); in m_numaker_gmacdev_init()
249 gmacdev->ClockDivMdc = synopGMAC_get_mdc_clk_div(gmacdev); in m_numaker_gmacdev_init()
252 status = reset_phy(gmacdev); in m_numaker_gmacdev_init()
255 synopGMAC_setup_tx_desc_queue(gmacdev, TRANSMIT_DESC_SIZE, RINGMODE); in m_numaker_gmacdev_init()
256 synopGMAC_init_tx_desc_base(gmacdev); in m_numaker_gmacdev_init()
258 synopGMAC_setup_rx_desc_queue(gmacdev, RECEIVE_DESC_SIZE, RINGMODE); in m_numaker_gmacdev_init()
259 synopGMAC_init_rx_desc_base(gmacdev); in m_numaker_gmacdev_init()
262 synopGMAC_dma_bus_mode_init(gmacdev, in m_numaker_gmacdev_init()
264 synopGMAC_dma_control_init(gmacdev, in m_numaker_gmacdev_init()
268 synopGMAC_mac_init(gmacdev); in m_numaker_gmacdev_init()
269 synopGMAC_promisc_enable(gmacdev); in m_numaker_gmacdev_init()
272 synopGMAC_pause_control(gmacdev); in m_numaker_gmacdev_init()
281 synopGMAC_enable_rx_chksum_offload(gmacdev); in m_numaker_gmacdev_init()
284 synopGMAC_rx_tcpip_chksum_drop_enable(gmacdev); in m_numaker_gmacdev_init()
289 synopGMAC_set_rx_qptr(gmacdev, (u32)((u64)(skb->data) & NUMAKER_MASK_32), in m_numaker_gmacdev_init()
295 synopGMAC_set_tx_qptr(gmacdev, (u32)((u64)(skb->data) & NUMAKER_MASK_32), in m_numaker_gmacdev_init()
301 synopGMAC_clear_interrupt(gmacdev); in m_numaker_gmacdev_init()
306 static int m_numaker_gmacdev_get_rx_buf(synopGMACdevice *gmacdev, uint16_t *len, uint8_t **buf) in m_numaker_gmacdev_get_rx_buf() argument
308 DmaDesc *rxdesc = gmacdev->RxBusyDesc; in m_numaker_gmacdev_get_rx_buf()
320 synopGMAC_enable_interrupt(gmacdev, DmaIntEnable); in m_numaker_gmacdev_get_rx_buf()
334 static void m_numaker_gmacdev_rx_next(synopGMACdevice *gmacdev) in m_numaker_gmacdev_rx_next() argument
344 static void m_numaker_gmacdev_trigger_rx(synopGMACdevice *gmacdev) in m_numaker_gmacdev_trigger_rx() argument
349 synopGMAC_enable_interrupt(gmacdev, DmaIntEnable); in m_numaker_gmacdev_trigger_rx()
352 synopGMAC_enable_dma_rx(gmacdev); in m_numaker_gmacdev_trigger_rx()
353 synopGMAC_resume_dma_rx(gmacdev); in m_numaker_gmacdev_trigger_rx()
361 synopGMACdevice *gmacdev = data->gmacdev; in m_numaker_gmacdev_packet_rx() local
376 if (m_numaker_gmacdev_get_rx_buf(gmacdev, &len, &buffer) != 0) { in m_numaker_gmacdev_packet_rx()
410 m_numaker_gmacdev_rx_next(gmacdev); in m_numaker_gmacdev_packet_rx()
412 m_numaker_gmacdev_trigger_rx(gmacdev); in m_numaker_gmacdev_packet_rx()
418 static uint8_t *m_numaker_gmacdev_get_tx_buf(synopGMACdevice *gmacdev) in m_numaker_gmacdev_get_tx_buf() argument
420 DmaDesc *txdesc = gmacdev->TxNextDesc; in m_numaker_gmacdev_get_tx_buf()
433 static void m_numaker_gmacdev_trigger_tx(synopGMACdevice *gmacdev, uint16_t length) in m_numaker_gmacdev_trigger_tx() argument
435 DmaDesc *txdesc = gmacdev->TxNextDesc; in m_numaker_gmacdev_trigger_tx()
436 uint32_t txnext = gmacdev->TxNext; in m_numaker_gmacdev_trigger_tx()
440 (gmacdev->BusyTxDesc)++; in m_numaker_gmacdev_trigger_tx()
449 synopGMAC_tx_checksum_offload_tcp_pseudo(gmacdev, txdesc); in m_numaker_gmacdev_trigger_tx()
451 synopGMAC_tx_checksum_offload_bypass(gmacdev, txdesc); in m_numaker_gmacdev_trigger_tx()
456 gmacdev->TxNext = synopGMAC_is_last_tx_desc(gmacdev, txdesc) ? 0 : txnext + 1; in m_numaker_gmacdev_trigger_tx()
457 gmacdev->TxNextDesc = in m_numaker_gmacdev_trigger_tx()
458 synopGMAC_is_last_tx_desc(gmacdev, txdesc) ? gmacdev->TxDesc : (txdesc + 1); in m_numaker_gmacdev_trigger_tx()
461 synopGMAC_enable_interrupt(gmacdev, DmaIntEnable); in m_numaker_gmacdev_trigger_tx()
463 synopGMAC_resume_dma_tx(gmacdev); in m_numaker_gmacdev_trigger_tx()
469 synopGMACdevice *gmacdev = data->gmacdev; in numaker_eth_tx() local
481 buffer = m_numaker_gmacdev_get_tx_buf(gmacdev); in numaker_eth_tx()
492 m_numaker_gmacdev_trigger_tx(gmacdev, total_len); in numaker_eth_tx()
509 synopGMACdevice *gmacdev = data->gmacdev; in numaker_eth_if_init() local
521 m_numaker_gmacdev_enable(gmacdev); in numaker_eth_if_init()
565 synopGMACdevice *gmacdev = data->gmacdev; in eth_numaker_isr() local
575 mac_status_reg = synopGMACReadReg((u32 *)gmacdev->MacBase, GmacInterruptStatus); in eth_numaker_isr()
577 gmacdev->synopGMACNetStats.ts_int = 1; in eth_numaker_isr()
578 status = synopGMACReadReg((u32 *)gmacdev->MacBase, GmacTSStatus); in eth_numaker_isr()
591 reg = synopGMACReadReg((u32 *)gmacdev->MacBase, GmacRgmiiCtrlSts); in eth_numaker_isr()
594 synopGMACWriteReg((u32 *)gmacdev->MacBase, GmacInterruptStatus, mac_status_reg); in eth_numaker_isr()
598 dma_status_reg = synopGMACReadReg((u32 *)gmacdev->DmaBase, DmaStatus); in eth_numaker_isr()
605 synopGMAC_disable_interrupt_all(gmacdev); in eth_numaker_isr()
609 synopGMAC_powerup_mac(gmacdev); in eth_numaker_isr()
617 interrupt = synopGMAC_get_interrupt_type(gmacdev); in eth_numaker_isr()
621 synopGMAC_disable_dma_tx(gmacdev); in eth_numaker_isr()
622 synopGMAC_disable_dma_rx(gmacdev); in eth_numaker_isr()
624 synopGMAC_take_desc_ownership_tx(gmacdev); in eth_numaker_isr()
625 synopGMAC_take_desc_ownership_rx(gmacdev); in eth_numaker_isr()
627 synopGMAC_init_tx_rx_desc_queue(gmacdev); in eth_numaker_isr()
629 synopGMAC_reset(gmacdev); /* reset the DMA engine and the GMAC ip */ in eth_numaker_isr()
631 synopGMAC_dma_bus_mode_init(gmacdev, DmaFixedBurstEnable | DmaBurstLength8 | in eth_numaker_isr()
633 synopGMAC_dma_control_init(gmacdev, DmaStoreAndForward); in eth_numaker_isr()
634 synopGMAC_init_rx_desc_base(gmacdev); in eth_numaker_isr()
635 synopGMAC_init_tx_desc_base(gmacdev); in eth_numaker_isr()
636 synopGMAC_mac_init(gmacdev); in eth_numaker_isr()
637 synopGMAC_enable_dma_rx(gmacdev); in eth_numaker_isr()
638 synopGMAC_enable_dma_tx(gmacdev); in eth_numaker_isr()
652 if (gmacdev->GMAC_Power_down == 0) { in eth_numaker_isr()
653 gmacdev->synopGMACNetStats.rx_over_errors++; in eth_numaker_isr()
656 synopGMAC_resume_dma_rx(gmacdev); in eth_numaker_isr()
663 if (gmacdev->GMAC_Power_down == 0) { in eth_numaker_isr()
664 gmacdev->synopGMACNetStats.rx_over_errors++; in eth_numaker_isr()
665 synopGMAC_enable_dma_rx(gmacdev); in eth_numaker_isr()
677 if (gmacdev->GMAC_Power_down == 0) { in eth_numaker_isr()
685 if (gmacdev->GMAC_Power_down == 0) { in eth_numaker_isr()
686 synopGMAC_disable_dma_tx(gmacdev); in eth_numaker_isr()
687 synopGMAC_take_desc_ownership_tx(gmacdev); in eth_numaker_isr()
688 synopGMAC_enable_dma_tx(gmacdev); in eth_numaker_isr()
694 synopGMAC_enable_interrupt(gmacdev, dma_ie); in eth_numaker_isr()
706 synopGMACdevice *gmacdev; in eth_numaker_init() local
713 gmacdev = &GMACdev[NUMAKER_GMAC_INTF]; in eth_numaker_init()
714 data->gmacdev = gmacdev; in eth_numaker_init()
757 ret = m_numaker_gmacdev_init(gmacdev, mac_addr, cfg->gmac_base); in eth_numaker_init()