Lines Matching refs:priv

376 #define emac_read(reg)		  ioread32(priv->emac_base + (reg))
377 #define emac_write(reg, val) iowrite32(val, priv->emac_base + (reg))
379 #define emac_ctrl_read(reg) ioread32((priv->ctrl_base + (reg)))
380 #define emac_ctrl_write(reg, val) iowrite32(val, (priv->ctrl_base + (reg)))
389 static void emac_dump_regs(struct emac_priv *priv) in emac_dump_regs() argument
391 struct device *emac_dev = &priv->ndev->dev; in emac_dump_regs()
395 if (priv->version == EMAC_VERSION_1) { in emac_dump_regs()
470 cpdma_ctlr_dump(priv->dma); in emac_dump_regs()
499 struct emac_priv *priv = netdev_priv(ndev); in emac_get_settings() local
500 if (priv->phydev) in emac_get_settings()
501 return phy_ethtool_gset(priv->phydev, ecmd); in emac_get_settings()
517 struct emac_priv *priv = netdev_priv(ndev); in emac_set_settings() local
518 if (priv->phydev) in emac_set_settings()
519 return phy_ethtool_sset(priv->phydev, ecmd); in emac_set_settings()
536 struct emac_priv *priv = netdev_priv(ndev); in emac_get_coalesce() local
538 coal->rx_coalesce_usecs = priv->coal_intvl; in emac_get_coalesce()
554 struct emac_priv *priv = netdev_priv(ndev); in emac_set_coalesce() local
563 switch (priv->version) { in emac_set_coalesce()
566 prescale = priv->bus_freq_mhz * 4; in emac_set_coalesce()
604 prescale = coal_intvl * priv->bus_freq_mhz; in emac_set_coalesce()
607 coal_intvl = prescale / priv->bus_freq_mhz; in emac_set_coalesce()
615 priv->coal_intvl = coal_intvl; in emac_set_coalesce()
644 static void emac_update_phystatus(struct emac_priv *priv) in emac_update_phystatus() argument
649 struct net_device *ndev = priv->ndev; in emac_update_phystatus()
654 if (priv->phydev) in emac_update_phystatus()
655 new_duplex = priv->phydev->duplex; in emac_update_phystatus()
660 if ((priv->link) && (new_duplex != cur_duplex)) { in emac_update_phystatus()
661 priv->duplex = new_duplex; in emac_update_phystatus()
662 if (DUPLEX_FULL == priv->duplex) in emac_update_phystatus()
668 if (priv->speed == SPEED_1000 && (priv->version == EMAC_VERSION_2)) { in emac_update_phystatus()
677 if (priv->rmii_en && (priv->speed == SPEED_100)) in emac_update_phystatus()
686 if (priv->link) { in emac_update_phystatus()
736 static int hash_add(struct emac_priv *priv, u8 *mac_addr) in hash_add() argument
738 struct device *emac_dev = &priv->ndev->dev; in hash_add()
744 if (netif_msg_drv(priv)) { in hash_add()
753 if (priv->multicast_hash_cnt[hash_value] == 0) { in hash_add()
757 priv->mac_hash1 |= hash_bit; in hash_add()
760 priv->mac_hash2 |= hash_bit; in hash_add()
765 ++priv->multicast_hash_cnt[hash_value]; in hash_add()
778 static int hash_del(struct emac_priv *priv, u8 *mac_addr) in hash_del() argument
784 if (priv->multicast_hash_cnt[hash_value] > 0) { in hash_del()
786 --priv->multicast_hash_cnt[hash_value]; in hash_del()
791 if (priv->multicast_hash_cnt[hash_value] > 0) in hash_del()
796 priv->mac_hash1 &= ~hash_bit; in hash_del()
799 priv->mac_hash2 &= ~hash_bit; in hash_del()
821 static void emac_add_mcast(struct emac_priv *priv, u32 action, u8 *mac_addr) in emac_add_mcast() argument
823 struct device *emac_dev = &priv->ndev->dev; in emac_add_mcast()
828 update = hash_add(priv, mac_addr); in emac_add_mcast()
831 update = hash_del(priv, mac_addr); in emac_add_mcast()
835 priv->mac_hash1 = EMAC_ALL_MULTI_REG_VALUE; in emac_add_mcast()
836 priv->mac_hash2 = EMAC_ALL_MULTI_REG_VALUE; in emac_add_mcast()
840 priv->mac_hash1 = 0; in emac_add_mcast()
841 priv->mac_hash2 = 0; in emac_add_mcast()
842 memset(&(priv->multicast_hash_cnt[0]), 0, in emac_add_mcast()
843 sizeof(priv->multicast_hash_cnt[0]) * in emac_add_mcast()
847 if (netif_msg_drv(priv)) in emac_add_mcast()
855 emac_write(EMAC_MACHASH1, priv->mac_hash1); in emac_add_mcast()
856 emac_write(EMAC_MACHASH2, priv->mac_hash2); in emac_add_mcast()
870 struct emac_priv *priv = netdev_priv(ndev); in emac_dev_mcast_set() local
881 emac_add_mcast(priv, EMAC_ALL_MULTI_SET, NULL); in emac_dev_mcast_set()
886 emac_add_mcast(priv, EMAC_ALL_MULTI_CLR, NULL); in emac_dev_mcast_set()
889 emac_add_mcast(priv, EMAC_MULTICAST_ADD, in emac_dev_mcast_set()
894 emac_add_mcast(priv, EMAC_ALL_MULTI_CLR, NULL); in emac_dev_mcast_set()
912 static void emac_int_disable(struct emac_priv *priv) in emac_int_disable() argument
914 if (priv->version == EMAC_VERSION_2) { in emac_int_disable()
924 if (priv->int_disable) in emac_int_disable()
925 priv->int_disable(); in emac_int_disable()
952 static void emac_int_enable(struct emac_priv *priv) in emac_int_enable() argument
954 if (priv->version == EMAC_VERSION_2) { in emac_int_enable()
955 if (priv->int_enable) in emac_int_enable()
956 priv->int_enable(); in emac_int_enable()
985 struct emac_priv *priv = netdev_priv(ndev); in emac_irq() local
987 ++priv->isr_count; in emac_irq()
988 if (likely(netif_running(priv->ndev))) { in emac_irq()
989 emac_int_disable(priv); in emac_irq()
990 napi_schedule(&priv->napi); in emac_irq()
997 static struct sk_buff *emac_rx_alloc(struct emac_priv *priv) in emac_rx_alloc() argument
999 struct sk_buff *skb = netdev_alloc_skb(priv->ndev, priv->rx_buf_size); in emac_rx_alloc()
1010 struct emac_priv *priv = netdev_priv(ndev); in emac_rx_handler() local
1034 skb = emac_rx_alloc(priv); in emac_rx_handler()
1036 if (netif_msg_rx_err(priv) && net_ratelimit()) in emac_rx_handler()
1042 ret = cpdma_chan_submit(priv->rxchan, skb, skb->data, in emac_rx_handler()
1079 struct emac_priv *priv = netdev_priv(ndev); in emac_dev_xmit() local
1082 if (unlikely(!priv->link)) { in emac_dev_xmit()
1083 if (netif_msg_tx_err(priv) && net_ratelimit()) in emac_dev_xmit()
1090 if (netif_msg_tx_err(priv) && net_ratelimit()) in emac_dev_xmit()
1097 ret_code = cpdma_chan_submit(priv->txchan, skb, skb->data, skb->len, in emac_dev_xmit()
1100 if (netif_msg_tx_err(priv) && net_ratelimit()) in emac_dev_xmit()
1108 if (unlikely(!cpdma_check_free_tx_desc(priv->txchan))) in emac_dev_xmit()
1131 struct emac_priv *priv = netdev_priv(ndev); in emac_dev_tx_timeout() local
1134 if (netif_msg_tx_err(priv)) in emac_dev_tx_timeout()
1137 emac_dump_regs(priv); in emac_dev_tx_timeout()
1140 emac_int_disable(priv); in emac_dev_tx_timeout()
1141 cpdma_chan_stop(priv->txchan); in emac_dev_tx_timeout()
1142 cpdma_chan_start(priv->txchan); in emac_dev_tx_timeout()
1143 emac_int_enable(priv); in emac_dev_tx_timeout()
1156 static void emac_set_type0addr(struct emac_priv *priv, u32 ch, char *mac_addr) in emac_set_type0addr() argument
1183 static void emac_set_type1addr(struct emac_priv *priv, u32 ch, char *mac_addr) in emac_set_type1addr() argument
1192 emac_set_type0addr(priv, ch, mac_addr); in emac_set_type1addr()
1207 static void emac_set_type2addr(struct emac_priv *priv, u32 ch, in emac_set_type2addr() argument
1218 emac_set_type0addr(priv, ch, mac_addr); in emac_set_type2addr()
1231 static void emac_setmac(struct emac_priv *priv, u32 ch, char *mac_addr) in emac_setmac() argument
1233 struct device *emac_dev = &priv->ndev->dev; in emac_setmac()
1235 if (priv->rx_addr_type == 0) { in emac_setmac()
1236 emac_set_type0addr(priv, ch, mac_addr); in emac_setmac()
1237 } else if (priv->rx_addr_type == 1) { in emac_setmac()
1240 emac_set_type1addr(priv, ch, mac_addr); in emac_setmac()
1241 } else if (priv->rx_addr_type == 2) { in emac_setmac()
1242 emac_set_type2addr(priv, ch, mac_addr, ch, 1); in emac_setmac()
1243 emac_set_type0addr(priv, ch, mac_addr); in emac_setmac()
1245 if (netif_msg_drv(priv)) in emac_setmac()
1261 struct emac_priv *priv = netdev_priv(ndev); in emac_dev_setmac_addr() local
1262 struct device *emac_dev = &priv->ndev->dev; in emac_dev_setmac_addr()
1269 memcpy(priv->mac_addr, sa->sa_data, ndev->addr_len); in emac_dev_setmac_addr()
1274 emac_setmac(priv, EMAC_DEF_RX_CH, priv->mac_addr); in emac_dev_setmac_addr()
1277 if (netif_msg_drv(priv)) in emac_dev_setmac_addr()
1279 priv->mac_addr); in emac_dev_setmac_addr()
1293 static int emac_hw_enable(struct emac_priv *priv) in emac_hw_enable() argument
1303 emac_int_disable(priv); in emac_hw_enable()
1308 ((priv->speed == 1000) ? EMAC_MACCONTROL_GIGABITEN : 0x0) | in emac_hw_enable()
1310 ((priv->duplex == DUPLEX_FULL) ? 0x1 : 0)); in emac_hw_enable()
1336 priv->rx_addr_type = (emac_read(EMAC_MACCONFIG) >> 8) & 0xFF; in emac_hw_enable()
1340 emac_setmac(priv, EMAC_DEF_RX_CH, priv->mac_addr); in emac_hw_enable()
1348 napi_enable(&priv->napi); in emac_hw_enable()
1349 emac_int_enable(priv); in emac_hw_enable()
1370 struct emac_priv *priv = container_of(napi, struct emac_priv, napi); in emac_poll() local
1371 struct net_device *ndev = priv->ndev; in emac_poll()
1381 if (priv->version == EMAC_VERSION_2) in emac_poll()
1385 num_tx_pkts = cpdma_chan_process(priv->txchan, in emac_poll()
1391 if (priv->version == EMAC_VERSION_2) in emac_poll()
1395 num_rx_pkts = cpdma_chan_process(priv->rxchan, budget); in emac_poll()
1399 if (priv->version == EMAC_VERSION_2) in emac_poll()
1406 napi_disable(&priv->napi); in emac_poll()
1424 if (netif_msg_hw(priv) && net_ratelimit()) in emac_poll()
1430 emac_int_enable(priv); in emac_poll()
1446 struct emac_priv *priv = netdev_priv(ndev); in emac_poll_controller() local
1448 emac_int_disable(priv); in emac_poll_controller()
1450 emac_int_enable(priv); in emac_poll_controller()
1456 struct emac_priv *priv = netdev_priv(ndev); in emac_adjust_link() local
1457 struct phy_device *phydev = priv->phydev; in emac_adjust_link()
1461 spin_lock_irqsave(&priv->lock, flags); in emac_adjust_link()
1465 if (phydev->duplex != priv->duplex) { in emac_adjust_link()
1467 priv->duplex = phydev->duplex; in emac_adjust_link()
1469 if (phydev->speed != priv->speed) { in emac_adjust_link()
1471 priv->speed = phydev->speed; in emac_adjust_link()
1473 if (!priv->link) { in emac_adjust_link()
1475 priv->link = 1; in emac_adjust_link()
1478 } else if (priv->link) { in emac_adjust_link()
1480 priv->link = 0; in emac_adjust_link()
1481 priv->speed = 0; in emac_adjust_link()
1482 priv->duplex = ~0; in emac_adjust_link()
1485 emac_update_phystatus(priv); in emac_adjust_link()
1486 phy_print_status(priv->phydev); in emac_adjust_link()
1489 spin_unlock_irqrestore(&priv->lock, flags); in emac_adjust_link()
1508 struct emac_priv *priv = netdev_priv(ndev); in emac_devioctl() local
1515 return phy_mii_ioctl(priv->phydev, ifrq, cmd); in emac_devioctl()
1541 struct emac_priv *priv = netdev_priv(ndev); in emac_dev_open() local
1543 ret = pm_runtime_get_sync(&priv->pdev->dev); in emac_dev_open()
1545 pm_runtime_put_noidle(&priv->pdev->dev); in emac_dev_open()
1546 dev_err(&priv->pdev->dev, "%s: failed to get_sync(%d)\n", in emac_dev_open()
1553 ndev->dev_addr[cnt] = priv->mac_addr[cnt]; in emac_dev_open()
1556 priv->rx_buf_size = EMAC_DEF_MAX_FRAME_SIZE + NET_IP_ALIGN; in emac_dev_open()
1558 priv->mac_hash1 = 0; in emac_dev_open()
1559 priv->mac_hash2 = 0; in emac_dev_open()
1564 struct sk_buff *skb = emac_rx_alloc(priv); in emac_dev_open()
1569 ret = cpdma_chan_submit(priv->rxchan, skb, skb->data, in emac_dev_open()
1576 while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, in emac_dev_open()
1595 emac_hw_enable(priv); in emac_dev_open()
1598 if (priv->coal_intvl != 0) { in emac_dev_open()
1601 coal.rx_coalesce_usecs = (priv->coal_intvl << 4); in emac_dev_open()
1605 cpdma_ctlr_start(priv->dma); in emac_dev_open()
1607 priv->phydev = NULL; in emac_dev_open()
1609 if (priv->phy_node) { in emac_dev_open()
1610 priv->phydev = of_phy_connect(ndev, priv->phy_node, in emac_dev_open()
1612 if (!priv->phydev) { in emac_dev_open()
1614 priv->phy_node->full_name); in emac_dev_open()
1621 if (!priv->phydev && !priv->phy_id) { in emac_dev_open()
1627 priv->phy_id = dev_name(phy); in emac_dev_open()
1630 if (!priv->phydev && priv->phy_id && *priv->phy_id) { in emac_dev_open()
1631 priv->phydev = phy_connect(ndev, priv->phy_id, in emac_dev_open()
1635 if (IS_ERR(priv->phydev)) { in emac_dev_open()
1637 priv->phy_id); in emac_dev_open()
1638 ret = PTR_ERR(priv->phydev); in emac_dev_open()
1639 priv->phydev = NULL; in emac_dev_open()
1643 priv->link = 0; in emac_dev_open()
1644 priv->speed = 0; in emac_dev_open()
1645 priv->duplex = ~0; in emac_dev_open()
1649 priv->phydev->drv->name, dev_name(&priv->phydev->dev), in emac_dev_open()
1650 priv->phydev->phy_id); in emac_dev_open()
1653 if (!priv->phydev) { in emac_dev_open()
1656 priv->link = 1; in emac_dev_open()
1657 priv->speed = SPEED_100; in emac_dev_open()
1658 priv->duplex = DUPLEX_FULL; in emac_dev_open()
1659 emac_update_phystatus(priv); in emac_dev_open()
1663 emac_dump_regs(priv); in emac_dev_open()
1665 if (netif_msg_drv(priv)) in emac_dev_open()
1668 if (priv->phydev) in emac_dev_open()
1669 phy_start(priv->phydev); in emac_dev_open()
1674 emac_int_disable(priv); in emac_dev_open()
1675 napi_disable(&priv->napi); in emac_dev_open()
1679 res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, q); in emac_dev_open()
1689 cpdma_ctlr_stop(priv->dma); in emac_dev_open()
1690 pm_runtime_put(&priv->pdev->dev); in emac_dev_open()
1708 struct emac_priv *priv = netdev_priv(ndev); in emac_dev_stop() local
1713 napi_disable(&priv->napi); in emac_dev_stop()
1716 emac_int_disable(priv); in emac_dev_stop()
1717 cpdma_ctlr_stop(priv->dma); in emac_dev_stop()
1720 if (priv->phydev) in emac_dev_stop()
1721 phy_disconnect(priv->phydev); in emac_dev_stop()
1724 while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, i))) { in emac_dev_stop()
1726 free_irq(irq_num, priv->ndev); in emac_dev_stop()
1730 if (netif_msg_drv(priv)) in emac_dev_stop()
1733 pm_runtime_put(&priv->pdev->dev); in emac_dev_stop()
1747 struct emac_priv *priv = netdev_priv(ndev); in emac_dev_getnetstats() local
1752 err = pm_runtime_get_sync(&priv->pdev->dev); in emac_dev_getnetstats()
1754 pm_runtime_put_noidle(&priv->pdev->dev); in emac_dev_getnetstats()
1755 dev_err(&priv->pdev->dev, "%s: failed to get_sync(%d)\n", in emac_dev_getnetstats()
1801 pm_runtime_put(&priv->pdev->dev); in emac_dev_getnetstats()
1823 davinci_emac_of_get_pdata(struct platform_device *pdev, struct emac_priv *priv) in davinci_emac_of_get_pdata() argument
1863 priv->phy_node = of_parse_phandle(np, "phy-handle", 0); in davinci_emac_of_get_pdata()
1864 if (!priv->phy_node) { in davinci_emac_of_get_pdata()
1868 priv->phy_node = of_node_get(np); in davinci_emac_of_get_pdata()
1911 struct emac_priv *priv; in davinci_emac_probe() local
1935 priv = netdev_priv(ndev); in davinci_emac_probe()
1936 priv->pdev = pdev; in davinci_emac_probe()
1937 priv->ndev = ndev; in davinci_emac_probe()
1938 priv->msg_enable = netif_msg_init(debug_level, DAVINCI_EMAC_DEBUG); in davinci_emac_probe()
1940 spin_lock_init(&priv->lock); in davinci_emac_probe()
1942 pdata = davinci_emac_of_get_pdata(pdev, priv); in davinci_emac_probe()
1950 memcpy(priv->mac_addr, pdata->mac_addr, ETH_ALEN); in davinci_emac_probe()
1951 priv->phy_id = pdata->phy_id; in davinci_emac_probe()
1952 priv->rmii_en = pdata->rmii_en; in davinci_emac_probe()
1953 priv->version = pdata->version; in davinci_emac_probe()
1954 priv->int_enable = pdata->interrupt_enable; in davinci_emac_probe()
1955 priv->int_disable = pdata->interrupt_disable; in davinci_emac_probe()
1957 priv->coal_intvl = 0; in davinci_emac_probe()
1958 priv->bus_freq_mhz = (u32)(emac_bus_frequency / 1000000); in davinci_emac_probe()
1962 priv->emac_base_phys = res->start + pdata->ctrl_reg_offset; in davinci_emac_probe()
1963 priv->remap_addr = devm_ioremap_resource(&pdev->dev, res); in davinci_emac_probe()
1964 if (IS_ERR(priv->remap_addr)) { in davinci_emac_probe()
1965 rc = PTR_ERR(priv->remap_addr); in davinci_emac_probe()
1971 priv->ctrl_base = in davinci_emac_probe()
1973 if (IS_ERR(priv->ctrl_base)) { in davinci_emac_probe()
1974 rc = PTR_ERR(priv->ctrl_base); in davinci_emac_probe()
1978 priv->ctrl_base = priv->remap_addr + pdata->ctrl_mod_reg_offset; in davinci_emac_probe()
1981 priv->emac_base = priv->remap_addr + pdata->ctrl_reg_offset; in davinci_emac_probe()
1982 ndev->base_addr = (unsigned long)priv->remap_addr; in davinci_emac_probe()
1990 dma_params.dmaregs = priv->emac_base; in davinci_emac_probe()
1991 dma_params.rxthresh = priv->emac_base + 0x120; in davinci_emac_probe()
1992 dma_params.rxfree = priv->emac_base + 0x140; in davinci_emac_probe()
1993 dma_params.txhdp = priv->emac_base + 0x600; in davinci_emac_probe()
1994 dma_params.rxhdp = priv->emac_base + 0x620; in davinci_emac_probe()
1995 dma_params.txcp = priv->emac_base + 0x640; in davinci_emac_probe()
1996 dma_params.rxcp = priv->emac_base + 0x660; in davinci_emac_probe()
2006 priv->dma = cpdma_ctlr_create(&dma_params); in davinci_emac_probe()
2007 if (!priv->dma) { in davinci_emac_probe()
2013 priv->txchan = cpdma_chan_create(priv->dma, tx_chan_num(EMAC_DEF_TX_CH), in davinci_emac_probe()
2015 priv->rxchan = cpdma_chan_create(priv->dma, rx_chan_num(EMAC_DEF_RX_CH), in davinci_emac_probe()
2017 if (WARN_ON(!priv->txchan || !priv->rxchan)) { in davinci_emac_probe()
2030 rc = davinci_emac_try_get_mac(pdev, res_ctrl ? 0 : 1, priv->mac_addr); in davinci_emac_probe()
2032 ether_addr_copy(ndev->dev_addr, priv->mac_addr); in davinci_emac_probe()
2034 if (!is_valid_ether_addr(priv->mac_addr)) { in davinci_emac_probe()
2037 memcpy(priv->mac_addr, ndev->dev_addr, ndev->addr_len); in davinci_emac_probe()
2039 priv->mac_addr); in davinci_emac_probe()
2044 netif_napi_add(ndev, &priv->napi, emac_poll, EMAC_POLL_WEIGHT); in davinci_emac_probe()
2066 if (netif_msg_probe(priv)) { in davinci_emac_probe()
2069 (void *)priv->emac_base_phys, ndev->irq); in davinci_emac_probe()
2076 if (priv->txchan) in davinci_emac_probe()
2077 cpdma_chan_destroy(priv->txchan); in davinci_emac_probe()
2078 if (priv->rxchan) in davinci_emac_probe()
2079 cpdma_chan_destroy(priv->rxchan); in davinci_emac_probe()
2080 cpdma_ctlr_destroy(priv->dma); in davinci_emac_probe()
2096 struct emac_priv *priv = netdev_priv(ndev); in davinci_emac_remove() local
2100 if (priv->txchan) in davinci_emac_remove()
2101 cpdma_chan_destroy(priv->txchan); in davinci_emac_remove()
2102 if (priv->rxchan) in davinci_emac_remove()
2103 cpdma_chan_destroy(priv->rxchan); in davinci_emac_remove()
2104 cpdma_ctlr_destroy(priv->dma); in davinci_emac_remove()