Lines Matching +full:queue +full:- +full:pkt +full:- +full:rxfree

1 // SPDX-License-Identifier: GPL-2.0+
9 * ---------------------------------------------------------------------------
11 * 0-5 A number of folks worked on this driver in bits and pieces but the major
13 * 6.0 Anant Gole - rewrote the driver as per Linux conventions
14 * 6.1 Chaithrika U S - added support for Gigabit and RMII features,
38 #include <linux/dma-mapping.h>
107 #define EMAC_DEF_MIN_ETHPKTSIZE (60) /* Minimum ethernet pkt size */
117 #define EMAC_DEF_RX_MAX_SERVICE (64) /* should = netdev->weight */
320 u32 speed; /* 0=Auto Neg, 1=No PHY, 10,100, 1000 - mbps */
358 #define emac_read(reg) ioread32(priv->emac_base + (reg))
359 #define emac_write(reg, val) iowrite32(val, priv->emac_base + (reg))
361 #define emac_ctrl_read(reg) ioread32((priv->ctrl_base + (reg)))
362 #define emac_ctrl_write(reg, val) iowrite32(val, (priv->ctrl_base + (reg)))
365 * emac_get_drvinfo - Get EMAC driver information
375 strscpy(info->driver, emac_version_string, sizeof(info->driver)); in emac_get_drvinfo()
376 strscpy(info->version, EMAC_MODULE_VERSION, sizeof(info->version)); in emac_get_drvinfo()
380 * emac_get_coalesce - Get interrupt coalesce settings for this device
396 coal->rx_coalesce_usecs = priv->coal_intvl; in emac_get_coalesce()
402 * emac_set_coalesce - Set interrupt coalesce settings for this device
420 if (!coal->rx_coalesce_usecs) { in emac_set_coalesce()
421 priv->coal_intvl = 0; in emac_set_coalesce()
423 switch (priv->version) { in emac_set_coalesce()
435 coal_intvl = coal->rx_coalesce_usecs; in emac_set_coalesce()
437 switch (priv->version) { in emac_set_coalesce()
440 prescale = priv->bus_freq_mhz * 4; in emac_set_coalesce()
478 prescale = coal_intvl * priv->bus_freq_mhz; in emac_set_coalesce()
481 coal_intvl = prescale / priv->bus_freq_mhz; in emac_set_coalesce()
489 priv->coal_intvl = coal_intvl; in emac_set_coalesce()
512 * emac_update_phystatus - Update Phy status
515 * Updates phy status and takes action for network queue if required
524 struct net_device *ndev = priv->ndev; in emac_update_phystatus()
529 if (ndev->phydev) in emac_update_phystatus()
530 new_duplex = ndev->phydev->duplex; in emac_update_phystatus()
535 if ((priv->link) && (new_duplex != cur_duplex)) { in emac_update_phystatus()
536 priv->duplex = new_duplex; in emac_update_phystatus()
537 if (DUPLEX_FULL == priv->duplex) in emac_update_phystatus()
543 if (priv->speed == SPEED_1000 && (priv->version == EMAC_VERSION_2)) { in emac_update_phystatus()
552 if (priv->rmii_en && (priv->speed == SPEED_100)) in emac_update_phystatus()
561 if (priv->link) { in emac_update_phystatus()
565 /* reactivate the transmit queue if it is stopped */ in emac_update_phystatus()
578 * hash_get - Calculate hash value from mac address
604 * emac_hash_add - Hash function to add mac addr from hash table
613 struct device *emac_dev = &priv->ndev->dev; in emac_hash_add()
622 hash_value, (EMAC_NUM_MULTICAST_BITS - 1)); in emac_hash_add()
624 return -1; in emac_hash_add()
628 if (priv->multicast_hash_cnt[hash_value] == 0) { in emac_hash_add()
632 priv->mac_hash1 |= hash_bit; in emac_hash_add()
634 hash_bit = BIT((hash_value - 32)); in emac_hash_add()
635 priv->mac_hash2 |= hash_bit; in emac_hash_add()
640 ++priv->multicast_hash_cnt[hash_value]; in emac_hash_add()
646 * emac_hash_del - Hash function to delete mac addr from hash table
659 if (priv->multicast_hash_cnt[hash_value] > 0) { in emac_hash_del()
661 --priv->multicast_hash_cnt[hash_value]; in emac_hash_del()
666 if (priv->multicast_hash_cnt[hash_value] > 0) in emac_hash_del()
671 priv->mac_hash1 &= ~hash_bit; in emac_hash_del()
673 hash_bit = BIT((hash_value - 32)); in emac_hash_del()
674 priv->mac_hash2 &= ~hash_bit; in emac_hash_del()
688 * emac_add_mcast - Set multicast address in the EMAC adapter (Internal)
693 * Set multicast addresses in EMAC adapter - internal function
698 struct device *emac_dev = &priv->ndev->dev; in emac_add_mcast()
699 int update = -1; in emac_add_mcast()
710 priv->mac_hash1 = EMAC_ALL_MULTI_REG_VALUE; in emac_add_mcast()
711 priv->mac_hash2 = EMAC_ALL_MULTI_REG_VALUE; in emac_add_mcast()
715 priv->mac_hash1 = 0; in emac_add_mcast()
716 priv->mac_hash2 = 0; in emac_add_mcast()
717 memset(&(priv->multicast_hash_cnt[0]), 0, in emac_add_mcast()
718 sizeof(priv->multicast_hash_cnt[0]) * in emac_add_mcast()
730 emac_write(EMAC_MACHASH1, priv->mac_hash1); in emac_add_mcast()
731 emac_write(EMAC_MACHASH2, priv->mac_hash2); in emac_add_mcast()
736 * emac_dev_mcast_set - Set multicast address in the EMAC adapter
748 if (ndev->flags & IFF_PROMISC) { in emac_dev_mcast_set()
753 if ((ndev->flags & IFF_ALLMULTI) || in emac_dev_mcast_set()
765 (u8 *) ha->addr); in emac_dev_mcast_set()
781 * emac_int_disable - Disable EMAC module interrupt (from adapter)
789 if (priv->version == EMAC_VERSION_2) { in emac_int_disable()
799 if (priv->int_disable) in emac_int_disable()
800 priv->int_disable(); in emac_int_disable()
808 /* ack txen- only then a new pulse will be generated */ in emac_int_disable()
821 * emac_int_enable - Enable EMAC module interrupt (from adapter)
829 if (priv->version == EMAC_VERSION_2) { in emac_int_enable()
830 if (priv->int_enable) in emac_int_enable()
831 priv->int_enable(); in emac_int_enable()
848 * emac_irq - EMAC interrupt handler
852 * EMAC Interrupt handler - we only schedule NAPI and not process any packets
862 ++priv->isr_count; in emac_irq()
863 if (likely(netif_running(priv->ndev))) { in emac_irq()
865 napi_schedule(&priv->napi); in emac_irq()
874 struct sk_buff *skb = netdev_alloc_skb(priv->ndev, priv->rx_buf_size); in emac_rx_alloc()
884 struct net_device *ndev = skb->dev; in emac_rx_handler()
886 struct device *emac_dev = &ndev->dev; in emac_rx_handler()
897 ndev->stats.rx_errors++; in emac_rx_handler()
903 skb->protocol = eth_type_trans(skb, ndev); in emac_rx_handler()
905 ndev->stats.rx_bytes += len; in emac_rx_handler()
906 ndev->stats.rx_packets++; in emac_rx_handler()
917 ret = cpdma_chan_submit(priv->rxchan, skb, skb->data, in emac_rx_handler()
920 WARN_ON(ret == -ENOMEM); in emac_rx_handler()
928 struct net_device *ndev = skb->dev; in emac_tx_handler()
930 /* Check whether the queue is stopped due to stalled tx dma, if the in emac_tx_handler()
931 * queue is stopped then start the queue as we have free desc for tx in emac_tx_handler()
935 ndev->stats.tx_packets++; in emac_tx_handler()
936 ndev->stats.tx_bytes += len; in emac_tx_handler()
941 * emac_dev_xmit - EMAC Transmit function
945 * Called by the system to transmit a packet - we queue the packet in
946 * EMAC hardware transmit queue
952 struct device *emac_dev = &ndev->dev; in emac_dev_xmit()
957 if (unlikely(!priv->link)) { in emac_dev_xmit()
972 ret_code = cpdma_chan_submit(priv->txchan, skb, skb->data, skb->len, in emac_dev_xmit()
983 if (unlikely(!cpdma_check_free_tx_desc(priv->txchan))) in emac_dev_xmit()
989 ndev->stats.tx_dropped++; in emac_dev_xmit()
995 * emac_dev_tx_timeout - EMAC Transmit timeout function
997 * @txqueue: the index of the hung transmit queue
1002 * error and re-initialize the TX channel for hardware operation
1008 struct device *emac_dev = &ndev->dev; in emac_dev_tx_timeout()
1013 ndev->stats.tx_errors++; in emac_dev_tx_timeout()
1015 cpdma_chan_stop(priv->txchan); in emac_dev_tx_timeout()
1016 cpdma_chan_start(priv->txchan); in emac_dev_tx_timeout()
1021 * emac_set_type0addr - Set EMAC Type0 mac address
1048 * emac_set_type1addr - Set EMAC Type1 mac address
1070 * emac_set_type2addr - Set EMAC Type2 mac address
1096 * emac_setmac - Set mac address in the adapter (internal function)
1107 struct device *emac_dev = &priv->ndev->dev; in emac_setmac()
1109 if (priv->rx_addr_type == 0) { in emac_setmac()
1111 } else if (priv->rx_addr_type == 1) { in emac_setmac()
1115 } else if (priv->rx_addr_type == 2) { in emac_setmac()
1125 * emac_dev_setmac_addr - Set mac address in the adapter
1136 struct device *emac_dev = &priv->ndev->dev; in emac_dev_setmac_addr()
1139 if (!is_valid_ether_addr(sa->sa_data)) in emac_dev_setmac_addr()
1140 return -EADDRNOTAVAIL; in emac_dev_setmac_addr()
1143 memcpy(priv->mac_addr, sa->sa_data, ndev->addr_len); in emac_dev_setmac_addr()
1144 eth_hw_addr_set(ndev, sa->sa_data); in emac_dev_setmac_addr()
1148 emac_setmac(priv, EMAC_DEF_RX_CH, priv->mac_addr); in emac_dev_setmac_addr()
1153 priv->mac_addr); in emac_dev_setmac_addr()
1159 * emac_hw_enable - Enable EMAC hardware for packet transmission/reception
1162 * Enables EMAC hardware for packet processing - enables PHY, enables RX
1182 ((priv->speed == 1000) ? EMAC_MACCONTROL_GIGABITEN : 0x0) | in emac_hw_enable()
1184 ((priv->duplex == DUPLEX_FULL) ? 0x1 : 0)); in emac_hw_enable()
1210 priv->rx_addr_type = (emac_read(EMAC_MACCONFIG) >> 8) & 0xFF; in emac_hw_enable()
1214 emac_setmac(priv, EMAC_DEF_RX_CH, priv->mac_addr); in emac_hw_enable()
1222 napi_enable(&priv->napi); in emac_hw_enable()
1229 * emac_poll - EMAC NAPI Poll function
1239 * Returns number of packets received (in most cases; else TX pkts - rarely)
1245 struct net_device *ndev = priv->ndev; in emac_poll()
1246 struct device *emac_dev = &ndev->dev; in emac_poll()
1255 if (priv->version == EMAC_VERSION_2) in emac_poll()
1259 cpdma_chan_process(priv->txchan, EMAC_DEF_TX_MAX_SERVICE); in emac_poll()
1264 if (priv->version == EMAC_VERSION_2) in emac_poll()
1268 num_rx_pkts = cpdma_chan_process(priv->rxchan, budget); in emac_poll()
1272 if (priv->version == EMAC_VERSION_2) in emac_poll()
1279 napi_disable(&priv->napi); in emac_poll()
1311 * emac_poll_controller - EMAC Poll controller function
1322 emac_irq(ndev->irq, ndev); in emac_poll_controller()
1330 struct phy_device *phydev = ndev->phydev; in emac_adjust_link()
1334 spin_lock_irqsave(&priv->lock, flags); in emac_adjust_link()
1336 if (phydev->link) { in emac_adjust_link()
1337 /* check the mode of operation - full/half duplex */ in emac_adjust_link()
1338 if (phydev->duplex != priv->duplex) { in emac_adjust_link()
1340 priv->duplex = phydev->duplex; in emac_adjust_link()
1342 if (phydev->speed != priv->speed) { in emac_adjust_link()
1344 priv->speed = phydev->speed; in emac_adjust_link()
1346 if (!priv->link) { in emac_adjust_link()
1348 priv->link = 1; in emac_adjust_link()
1351 } else if (priv->link) { in emac_adjust_link()
1353 priv->link = 0; in emac_adjust_link()
1354 priv->speed = 0; in emac_adjust_link()
1355 priv->duplex = ~0; in emac_adjust_link()
1359 phy_print_status(ndev->phydev); in emac_adjust_link()
1362 spin_unlock_irqrestore(&priv->lock, flags); in emac_adjust_link()
1370 * emac_devioctl - EMAC adapter ioctl
1382 return -EINVAL; in emac_devioctl()
1386 if (ndev->phydev) in emac_devioctl()
1387 return phy_mii_ioctl(ndev->phydev, ifrq, cmd); in emac_devioctl()
1389 return -EOPNOTSUPP; in emac_devioctl()
1394 if (dev->parent && dev->parent->of_node) in match_first_device()
1395 return of_device_is_compatible(dev->parent->of_node, in match_first_device()
1402 * emac_dev_open - EMAC device open
1407 * network queue.
1413 struct device *emac_dev = &ndev->dev; in emac_dev_open()
1422 ret = pm_runtime_resume_and_get(&priv->pdev->dev); in emac_dev_open()
1424 dev_err(&priv->pdev->dev, "%s: failed to get_sync(%d)\n", in emac_dev_open()
1430 eth_hw_addr_set(ndev, priv->mac_addr); in emac_dev_open()
1433 priv->rx_buf_size = EMAC_DEF_MAX_FRAME_SIZE + NET_IP_ALIGN; in emac_dev_open()
1435 priv->mac_hash1 = 0; in emac_dev_open()
1436 priv->mac_hash2 = 0; in emac_dev_open()
1446 ret = cpdma_chan_idle_submit(priv->rxchan, skb, skb->data, in emac_dev_open()
1453 if (dev_of_node(&priv->pdev->dev)) { in emac_dev_open()
1454 while ((ret = platform_get_irq_optional(priv->pdev, res_num)) != -ENXIO) { in emac_dev_open()
1458 ret = request_irq(ret, emac_irq, 0, ndev->name, ndev); in emac_dev_open()
1466 while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, res_num))) { in emac_dev_open()
1467 for (irq_num = res->start; irq_num <= res->end; irq_num++) { in emac_dev_open()
1468 ret = request_irq(irq_num, emac_irq, 0, ndev->name, ndev); in emac_dev_open()
1477 res_num--; in emac_dev_open()
1478 irq_num--; in emac_dev_open()
1485 if (priv->coal_intvl != 0) { in emac_dev_open()
1488 coal.rx_coalesce_usecs = (priv->coal_intvl << 4); in emac_dev_open()
1492 cpdma_ctlr_start(priv->dma); in emac_dev_open()
1494 if (priv->phy_node) { in emac_dev_open()
1495 phydev = of_phy_connect(ndev, priv->phy_node, in emac_dev_open()
1499 priv->phy_node); in emac_dev_open()
1500 ret = -ENODEV; in emac_dev_open()
1506 if (!phydev && !priv->phy_id) { in emac_dev_open()
1516 priv->phy_id = dev_name(phy); in emac_dev_open()
1517 if (!priv->phy_id || !*priv->phy_id) in emac_dev_open()
1522 if (!phydev && priv->phy_id && *priv->phy_id) { in emac_dev_open()
1523 phydev = phy_connect(ndev, priv->phy_id, in emac_dev_open()
1529 priv->phy_id); in emac_dev_open()
1534 priv->link = 0; in emac_dev_open()
1535 priv->speed = 0; in emac_dev_open()
1536 priv->duplex = ~0; in emac_dev_open()
1544 priv->link = 1; in emac_dev_open()
1545 priv->speed = SPEED_100; in emac_dev_open()
1546 priv->duplex = DUPLEX_FULL; in emac_dev_open()
1551 dev_notice(emac_dev, "DaVinci EMAC: Opened %s\n", ndev->name); in emac_dev_open()
1560 napi_disable(&priv->napi); in emac_dev_open()
1563 if (dev_of_node(&priv->pdev->dev)) { in emac_dev_open()
1564 for (q = res_num - 1; q >= 0; q--) { in emac_dev_open()
1565 irq_num = platform_get_irq(priv->pdev, q); in emac_dev_open()
1570 for (q = res_num; q >= 0; q--) { in emac_dev_open()
1571 res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, q); in emac_dev_open()
1576 irq_num = res->end; in emac_dev_open()
1578 for (m = irq_num; m >= res->start; m--) in emac_dev_open()
1582 cpdma_ctlr_stop(priv->dma); in emac_dev_open()
1583 pm_runtime_put(&priv->pdev->dev); in emac_dev_open()
1588 * emac_dev_stop - EMAC device stop
1592 * queue, disable interrupts and cleanup TX/RX channels.
1602 struct device *emac_dev = &ndev->dev; in emac_dev_stop()
1607 napi_disable(&priv->napi); in emac_dev_stop()
1611 cpdma_ctlr_stop(priv->dma); in emac_dev_stop()
1614 if (ndev->phydev) in emac_dev_stop()
1615 phy_disconnect(ndev->phydev); in emac_dev_stop()
1618 if (dev_of_node(&priv->pdev->dev)) { in emac_dev_stop()
1620 ret = platform_get_irq_optional(priv->pdev, i); in emac_dev_stop()
1621 if (ret < 0 && ret != -ENXIO) in emac_dev_stop()
1624 free_irq(ret, priv->ndev); in emac_dev_stop()
1631 while ((res = platform_get_resource(priv->pdev, IORESOURCE_IRQ, i))) { in emac_dev_stop()
1632 for (irq_num = res->start; irq_num <= res->end; irq_num++) in emac_dev_stop()
1633 free_irq(irq_num, priv->ndev); in emac_dev_stop()
1639 dev_notice(emac_dev, "DaVinci EMAC: %s stopped\n", ndev->name); in emac_dev_stop()
1641 pm_runtime_put(&priv->pdev->dev); in emac_dev_stop()
1646 * emac_dev_getnetstats - EMAC get statistics function
1660 err = pm_runtime_resume_and_get(&priv->pdev->dev); in emac_dev_getnetstats()
1662 dev_err(&priv->pdev->dev, "%s: failed to get_sync(%d)\n", in emac_dev_getnetstats()
1664 return &ndev->stats; in emac_dev_getnetstats()
1676 ndev->stats.multicast += emac_read(EMAC_RXMCASTFRAMES); in emac_dev_getnetstats()
1679 ndev->stats.collisions += (emac_read(EMAC_TXCOLLISION) + in emac_dev_getnetstats()
1686 ndev->stats.rx_length_errors += (emac_read(EMAC_RXOVERSIZED) + in emac_dev_getnetstats()
1693 ndev->stats.rx_over_errors += (emac_read(EMAC_RXSOFOVERRUNS) + in emac_dev_getnetstats()
1698 ndev->stats.rx_fifo_errors += emac_read(EMAC_RXDMAOVERRUNS); in emac_dev_getnetstats()
1701 ndev->stats.tx_carrier_errors += in emac_dev_getnetstats()
1705 ndev->stats.tx_fifo_errors += emac_read(EMAC_TXUNDERRUN); in emac_dev_getnetstats()
1708 pm_runtime_put(&priv->pdev->dev); in emac_dev_getnetstats()
1710 return &ndev->stats; in emac_dev_getnetstats()
1734 if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node) in davinci_emac_of_get_pdata()
1735 return dev_get_platdata(&pdev->dev); in davinci_emac_of_get_pdata()
1737 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in davinci_emac_of_get_pdata()
1741 np = pdev->dev.of_node; in davinci_emac_of_get_pdata()
1742 pdata->version = EMAC_VERSION_2; in davinci_emac_of_get_pdata()
1744 if (!is_valid_ether_addr(pdata->mac_addr)) in davinci_emac_of_get_pdata()
1745 of_get_mac_address(np, pdata->mac_addr); in davinci_emac_of_get_pdata()
1747 of_property_read_u32(np, "ti,davinci-ctrl-reg-offset", in davinci_emac_of_get_pdata()
1748 &pdata->ctrl_reg_offset); in davinci_emac_of_get_pdata()
1750 of_property_read_u32(np, "ti,davinci-ctrl-mod-reg-offset", in davinci_emac_of_get_pdata()
1751 &pdata->ctrl_mod_reg_offset); in davinci_emac_of_get_pdata()
1753 of_property_read_u32(np, "ti,davinci-ctrl-ram-offset", in davinci_emac_of_get_pdata()
1754 &pdata->ctrl_ram_offset); in davinci_emac_of_get_pdata()
1756 of_property_read_u32(np, "ti,davinci-ctrl-ram-size", in davinci_emac_of_get_pdata()
1757 &pdata->ctrl_ram_size); in davinci_emac_of_get_pdata()
1759 of_property_read_u8(np, "ti,davinci-rmii-en", &pdata->rmii_en); in davinci_emac_of_get_pdata()
1761 pdata->no_bd_ram = of_property_read_bool(np, "ti,davinci-no-bd-ram"); in davinci_emac_of_get_pdata()
1763 priv->phy_node = of_parse_phandle(np, "phy-handle", 0); in davinci_emac_of_get_pdata()
1764 if (!priv->phy_node) { in davinci_emac_of_get_pdata()
1766 pdata->phy_id = NULL; in davinci_emac_of_get_pdata()
1768 priv->phy_node = of_node_get(np); in davinci_emac_of_get_pdata()
1771 auxdata = pdev->dev.platform_data; in davinci_emac_of_get_pdata()
1773 pdata->interrupt_enable = auxdata->interrupt_enable; in davinci_emac_of_get_pdata()
1774 pdata->interrupt_disable = auxdata->interrupt_disable; in davinci_emac_of_get_pdata()
1777 auxdata = device_get_match_data(&pdev->dev); in davinci_emac_of_get_pdata()
1779 pdata->version = auxdata->version; in davinci_emac_of_get_pdata()
1780 pdata->hw_ram_addr = auxdata->hw_ram_addr; in davinci_emac_of_get_pdata()
1789 if (!pdev->dev.of_node) in davinci_emac_try_get_mac()
1790 return -EINVAL; in davinci_emac_try_get_mac()
1792 return ti_cm_get_macid(&pdev->dev, instance, mac_addr); in davinci_emac_try_get_mac()
1796 * davinci_emac_probe - EMAC device probe
1805 struct device_node *np = pdev->dev.of_node; in davinci_emac_probe()
1818 emac_clk = devm_clk_get(&pdev->dev, NULL); in davinci_emac_probe()
1820 dev_err(&pdev->dev, "failed to get EMAC clock\n"); in davinci_emac_probe()
1821 return -EBUSY; in davinci_emac_probe()
1824 devm_clk_put(&pdev->dev, emac_clk); in davinci_emac_probe()
1830 return -ENOMEM; in davinci_emac_probe()
1834 priv->pdev = pdev; in davinci_emac_probe()
1835 priv->ndev = ndev; in davinci_emac_probe()
1836 priv->msg_enable = netif_msg_init(debug_level, DAVINCI_EMAC_DEBUG); in davinci_emac_probe()
1838 spin_lock_init(&priv->lock); in davinci_emac_probe()
1842 dev_err(&pdev->dev, "no platform data\n"); in davinci_emac_probe()
1843 rc = -ENODEV; in davinci_emac_probe()
1848 memcpy(priv->mac_addr, pdata->mac_addr, ETH_ALEN); in davinci_emac_probe()
1849 priv->phy_id = pdata->phy_id; in davinci_emac_probe()
1850 priv->rmii_en = pdata->rmii_en; in davinci_emac_probe()
1851 priv->version = pdata->version; in davinci_emac_probe()
1852 priv->int_enable = pdata->interrupt_enable; in davinci_emac_probe()
1853 priv->int_disable = pdata->interrupt_disable; in davinci_emac_probe()
1855 priv->coal_intvl = 0; in davinci_emac_probe()
1856 priv->bus_freq_mhz = (u32)(emac_bus_frequency / 1000000); in davinci_emac_probe()
1859 priv->remap_addr = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in davinci_emac_probe()
1860 if (IS_ERR(priv->remap_addr)) { in davinci_emac_probe()
1861 rc = PTR_ERR(priv->remap_addr); in davinci_emac_probe()
1864 priv->emac_base_phys = res->start + pdata->ctrl_reg_offset; in davinci_emac_probe()
1868 priv->ctrl_base = in davinci_emac_probe()
1869 devm_ioremap_resource(&pdev->dev, res_ctrl); in davinci_emac_probe()
1870 if (IS_ERR(priv->ctrl_base)) { in davinci_emac_probe()
1871 rc = PTR_ERR(priv->ctrl_base); in davinci_emac_probe()
1875 priv->ctrl_base = priv->remap_addr + pdata->ctrl_mod_reg_offset; in davinci_emac_probe()
1878 priv->emac_base = priv->remap_addr + pdata->ctrl_reg_offset; in davinci_emac_probe()
1879 ndev->base_addr = (unsigned long)priv->remap_addr; in davinci_emac_probe()
1881 hw_ram_addr = pdata->hw_ram_addr; in davinci_emac_probe()
1883 hw_ram_addr = (u32 __force)res->start + pdata->ctrl_ram_offset; in davinci_emac_probe()
1886 dma_params.dev = &pdev->dev; in davinci_emac_probe()
1887 dma_params.dmaregs = priv->emac_base; in davinci_emac_probe()
1888 dma_params.rxthresh = priv->emac_base + 0x120; in davinci_emac_probe()
1889 dma_params.rxfree = priv->emac_base + 0x140; in davinci_emac_probe()
1890 dma_params.txhdp = priv->emac_base + 0x600; in davinci_emac_probe()
1891 dma_params.rxhdp = priv->emac_base + 0x620; in davinci_emac_probe()
1892 dma_params.txcp = priv->emac_base + 0x640; in davinci_emac_probe()
1893 dma_params.rxcp = priv->emac_base + 0x660; in davinci_emac_probe()
1897 dma_params.desc_mem_size = pdata->ctrl_ram_size; in davinci_emac_probe()
1900 dma_params.desc_mem_phys = pdata->no_bd_ram ? 0 : in davinci_emac_probe()
1901 (u32 __force)res->start + pdata->ctrl_ram_offset; in davinci_emac_probe()
1903 priv->dma = cpdma_ctlr_create(&dma_params); in davinci_emac_probe()
1904 if (!priv->dma) { in davinci_emac_probe()
1905 dev_err(&pdev->dev, "error initializing DMA\n"); in davinci_emac_probe()
1906 rc = -ENOMEM; in davinci_emac_probe()
1910 priv->txchan = cpdma_chan_create(priv->dma, EMAC_DEF_TX_CH, in davinci_emac_probe()
1912 if (IS_ERR(priv->txchan)) { in davinci_emac_probe()
1913 dev_err(&pdev->dev, "error initializing tx dma channel\n"); in davinci_emac_probe()
1914 rc = PTR_ERR(priv->txchan); in davinci_emac_probe()
1918 priv->rxchan = cpdma_chan_create(priv->dma, EMAC_DEF_RX_CH, in davinci_emac_probe()
1920 if (IS_ERR(priv->rxchan)) { in davinci_emac_probe()
1921 dev_err(&pdev->dev, "error initializing rx dma channel\n"); in davinci_emac_probe()
1922 rc = PTR_ERR(priv->rxchan); in davinci_emac_probe()
1929 ndev->irq = rc; in davinci_emac_probe()
1932 if (!is_valid_ether_addr(priv->mac_addr)) { in davinci_emac_probe()
1933 rc = davinci_emac_try_get_mac(pdev, res_ctrl ? 0 : 1, priv->mac_addr); in davinci_emac_probe()
1935 eth_hw_addr_set(ndev, priv->mac_addr); in davinci_emac_probe()
1937 if (!is_valid_ether_addr(priv->mac_addr)) { in davinci_emac_probe()
1940 memcpy(priv->mac_addr, ndev->dev_addr, ndev->addr_len); in davinci_emac_probe()
1941 dev_warn(&pdev->dev, "using random MAC addr: %pM\n", in davinci_emac_probe()
1942 priv->mac_addr); in davinci_emac_probe()
1945 ndev->netdev_ops = &emac_netdev_ops; in davinci_emac_probe()
1946 ndev->ethtool_ops = &ethtool_ops; in davinci_emac_probe()
1947 netif_napi_add(ndev, &priv->napi, emac_poll); in davinci_emac_probe()
1949 pm_runtime_enable(&pdev->dev); in davinci_emac_probe()
1950 rc = pm_runtime_resume_and_get(&pdev->dev); in davinci_emac_probe()
1952 dev_err(&pdev->dev, "%s: failed to get_sync(%d)\n", in davinci_emac_probe()
1958 SET_NETDEV_DEV(ndev, &pdev->dev); in davinci_emac_probe()
1961 dev_err(&pdev->dev, "error in register_netdev\n"); in davinci_emac_probe()
1962 rc = -ENODEV; in davinci_emac_probe()
1963 pm_runtime_put(&pdev->dev); in davinci_emac_probe()
1969 dev_notice(&pdev->dev, "DaVinci EMAC Probe found device " in davinci_emac_probe()
1971 &priv->emac_base_phys, ndev->irq); in davinci_emac_probe()
1973 pm_runtime_put(&pdev->dev); in davinci_emac_probe()
1978 netif_napi_del(&priv->napi); in davinci_emac_probe()
1980 cpdma_chan_destroy(priv->rxchan); in davinci_emac_probe()
1982 cpdma_chan_destroy(priv->txchan); in davinci_emac_probe()
1984 cpdma_ctlr_destroy(priv->dma); in davinci_emac_probe()
1988 of_node_put(priv->phy_node); in davinci_emac_probe()
1995 * davinci_emac_remove - EMAC device remove
2005 struct device_node *np = pdev->dev.of_node; in davinci_emac_remove()
2007 dev_notice(&ndev->dev, "DaVinci EMAC: davinci_emac_remove()\n"); in davinci_emac_remove()
2009 if (priv->txchan) in davinci_emac_remove()
2010 cpdma_chan_destroy(priv->txchan); in davinci_emac_remove()
2011 if (priv->rxchan) in davinci_emac_remove()
2012 cpdma_chan_destroy(priv->rxchan); in davinci_emac_remove()
2013 cpdma_ctlr_destroy(priv->dma); in davinci_emac_remove()
2016 of_node_put(priv->phy_node); in davinci_emac_remove()
2017 pm_runtime_disable(&pdev->dev); in davinci_emac_remove()
2058 {.compatible = "ti,davinci-dm6467-emac", },
2059 {.compatible = "ti,am3517-emac", .data = &am3517_emac_data, },
2060 {.compatible = "ti,dm816-emac", .data = &dm816_emac_data, },
2077 * davinci_emac_init - EMAC driver module init
2089 * davinci_emac_exit - EMAC driver module exit