Lines Matching +full:ps +full:- +full:speed

1 // SPDX-License-Identifier: GPL-2.0-only
6 * Copyright 2001-2003, 2006 MontaVista Software Inc.
8 * Added ethtool/mii-tool support,
11 * or riemer@riemer-nt.de: fixed the link beat detection with
14 * converted to use linux-2.6.x's PHY framework
22 #include <linux/dma-mapping.h>
67 #define DRV_DESC "Au1xxx on-chip Ethernet driver"
202 * make sure there's no out-of-order writes, and that all writes
207 * board-specific configurations
221 * needed in case of a dual-PHY accessible only through the MAC0's MII
241 * ps: make sure the used irqs are configured properly in the board
242 * specific irq-map
249 spin_lock_irqsave(&aup->lock, flags); in au1000_enable_mac()
251 if (force_reset || (!aup->mac_enabled)) { in au1000_enable_mac()
252 writel(MAC_EN_CLOCK_ENABLE, aup->enable); in au1000_enable_mac()
256 | MAC_EN_CLOCK_ENABLE), aup->enable); in au1000_enable_mac()
260 aup->mac_enabled = 1; in au1000_enable_mac()
263 spin_unlock_irqrestore(&aup->lock, flags); in au1000_enable_mac()
272 u32 *const mii_control_reg = &aup->mac->mii_control; in au1000_mdio_read()
273 u32 *const mii_data_reg = &aup->mac->mii_data; in au1000_mdio_read()
279 if (--timedout == 0) { in au1000_mdio_read()
281 return -1; in au1000_mdio_read()
293 if (--timedout == 0) { in au1000_mdio_read()
295 return -1; in au1000_mdio_read()
305 u32 *const mii_control_reg = &aup->mac->mii_control; in au1000_mdio_write()
306 u32 *const mii_data_reg = &aup->mac->mii_data; in au1000_mdio_write()
312 if (--timedout == 0) { in au1000_mdio_write()
327 struct net_device *const dev = bus->priv; in au1000_mdiobus_read()
340 struct net_device *const dev = bus->priv; in au1000_mdiobus_write()
353 struct net_device *const dev = bus->priv; in au1000_mdiobus_reset()
370 reg = readl(&aup->mac->control); in au1000_hard_stop()
372 writel(reg, &aup->mac->control); in au1000_hard_stop()
384 reg = readl(&aup->mac->control); in au1000_enable_rx_tx()
386 writel(reg, &aup->mac->control); in au1000_enable_rx_tx()
395 struct phy_device *phydev = dev->phydev; in au1000_adjust_link()
403 spin_lock_irqsave(&aup->lock, flags); in au1000_adjust_link()
405 if (phydev->link && (aup->old_speed != phydev->speed)) { in au1000_adjust_link()
406 /* speed changed */ in au1000_adjust_link()
408 switch (phydev->speed) { in au1000_adjust_link()
413 netdev_warn(dev, "Speed (%d) is not 10/100 ???\n", in au1000_adjust_link()
414 phydev->speed); in au1000_adjust_link()
418 aup->old_speed = phydev->speed; in au1000_adjust_link()
423 if (phydev->link && (aup->old_duplex != phydev->duplex)) { in au1000_adjust_link()
429 reg = readl(&aup->mac->control); in au1000_adjust_link()
430 if (DUPLEX_FULL == phydev->duplex) { in au1000_adjust_link()
437 writel(reg, &aup->mac->control); in au1000_adjust_link()
442 aup->old_duplex = phydev->duplex; in au1000_adjust_link()
447 if (phydev->link != aup->old_link) { in au1000_adjust_link()
450 if (!phydev->link) { in au1000_adjust_link()
452 aup->old_speed = 0; in au1000_adjust_link()
453 aup->old_duplex = -1; in au1000_adjust_link()
456 aup->old_link = phydev->link; in au1000_adjust_link()
460 spin_unlock_irqrestore(&aup->lock, flags); in au1000_adjust_link()
463 if (phydev->link) in au1000_adjust_link()
465 phydev->speed, in au1000_adjust_link()
466 DUPLEX_FULL == phydev->duplex ? "Full" : "Half"); in au1000_adjust_link()
478 if (aup->phy_static_config) { in au1000_mii_probe()
479 BUG_ON(aup->mac_id < 0 || aup->mac_id > 1); in au1000_mii_probe()
481 if (aup->phy_addr) in au1000_mii_probe()
482 phydev = mdiobus_get_phy(aup->mii_bus, aup->phy_addr); in au1000_mii_probe()
484 netdev_info(dev, "using PHY-less setup\n"); in au1000_mii_probe()
492 if (mdiobus_get_phy(aup->mii_bus, phy_addr)) { in au1000_mii_probe()
493 phydev = mdiobus_get_phy(aup->mii_bus, phy_addr); in au1000_mii_probe()
494 if (!aup->phy_search_highest_addr) in au1000_mii_probe()
499 if (aup->phy1_search_mac0) { in au1000_mii_probe()
501 if (!phydev && (aup->mac_id == 1)) { in au1000_mii_probe()
503 dev_info(&dev->dev, ": no PHY found on MAC1, " in au1000_mii_probe()
506 /* find the first (lowest address) non-attached in au1000_mii_probe()
511 mdiobus_get_phy(aup->mii_bus, in au1000_mii_probe()
514 if (aup->mac_id == 1) in au1000_mii_probe()
522 if (tmp_phydev->attached_dev) in au1000_mii_probe()
533 return -1; in au1000_mii_probe()
537 BUG_ON(phydev->attached_dev); in au1000_mii_probe()
549 aup->old_link = 0; in au1000_mii_probe()
550 aup->old_speed = 0; in au1000_mii_probe()
551 aup->old_duplex = -1; in au1000_mii_probe()
566 pDB = aup->pDBfree; in au1000_GetFreeDB()
569 aup->pDBfree = pDB->pnext; in au1000_GetFreeDB()
576 struct db_dest *pDBfree = aup->pDBfree; in au1000_ReleaseDB()
578 pDBfree->pnext = pDB; in au1000_ReleaseDB()
579 aup->pDBfree = pDB; in au1000_ReleaseDB()
589 writel(MAC_EN_CLOCK_ENABLE, aup->enable); in au1000_reset_mac_unlocked()
592 writel(0, aup->enable); in au1000_reset_mac_unlocked()
596 aup->tx_full = 0; in au1000_reset_mac_unlocked()
599 aup->rx_dma_ring[i]->buff_stat &= ~0xf; in au1000_reset_mac_unlocked()
603 aup->tx_dma_ring[i]->buff_stat &= ~0xf; in au1000_reset_mac_unlocked()
606 aup->mac_enabled = 0; in au1000_reset_mac_unlocked()
618 spin_lock_irqsave(&aup->lock, flags); in au1000_reset_mac()
622 spin_unlock_irqrestore(&aup->lock, flags); in au1000_reset_mac()
627 * of the rx and tx MAC DMA registers so they are fixed by the hardware --
636 aup->rx_dma_ring[i] = (struct rx_dma *) in au1000_setup_hw_rings()
640 aup->tx_dma_ring[i] = (struct tx_dma *) in au1000_setup_hw_rings()
653 strscpy(info->driver, DRV_NAME, sizeof(info->driver)); in au1000_get_drvinfo()
654 snprintf(info->bus_info, sizeof(info->bus_info), "%s %d", DRV_NAME, in au1000_get_drvinfo()
655 aup->mac_id); in au1000_get_drvinfo()
661 aup->msg_enable = value; in au1000_set_msglevel()
667 return aup->msg_enable; in au1000_get_msglevel()
684 * do the same -- reset the device and disable the clocks to
700 spin_lock_irqsave(&aup->lock, flags); in au1000_init()
702 writel(0, &aup->mac->control); in au1000_init()
703 aup->tx_head = (aup->tx_dma_ring[0]->buff_stat & 0xC) >> 2; in au1000_init()
704 aup->tx_tail = aup->tx_head; in au1000_init()
705 aup->rx_head = (aup->rx_dma_ring[0]->buff_stat & 0xC) >> 2; in au1000_init()
707 writel(dev->dev_addr[5]<<8 | dev->dev_addr[4], in au1000_init()
708 &aup->mac->mac_addr_high); in au1000_init()
709 writel(dev->dev_addr[3]<<24 | dev->dev_addr[2]<<16 | in au1000_init()
710 dev->dev_addr[1]<<8 | dev->dev_addr[0], in au1000_init()
711 &aup->mac->mac_addr_low); in au1000_init()
715 aup->rx_dma_ring[i]->buff_stat |= RX_DMA_ENABLE; in au1000_init()
723 if (dev->phydev) { in au1000_init()
724 if (dev->phydev->link && (DUPLEX_FULL == dev->phydev->duplex)) in au1000_init()
728 } else { /* PHY-less op, assume full-duplex */ in au1000_init()
732 writel(control, &aup->mac->control); in au1000_init()
733 writel(0x8100, &aup->mac->vlan1_tag); /* activate vlan support */ in au1000_init()
736 spin_unlock_irqrestore(&aup->lock, flags); in au1000_init()
742 struct net_device_stats *ps = &dev->stats; in au1000_update_rx_stats() local
744 ps->rx_packets++; in au1000_update_rx_stats()
746 ps->multicast++; in au1000_update_rx_stats()
749 ps->rx_errors++; in au1000_update_rx_stats()
751 ps->rx_missed_errors++; in au1000_update_rx_stats()
753 ps->rx_length_errors++; in au1000_update_rx_stats()
755 ps->rx_crc_errors++; in au1000_update_rx_stats()
757 ps->collisions++; in au1000_update_rx_stats()
759 ps->rx_bytes += status & RX_FRAME_LEN_MASK; in au1000_update_rx_stats()
775 netif_dbg(aup, rx_status, dev, "au1000_rx head %d\n", aup->rx_head); in au1000_rx()
777 prxd = aup->rx_dma_ring[aup->rx_head]; in au1000_rx()
778 buff_stat = prxd->buff_stat; in au1000_rx()
780 status = prxd->status; in au1000_rx()
781 pDB = aup->rx_db_inuse[aup->rx_head]; in au1000_rx()
787 frmlen -= 4; /* Remove FCS */ in au1000_rx()
790 dev->stats.rx_dropped++; in au1000_rx()
795 (unsigned char *)pDB->vaddr, frmlen); in au1000_rx()
797 skb->protocol = eth_type_trans(skb, dev); in au1000_rx()
823 prxd->buff_stat = lower_32_bits(pDB->dma_addr) | RX_DMA_ENABLE; in au1000_rx()
824 aup->rx_head = (aup->rx_head + 1) & (NUM_RX_DMA - 1); in au1000_rx()
828 prxd = aup->rx_dma_ring[aup->rx_head]; in au1000_rx()
829 buff_stat = prxd->buff_stat; in au1000_rx()
836 struct net_device_stats *ps = &dev->stats; in au1000_update_tx_stats() local
839 if (!dev->phydev || (DUPLEX_FULL == dev->phydev->duplex)) { in au1000_update_tx_stats()
844 ps->tx_errors++; in au1000_update_tx_stats()
845 ps->tx_aborted_errors++; in au1000_update_tx_stats()
848 ps->tx_errors++; in au1000_update_tx_stats()
849 ps->tx_aborted_errors++; in au1000_update_tx_stats()
851 ps->tx_carrier_errors++; in au1000_update_tx_stats()
866 ptxd = aup->tx_dma_ring[aup->tx_tail]; in au1000_tx_ack()
868 while (ptxd->buff_stat & TX_T_DONE) { in au1000_tx_ack()
869 au1000_update_tx_stats(dev, ptxd->status); in au1000_tx_ack()
870 ptxd->buff_stat &= ~TX_T_DONE; in au1000_tx_ack()
871 ptxd->len = 0; in au1000_tx_ack()
874 aup->tx_tail = (aup->tx_tail + 1) & (NUM_TX_DMA - 1); in au1000_tx_ack()
875 ptxd = aup->tx_dma_ring[aup->tx_tail]; in au1000_tx_ack()
877 if (aup->tx_full) { in au1000_tx_ack()
878 aup->tx_full = 0; in au1000_tx_ack()
905 retval = request_irq(dev->irq, au1000_interrupt, 0, in au1000_open()
906 dev->name, dev); in au1000_open()
908 netdev_err(dev, "unable to get IRQ %d\n", dev->irq); in au1000_open()
915 free_irq(dev->irq, dev); in au1000_open()
919 if (dev->phydev) in au1000_open()
920 phy_start(dev->phydev); in au1000_open()
936 if (dev->phydev) in au1000_close()
937 phy_stop(dev->phydev); in au1000_close()
939 spin_lock_irqsave(&aup->lock, flags); in au1000_close()
947 free_irq(dev->irq, dev); in au1000_close()
948 spin_unlock_irqrestore(&aup->lock, flags); in au1000_close()
959 struct net_device_stats *ps = &dev->stats; in au1000_tx() local
966 (unsigned)aup, skb->len, in au1000_tx()
967 skb->data, aup->tx_head); in au1000_tx()
969 ptxd = aup->tx_dma_ring[aup->tx_head]; in au1000_tx()
970 buff_stat = ptxd->buff_stat; in au1000_tx()
974 aup->tx_full = 1; in au1000_tx()
977 au1000_update_tx_stats(dev, ptxd->status); in au1000_tx()
978 ptxd->len = 0; in au1000_tx()
981 if (aup->tx_full) { in au1000_tx()
982 aup->tx_full = 0; in au1000_tx()
986 pDB = aup->tx_db_inuse[aup->tx_head]; in au1000_tx()
987 skb_copy_from_linear_data(skb, (void *)pDB->vaddr, skb->len); in au1000_tx()
988 if (skb->len < ETH_ZLEN) { in au1000_tx()
989 for (i = skb->len; i < ETH_ZLEN; i++) in au1000_tx()
990 ((char *)pDB->vaddr)[i] = 0; in au1000_tx()
992 ptxd->len = ETH_ZLEN; in au1000_tx()
994 ptxd->len = skb->len; in au1000_tx()
996 ps->tx_packets++; in au1000_tx()
997 ps->tx_bytes += ptxd->len; in au1000_tx()
999 ptxd->buff_stat = lower_32_bits(pDB->dma_addr) | TX_DMA_ENABLE; in au1000_tx()
1002 aup->tx_head = (aup->tx_head + 1) & (NUM_TX_DMA - 1); in au1000_tx()
1024 netif_dbg(aup, drv, dev, "%s: flags=%x\n", __func__, dev->flags); in au1000_multicast_list()
1025 reg = readl(&aup->mac->control); in au1000_multicast_list()
1026 if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ in au1000_multicast_list()
1028 } else if ((dev->flags & IFF_ALLMULTI) || in au1000_multicast_list()
1039 set_bit(ether_crc(ETH_ALEN, ha->addr)>>26, in au1000_multicast_list()
1041 writel(mc_filter[1], &aup->mac->multi_hash_high); in au1000_multicast_list()
1042 writel(mc_filter[0], &aup->mac->multi_hash_low); in au1000_multicast_list()
1046 writel(reg, &aup->mac->control); in au1000_multicast_list()
1071 dev_err(&pdev->dev, "failed to retrieve base register\n"); in au1000_probe()
1072 err = -ENODEV; in au1000_probe()
1078 dev_err(&pdev->dev, "failed to retrieve MAC Enable register\n"); in au1000_probe()
1079 err = -ENODEV; in au1000_probe()
1085 err = -ENODEV; in au1000_probe()
1091 dev_err(&pdev->dev, "failed to retrieve MACDMA registers\n"); in au1000_probe()
1092 err = -ENODEV; in au1000_probe()
1096 if (!request_mem_region(base->start, resource_size(base), in au1000_probe()
1097 pdev->name)) { in au1000_probe()
1098 dev_err(&pdev->dev, "failed to request memory region for base registers\n"); in au1000_probe()
1099 err = -ENXIO; in au1000_probe()
1103 if (!request_mem_region(macen->start, resource_size(macen), in au1000_probe()
1104 pdev->name)) { in au1000_probe()
1105 dev_err(&pdev->dev, "failed to request memory region for MAC enable register\n"); in au1000_probe()
1106 err = -ENXIO; in au1000_probe()
1110 if (!request_mem_region(macdma->start, resource_size(macdma), in au1000_probe()
1111 pdev->name)) { in au1000_probe()
1112 dev_err(&pdev->dev, "failed to request MACDMA memory region\n"); in au1000_probe()
1113 err = -ENXIO; in au1000_probe()
1119 err = -ENOMEM; in au1000_probe()
1123 SET_NETDEV_DEV(dev, &pdev->dev); in au1000_probe()
1127 spin_lock_init(&aup->lock); in au1000_probe()
1128 aup->msg_enable = (au1000_debug < 4 ? in au1000_probe()
1134 aup->vaddr = dma_alloc_coherent(&pdev->dev, MAX_BUF_SIZE * in au1000_probe()
1136 &aup->dma_addr, 0); in au1000_probe()
1137 if (!aup->vaddr) { in au1000_probe()
1138 dev_err(&pdev->dev, "failed to allocate data buffers\n"); in au1000_probe()
1139 err = -ENOMEM; in au1000_probe()
1143 /* aup->mac is the base address of the MAC's registers */ in au1000_probe()
1144 aup->mac = (struct mac_reg *) in au1000_probe()
1145 ioremap(base->start, resource_size(base)); in au1000_probe()
1146 if (!aup->mac) { in au1000_probe()
1147 dev_err(&pdev->dev, "failed to ioremap MAC registers\n"); in au1000_probe()
1148 err = -ENXIO; in au1000_probe()
1153 aup->enable = (u32 *)ioremap(macen->start, in au1000_probe()
1155 if (!aup->enable) { in au1000_probe()
1156 dev_err(&pdev->dev, "failed to ioremap MAC enable register\n"); in au1000_probe()
1157 err = -ENXIO; in au1000_probe()
1160 aup->mac_id = pdev->id; in au1000_probe()
1162 aup->macdma = ioremap(macdma->start, resource_size(macdma)); in au1000_probe()
1163 if (!aup->macdma) { in au1000_probe()
1164 dev_err(&pdev->dev, "failed to ioremap MACDMA registers\n"); in au1000_probe()
1165 err = -ENXIO; in au1000_probe()
1169 au1000_setup_hw_rings(aup, aup->macdma); in au1000_probe()
1171 writel(0, aup->enable); in au1000_probe()
1172 aup->mac_enabled = 0; in au1000_probe()
1174 pd = dev_get_platdata(&pdev->dev); in au1000_probe()
1176 dev_info(&pdev->dev, "no platform_data passed," in au1000_probe()
1178 aup->phy1_search_mac0 = 1; in au1000_probe()
1180 if (is_valid_ether_addr(pd->mac)) { in au1000_probe()
1181 eth_hw_addr_set(dev, pd->mac); in au1000_probe()
1187 aup->phy_static_config = pd->phy_static_config; in au1000_probe()
1188 aup->phy_search_highest_addr = pd->phy_search_highest_addr; in au1000_probe()
1189 aup->phy1_search_mac0 = pd->phy1_search_mac0; in au1000_probe()
1190 aup->phy_addr = pd->phy_addr; in au1000_probe()
1191 aup->phy_busid = pd->phy_busid; in au1000_probe()
1192 aup->phy_irq = pd->phy_irq; in au1000_probe()
1195 if (aup->phy_busid > 0) { in au1000_probe()
1196 dev_err(&pdev->dev, "MAC0-associated PHY attached 2nd MACs MII bus not supported yet\n"); in au1000_probe()
1197 err = -ENODEV; in au1000_probe()
1201 aup->mii_bus = mdiobus_alloc(); in au1000_probe()
1202 if (!aup->mii_bus) { in au1000_probe()
1203 dev_err(&pdev->dev, "failed to allocate mdiobus structure\n"); in au1000_probe()
1204 err = -ENOMEM; in au1000_probe()
1208 aup->mii_bus->priv = dev; in au1000_probe()
1209 aup->mii_bus->read = au1000_mdiobus_read; in au1000_probe()
1210 aup->mii_bus->write = au1000_mdiobus_write; in au1000_probe()
1211 aup->mii_bus->reset = au1000_mdiobus_reset; in au1000_probe()
1212 aup->mii_bus->name = "au1000_eth_mii"; in au1000_probe()
1213 snprintf(aup->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", in au1000_probe()
1214 pdev->name, aup->mac_id); in au1000_probe()
1217 if (aup->phy_static_config) in au1000_probe()
1218 if (aup->phy_irq && aup->phy_busid == aup->mac_id) in au1000_probe()
1219 aup->mii_bus->irq[aup->phy_addr] = aup->phy_irq; in au1000_probe()
1221 err = mdiobus_register(aup->mii_bus); in au1000_probe()
1223 dev_err(&pdev->dev, "failed to register MDIO bus\n"); in au1000_probe()
1233 pDB = aup->db; in au1000_probe()
1235 pDB->pnext = pDBfree; in au1000_probe()
1237 pDB->vaddr = aup->vaddr + MAX_BUF_SIZE * i; in au1000_probe()
1238 pDB->dma_addr = aup->dma_addr + MAX_BUF_SIZE * i; in au1000_probe()
1241 aup->pDBfree = pDBfree; in au1000_probe()
1243 err = -ENODEV; in au1000_probe()
1249 aup->rx_dma_ring[i]->buff_stat = lower_32_bits(pDB->dma_addr); in au1000_probe()
1250 aup->rx_db_inuse[i] = pDB; in au1000_probe()
1258 aup->tx_dma_ring[i]->buff_stat = lower_32_bits(pDB->dma_addr); in au1000_probe()
1259 aup->tx_dma_ring[i]->len = 0; in au1000_probe()
1260 aup->tx_db_inuse[i] = pDB; in au1000_probe()
1263 dev->base_addr = base->start; in au1000_probe()
1264 dev->irq = irq; in au1000_probe()
1265 dev->netdev_ops = &au1000_netdev_ops; in au1000_probe()
1266 dev->ethtool_ops = &au1000_ethtool_ops; in au1000_probe()
1267 dev->watchdog_timeo = ETH_TX_TIMEOUT; in au1000_probe()
1282 (unsigned long)base->start, irq); in au1000_probe()
1287 if (aup->mii_bus) in au1000_probe()
1288 mdiobus_unregister(aup->mii_bus); in au1000_probe()
1290 /* here we should have a valid dev plus aup-> register addresses in au1000_probe()
1296 if (aup->rx_db_inuse[i]) in au1000_probe()
1297 au1000_ReleaseDB(aup, aup->rx_db_inuse[i]); in au1000_probe()
1300 if (aup->tx_db_inuse[i]) in au1000_probe()
1301 au1000_ReleaseDB(aup, aup->tx_db_inuse[i]); in au1000_probe()
1304 mdiobus_free(aup->mii_bus); in au1000_probe()
1306 iounmap(aup->macdma); in au1000_probe()
1308 iounmap(aup->enable); in au1000_probe()
1310 iounmap(aup->mac); in au1000_probe()
1312 dma_free_coherent(&pdev->dev, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS), in au1000_probe()
1313 aup->vaddr, aup->dma_addr); in au1000_probe()
1317 release_mem_region(macdma->start, resource_size(macdma)); in au1000_probe()
1319 release_mem_region(macen->start, resource_size(macen)); in au1000_probe()
1321 release_mem_region(base->start, resource_size(base)); in au1000_probe()
1334 mdiobus_unregister(aup->mii_bus); in au1000_remove()
1335 mdiobus_free(aup->mii_bus); in au1000_remove()
1338 if (aup->rx_db_inuse[i]) in au1000_remove()
1339 au1000_ReleaseDB(aup, aup->rx_db_inuse[i]); in au1000_remove()
1342 if (aup->tx_db_inuse[i]) in au1000_remove()
1343 au1000_ReleaseDB(aup, aup->tx_db_inuse[i]); in au1000_remove()
1345 dma_free_coherent(&pdev->dev, MAX_BUF_SIZE * (NUM_TX_BUFFS + NUM_RX_BUFFS), in au1000_remove()
1346 aup->vaddr, aup->dma_addr); in au1000_remove()
1348 iounmap(aup->macdma); in au1000_remove()
1349 iounmap(aup->mac); in au1000_remove()
1350 iounmap(aup->enable); in au1000_remove()
1353 release_mem_region(base->start, resource_size(base)); in au1000_remove()
1356 release_mem_region(base->start, resource_size(base)); in au1000_remove()
1359 release_mem_region(macen->start, resource_size(macen)); in au1000_remove()
1368 .name = "au1000-eth",
1374 MODULE_ALIAS("platform:au1000-eth");