Lines Matching +full:tx +full:- +full:buffer +full:- +full:descriptors
4 * SPDX-License-Identifier: Apache-2.0
64 /* Delay execution for given amount of ticks for SDK-HAL */
74 synopGMAC_write_phy_reg((u32 *)gmacdev->MacBase, addr, reg, data); in mdio_write()
81 synopGMAC_read_phy_reg((u32 *)gmacdev->MacBase, addr, reg, &data); in mdio_read()
108 return -EIO; in reset_phy()
116 gmacdev->LinkState = LINKUP; in reset_phy()
119 gmacdev->LinkState = LINKDOWN; in reset_phy()
121 return -EIO; in reset_phy()
135 return -EIO; in reset_phy()
141 gmacdev->DuplexMode = FULLDUPLEX; in reset_phy()
142 gmacdev->Speed = SPEED100; in reset_phy()
147 gmacdev->DuplexMode = HALFDUPLEX; in reset_phy()
148 gmacdev->Speed = SPEED100; in reset_phy()
153 gmacdev->DuplexMode = FULLDUPLEX; in reset_phy()
154 gmacdev->Speed = SPEED10; in reset_phy()
159 gmacdev->DuplexMode = HALFDUPLEX; in reset_phy()
160 gmacdev->Speed = SPEED10; in reset_phy()
175 * we only want bottom 16 bits of word1 (MAC bits 32-47) in m_numaker_read_mac_addr()
184 /* Generate a semi-unique MAC address from the UUID */ in m_numaker_read_mac_addr()
217 /* Enable INT & TX/RX */ in m_numaker_gmacdev_enable()
244 gmacdev->Intf = NUMAKER_GMAC_INTF; in m_numaker_gmacdev_init()
249 gmacdev->ClockDivMdc = synopGMAC_get_mdc_clk_div(gmacdev); in m_numaker_gmacdev_init()
254 /* Set up the tx and rx descriptor queue/ring */ in m_numaker_gmacdev_init()
289 synopGMAC_set_rx_qptr(gmacdev, (u32)((u64)(skb->data) & NUMAKER_MASK_32), in m_numaker_gmacdev_init()
290 sizeof(skb->data), (u32)((u64)skb & 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()
296 sizeof(skb->data), (u32)((u64)skb & NUMAKER_MASK_32), in m_numaker_gmacdev_init()
308 DmaDesc *rxdesc = gmacdev->RxBusyDesc; in m_numaker_gmacdev_get_rx_buf()
312 return -EIO; in m_numaker_gmacdev_get_rx_buf()
315 return -EIO; in m_numaker_gmacdev_get_rx_buf()
321 return -ENOSPC; /* No available RX frame */ in m_numaker_gmacdev_get_rx_buf()
325 if (*len > (NU_ETH_MAX_FLEN - 4)) { in m_numaker_gmacdev_get_rx_buf()
338 * No-op at this stage in m_numaker_gmacdev_rx_next()
339 * DmaDesc * rxdesc = (gmacdev->RxBusyDesc - 1); in m_numaker_gmacdev_rx_next()
340 * rxdesc->status = DescOwnByDma; in m_numaker_gmacdev_rx_next()
360 struct eth_numaker_data *data = dev->data; in m_numaker_gmacdev_packet_rx()
361 synopGMACdevice *gmacdev = data->gmacdev; in m_numaker_gmacdev_packet_rx()
362 uint8_t *buffer; in m_numaker_gmacdev_packet_rx() local
368 /* Get exclusive access, use spin-lock instead of mutex in ISR */ in m_numaker_gmacdev_packet_rx()
369 key = k_spin_lock(&data->rx_frame_buf_lock); in m_numaker_gmacdev_packet_rx()
372 * 2. recv one RX and set pending interrupt for rx-next. in m_numaker_gmacdev_packet_rx()
376 if (m_numaker_gmacdev_get_rx_buf(gmacdev, &len, &buffer) != 0) { in m_numaker_gmacdev_packet_rx()
384 /* Allocate a memory buffer chain from buffer pool in m_numaker_gmacdev_packet_rx()
387 pkt = net_pkt_rx_alloc_with_buffer(data->iface, len, AF_UNSPEC, 0, K_NO_WAIT); in m_numaker_gmacdev_packet_rx()
389 LOG_ERR("pkt alloc frame-len=%d failed", len); in m_numaker_gmacdev_packet_rx()
395 if (net_pkt_write(pkt, buffer, len)) { in m_numaker_gmacdev_packet_rx()
402 res = net_recv_data(data->iface, pkt); in m_numaker_gmacdev_packet_rx()
415 k_spin_unlock(&data->rx_frame_buf_lock, key); in m_numaker_gmacdev_packet_rx()
420 DmaDesc *txdesc = gmacdev->TxNextDesc; in m_numaker_gmacdev_get_tx_buf()
430 return (uint8_t *)(txdesc->buffer1); in m_numaker_gmacdev_get_tx_buf()
435 DmaDesc *txdesc = gmacdev->TxNextDesc; in m_numaker_gmacdev_trigger_tx()
436 uint32_t txnext = gmacdev->TxNext; in m_numaker_gmacdev_trigger_tx()
439 /* busy tx descriptor is incremented by one as it will be handed over to DMA */ in m_numaker_gmacdev_trigger_tx()
440 (gmacdev->BusyTxDesc)++; in m_numaker_gmacdev_trigger_tx()
442 txdesc->length |= ((length << DescSize1Shift) & DescSize1Mask); in m_numaker_gmacdev_trigger_tx()
443 txdesc->status |= (DescTxFirst | DescTxLast | DescTxIntEnable); in m_numaker_gmacdev_trigger_tx()
454 txdesc->status |= DescOwnByDma; 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()
462 /* Trigger TX DMA */ in m_numaker_gmacdev_trigger_tx()
468 struct eth_numaker_data *data = dev->data; in numaker_eth_tx()
469 synopGMACdevice *gmacdev = data->gmacdev; in numaker_eth_tx()
471 uint8_t *buffer; in numaker_eth_tx() local
474 k_mutex_lock(&data->tx_frame_buf_mutex, K_FOREVER); in numaker_eth_tx()
477 LOG_ERR("TX packet length [%d] over max [%d]", total_len, NET_ETH_MAX_FRAME_SIZE); in numaker_eth_tx()
481 buffer = m_numaker_gmacdev_get_tx_buf(gmacdev); in numaker_eth_tx()
482 LOG_DBG("buffer=0x%x", (uint32_t)buffer); in numaker_eth_tx()
483 if (buffer == NULL) { in numaker_eth_tx()
487 if (net_pkt_read(pkt, buffer, total_len)) { in numaker_eth_tx()
491 /* Prepare transmit descriptors to give to DMA */ in numaker_eth_tx()
494 k_mutex_unlock(&data->tx_frame_buf_mutex); in numaker_eth_tx()
499 LOG_ERR("Writing pkt to TX descriptor failed"); in numaker_eth_tx()
500 k_mutex_unlock(&data->tx_frame_buf_mutex); in numaker_eth_tx()
501 return -EIO; in numaker_eth_tx()
507 struct eth_numaker_data *data = dev->data; in numaker_eth_if_init()
509 synopGMACdevice *gmacdev = data->gmacdev; in numaker_eth_if_init()
514 m_numaker_read_mac_addr(data->mac_addr); in numaker_eth_if_init()
516 net_if_set_link_addr(iface, data->mac_addr, sizeof(data->mac_addr), NET_LINK_ETHERNET); in numaker_eth_if_init()
517 data->iface = iface; in numaker_eth_if_init()
520 /* Enable GMAC device INT & TX/RX */ in numaker_eth_if_init()
527 struct eth_numaker_data *data = dev->data; in numaker_eth_set_config()
531 memcpy(data->mac_addr, config->mac_address.addr, sizeof(data->mac_addr)); in numaker_eth_set_config()
532 synopGMAC_set_mac_address(NUMAKER_GMAC_INTF, data->mac_addr); in numaker_eth_set_config()
533 net_if_set_link_addr(data->iface, data->mac_addr, sizeof(data->mac_addr), in numaker_eth_set_config()
535 LOG_DBG("%s MAC set to %02x:%02x:%02x:%02x:%02x:%02x", dev->name, data->mac_addr[0], in numaker_eth_set_config()
536 data->mac_addr[1], data->mac_addr[2], data->mac_addr[3], data->mac_addr[4], in numaker_eth_set_config()
537 data->mac_addr[5]); in numaker_eth_set_config()
540 return -ENOTSUP; in numaker_eth_set_config()
564 struct eth_numaker_data *data = dev->data; in eth_numaker_isr()
565 synopGMACdevice *gmacdev = data->gmacdev; in eth_numaker_isr()
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()
630 synopGMAC_set_mac_address(NUMAKER_GMAC_INTF, data->mac_addr); 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()
655 /* To handle GBPS with 12 descriptors. */ 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()
672 /* No-op at this stage for TX INT */ in eth_numaker_isr()
676 LOG_ERR("Abnormal Tx Interrupt Seen"); in eth_numaker_isr()
677 if (gmacdev->GMAC_Power_down == 0) { in eth_numaker_isr()
679 /* No-op at this stage for TX INT */ in eth_numaker_isr()
685 if (gmacdev->GMAC_Power_down == 0) { in eth_numaker_isr()
697 /* Declare pin-ctrl __pinctrl_dev_config__device_dts_ord_xx before
704 const struct eth_numaker_config *cfg = dev->config; in eth_numaker_init()
705 struct eth_numaker_data *data = dev->data; in eth_numaker_init()
714 data->gmacdev = gmacdev; in eth_numaker_init()
716 k_mutex_init(&data->tx_frame_buf_mutex); in eth_numaker_init()
718 eth_phy_addr = cfg->phy_addr; in eth_numaker_init()
723 scc_subsys.pcc.clk_modidx = cfg->clk_modidx; in eth_numaker_init()
724 scc_subsys.pcc.clk_src = cfg->clk_src; in eth_numaker_init()
725 scc_subsys.pcc.clk_div = cfg->clk_div; in eth_numaker_init()
728 ret = clock_control_on(cfg->clk_dev, (clock_control_subsys_t)&scc_subsys); in eth_numaker_init()
736 if (!device_is_ready(cfg->reset.dev)) { in eth_numaker_init()
738 return -ENODEV; in eth_numaker_init()
744 ret = pinctrl_apply_state(cfg->pincfg, PINCTRL_STATE_DEFAULT); in eth_numaker_init()
751 reset_line_toggle_dt(&cfg->reset); in eth_numaker_init()
757 ret = m_numaker_gmacdev_init(gmacdev, mac_addr, cfg->gmac_base); in eth_numaker_init()