Lines Matching +full:ep9301 +full:- +full:eth

1 // SPDX-License-Identifier: GPL-2.0-or-later
10 #include <linux/dma-mapping.h>
25 #define DRV_MODULE_NAME "ep93xx-eth"
176 #define rdb(ep, off) __raw_readb((ep)->base_addr + (off))
177 #define rdw(ep, off) __raw_readw((ep)->base_addr + (off))
178 #define rdl(ep, off) __raw_readl((ep)->base_addr + (off))
179 #define wrb(ep, off, val) __raw_writeb((val), (ep)->base_addr + (off))
180 #define wrw(ep, off, val) __raw_writew((val), (ep)->base_addr + (off))
181 #define wrl(ep, off, val) __raw_writel((val), (ep)->base_addr + (off))
238 entry = ep->rx_pointer; in ep93xx_rx()
239 rstat = ep->descs->rstat + entry; in ep93xx_rx()
241 rstat0 = rstat->rstat0; in ep93xx_rx()
242 rstat1 = rstat->rstat1; in ep93xx_rx()
246 rstat->rstat0 = 0; in ep93xx_rx()
247 rstat->rstat1 = 0; in ep93xx_rx()
250 pr_crit("not end-of-frame %.8x %.8x\n", rstat0, rstat1); in ep93xx_rx()
252 pr_crit("not end-of-buffer %.8x %.8x\n", rstat0, rstat1); in ep93xx_rx()
257 dev->stats.rx_errors++; in ep93xx_rx()
259 dev->stats.rx_fifo_errors++; in ep93xx_rx()
261 dev->stats.rx_frame_errors++; in ep93xx_rx()
263 dev->stats.rx_length_errors++; in ep93xx_rx()
265 dev->stats.rx_crc_errors++; in ep93xx_rx()
277 length -= 4; in ep93xx_rx()
281 struct ep93xx_rdesc *rxd = &ep->descs->rdesc[entry]; in ep93xx_rx()
283 dma_sync_single_for_cpu(dev->dev.parent, rxd->buf_addr, in ep93xx_rx()
285 skb_copy_to_linear_data(skb, ep->rx_buf[entry], length); in ep93xx_rx()
286 dma_sync_single_for_device(dev->dev.parent, in ep93xx_rx()
287 rxd->buf_addr, length, in ep93xx_rx()
290 skb->protocol = eth_type_trans(skb, dev); in ep93xx_rx()
292 napi_gro_receive(&ep->napi, skb); in ep93xx_rx()
294 dev->stats.rx_packets++; in ep93xx_rx()
295 dev->stats.rx_bytes += length; in ep93xx_rx()
297 dev->stats.rx_dropped++; in ep93xx_rx()
301 ep->rx_pointer = (entry + 1) & (RX_QUEUE_ENTRIES - 1); in ep93xx_rx()
311 struct net_device *dev = ep->dev; in ep93xx_poll()
316 spin_lock_irq(&ep->rx_lock); in ep93xx_poll()
318 spin_unlock_irq(&ep->rx_lock); in ep93xx_poll()
335 if (unlikely(skb->len > MAX_PKT_SIZE)) { in ep93xx_xmit()
336 dev->stats.tx_dropped++; in ep93xx_xmit()
341 entry = ep->tx_pointer; in ep93xx_xmit()
342 ep->tx_pointer = (ep->tx_pointer + 1) & (TX_QUEUE_ENTRIES - 1); in ep93xx_xmit()
344 txd = &ep->descs->tdesc[entry]; in ep93xx_xmit()
346 txd->tdesc1 = TDESC1_EOF | (entry << 16) | (skb->len & 0xfff); in ep93xx_xmit()
347 dma_sync_single_for_cpu(dev->dev.parent, txd->buf_addr, skb->len, in ep93xx_xmit()
349 skb_copy_and_csum_dev(skb, ep->tx_buf[entry]); in ep93xx_xmit()
350 dma_sync_single_for_device(dev->dev.parent, txd->buf_addr, skb->len, in ep93xx_xmit()
354 spin_lock_irq(&ep->tx_pending_lock); in ep93xx_xmit()
355 ep->tx_pending++; in ep93xx_xmit()
356 if (ep->tx_pending == TX_QUEUE_ENTRIES) in ep93xx_xmit()
358 spin_unlock_irq(&ep->tx_pending_lock); in ep93xx_xmit()
372 spin_lock(&ep->tx_pending_lock); in ep93xx_tx_complete()
378 entry = ep->tx_clean_pointer; in ep93xx_tx_complete()
379 tstat = ep->descs->tstat + entry; in ep93xx_tx_complete()
381 tstat0 = tstat->tstat0; in ep93xx_tx_complete()
385 tstat->tstat0 = 0; in ep93xx_tx_complete()
393 int length = ep->descs->tdesc[entry].tdesc1 & 0xfff; in ep93xx_tx_complete()
395 dev->stats.tx_packets++; in ep93xx_tx_complete()
396 dev->stats.tx_bytes += length; in ep93xx_tx_complete()
398 dev->stats.tx_errors++; in ep93xx_tx_complete()
402 dev->stats.tx_window_errors++; in ep93xx_tx_complete()
404 dev->stats.tx_fifo_errors++; in ep93xx_tx_complete()
405 dev->stats.collisions += (tstat0 >> 16) & 0x1f; in ep93xx_tx_complete()
407 ep->tx_clean_pointer = (entry + 1) & (TX_QUEUE_ENTRIES - 1); in ep93xx_tx_complete()
408 if (ep->tx_pending == TX_QUEUE_ENTRIES) in ep93xx_tx_complete()
410 ep->tx_pending--; in ep93xx_tx_complete()
412 spin_unlock(&ep->tx_pending_lock); in ep93xx_tx_complete()
429 spin_lock(&ep->rx_lock); in ep93xx_irq()
430 if (likely(napi_schedule_prep(&ep->napi))) { in ep93xx_irq()
432 __napi_schedule(&ep->napi); in ep93xx_irq()
434 spin_unlock(&ep->rx_lock); in ep93xx_irq()
445 struct device *dev = ep->dev->dev.parent; in ep93xx_free_buffers()
448 if (!ep->descs) in ep93xx_free_buffers()
454 d = ep->descs->rdesc[i].buf_addr; in ep93xx_free_buffers()
458 kfree(ep->rx_buf[i]); in ep93xx_free_buffers()
464 d = ep->descs->tdesc[i].buf_addr; in ep93xx_free_buffers()
468 kfree(ep->tx_buf[i]); in ep93xx_free_buffers()
471 dma_free_coherent(dev, sizeof(struct ep93xx_descs), ep->descs, in ep93xx_free_buffers()
472 ep->descs_dma_addr); in ep93xx_free_buffers()
473 ep->descs = NULL; in ep93xx_free_buffers()
478 struct device *dev = ep->dev->dev.parent; in ep93xx_alloc_buffers()
481 ep->descs = dma_alloc_coherent(dev, sizeof(struct ep93xx_descs), in ep93xx_alloc_buffers()
482 &ep->descs_dma_addr, GFP_KERNEL); in ep93xx_alloc_buffers()
483 if (ep->descs == NULL) in ep93xx_alloc_buffers()
500 ep->rx_buf[i] = buf; in ep93xx_alloc_buffers()
501 ep->descs->rdesc[i].buf_addr = d; in ep93xx_alloc_buffers()
502 ep->descs->rdesc[i].rdesc1 = (i << 16) | PKT_BUF_SIZE; in ep93xx_alloc_buffers()
519 ep->tx_buf[i] = buf; in ep93xx_alloc_buffers()
520 ep->descs->tdesc[i].buf_addr = d; in ep93xx_alloc_buffers()
548 wrl(ep, REG_SELFCTL, ((ep->mdc_divisor - 1) << 9)); in ep93xx_start_hw()
551 if ((ep93xx_mdio_read(dev, ep->mii.phy_id, MII_BMSR) & 0x0040) != 0) in ep93xx_start_hw()
552 wrl(ep, REG_SELFCTL, ((ep->mdc_divisor - 1) << 9) | (1 << 8)); in ep93xx_start_hw()
555 addr = ep->descs_dma_addr + offsetof(struct ep93xx_descs, rdesc); in ep93xx_start_hw()
561 addr = ep->descs_dma_addr + offsetof(struct ep93xx_descs, rstat); in ep93xx_start_hw()
567 addr = ep->descs_dma_addr + offsetof(struct ep93xx_descs, tdesc); in ep93xx_start_hw()
573 addr = ep->descs_dma_addr + offsetof(struct ep93xx_descs, tstat); in ep93xx_start_hw()
596 wrb(ep, REG_INDAD0, dev->dev_addr[0]); in ep93xx_start_hw()
597 wrb(ep, REG_INDAD1, dev->dev_addr[1]); in ep93xx_start_hw()
598 wrb(ep, REG_INDAD2, dev->dev_addr[2]); in ep93xx_start_hw()
599 wrb(ep, REG_INDAD3, dev->dev_addr[3]); in ep93xx_start_hw()
600 wrb(ep, REG_INDAD4, dev->dev_addr[4]); in ep93xx_start_hw()
601 wrb(ep, REG_INDAD5, dev->dev_addr[5]); in ep93xx_start_hw()
634 return -ENOMEM; in ep93xx_open()
636 napi_enable(&ep->napi); in ep93xx_open()
639 napi_disable(&ep->napi); in ep93xx_open()
641 return -EIO; in ep93xx_open()
644 spin_lock_init(&ep->rx_lock); in ep93xx_open()
645 ep->rx_pointer = 0; in ep93xx_open()
646 ep->tx_clean_pointer = 0; in ep93xx_open()
647 ep->tx_pointer = 0; in ep93xx_open()
648 spin_lock_init(&ep->tx_pending_lock); in ep93xx_open()
649 ep->tx_pending = 0; in ep93xx_open()
651 err = request_irq(ep->irq, ep93xx_irq, IRQF_SHARED, dev->name, dev); in ep93xx_open()
653 napi_disable(&ep->napi); in ep93xx_open()
670 napi_disable(&ep->napi); in ep93xx_close()
674 free_irq(ep->irq, dev); in ep93xx_close()
686 return generic_mii_ioctl(&ep->mii, data, cmd, NULL); in ep93xx_ioctl()
691 strscpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); in ep93xx_get_drvinfo()
699 mii_ethtool_get_link_ksettings(&ep->mii, cmd); in ep93xx_get_link_ksettings()
708 return mii_ethtool_set_link_ksettings(&ep->mii, cmd); in ep93xx_set_link_ksettings()
714 return mii_nway_restart(&ep->mii); in ep93xx_nway_reset()
720 return mii_link_ok(&ep->mii); in ep93xx_get_link()
756 if (ep->base_addr != NULL) in ep93xx_eth_remove()
757 iounmap(ep->base_addr); in ep93xx_eth_remove()
759 if (ep->res != NULL) { in ep93xx_eth_remove()
761 release_mem_region(mem->start, resource_size(mem)); in ep93xx_eth_remove()
780 return -ENODEV; in ep93xx_eth_probe()
785 return -ENXIO; in ep93xx_eth_probe()
787 base_addr = ioremap(mem->start, resource_size(mem)); in ep93xx_eth_probe()
789 return dev_err_probe(&pdev->dev, -EIO, "Failed to ioremap ethernet registers\n"); in ep93xx_eth_probe()
791 np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0); in ep93xx_eth_probe()
793 return dev_err_probe(&pdev->dev, -ENODEV, "Please provide \"phy-handle\"\n"); in ep93xx_eth_probe()
798 return dev_err_probe(&pdev->dev, -ENOENT, "Failed to locate \"phy_id\"\n"); in ep93xx_eth_probe()
802 err = -ENOMEM; in ep93xx_eth_probe()
808 dev->ethtool_ops = &ep93xx_ethtool_ops; in ep93xx_eth_probe()
809 dev->netdev_ops = &ep93xx_netdev_ops; in ep93xx_eth_probe()
810 dev->features |= NETIF_F_SG | NETIF_F_HW_CSUM; in ep93xx_eth_probe()
813 ep->dev = dev; in ep93xx_eth_probe()
814 SET_NETDEV_DEV(dev, &pdev->dev); in ep93xx_eth_probe()
815 netif_napi_add(dev, &ep->napi, ep93xx_poll); in ep93xx_eth_probe()
819 ep->res = request_mem_region(mem->start, resource_size(mem), in ep93xx_eth_probe()
820 dev_name(&pdev->dev)); in ep93xx_eth_probe()
821 if (ep->res == NULL) { in ep93xx_eth_probe()
822 dev_err(&pdev->dev, "Could not reserve memory region\n"); in ep93xx_eth_probe()
823 err = -ENOMEM; in ep93xx_eth_probe()
827 ep->base_addr = base_addr; in ep93xx_eth_probe()
828 ep->irq = irq; in ep93xx_eth_probe()
830 ep->mii.phy_id = phy_id; in ep93xx_eth_probe()
831 ep->mii.phy_id_mask = 0x1f; in ep93xx_eth_probe()
832 ep->mii.reg_num_mask = 0x1f; in ep93xx_eth_probe()
833 ep->mii.dev = dev; in ep93xx_eth_probe()
834 ep->mii.mdio_read = ep93xx_mdio_read; in ep93xx_eth_probe()
835 ep->mii.mdio_write = ep93xx_mdio_write; in ep93xx_eth_probe()
836 ep->mdc_divisor = 40; /* Max HCLK 100 MHz, min MDIO clk 2.5 MHz. */ in ep93xx_eth_probe()
838 if (is_zero_ether_addr(dev->dev_addr)) in ep93xx_eth_probe()
843 dev_err(&pdev->dev, "Failed to register netdev\n"); in ep93xx_eth_probe()
847 printk(KERN_INFO "%s: ep93xx on-chip ethernet, IRQ %d, %pM\n", in ep93xx_eth_probe()
848 dev->name, ep->irq, dev->dev_addr); in ep93xx_eth_probe()
858 { .compatible = "cirrus,ep9301-eth" },
867 .name = "ep93xx-eth",
876 MODULE_ALIAS("platform:ep93xx-eth");