Lines Matching refs:priv
84 static int ftmac100_alloc_rx_page(struct ftmac100 *priv,
100 static void ftmac100_enable_all_int(struct ftmac100 *priv) in ftmac100_enable_all_int() argument
102 iowrite32(INT_MASK_ALL_ENABLED, priv->base + FTMAC100_OFFSET_IMR); in ftmac100_enable_all_int()
105 static void ftmac100_disable_all_int(struct ftmac100 *priv) in ftmac100_disable_all_int() argument
107 iowrite32(INT_MASK_ALL_DISABLED, priv->base + FTMAC100_OFFSET_IMR); in ftmac100_disable_all_int()
110 static void ftmac100_set_rx_ring_base(struct ftmac100 *priv, dma_addr_t addr) in ftmac100_set_rx_ring_base() argument
112 iowrite32(addr, priv->base + FTMAC100_OFFSET_RXR_BADR); in ftmac100_set_rx_ring_base()
115 static void ftmac100_set_tx_ring_base(struct ftmac100 *priv, dma_addr_t addr) in ftmac100_set_tx_ring_base() argument
117 iowrite32(addr, priv->base + FTMAC100_OFFSET_TXR_BADR); in ftmac100_set_tx_ring_base()
120 static void ftmac100_txdma_start_polling(struct ftmac100 *priv) in ftmac100_txdma_start_polling() argument
122 iowrite32(1, priv->base + FTMAC100_OFFSET_TXPD); in ftmac100_txdma_start_polling()
125 static int ftmac100_reset(struct ftmac100 *priv) in ftmac100_reset() argument
127 struct net_device *netdev = priv->netdev; in ftmac100_reset()
131 iowrite32(FTMAC100_MACCR_SW_RST, priv->base + FTMAC100_OFFSET_MACCR); in ftmac100_reset()
136 maccr = ioread32(priv->base + FTMAC100_OFFSET_MACCR); in ftmac100_reset()
154 static void ftmac100_set_mac(struct ftmac100 *priv, const unsigned char *mac) in ftmac100_set_mac() argument
159 iowrite32(maddr, priv->base + FTMAC100_OFFSET_MAC_MADR); in ftmac100_set_mac()
160 iowrite32(laddr, priv->base + FTMAC100_OFFSET_MAC_LADR); in ftmac100_set_mac()
172 static int ftmac100_start_hw(struct ftmac100 *priv) in ftmac100_start_hw() argument
174 struct net_device *netdev = priv->netdev; in ftmac100_start_hw()
176 if (ftmac100_reset(priv)) in ftmac100_start_hw()
180 ftmac100_set_rx_ring_base(priv, in ftmac100_start_hw()
181 priv->descs_dma_addr + in ftmac100_start_hw()
183 ftmac100_set_tx_ring_base(priv, in ftmac100_start_hw()
184 priv->descs_dma_addr + in ftmac100_start_hw()
187 iowrite32(FTMAC100_APTC_RXPOLL_CNT(1), priv->base + FTMAC100_OFFSET_APTC); in ftmac100_start_hw()
189 ftmac100_set_mac(priv, netdev->dev_addr); in ftmac100_start_hw()
191 iowrite32(MACCR_ENABLE_ALL, priv->base + FTMAC100_OFFSET_MACCR); in ftmac100_start_hw()
195 static void ftmac100_stop_hw(struct ftmac100 *priv) in ftmac100_stop_hw() argument
197 iowrite32(0, priv->base + FTMAC100_OFFSET_MACCR); in ftmac100_stop_hw()
304 static void ftmac100_rx_pointer_advance(struct ftmac100 *priv) in ftmac100_rx_pointer_advance() argument
306 priv->rx_pointer = ftmac100_next_rx_pointer(priv->rx_pointer); in ftmac100_rx_pointer_advance()
309 static struct ftmac100_rxdes *ftmac100_current_rxdes(struct ftmac100 *priv) in ftmac100_current_rxdes() argument
311 return &priv->descs->rxdes[priv->rx_pointer]; in ftmac100_current_rxdes()
315 ftmac100_rx_locate_first_segment(struct ftmac100 *priv) in ftmac100_rx_locate_first_segment() argument
317 struct ftmac100_rxdes *rxdes = ftmac100_current_rxdes(priv); in ftmac100_rx_locate_first_segment()
324 ftmac100_rx_pointer_advance(priv); in ftmac100_rx_locate_first_segment()
325 rxdes = ftmac100_current_rxdes(priv); in ftmac100_rx_locate_first_segment()
331 static bool ftmac100_rx_packet_error(struct ftmac100 *priv, in ftmac100_rx_packet_error() argument
334 struct net_device *netdev = priv->netdev; in ftmac100_rx_packet_error()
376 static void ftmac100_rx_drop_packet(struct ftmac100 *priv) in ftmac100_rx_drop_packet() argument
378 struct net_device *netdev = priv->netdev; in ftmac100_rx_drop_packet()
379 struct ftmac100_rxdes *rxdes = ftmac100_current_rxdes(priv); in ftmac100_rx_drop_packet()
390 ftmac100_rx_pointer_advance(priv); in ftmac100_rx_drop_packet()
391 rxdes = ftmac100_current_rxdes(priv); in ftmac100_rx_drop_packet()
397 static bool ftmac100_rx_packet(struct ftmac100 *priv, int *processed) in ftmac100_rx_packet() argument
399 struct net_device *netdev = priv->netdev; in ftmac100_rx_packet()
406 rxdes = ftmac100_rx_locate_first_segment(priv); in ftmac100_rx_packet()
410 if (unlikely(ftmac100_rx_packet_error(priv, rxdes))) { in ftmac100_rx_packet()
411 ftmac100_rx_drop_packet(priv); in ftmac100_rx_packet()
428 ftmac100_rx_drop_packet(priv); in ftmac100_rx_packet()
436 dma_unmap_page(priv->dev, map, RX_BUF_SIZE, DMA_FROM_DEVICE); in ftmac100_rx_packet()
452 ftmac100_alloc_rx_page(priv, rxdes, GFP_ATOMIC); in ftmac100_rx_packet()
454 ftmac100_rx_pointer_advance(priv); in ftmac100_rx_packet()
564 static void ftmac100_tx_pointer_advance(struct ftmac100 *priv) in ftmac100_tx_pointer_advance() argument
566 priv->tx_pointer = ftmac100_next_tx_pointer(priv->tx_pointer); in ftmac100_tx_pointer_advance()
569 static void ftmac100_tx_clean_pointer_advance(struct ftmac100 *priv) in ftmac100_tx_clean_pointer_advance() argument
571 priv->tx_clean_pointer = ftmac100_next_tx_pointer(priv->tx_clean_pointer); in ftmac100_tx_clean_pointer_advance()
574 static struct ftmac100_txdes *ftmac100_current_txdes(struct ftmac100 *priv) in ftmac100_current_txdes() argument
576 return &priv->descs->txdes[priv->tx_pointer]; in ftmac100_current_txdes()
579 static struct ftmac100_txdes *ftmac100_current_clean_txdes(struct ftmac100 *priv) in ftmac100_current_clean_txdes() argument
581 return &priv->descs->txdes[priv->tx_clean_pointer]; in ftmac100_current_clean_txdes()
584 static bool ftmac100_tx_complete_packet(struct ftmac100 *priv) in ftmac100_tx_complete_packet() argument
586 struct net_device *netdev = priv->netdev; in ftmac100_tx_complete_packet()
591 if (priv->tx_pending == 0) in ftmac100_tx_complete_packet()
594 txdes = ftmac100_current_clean_txdes(priv); in ftmac100_tx_complete_packet()
614 dma_unmap_single(priv->dev, map, skb_headlen(skb), DMA_TO_DEVICE); in ftmac100_tx_complete_packet()
619 ftmac100_tx_clean_pointer_advance(priv); in ftmac100_tx_complete_packet()
621 spin_lock(&priv->tx_lock); in ftmac100_tx_complete_packet()
622 priv->tx_pending--; in ftmac100_tx_complete_packet()
623 spin_unlock(&priv->tx_lock); in ftmac100_tx_complete_packet()
629 static void ftmac100_tx_complete(struct ftmac100 *priv) in ftmac100_tx_complete() argument
631 while (ftmac100_tx_complete_packet(priv)) in ftmac100_tx_complete()
635 static int ftmac100_xmit(struct ftmac100 *priv, struct sk_buff *skb, in ftmac100_xmit() argument
638 struct net_device *netdev = priv->netdev; in ftmac100_xmit()
642 txdes = ftmac100_current_txdes(priv); in ftmac100_xmit()
643 ftmac100_tx_pointer_advance(priv); in ftmac100_xmit()
654 spin_lock(&priv->tx_lock); in ftmac100_xmit()
655 priv->tx_pending++; in ftmac100_xmit()
656 if (priv->tx_pending == TX_QUEUE_ENTRIES) in ftmac100_xmit()
661 spin_unlock(&priv->tx_lock); in ftmac100_xmit()
663 ftmac100_txdma_start_polling(priv); in ftmac100_xmit()
670 static int ftmac100_alloc_rx_page(struct ftmac100 *priv, in ftmac100_alloc_rx_page() argument
673 struct net_device *netdev = priv->netdev; in ftmac100_alloc_rx_page()
684 map = dma_map_page(priv->dev, page, 0, RX_BUF_SIZE, DMA_FROM_DEVICE); in ftmac100_alloc_rx_page()
685 if (unlikely(dma_mapping_error(priv->dev, map))) { in ftmac100_alloc_rx_page()
699 static void ftmac100_free_buffers(struct ftmac100 *priv) in ftmac100_free_buffers() argument
704 struct ftmac100_rxdes *rxdes = &priv->descs->rxdes[i]; in ftmac100_free_buffers()
711 dma_unmap_page(priv->dev, map, RX_BUF_SIZE, DMA_FROM_DEVICE); in ftmac100_free_buffers()
716 struct ftmac100_txdes *txdes = &priv->descs->txdes[i]; in ftmac100_free_buffers()
723 dma_unmap_single(priv->dev, map, skb_headlen(skb), DMA_TO_DEVICE); in ftmac100_free_buffers()
727 dma_free_coherent(priv->dev, sizeof(struct ftmac100_descs), in ftmac100_free_buffers()
728 priv->descs, priv->descs_dma_addr); in ftmac100_free_buffers()
731 static int ftmac100_alloc_buffers(struct ftmac100 *priv) in ftmac100_alloc_buffers() argument
735 priv->descs = dma_zalloc_coherent(priv->dev, in ftmac100_alloc_buffers()
737 &priv->descs_dma_addr, in ftmac100_alloc_buffers()
739 if (!priv->descs) in ftmac100_alloc_buffers()
743 ftmac100_rxdes_set_end_of_ring(&priv->descs->rxdes[RX_QUEUE_ENTRIES - 1]); in ftmac100_alloc_buffers()
746 struct ftmac100_rxdes *rxdes = &priv->descs->rxdes[i]; in ftmac100_alloc_buffers()
748 if (ftmac100_alloc_rx_page(priv, rxdes, GFP_KERNEL)) in ftmac100_alloc_buffers()
753 ftmac100_txdes_set_end_of_ring(&priv->descs->txdes[TX_QUEUE_ENTRIES - 1]); in ftmac100_alloc_buffers()
757 ftmac100_free_buffers(priv); in ftmac100_alloc_buffers()
766 struct ftmac100 *priv = netdev_priv(netdev); in ftmac100_mdio_read() local
774 iowrite32(phycr, priv->base + FTMAC100_OFFSET_PHYCR); in ftmac100_mdio_read()
777 phycr = ioread32(priv->base + FTMAC100_OFFSET_PHYCR); in ftmac100_mdio_read()
792 struct ftmac100 *priv = netdev_priv(netdev); in ftmac100_mdio_write() local
802 iowrite32(data, priv->base + FTMAC100_OFFSET_PHYWDATA); in ftmac100_mdio_write()
803 iowrite32(phycr, priv->base + FTMAC100_OFFSET_PHYCR); in ftmac100_mdio_write()
806 phycr = ioread32(priv->base + FTMAC100_OFFSET_PHYCR); in ftmac100_mdio_write()
830 struct ftmac100 *priv = netdev_priv(netdev); in ftmac100_get_settings() local
831 return mii_ethtool_gset(&priv->mii, cmd); in ftmac100_get_settings()
836 struct ftmac100 *priv = netdev_priv(netdev); in ftmac100_set_settings() local
837 return mii_ethtool_sset(&priv->mii, cmd); in ftmac100_set_settings()
842 struct ftmac100 *priv = netdev_priv(netdev); in ftmac100_nway_reset() local
843 return mii_nway_restart(&priv->mii); in ftmac100_nway_reset()
848 struct ftmac100 *priv = netdev_priv(netdev); in ftmac100_get_link() local
849 return mii_link_ok(&priv->mii); in ftmac100_get_link()
866 struct ftmac100 *priv = netdev_priv(netdev); in ftmac100_interrupt() local
870 ftmac100_disable_all_int(priv); in ftmac100_interrupt()
871 napi_schedule(&priv->napi); in ftmac100_interrupt()
882 struct ftmac100 *priv = container_of(napi, struct ftmac100, napi); in ftmac100_poll() local
883 struct net_device *netdev = priv->netdev; in ftmac100_poll()
888 status = ioread32(priv->base + FTMAC100_OFFSET_ISR); in ftmac100_poll()
901 retry = ftmac100_rx_packet(priv, &rx); in ftmac100_poll()
917 ftmac100_tx_complete(priv); in ftmac100_poll()
941 mii_check_link(&priv->mii); in ftmac100_poll()
948 ftmac100_enable_all_int(priv); in ftmac100_poll()
959 struct ftmac100 *priv = netdev_priv(netdev); in ftmac100_open() local
962 err = ftmac100_alloc_buffers(priv); in ftmac100_open()
968 err = request_irq(priv->irq, ftmac100_interrupt, 0, netdev->name, netdev); in ftmac100_open()
970 netdev_err(netdev, "failed to request irq %d\n", priv->irq); in ftmac100_open()
974 priv->rx_pointer = 0; in ftmac100_open()
975 priv->tx_clean_pointer = 0; in ftmac100_open()
976 priv->tx_pointer = 0; in ftmac100_open()
977 priv->tx_pending = 0; in ftmac100_open()
979 err = ftmac100_start_hw(priv); in ftmac100_open()
983 napi_enable(&priv->napi); in ftmac100_open()
986 ftmac100_enable_all_int(priv); in ftmac100_open()
991 free_irq(priv->irq, netdev); in ftmac100_open()
993 ftmac100_free_buffers(priv); in ftmac100_open()
1000 struct ftmac100 *priv = netdev_priv(netdev); in ftmac100_stop() local
1002 ftmac100_disable_all_int(priv); in ftmac100_stop()
1004 napi_disable(&priv->napi); in ftmac100_stop()
1005 ftmac100_stop_hw(priv); in ftmac100_stop()
1006 free_irq(priv->irq, netdev); in ftmac100_stop()
1007 ftmac100_free_buffers(priv); in ftmac100_stop()
1014 struct ftmac100 *priv = netdev_priv(netdev); in ftmac100_hard_start_xmit() local
1026 map = dma_map_single(priv->dev, skb->data, skb_headlen(skb), DMA_TO_DEVICE); in ftmac100_hard_start_xmit()
1027 if (unlikely(dma_mapping_error(priv->dev, map))) { in ftmac100_hard_start_xmit()
1037 return ftmac100_xmit(priv, skb, map); in ftmac100_hard_start_xmit()
1043 struct ftmac100 *priv = netdev_priv(netdev); in ftmac100_do_ioctl() local
1046 return generic_mii_ioctl(&priv->mii, data, cmd, NULL); in ftmac100_do_ioctl()
1066 struct ftmac100 *priv; in ftmac100_probe() local
1081 netdev = alloc_etherdev(sizeof(*priv)); in ftmac100_probe()
1094 priv = netdev_priv(netdev); in ftmac100_probe()
1095 priv->netdev = netdev; in ftmac100_probe()
1096 priv->dev = &pdev->dev; in ftmac100_probe()
1098 spin_lock_init(&priv->tx_lock); in ftmac100_probe()
1101 netif_napi_add(netdev, &priv->napi, ftmac100_poll, 64); in ftmac100_probe()
1104 priv->res = request_mem_region(res->start, resource_size(res), in ftmac100_probe()
1106 if (!priv->res) { in ftmac100_probe()
1112 priv->base = ioremap(res->start, resource_size(res)); in ftmac100_probe()
1113 if (!priv->base) { in ftmac100_probe()
1119 priv->irq = irq; in ftmac100_probe()
1122 priv->mii.phy_id = 0; in ftmac100_probe()
1123 priv->mii.phy_id_mask = 0x1f; in ftmac100_probe()
1124 priv->mii.reg_num_mask = 0x1f; in ftmac100_probe()
1125 priv->mii.dev = netdev; in ftmac100_probe()
1126 priv->mii.mdio_read = ftmac100_mdio_read; in ftmac100_probe()
1127 priv->mii.mdio_write = ftmac100_mdio_write; in ftmac100_probe()
1136 netdev_info(netdev, "irq %d, mapped at %p\n", priv->irq, priv->base); in ftmac100_probe()
1147 iounmap(priv->base); in ftmac100_probe()
1149 release_resource(priv->res); in ftmac100_probe()
1151 netif_napi_del(&priv->napi); in ftmac100_probe()
1160 struct ftmac100 *priv; in ftmac100_remove() local
1163 priv = netdev_priv(netdev); in ftmac100_remove()
1167 iounmap(priv->base); in ftmac100_remove()
1168 release_resource(priv->res); in ftmac100_remove()
1170 netif_napi_del(&priv->napi); in ftmac100_remove()