Lines Matching refs:lp

378 static dma_addr_t korina_tx_dma(struct korina_private *lp, int idx)  in korina_tx_dma()  argument
380 return lp->td_dma + (idx * sizeof(struct dma_desc)); in korina_tx_dma()
383 static dma_addr_t korina_rx_dma(struct korina_private *lp, int idx) in korina_rx_dma() argument
385 return lp->rd_dma + (idx * sizeof(struct dma_desc)); in korina_rx_dma()
406 struct korina_private *lp = netdev_priv(dev); in korina_abort_tx() local
408 korina_abort_dma(dev, lp->tx_dma_regs); in korina_abort_tx()
413 struct korina_private *lp = netdev_priv(dev); in korina_abort_rx() local
415 korina_abort_dma(dev, lp->rx_dma_regs); in korina_abort_rx()
422 struct korina_private *lp = netdev_priv(dev); in korina_send_packet() local
430 spin_lock_irqsave(&lp->lock, flags); in korina_send_packet()
432 idx = lp->tx_chain_tail; in korina_send_packet()
433 td = &lp->td_ring[idx]; in korina_send_packet()
436 if (lp->tx_count >= (KORINA_NUM_TDS - 2)) { in korina_send_packet()
437 lp->tx_full = 1; in korina_send_packet()
439 if (lp->tx_count == (KORINA_NUM_TDS - 2)) in korina_send_packet()
445 lp->tx_count++; in korina_send_packet()
447 lp->tx_skb[idx] = skb; in korina_send_packet()
452 ca = dma_map_single(lp->dmadev, skb->data, length, DMA_TO_DEVICE); in korina_send_packet()
453 if (dma_mapping_error(lp->dmadev, ca)) in korina_send_packet()
456 lp->tx_skb_dma[idx] = ca; in korina_send_packet()
462 if (readl(&(lp->tx_dma_regs->dmandptr)) == 0) { in korina_send_packet()
463 if (lp->tx_chain_status == desc_is_empty) { in korina_send_packet()
468 lp->tx_chain_tail = chain_next; in korina_send_packet()
470 writel(korina_tx_dma(lp, lp->tx_chain_head), in korina_send_packet()
471 &lp->tx_dma_regs->dmandptr); in korina_send_packet()
473 lp->tx_chain_head = lp->tx_chain_tail; in korina_send_packet()
479 lp->td_ring[chain_prev].control &= in korina_send_packet()
482 lp->td_ring[chain_prev].link = korina_tx_dma(lp, idx); in korina_send_packet()
484 lp->tx_chain_tail = chain_next; in korina_send_packet()
486 writel(korina_tx_dma(lp, lp->tx_chain_head), in korina_send_packet()
487 &lp->tx_dma_regs->dmandptr); in korina_send_packet()
489 lp->tx_chain_head = lp->tx_chain_tail; in korina_send_packet()
490 lp->tx_chain_status = desc_is_empty; in korina_send_packet()
493 if (lp->tx_chain_status == desc_is_empty) { in korina_send_packet()
498 lp->tx_chain_tail = chain_next; in korina_send_packet()
499 lp->tx_chain_status = desc_filled; in korina_send_packet()
504 lp->td_ring[chain_prev].control &= in korina_send_packet()
506 lp->td_ring[chain_prev].link = korina_tx_dma(lp, idx); in korina_send_packet()
507 lp->tx_chain_tail = chain_next; in korina_send_packet()
512 spin_unlock_irqrestore(&lp->lock, flags); in korina_send_packet()
519 spin_unlock_irqrestore(&lp->lock, flags); in korina_send_packet()
524 static int korina_mdio_wait(struct korina_private *lp) in korina_mdio_wait() argument
528 return readl_poll_timeout_atomic(&lp->eth_regs->miimind, in korina_mdio_wait()
535 struct korina_private *lp = netdev_priv(dev); in korina_mdio_read() local
538 ret = korina_mdio_wait(lp); in korina_mdio_read()
542 writel(phy << 8 | reg, &lp->eth_regs->miimaddr); in korina_mdio_read()
543 writel(1, &lp->eth_regs->miimcmd); in korina_mdio_read()
545 ret = korina_mdio_wait(lp); in korina_mdio_read()
549 if (readl(&lp->eth_regs->miimind) & ETH_MII_IND_NV) in korina_mdio_read()
552 ret = readl(&lp->eth_regs->miimrdd); in korina_mdio_read()
553 writel(0, &lp->eth_regs->miimcmd); in korina_mdio_read()
559 struct korina_private *lp = netdev_priv(dev); in korina_mdio_write() local
561 if (korina_mdio_wait(lp)) in korina_mdio_write()
564 writel(0, &lp->eth_regs->miimcmd); in korina_mdio_write()
565 writel(phy << 8 | reg, &lp->eth_regs->miimaddr); in korina_mdio_write()
566 writel(val, &lp->eth_regs->miimwtd); in korina_mdio_write()
573 struct korina_private *lp = netdev_priv(dev); in korina_rx_dma_interrupt() local
577 dmas = readl(&lp->rx_dma_regs->dmas); in korina_rx_dma_interrupt()
579 dmasm = readl(&lp->rx_dma_regs->dmasm); in korina_rx_dma_interrupt()
582 &lp->rx_dma_regs->dmasm); in korina_rx_dma_interrupt()
584 napi_schedule(&lp->napi); in korina_rx_dma_interrupt()
598 struct korina_private *lp = netdev_priv(dev); in korina_rx() local
599 struct dma_desc *rd = &lp->rd_ring[lp->rx_next_done]; in korina_rx()
606 skb = lp->rx_skb[lp->rx_next_done]; in korina_rx()
643 ca = dma_map_single(lp->dmadev, skb_new->data, KORINA_RBSIZE, in korina_rx()
645 if (dma_mapping_error(lp->dmadev, ca)) { in korina_rx()
651 dma_unmap_single(lp->dmadev, lp->rx_skb_dma[lp->rx_next_done], in korina_rx()
659 napi_gro_receive(&lp->napi, skb); in korina_rx()
667 lp->rx_skb[lp->rx_next_done] = skb_new; in korina_rx()
668 lp->rx_skb_dma[lp->rx_next_done] = ca; in korina_rx()
674 rd->ca = lp->rx_skb_dma[lp->rx_next_done]; in korina_rx()
678 lp->rd_ring[(lp->rx_next_done - 1) & in korina_rx()
682 lp->rx_next_done = (lp->rx_next_done + 1) & KORINA_RDS_MASK; in korina_rx()
683 rd = &lp->rd_ring[lp->rx_next_done]; in korina_rx()
684 writel((u32)~DMA_STAT_DONE, &lp->rx_dma_regs->dmas); in korina_rx()
687 dmas = readl(&lp->rx_dma_regs->dmas); in korina_rx()
691 &lp->rx_dma_regs->dmas); in korina_rx()
693 lp->dma_halt_cnt++; in korina_rx()
695 rd->ca = lp->rx_skb_dma[lp->rx_next_done]; in korina_rx()
696 writel(korina_rx_dma(lp, rd - lp->rd_ring), in korina_rx()
697 &lp->rx_dma_regs->dmandptr); in korina_rx()
705 struct korina_private *lp = in korina_poll() local
707 struct net_device *dev = lp->dev; in korina_poll()
714 writel(readl(&lp->rx_dma_regs->dmasm) & in korina_poll()
716 &lp->rx_dma_regs->dmasm); in korina_poll()
726 struct korina_private *lp = netdev_priv(dev); in korina_multicast_list() local
754 &lp->eth_regs->ethhash0); in korina_multicast_list()
756 &lp->eth_regs->ethhash1); in korina_multicast_list()
759 spin_lock_irqsave(&lp->lock, flags); in korina_multicast_list()
760 writel(recognise, &lp->eth_regs->etharc); in korina_multicast_list()
761 spin_unlock_irqrestore(&lp->lock, flags); in korina_multicast_list()
766 struct korina_private *lp = netdev_priv(dev); in korina_tx() local
767 struct dma_desc *td = &lp->td_ring[lp->tx_next_done]; in korina_tx()
771 spin_lock(&lp->lock); in korina_tx()
775 if (lp->tx_full == 1) { in korina_tx()
777 lp->tx_full = 0; in korina_tx()
780 devcs = lp->td_ring[lp->tx_next_done].devcs; in korina_tx()
792 lp->tx_skb[lp->tx_next_done]->len; in korina_tx()
819 if (lp->tx_skb[lp->tx_next_done]) { in korina_tx()
820 dma_unmap_single(lp->dmadev, in korina_tx()
821 lp->tx_skb_dma[lp->tx_next_done], in korina_tx()
822 lp->tx_skb[lp->tx_next_done]->len, in korina_tx()
824 dev_kfree_skb_any(lp->tx_skb[lp->tx_next_done]); in korina_tx()
825 lp->tx_skb[lp->tx_next_done] = NULL; in korina_tx()
828 lp->td_ring[lp->tx_next_done].control = DMA_DESC_IOF; in korina_tx()
829 lp->td_ring[lp->tx_next_done].devcs = ETH_TX_FD | ETH_TX_LD; in korina_tx()
830 lp->td_ring[lp->tx_next_done].link = 0; in korina_tx()
831 lp->td_ring[lp->tx_next_done].ca = 0; in korina_tx()
832 lp->tx_count--; in korina_tx()
835 lp->tx_next_done = (lp->tx_next_done + 1) & KORINA_TDS_MASK; in korina_tx()
836 td = &lp->td_ring[lp->tx_next_done]; in korina_tx()
841 dmas = readl(&lp->tx_dma_regs->dmas); in korina_tx()
842 writel(~dmas, &lp->tx_dma_regs->dmas); in korina_tx()
844 writel(readl(&lp->tx_dma_regs->dmasm) & in korina_tx()
846 &lp->tx_dma_regs->dmasm); in korina_tx()
848 spin_unlock(&lp->lock); in korina_tx()
855 struct korina_private *lp = netdev_priv(dev); in korina_tx_dma_interrupt() local
859 dmas = readl(&lp->tx_dma_regs->dmas); in korina_tx_dma_interrupt()
862 dmasm = readl(&lp->tx_dma_regs->dmasm); in korina_tx_dma_interrupt()
864 &lp->tx_dma_regs->dmasm); in korina_tx_dma_interrupt()
868 if (lp->tx_chain_status == desc_filled && in korina_tx_dma_interrupt()
869 (readl(&(lp->tx_dma_regs->dmandptr)) == 0)) { in korina_tx_dma_interrupt()
870 writel(korina_tx_dma(lp, lp->tx_chain_head), in korina_tx_dma_interrupt()
871 &lp->tx_dma_regs->dmandptr); in korina_tx_dma_interrupt()
872 lp->tx_chain_status = desc_is_empty; in korina_tx_dma_interrupt()
873 lp->tx_chain_head = lp->tx_chain_tail; in korina_tx_dma_interrupt()
889 struct korina_private *lp = netdev_priv(dev); in korina_check_media() local
891 mii_check_media(&lp->mii_if, 1, init_media); in korina_check_media()
893 if (lp->mii_if.full_duplex) in korina_check_media()
894 writel(readl(&lp->eth_regs->ethmac2) | ETH_MAC2_FD, in korina_check_media()
895 &lp->eth_regs->ethmac2); in korina_check_media()
897 writel(readl(&lp->eth_regs->ethmac2) & ~ETH_MAC2_FD, in korina_check_media()
898 &lp->eth_regs->ethmac2); in korina_check_media()
903 struct korina_private *lp = from_timer(lp, t, media_check_timer); in korina_poll_media() local
904 struct net_device *dev = lp->dev; in korina_poll_media()
907 mod_timer(&lp->media_check_timer, jiffies + HZ); in korina_poll_media()
922 struct korina_private *lp = netdev_priv(dev); in korina_ioctl() local
928 spin_lock_irq(&lp->lock); in korina_ioctl()
929 rc = generic_mii_ioctl(&lp->mii_if, data, cmd, NULL); in korina_ioctl()
930 spin_unlock_irq(&lp->lock); in korina_ioctl()
931 korina_set_carrier(&lp->mii_if); in korina_ioctl()
940 struct korina_private *lp = netdev_priv(dev); in netdev_get_drvinfo() local
944 strscpy(info->bus_info, lp->dev->name, sizeof(info->bus_info)); in netdev_get_drvinfo()
950 struct korina_private *lp = netdev_priv(dev); in netdev_get_link_ksettings() local
952 spin_lock_irq(&lp->lock); in netdev_get_link_ksettings()
953 mii_ethtool_get_link_ksettings(&lp->mii_if, cmd); in netdev_get_link_ksettings()
954 spin_unlock_irq(&lp->lock); in netdev_get_link_ksettings()
962 struct korina_private *lp = netdev_priv(dev); in netdev_set_link_ksettings() local
965 spin_lock_irq(&lp->lock); in netdev_set_link_ksettings()
966 rc = mii_ethtool_set_link_ksettings(&lp->mii_if, cmd); in netdev_set_link_ksettings()
967 spin_unlock_irq(&lp->lock); in netdev_set_link_ksettings()
968 korina_set_carrier(&lp->mii_if); in netdev_set_link_ksettings()
975 struct korina_private *lp = netdev_priv(dev); in netdev_get_link() local
977 return mii_link_ok(&lp->mii_if); in netdev_get_link()
989 struct korina_private *lp = netdev_priv(dev); in korina_alloc_ring() local
996 lp->td_ring[i].control = DMA_DESC_IOF; in korina_alloc_ring()
997 lp->td_ring[i].devcs = ETH_TX_FD | ETH_TX_LD; in korina_alloc_ring()
998 lp->td_ring[i].ca = 0; in korina_alloc_ring()
999 lp->td_ring[i].link = 0; in korina_alloc_ring()
1001 lp->tx_next_done = lp->tx_chain_head = lp->tx_chain_tail = in korina_alloc_ring()
1002 lp->tx_full = lp->tx_count = 0; in korina_alloc_ring()
1003 lp->tx_chain_status = desc_is_empty; in korina_alloc_ring()
1010 lp->rx_skb[i] = skb; in korina_alloc_ring()
1011 lp->rd_ring[i].control = DMA_DESC_IOD | in korina_alloc_ring()
1013 lp->rd_ring[i].devcs = 0; in korina_alloc_ring()
1014 ca = dma_map_single(lp->dmadev, skb->data, KORINA_RBSIZE, in korina_alloc_ring()
1016 if (dma_mapping_error(lp->dmadev, ca)) in korina_alloc_ring()
1018 lp->rd_ring[i].ca = ca; in korina_alloc_ring()
1019 lp->rx_skb_dma[i] = ca; in korina_alloc_ring()
1020 lp->rd_ring[i].link = korina_rx_dma(lp, i + 1); in korina_alloc_ring()
1025 lp->rd_ring[i - 1].link = lp->rd_dma; in korina_alloc_ring()
1026 lp->rd_ring[i - 1].control |= DMA_DESC_COD; in korina_alloc_ring()
1028 lp->rx_next_done = 0; in korina_alloc_ring()
1029 lp->rx_chain_head = 0; in korina_alloc_ring()
1030 lp->rx_chain_tail = 0; in korina_alloc_ring()
1031 lp->rx_chain_status = desc_is_empty; in korina_alloc_ring()
1038 struct korina_private *lp = netdev_priv(dev); in korina_free_ring() local
1042 lp->rd_ring[i].control = 0; in korina_free_ring()
1043 if (lp->rx_skb[i]) { in korina_free_ring()
1044 dma_unmap_single(lp->dmadev, lp->rx_skb_dma[i], in korina_free_ring()
1046 dev_kfree_skb_any(lp->rx_skb[i]); in korina_free_ring()
1047 lp->rx_skb[i] = NULL; in korina_free_ring()
1052 lp->td_ring[i].control = 0; in korina_free_ring()
1053 if (lp->tx_skb[i]) { in korina_free_ring()
1054 dma_unmap_single(lp->dmadev, lp->tx_skb_dma[i], in korina_free_ring()
1055 lp->tx_skb[i]->len, DMA_TO_DEVICE); in korina_free_ring()
1056 dev_kfree_skb_any(lp->tx_skb[i]); in korina_free_ring()
1057 lp->tx_skb[i] = NULL; in korina_free_ring()
1067 struct korina_private *lp = netdev_priv(dev); in korina_init() local
1074 writel(0, &lp->eth_regs->ethintfc); in korina_init()
1075 while ((readl(&lp->eth_regs->ethintfc) & ETH_INT_FC_RIP)) in korina_init()
1079 writel(ETH_INT_FC_EN, &lp->eth_regs->ethintfc); in korina_init()
1088 writel(0, &lp->rx_dma_regs->dmas); in korina_init()
1090 writel(0, &lp->rx_dma_regs->dmandptr); in korina_init()
1091 writel(korina_rx_dma(lp, 0), &lp->rx_dma_regs->dmadptr); in korina_init()
1093 writel(readl(&lp->tx_dma_regs->dmasm) & in korina_init()
1095 &lp->tx_dma_regs->dmasm); in korina_init()
1096 writel(readl(&lp->rx_dma_regs->dmasm) & in korina_init()
1098 &lp->rx_dma_regs->dmasm); in korina_init()
1101 writel(ETH_ARC_AB, &lp->eth_regs->etharc); in korina_init()
1104 writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal0); in korina_init()
1105 writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah0); in korina_init()
1107 writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal1); in korina_init()
1108 writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah1); in korina_init()
1110 writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal2); in korina_init()
1111 writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah2); in korina_init()
1113 writel(STATION_ADDRESS_LOW(dev), &lp->eth_regs->ethsal3); in korina_init()
1114 writel(STATION_ADDRESS_HIGH(dev), &lp->eth_regs->ethsah3); in korina_init()
1119 &lp->eth_regs->ethmac2); in korina_init()
1122 writel(0x15, &lp->eth_regs->ethipgt); in korina_init()
1124 writel(0x12, &lp->eth_regs->ethipgr); in korina_init()
1128 writel(((lp->mii_clock_freq) / MII_CLOCK + 1) & ~1, in korina_init()
1129 &lp->eth_regs->ethmcp); in korina_init()
1130 writel(0, &lp->eth_regs->miimcfg); in korina_init()
1133 writel(48, &lp->eth_regs->ethfifott); in korina_init()
1135 writel(ETH_MAC1_RE, &lp->eth_regs->ethmac1); in korina_init()
1139 napi_enable(&lp->napi); in korina_init()
1150 struct korina_private *lp = container_of(work, in korina_restart_task() local
1152 struct net_device *dev = lp->dev; in korina_restart_task()
1157 disable_irq(lp->rx_irq); in korina_restart_task()
1158 disable_irq(lp->tx_irq); in korina_restart_task()
1160 writel(readl(&lp->tx_dma_regs->dmasm) | in korina_restart_task()
1162 &lp->tx_dma_regs->dmasm); in korina_restart_task()
1163 writel(readl(&lp->rx_dma_regs->dmasm) | in korina_restart_task()
1165 &lp->rx_dma_regs->dmasm); in korina_restart_task()
1167 napi_disable(&lp->napi); in korina_restart_task()
1177 enable_irq(lp->tx_irq); in korina_restart_task()
1178 enable_irq(lp->rx_irq); in korina_restart_task()
1183 struct korina_private *lp = netdev_priv(dev); in korina_tx_timeout() local
1185 schedule_work(&lp->restart_task); in korina_tx_timeout()
1199 struct korina_private *lp = netdev_priv(dev); in korina_open() local
1211 ret = request_irq(lp->rx_irq, korina_rx_dma_interrupt, in korina_open()
1215 dev->name, lp->rx_irq); in korina_open()
1218 ret = request_irq(lp->tx_irq, korina_tx_dma_interrupt, in korina_open()
1222 dev->name, lp->tx_irq); in korina_open()
1226 mod_timer(&lp->media_check_timer, jiffies + 1); in korina_open()
1231 free_irq(lp->rx_irq, dev); in korina_open()
1239 struct korina_private *lp = netdev_priv(dev); in korina_close() local
1242 del_timer(&lp->media_check_timer); in korina_close()
1245 disable_irq(lp->rx_irq); in korina_close()
1246 disable_irq(lp->tx_irq); in korina_close()
1249 tmp = readl(&lp->tx_dma_regs->dmasm); in korina_close()
1251 writel(tmp, &lp->tx_dma_regs->dmasm); in korina_close()
1254 tmp = readl(&lp->rx_dma_regs->dmasm); in korina_close()
1256 writel(tmp, &lp->rx_dma_regs->dmasm); in korina_close()
1258 napi_disable(&lp->napi); in korina_close()
1260 cancel_work_sync(&lp->restart_task); in korina_close()
1264 free_irq(lp->rx_irq, dev); in korina_close()
1265 free_irq(lp->tx_irq, dev); in korina_close()
1287 struct korina_private *lp; in korina_probe() local
1298 lp = netdev_priv(dev); in korina_probe()
1309 lp->mii_clock_freq = clk_get_rate(clk); in korina_probe()
1311 lp->mii_clock_freq = 200000000; /* max possible input clk */ in korina_probe()
1314 lp->rx_irq = platform_get_irq_byname(pdev, "rx"); in korina_probe()
1315 lp->tx_irq = platform_get_irq_byname(pdev, "tx"); in korina_probe()
1322 lp->eth_regs = p; in korina_probe()
1329 lp->rx_dma_regs = p; in korina_probe()
1336 lp->tx_dma_regs = p; in korina_probe()
1338 lp->td_ring = dmam_alloc_coherent(&pdev->dev, TD_RING_SIZE, in korina_probe()
1339 &lp->td_dma, GFP_KERNEL); in korina_probe()
1340 if (!lp->td_ring) in korina_probe()
1343 lp->rd_ring = dmam_alloc_coherent(&pdev->dev, RD_RING_SIZE, in korina_probe()
1344 &lp->rd_dma, GFP_KERNEL); in korina_probe()
1345 if (!lp->rd_ring) in korina_probe()
1348 spin_lock_init(&lp->lock); in korina_probe()
1350 dev->irq = lp->rx_irq; in korina_probe()
1351 lp->dev = dev; in korina_probe()
1352 lp->dmadev = &pdev->dev; in korina_probe()
1357 netif_napi_add(dev, &lp->napi, korina_poll); in korina_probe()
1359 lp->mii_if.dev = dev; in korina_probe()
1360 lp->mii_if.mdio_read = korina_mdio_read; in korina_probe()
1361 lp->mii_if.mdio_write = korina_mdio_write; in korina_probe()
1362 lp->mii_if.phy_id = 1; in korina_probe()
1363 lp->mii_if.phy_id_mask = 0x1f; in korina_probe()
1364 lp->mii_if.reg_num_mask = 0x1f; in korina_probe()
1374 timer_setup(&lp->media_check_timer, korina_poll_media, 0); in korina_probe()
1376 INIT_WORK(&lp->restart_task, korina_restart_task); in korina_probe()