Lines Matching refs:bp

27 static u16 dnet_readw_mac(struct dnet *bp, u16 reg)  in dnet_readw_mac()  argument
32 dnet_writel(bp, reg, MACREG_ADDR); in dnet_readw_mac()
39 data_read = dnet_readl(bp, MACREG_DATA); in dnet_readw_mac()
46 static void dnet_writew_mac(struct dnet *bp, u16 reg, u16 val) in dnet_writew_mac() argument
49 dnet_writel(bp, val, MACREG_DATA); in dnet_writew_mac()
52 dnet_writel(bp, reg | DNET_INTERNAL_WRITE, MACREG_ADDR); in dnet_writew_mac()
59 static void __dnet_set_hwaddr(struct dnet *bp) in __dnet_set_hwaddr() argument
63 tmp = be16_to_cpup((const __be16 *)bp->dev->dev_addr); in __dnet_set_hwaddr()
64 dnet_writew_mac(bp, DNET_INTERNAL_MAC_ADDR_0_REG, tmp); in __dnet_set_hwaddr()
65 tmp = be16_to_cpup((const __be16 *)(bp->dev->dev_addr + 2)); in __dnet_set_hwaddr()
66 dnet_writew_mac(bp, DNET_INTERNAL_MAC_ADDR_1_REG, tmp); in __dnet_set_hwaddr()
67 tmp = be16_to_cpup((const __be16 *)(bp->dev->dev_addr + 4)); in __dnet_set_hwaddr()
68 dnet_writew_mac(bp, DNET_INTERNAL_MAC_ADDR_2_REG, tmp); in __dnet_set_hwaddr()
71 static void dnet_get_hwaddr(struct dnet *bp) in dnet_get_hwaddr() argument
88 tmp = dnet_readw_mac(bp, DNET_INTERNAL_MAC_ADDR_0_REG); in dnet_get_hwaddr()
90 tmp = dnet_readw_mac(bp, DNET_INTERNAL_MAC_ADDR_1_REG); in dnet_get_hwaddr()
92 tmp = dnet_readw_mac(bp, DNET_INTERNAL_MAC_ADDR_2_REG); in dnet_get_hwaddr()
96 eth_hw_addr_set(bp->dev, addr); in dnet_get_hwaddr()
101 struct dnet *bp = bus->priv; in dnet_mdio_read() local
104 while (!(dnet_readw_mac(bp, DNET_INTERNAL_GMII_MNG_CTL_REG) in dnet_mdio_read()
117 dnet_writew_mac(bp, DNET_INTERNAL_GMII_MNG_CTL_REG, value); in dnet_mdio_read()
120 while (!(dnet_readw_mac(bp, DNET_INTERNAL_GMII_MNG_CTL_REG) in dnet_mdio_read()
124 value = dnet_readw_mac(bp, DNET_INTERNAL_GMII_MNG_DAT_REG); in dnet_mdio_read()
134 struct dnet *bp = bus->priv; in dnet_mdio_write() local
139 while (!(dnet_readw_mac(bp, DNET_INTERNAL_GMII_MNG_CTL_REG) in dnet_mdio_write()
158 dnet_writew_mac(bp, DNET_INTERNAL_GMII_MNG_DAT_REG, value); in dnet_mdio_write()
161 dnet_writew_mac(bp, DNET_INTERNAL_GMII_MNG_CTL_REG, tmp); in dnet_mdio_write()
163 while (!(dnet_readw_mac(bp, DNET_INTERNAL_GMII_MNG_CTL_REG) in dnet_mdio_write()
172 struct dnet *bp = netdev_priv(dev); in dnet_handle_link_change() local
179 spin_lock_irqsave(&bp->lock, flags); in dnet_handle_link_change()
181 mode_reg = dnet_readw_mac(bp, DNET_INTERNAL_MODE_REG); in dnet_handle_link_change()
182 ctl_reg = dnet_readw_mac(bp, DNET_INTERNAL_RXTX_CONTROL_REG); in dnet_handle_link_change()
185 if (bp->duplex != phydev->duplex) { in dnet_handle_link_change()
193 bp->duplex = phydev->duplex; in dnet_handle_link_change()
197 if (bp->speed != phydev->speed) { in dnet_handle_link_change()
214 bp->speed = phydev->speed; in dnet_handle_link_change()
218 if (phydev->link != bp->link) { in dnet_handle_link_change()
226 bp->speed = 0; in dnet_handle_link_change()
227 bp->duplex = -1; in dnet_handle_link_change()
229 bp->link = phydev->link; in dnet_handle_link_change()
235 dnet_writew_mac(bp, DNET_INTERNAL_RXTX_CONTROL_REG, ctl_reg); in dnet_handle_link_change()
236 dnet_writew_mac(bp, DNET_INTERNAL_MODE_REG, mode_reg); in dnet_handle_link_change()
239 spin_unlock_irqrestore(&bp->lock, flags); in dnet_handle_link_change()
253 struct dnet *bp = netdev_priv(dev); in dnet_mii_probe() local
257 phydev = phy_find_first(bp->mii_bus); in dnet_mii_probe()
267 if (bp->capabilities & DNET_HAS_RMII) { in dnet_mii_probe()
283 if (bp->capabilities & DNET_HAS_GIGABIT) in dnet_mii_probe()
290 bp->link = 0; in dnet_mii_probe()
291 bp->speed = 0; in dnet_mii_probe()
292 bp->duplex = -1; in dnet_mii_probe()
297 static int dnet_mii_init(struct dnet *bp) in dnet_mii_init() argument
301 bp->mii_bus = mdiobus_alloc(); in dnet_mii_init()
302 if (bp->mii_bus == NULL) in dnet_mii_init()
305 bp->mii_bus->name = "dnet_mii_bus"; in dnet_mii_init()
306 bp->mii_bus->read = &dnet_mdio_read; in dnet_mii_init()
307 bp->mii_bus->write = &dnet_mdio_write; in dnet_mii_init()
309 snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", in dnet_mii_init()
310 bp->pdev->name, bp->pdev->id); in dnet_mii_init()
312 bp->mii_bus->priv = bp; in dnet_mii_init()
314 if (mdiobus_register(bp->mii_bus)) { in dnet_mii_init()
319 if (dnet_mii_probe(bp->dev) != 0) { in dnet_mii_init()
327 mdiobus_unregister(bp->mii_bus); in dnet_mii_init()
329 mdiobus_free(bp->mii_bus); in dnet_mii_init()
339 static void dnet_update_stats(struct dnet *bp) in dnet_update_stats() argument
341 u32 __iomem *reg = bp->regs + DNET_RX_PKT_IGNR_CNT; in dnet_update_stats()
342 u32 *p = &bp->hw_stats.rx_pkt_ignr; in dnet_update_stats()
343 u32 *end = &bp->hw_stats.rx_byte + 1; in dnet_update_stats()
351 reg = bp->regs + DNET_TX_UNICAST_CNT; in dnet_update_stats()
352 p = &bp->hw_stats.tx_unicast; in dnet_update_stats()
353 end = &bp->hw_stats.tx_byte + 1; in dnet_update_stats()
364 struct dnet *bp = container_of(napi, struct dnet, napi); in dnet_poll() local
365 struct net_device *dev = bp->dev; in dnet_poll()
379 if (!(dnet_readl(bp, RX_FIFO_WCNT) >> 16)) in dnet_poll()
382 cmd_word = dnet_readl(bp, RX_LEN_FIFO); in dnet_poll()
399 *data_ptr++ = dnet_readl(bp, RX_DATA_FIFO); in dnet_poll()
414 int_enable = dnet_readl(bp, INTR_ENB); in dnet_poll()
416 dnet_writel(bp, int_enable, INTR_ENB); in dnet_poll()
425 struct dnet *bp = netdev_priv(dev); in dnet_interrupt() local
430 spin_lock_irqsave(&bp->lock, flags); in dnet_interrupt()
433 int_src = dnet_readl(bp, INTR_SRC); in dnet_interrupt()
434 int_enable = dnet_readl(bp, INTR_ENB); in dnet_interrupt()
439 int_enable = dnet_readl(bp, INTR_ENB); in dnet_interrupt()
441 dnet_writel(bp, int_enable, INTR_ENB); in dnet_interrupt()
450 dnet_readl(bp, RX_STATUS), int_current); in dnet_interrupt()
452 dnet_writel(bp, DNET_SYS_CTL_RXFIFOFLUSH, SYS_CTL); in dnet_interrupt()
454 dnet_writel(bp, 0, SYS_CTL); in dnet_interrupt()
462 dnet_readl(bp, TX_STATUS), int_current); in dnet_interrupt()
464 dnet_writel(bp, DNET_SYS_CTL_TXFIFOFLUSH, SYS_CTL); in dnet_interrupt()
466 dnet_writel(bp, 0, SYS_CTL); in dnet_interrupt()
471 if (napi_schedule_prep(&bp->napi)) { in dnet_interrupt()
477 int_enable = dnet_readl(bp, INTR_ENB); in dnet_interrupt()
479 dnet_writel(bp, int_enable, INTR_ENB); in dnet_interrupt()
480 __napi_schedule(&bp->napi); in dnet_interrupt()
488 spin_unlock_irqrestore(&bp->lock, flags); in dnet_interrupt()
509 struct dnet *bp = netdev_priv(dev); in dnet_start_xmit() local
515 dnet_readl(bp, TX_STATUS); in dnet_start_xmit()
521 spin_lock_irqsave(&bp->lock, flags); in dnet_start_xmit()
523 dnet_readl(bp, TX_STATUS); in dnet_start_xmit()
532 if (wrsz < (DNET_FIFO_SIZE - dnet_readl(bp, TX_FIFO_WCNT))) { in dnet_start_xmit()
534 dnet_writel(bp, *bufp++, TX_DATA_FIFO); in dnet_start_xmit()
540 dnet_writel(bp, tx_cmd, TX_LEN_FIFO); in dnet_start_xmit()
543 if (dnet_readl(bp, TX_FIFO_WCNT) > DNET_FIFO_TX_DATA_AF_TH) { in dnet_start_xmit()
545 dnet_readl(bp, INTR_SRC); in dnet_start_xmit()
546 irq_enable = dnet_readl(bp, INTR_ENB); in dnet_start_xmit()
548 dnet_writel(bp, irq_enable, INTR_ENB); in dnet_start_xmit()
553 spin_unlock_irqrestore(&bp->lock, flags); in dnet_start_xmit()
561 static void dnet_reset_hw(struct dnet *bp) in dnet_reset_hw() argument
564 dnet_writew_mac(bp, DNET_INTERNAL_MODE_REG, DNET_INTERNAL_MODE_FCEN); in dnet_reset_hw()
570 dnet_writel(bp, DNET_FIFO_RX_CMD_AF_TH, RX_FIFO_TH); in dnet_reset_hw()
575 dnet_writel(bp, DNET_FIFO_TX_DATA_AE_TH, TX_FIFO_TH); in dnet_reset_hw()
578 dnet_writel(bp, DNET_SYS_CTL_RXFIFOFLUSH | DNET_SYS_CTL_TXFIFOFLUSH, in dnet_reset_hw()
581 dnet_writel(bp, 0, SYS_CTL); in dnet_reset_hw()
584 static void dnet_init_hw(struct dnet *bp) in dnet_init_hw() argument
588 dnet_reset_hw(bp); in dnet_init_hw()
589 __dnet_set_hwaddr(bp); in dnet_init_hw()
591 config = dnet_readw_mac(bp, DNET_INTERNAL_RXTX_CONTROL_REG); in dnet_init_hw()
593 if (bp->dev->flags & IFF_PROMISC) in dnet_init_hw()
596 if (!(bp->dev->flags & IFF_BROADCAST)) in dnet_init_hw()
605 dnet_writew_mac(bp, DNET_INTERNAL_RXTX_CONTROL_REG, config); in dnet_init_hw()
608 config = dnet_readl(bp, INTR_SRC); in dnet_init_hw()
611 dnet_writel(bp, DNET_INTR_ENB_GLOBAL_ENABLE | DNET_INTR_ENB_RX_SUMMARY | in dnet_init_hw()
620 struct dnet *bp = netdev_priv(dev); in dnet_open() local
626 napi_enable(&bp->napi); in dnet_open()
627 dnet_init_hw(bp); in dnet_open()
641 struct dnet *bp = netdev_priv(dev); in dnet_close() local
644 napi_disable(&bp->napi); in dnet_close()
649 dnet_reset_hw(bp); in dnet_close()
691 struct dnet *bp = netdev_priv(dev); in dnet_get_stats() local
693 struct dnet_stats *hwstat = &bp->hw_stats; in dnet_get_stats()
696 dnet_update_stats(bp); in dnet_get_stats()
754 struct dnet *bp; in dnet_probe() local
761 dev = alloc_etherdev(sizeof(*bp)); in dnet_probe()
768 bp = netdev_priv(dev); in dnet_probe()
769 bp->dev = dev; in dnet_probe()
774 spin_lock_init(&bp->lock); in dnet_probe()
776 bp->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); in dnet_probe()
777 if (IS_ERR(bp->regs)) { in dnet_probe()
778 err = PTR_ERR(bp->regs); in dnet_probe()
791 netif_napi_add(dev, &bp->napi, dnet_poll); in dnet_probe()
794 dev->base_addr = (unsigned long)bp->regs; in dnet_probe()
796 bp->capabilities = dnet_readl(bp, VERCAPS) & DNET_CAPS_MASK; in dnet_probe()
798 dnet_get_hwaddr(bp); in dnet_probe()
803 __dnet_set_hwaddr(bp); in dnet_probe()
819 err = dnet_mii_init(bp); in dnet_probe()
824 bp->regs, (unsigned int)res->start, dev->irq, dev->dev_addr); in dnet_probe()
826 (bp->capabilities & DNET_HAS_MDIO) ? "" : "no ", in dnet_probe()
827 (bp->capabilities & DNET_HAS_IRQ) ? "" : "no ", in dnet_probe()
828 (bp->capabilities & DNET_HAS_GIGABIT) ? "" : "no ", in dnet_probe()
829 (bp->capabilities & DNET_HAS_DMA) ? "" : "no "); in dnet_probe()
848 struct dnet *bp; in dnet_remove() local
853 bp = netdev_priv(dev); in dnet_remove()
856 mdiobus_unregister(bp->mii_bus); in dnet_remove()
857 mdiobus_free(bp->mii_bus); in dnet_remove()