Lines Matching +full:mii +full:- +full:rt
1 // SPDX-License-Identifier: GPL-2.0
13 #include <linux/dma-mapping.h>
20 #include <linux/mii.h>
72 #define nr64(reg) readq(np->regs + (reg))
73 #define nw64(reg, val) writeq((val), np->regs + (reg))
75 #define nr64_mac(reg) readq(np->mac_regs + (reg))
76 #define nw64_mac(reg, val) writeq((val), np->mac_regs + (reg))
78 #define nr64_ipp(reg) readq(np->regs + np->ipp_off + (reg))
79 #define nw64_ipp(reg, val) writeq((val), np->regs + np->ipp_off + (reg))
81 #define nr64_pcs(reg) readq(np->regs + np->pcs_off + (reg))
82 #define nw64_pcs(reg, val) writeq((val), np->regs + np->pcs_off + (reg))
84 #define nr64_xpcs(reg) readq(np->regs + np->xpcs_off + (reg))
85 #define nw64_xpcs(reg, val) writeq((val), np->regs + np->xpcs_off + (reg))
90 static int debug = -1;
95 spin_lock_irqsave(&np->parent->lock, flags)
97 spin_unlock_irqrestore(&np->parent->lock, flags)
104 while (--limit >= 0) { in __niu_wait_bits_clear_mac()
112 return -ENODEV; in __niu_wait_bits_clear_mac()
125 netdev_err(np->dev, "bits (%llx) of register %s would not clear, val[%llx]\n", in __niu_set_and_wait_clear_mac()
139 while (--limit >= 0) { in __niu_wait_bits_clear_ipp()
147 return -ENODEV; in __niu_wait_bits_clear_ipp()
164 netdev_err(np->dev, "bits (%llx) of register %s would not clear, val[%llx]\n", in __niu_set_and_wait_clear_ipp()
178 while (--limit >= 0) { in __niu_wait_bits_clear()
186 return -ENODEV; in __niu_wait_bits_clear()
204 netdev_err(np->dev, "bits (%llx) of register %s would not clear, val[%llx]\n", in __niu_set_and_wait_clear()
217 u64 val = (u64) lp->timer; in niu_ldg_rearm()
222 nw64(LDG_IMGMT(lp->ldg_num), val); in niu_ldg_rearm()
231 return -EINVAL; in niu_ldn_irq_enable()
237 mask_reg = LD_IM1(ldn - 64); in niu_ldn_irq_enable()
253 struct niu_parent *parent = np->parent; in niu_enable_ldn_in_ldg()
259 if (parent->ldg_map[i] != lp->ldg_num) in niu_enable_ldn_in_ldg()
273 for (i = 0; i < np->num_ldg; i++) { in niu_enable_interrupts()
274 struct niu_ldg *lp = &np->ldg[i]; in niu_enable_interrupts()
281 for (i = 0; i < np->num_ldg; i++) in niu_enable_interrupts()
282 niu_ldg_rearm(np, &np->ldg[i], on); in niu_enable_interrupts()
302 while (--limit > 0) { in mdio_wait()
310 return -ENODEV; in mdio_wait()
365 err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR, in esr2_set_tx_cfg()
369 err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR, in esr2_set_tx_cfg()
379 err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR, in esr2_set_rx_cfg()
383 err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR, in esr2_set_rx_cfg()
392 struct niu_link_config *lp = &np->link_config; in serdes_init_niu_10g_fiber()
401 if (lp->loopback_mode == LOOPBACK_PHY) { in serdes_init_niu_10g_fiber()
404 mdio_write(np, np->port, NIU_ESR2_DEV_ADDR, in serdes_init_niu_10g_fiber()
429 struct niu_link_config *lp = &np->link_config; in serdes_init_niu_1g_serdes()
443 if (np->port == 0) in serdes_init_niu_1g_serdes()
446 if (lp->loopback_mode == LOOPBACK_PHY) { in serdes_init_niu_1g_serdes()
449 mdio_write(np, np->port, NIU_ESR2_DEV_ADDR, in serdes_init_niu_1g_serdes()
459 err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR, in serdes_init_niu_1g_serdes()
462 netdev_err(np->dev, "NIU Port %d %s() mdio write to ESR2_TI_PLL_CFG_L failed\n", in serdes_init_niu_1g_serdes()
463 np->port, __func__); in serdes_init_niu_1g_serdes()
469 err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR, in serdes_init_niu_1g_serdes()
472 netdev_err(np->dev, "NIU Port %d %s() mdio write to ESR2_TI_PLL_STS_L failed\n", in serdes_init_niu_1g_serdes()
473 np->port, __func__); in serdes_init_niu_1g_serdes()
492 switch (np->port) { in serdes_init_niu_1g_serdes()
504 return -EINVAL; in serdes_init_niu_1g_serdes()
507 while (max_retry--) { in serdes_init_niu_1g_serdes()
516 netdev_err(np->dev, "Port %u signal bits [%08x] are not [%08x]\n", in serdes_init_niu_1g_serdes()
517 np->port, (int)(sig & mask), (int)val); in serdes_init_niu_1g_serdes()
518 return -ENODEV; in serdes_init_niu_1g_serdes()
526 struct niu_link_config *lp = &np->link_config; in serdes_init_niu_10g_serdes()
538 if (lp->loopback_mode == LOOPBACK_PHY) { in serdes_init_niu_10g_serdes()
541 mdio_write(np, np->port, NIU_ESR2_DEV_ADDR, in serdes_init_niu_10g_serdes()
551 err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR, in serdes_init_niu_10g_serdes()
554 netdev_err(np->dev, "NIU Port %d %s() mdio write to ESR2_TI_PLL_CFG_L failed\n", in serdes_init_niu_10g_serdes()
555 np->port, __func__); in serdes_init_niu_10g_serdes()
561 err = mdio_write(np, np->port, NIU_ESR2_DEV_ADDR, in serdes_init_niu_10g_serdes()
564 netdev_err(np->dev, "NIU Port %d %s() mdio write to ESR2_TI_PLL_STS_L failed\n", in serdes_init_niu_10g_serdes()
565 np->port, __func__); in serdes_init_niu_10g_serdes()
586 switch (np->port) { in serdes_init_niu_10g_serdes()
610 return -EINVAL; in serdes_init_niu_10g_serdes()
613 while (max_retry--) { in serdes_init_niu_10g_serdes()
623 np->port, (int)(sig & mask), (int)val); in serdes_init_niu_10g_serdes()
628 np->flags &= ~NIU_FLAGS_10G; in serdes_init_niu_10g_serdes()
629 np->mac_xcvr = MAC_XCVR_PCS; in serdes_init_niu_10g_serdes()
631 netdev_err(np->dev, "Port %u 10G/1G SERDES Link Failed\n", in serdes_init_niu_10g_serdes()
632 np->port); in serdes_init_niu_10g_serdes()
633 return -ENODEV; in serdes_init_niu_10g_serdes()
643 err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR, ESR_RXTX_CTRL_L(chan)); in esr_read_rxtx_ctrl()
646 err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR, in esr_read_rxtx_ctrl()
659 err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR, in esr_read_glue0()
663 err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR, in esr_read_glue0()
677 err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR, in esr_read_reset()
681 err = mdio_read(np, np->port, NIU_ESR_DEV_ADDR, in esr_read_reset()
695 err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR, in esr_write_rxtx_ctrl()
698 err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR, in esr_write_rxtx_ctrl()
707 err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR, in esr_write_glue0()
710 err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR, in esr_write_glue0()
720 err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR, in esr_reset()
724 err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR, in esr_reset()
730 err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR, in esr_reset()
736 err = mdio_write(np, np->port, NIU_ESR_DEV_ADDR, in esr_reset()
746 netdev_err(np->dev, "Port %u ESR_RESET did not clear [%08x]\n", in esr_reset()
747 np->port, reset); in esr_reset()
748 return -ENODEV; in esr_reset()
756 struct niu_link_config *lp = &np->link_config; in serdes_init_10g()
761 switch (np->port) { in serdes_init_10g()
772 return -EINVAL; in serdes_init_10g()
788 if (lp->loopback_mode == LOOPBACK_PHY) { in serdes_init_10g()
839 switch (np->port) { in serdes_init_10g()
863 return -EINVAL; in serdes_init_10g()
867 if (np->flags & NIU_FLAGS_HOTPLUG_PHY) { in serdes_init_10g()
868 np->flags &= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT; in serdes_init_10g()
871 netdev_err(np->dev, "Port %u signal bits [%08x] are not [%08x]\n", in serdes_init_10g()
872 np->port, (int)(sig & mask), (int)val); in serdes_init_10g()
873 return -ENODEV; in serdes_init_10g()
875 if (np->flags & NIU_FLAGS_HOTPLUG_PHY) in serdes_init_10g()
876 np->flags |= NIU_FLAGS_HOTPLUG_PHY_PRESENT; in serdes_init_10g()
886 switch (np->port) { in serdes_init_1g()
900 return -EINVAL; in serdes_init_1g()
909 struct niu_link_config *lp = &np->link_config; in serdes_init_1g_serdes()
918 switch (np->port) { in serdes_init_1g_serdes()
933 return -EINVAL; in serdes_init_1g_serdes()
949 if (lp->loopback_mode == LOOPBACK_PHY) { in serdes_init_1g_serdes()
1004 switch (np->port) { in serdes_init_1g_serdes()
1016 return -EINVAL; in serdes_init_1g_serdes()
1020 netdev_err(np->dev, "Port %u signal bits [%08x] are not [%08x]\n", in serdes_init_1g_serdes()
1021 np->port, (int)(sig & mask), (int)val); in serdes_init_1g_serdes()
1022 return -ENODEV; in serdes_init_1g_serdes()
1030 struct niu_link_config *lp = &np->link_config; in link_status_1g_serdes()
1041 spin_lock_irqsave(&np->lock, flags); in link_status_1g_serdes()
1051 lp->active_speed = current_speed; in link_status_1g_serdes()
1052 lp->active_duplex = current_duplex; in link_status_1g_serdes()
1053 spin_unlock_irqrestore(&np->lock, flags); in link_status_1g_serdes()
1062 struct niu_link_config *lp = &np->link_config; in link_status_10g_serdes()
1069 if (!(np->flags & NIU_FLAGS_10G)) in link_status_10g_serdes()
1074 spin_lock_irqsave(&np->lock, flags); in link_status_10g_serdes()
1086 lp->active_speed = current_speed; in link_status_10g_serdes()
1087 lp->active_duplex = current_duplex; in link_status_10g_serdes()
1088 spin_unlock_irqrestore(&np->lock, flags); in link_status_10g_serdes()
1095 struct niu_link_config *lp = &np->link_config; in link_status_mii()
1100 err = mii_read(np, np->phy_addr, MII_BMCR); in link_status_mii()
1105 err = mii_read(np, np->phy_addr, MII_BMSR); in link_status_mii()
1110 err = mii_read(np, np->phy_addr, MII_ADVERTISE); in link_status_mii()
1115 err = mii_read(np, np->phy_addr, MII_LPA); in link_status_mii()
1121 err = mii_read(np, np->phy_addr, MII_ESTATUS); in link_status_mii()
1126 err = mii_read(np, np->phy_addr, MII_CTRL1000); in link_status_mii()
1131 err = mii_read(np, np->phy_addr, MII_STAT1000); in link_status_mii()
1153 lp->supported = supported; in link_status_mii()
1161 lp->active_autoneg = 1; in link_status_mii()
1183 lp->active_autoneg = 0; in link_status_mii()
1198 lp->active_advertising = advertising; in link_status_mii()
1199 lp->active_speed = active_speed; in link_status_mii()
1200 lp->active_duplex = active_duplex; in link_status_mii()
1208 struct niu_link_config *lp = &np->link_config; in link_status_1g_rgmii()
1218 spin_lock_irqsave(&np->lock, flags); in link_status_1g_rgmii()
1220 err = -EINVAL; in link_status_1g_rgmii()
1222 err = mii_read(np, np->phy_addr, MII_BMSR); in link_status_1g_rgmii()
1232 lp->active_speed = current_speed; in link_status_1g_rgmii()
1233 lp->active_duplex = current_duplex; in link_status_1g_rgmii()
1237 spin_unlock_irqrestore(&np->lock, flags); in link_status_1g_rgmii()
1245 struct niu_link_config *lp = &np->link_config; in link_status_1g()
1249 spin_lock_irqsave(&np->lock, flags); in link_status_1g()
1252 lp->supported |= SUPPORTED_TP; in link_status_1g()
1253 lp->active_advertising |= ADVERTISED_TP; in link_status_1g()
1255 spin_unlock_irqrestore(&np->lock, flags); in link_status_1g()
1263 err = mdio_read(np, np->phy_addr, in bcm8704_reset()
1268 err = mdio_write(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR, in bcm8704_reset()
1274 while (--limit >= 0) { in bcm8704_reset()
1275 err = mdio_read(np, np->phy_addr, in bcm8704_reset()
1283 netdev_err(np->dev, "Port %u PHY will not reset (bmcr=%04x)\n", in bcm8704_reset()
1284 np->port, (err & 0xffff)); in bcm8704_reset()
1285 return -ENODEV; in bcm8704_reset()
1295 int err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, reg); in bcm8704_user_dev3_readback()
1298 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, reg); in bcm8704_user_dev3_readback()
1309 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in bcm8706_init_user_dev3()
1316 err = mdio_write(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in bcm8706_init_user_dev3()
1330 err = mdio_write(np, np->phy_addr, in bcm8704_init_user_dev3()
1344 err = mdio_write(np, np->phy_addr, in bcm8704_init_user_dev3()
1360 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in bcm8704_init_user_dev3()
1366 err = mdio_write(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in bcm8704_init_user_dev3()
1380 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV2_ADDR, in mrvl88x2011_act_led()
1388 return mdio_write(np, np->phy_addr, MRVL88X2011_USER_DEV2_ADDR, in mrvl88x2011_act_led()
1396 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV2_ADDR, in mrvl88x2011_led_blink_rate()
1402 err = mdio_write(np, np->phy_addr, MRVL88X2011_USER_DEV2_ADDR, in mrvl88x2011_led_blink_rate()
1423 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV3_ADDR, in xcvr_init_10g_mrvl88x2011()
1430 err = mdio_write(np, np->phy_addr, MRVL88X2011_USER_DEV3_ADDR, in xcvr_init_10g_mrvl88x2011()
1435 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV1_ADDR, in xcvr_init_10g_mrvl88x2011()
1440 if (np->link_config.loopback_mode == LOOPBACK_MAC) in xcvr_init_10g_mrvl88x2011()
1445 err = mdio_write(np, np->phy_addr, MRVL88X2011_USER_DEV1_ADDR, in xcvr_init_10g_mrvl88x2011()
1451 return mdio_write(np, np->phy_addr, MRVL88X2011_USER_DEV1_ADDR, in xcvr_init_10g_mrvl88x2011()
1462 err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR, in xcvr_diag_bcm870x()
1466 pr_info("Port %u PMA_PMD(MII_STAT1000) [%04x]\n", np->port, err); in xcvr_diag_bcm870x()
1468 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, 0x20); in xcvr_diag_bcm870x()
1471 pr_info("Port %u USER_DEV3(0x20) [%04x]\n", np->port, err); in xcvr_diag_bcm870x()
1473 err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR, in xcvr_diag_bcm870x()
1477 pr_info("Port %u PHYXS(MII_NWAYTEST) [%04x]\n", np->port, err); in xcvr_diag_bcm870x()
1481 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in xcvr_diag_bcm870x()
1485 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in xcvr_diag_bcm870x()
1491 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in xcvr_diag_bcm870x()
1495 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in xcvr_diag_bcm870x()
1504 np->port); in xcvr_diag_bcm870x()
1507 np->port); in xcvr_diag_bcm870x()
1516 struct niu_link_config *lp = &np->link_config; in xcvr_10g_set_lb_bcm870x()
1519 err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR, in xcvr_10g_set_lb_bcm870x()
1526 if (lp->loopback_mode == LOOPBACK_MAC) in xcvr_10g_set_lb_bcm870x()
1529 err = mdio_write(np, np->phy_addr, BCM8704_PCS_DEV_ADDR, in xcvr_10g_set_lb_bcm870x()
1542 if ((np->flags & NIU_FLAGS_HOTPLUG_PHY) && in xcvr_init_10g_bcm8706()
1543 (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT) == 0) in xcvr_init_10g_bcm8706()
1612 phy_id = phy_decode(np->parent->port_phy, np->port); in xcvr_init_10g()
1613 phy_id = np->parent->phy_probe_info.phy_id[phy_id][np->port]; in xcvr_init_10g()
1633 err = mii_write(np, np->phy_addr, MII_BMCR, BMCR_RESET); in mii_reset()
1638 while (--limit >= 0) { in mii_reset()
1640 err = mii_read(np, np->phy_addr, MII_BMCR); in mii_reset()
1647 netdev_err(np->dev, "Port %u MII would not reset, bmcr[%04x]\n", in mii_reset()
1648 np->port, err); in mii_reset()
1649 return -ENODEV; in mii_reset()
1669 err = mii_read(np, np->phy_addr, MII_BMSR); in xcvr_init_1g_rgmii()
1676 err = mii_read(np, np->phy_addr, MII_ESTATUS); in xcvr_init_1g_rgmii()
1683 err = mii_write(np, np->phy_addr, MII_BMCR, bmcr); in xcvr_init_1g_rgmii()
1692 err = mii_write(np, np->phy_addr, MII_CTRL1000, ctrl1000); in xcvr_init_1g_rgmii()
1699 err = mii_write(np, np->phy_addr, MII_BMCR, bmcr); in xcvr_init_1g_rgmii()
1703 err = mii_read(np, np->phy_addr, MII_BMCR); in xcvr_init_1g_rgmii()
1706 bmcr = mii_read(np, np->phy_addr, MII_BMCR); in xcvr_init_1g_rgmii()
1708 err = mii_read(np, np->phy_addr, MII_BMSR); in xcvr_init_1g_rgmii()
1717 struct niu_link_config *lp = &np->link_config; in mii_init_common()
1725 err = mii_read(np, np->phy_addr, MII_BMSR); in mii_init_common()
1732 err = mii_read(np, np->phy_addr, MII_ESTATUS); in mii_init_common()
1739 err = mii_write(np, np->phy_addr, MII_BMCR, bmcr); in mii_init_common()
1743 if (lp->loopback_mode == LOOPBACK_MAC) { in mii_init_common()
1745 if (lp->active_speed == SPEED_1000) in mii_init_common()
1747 if (lp->active_duplex == DUPLEX_FULL) in mii_init_common()
1751 if (lp->loopback_mode == LOOPBACK_PHY) { in mii_init_common()
1756 err = mii_write(np, np->phy_addr, BCM5464R_AUX_CTL, aux); in mii_init_common()
1761 if (lp->autoneg) { in mii_init_common()
1766 (lp->advertising & ADVERTISED_10baseT_Half)) in mii_init_common()
1769 (lp->advertising & ADVERTISED_10baseT_Full)) in mii_init_common()
1772 (lp->advertising & ADVERTISED_100baseT_Half)) in mii_init_common()
1775 (lp->advertising & ADVERTISED_100baseT_Full)) in mii_init_common()
1777 err = mii_write(np, np->phy_addr, MII_ADVERTISE, adv); in mii_init_common()
1784 (lp->advertising & ADVERTISED_1000baseT_Half)) in mii_init_common()
1787 (lp->advertising & ADVERTISED_1000baseT_Full)) in mii_init_common()
1789 err = mii_write(np, np->phy_addr, in mii_init_common()
1797 /* !lp->autoneg */ in mii_init_common()
1800 if (lp->duplex == DUPLEX_FULL) { in mii_init_common()
1803 } else if (lp->duplex == DUPLEX_HALF) in mii_init_common()
1806 return -EINVAL; in mii_init_common()
1808 if (lp->speed == SPEED_1000) { in mii_init_common()
1809 /* if X-full requested while not supported, or in mii_init_common()
1810 X-half requested while not supported... */ in mii_init_common()
1813 return -EINVAL; in mii_init_common()
1815 } else if (lp->speed == SPEED_100) { in mii_init_common()
1818 return -EINVAL; in mii_init_common()
1820 } else if (lp->speed == SPEED_10) { in mii_init_common()
1823 return -EINVAL; in mii_init_common()
1825 return -EINVAL; in mii_init_common()
1828 err = mii_write(np, np->phy_addr, MII_BMCR, bmcr); in mii_init_common()
1833 err = mii_read(np, np->phy_addr, MII_BMCR); in mii_init_common()
1838 err = mii_read(np, np->phy_addr, MII_BMSR); in mii_init_common()
1843 pr_info("Port %u after MII init bmcr[%04x] bmsr[%04x]\n", in mii_init_common()
1844 np->port, bmcr, bmsr); in mii_init_common()
1864 const struct niu_phy_ops *ops = np->phy_ops; in niu_xcvr_init()
1868 if (ops->xcvr_init) in niu_xcvr_init()
1869 err = ops->xcvr_init(np); in niu_xcvr_init()
1876 const struct niu_phy_ops *ops = np->phy_ops; in niu_serdes_init()
1880 if (ops->serdes_init) in niu_serdes_init()
1881 err = ops->serdes_init(np); in niu_serdes_init()
1891 struct niu_link_config *lp = &np->link_config; in niu_link_status_common()
1892 struct net_device *dev = np->dev; in niu_link_status_common()
1897 lp->active_speed == SPEED_10000 ? "10Gb/sec" : in niu_link_status_common()
1898 lp->active_speed == SPEED_1000 ? "1Gb/sec" : in niu_link_status_common()
1899 lp->active_speed == SPEED_100 ? "100Mbit/sec" : in niu_link_status_common()
1901 lp->active_duplex == DUPLEX_FULL ? "full" : "half"); in niu_link_status_common()
1903 spin_lock_irqsave(&np->lock, flags); in niu_link_status_common()
1906 spin_unlock_irqrestore(&np->lock, flags); in niu_link_status_common()
1911 spin_lock_irqsave(&np->lock, flags); in niu_link_status_common()
1913 spin_unlock_irqrestore(&np->lock, flags); in niu_link_status_common()
1926 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV1_ADDR, in link_status_10g_mrvl()
1932 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV1_ADDR, in link_status_10g_mrvl()
1940 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV3_ADDR, in link_status_10g_mrvl()
1945 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV3_ADDR, in link_status_10g_mrvl()
1952 /* Check XGXS Register : 4.0018.[0-3,12] */ in link_status_10g_mrvl()
1953 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV4_ADDR, in link_status_10g_mrvl()
1964 np->link_config.active_speed = SPEED_10000; in link_status_10g_mrvl()
1965 np->link_config.active_duplex = DUPLEX_FULL; in link_status_10g_mrvl()
1981 err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR, in link_status_10g_bcm8706()
1990 err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR, in link_status_10g_bcm8706()
2000 err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR, in link_status_10g_bcm8706()
2012 np->link_config.active_speed = SPEED_INVALID; in link_status_10g_bcm8706()
2013 np->link_config.active_duplex = DUPLEX_INVALID; in link_status_10g_bcm8706()
2018 np->link_config.active_speed = SPEED_10000; in link_status_10g_bcm8706()
2019 np->link_config.active_duplex = DUPLEX_FULL; in link_status_10g_bcm8706()
2033 err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR, in link_status_10g_bcom()
2042 err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR, in link_status_10g_bcom()
2051 err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR, in link_status_10g_bcom()
2067 np->link_config.active_speed = SPEED_10000; in link_status_10g_bcom()
2068 np->link_config.active_duplex = DUPLEX_FULL; in link_status_10g_bcom()
2079 int err = -EINVAL; in link_status_10g()
2081 spin_lock_irqsave(&np->lock, flags); in link_status_10g()
2083 if (np->link_config.loopback_mode == LOOPBACK_DISABLED) { in link_status_10g()
2086 phy_id = phy_decode(np->parent->port_phy, np->port); in link_status_10g()
2087 phy_id = np->parent->phy_probe_info.phy_id[phy_id][np->port]; in link_status_10g()
2101 spin_unlock_irqrestore(&np->lock, flags); in link_status_10g()
2111 switch (np->port) { in niu_10g_phy_present()
2150 spin_lock_irqsave(&np->lock, flags); in link_status_10g_hotplug()
2152 if (np->link_config.loopback_mode == LOOPBACK_DISABLED) { in link_status_10g_hotplug()
2153 phy_present_prev = (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT) ? in link_status_10g_hotplug()
2160 np->flags |= NIU_FLAGS_HOTPLUG_PHY_PRESENT; in link_status_10g_hotplug()
2161 if (np->phy_ops->xcvr_init) in link_status_10g_hotplug()
2162 err = np->phy_ops->xcvr_init(np); in link_status_10g_hotplug()
2164 err = mdio_read(np, np->phy_addr, in link_status_10g_hotplug()
2167 /* No mdio, back-to-back XAUI */ in link_status_10g_hotplug()
2171 np->flags &= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT; in link_status_10g_hotplug()
2174 np->flags &= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT; in link_status_10g_hotplug()
2176 netif_warn(np, link, np->dev, in link_status_10g_hotplug()
2181 if (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT) { in link_status_10g_hotplug()
2184 /* No mdio, back-to-back XAUI: it is C10NEM */ in link_status_10g_hotplug()
2186 np->link_config.active_speed = SPEED_10000; in link_status_10g_hotplug()
2187 np->link_config.active_duplex = DUPLEX_FULL; in link_status_10g_hotplug()
2192 spin_unlock_irqrestore(&np->lock, flags); in link_status_10g_hotplug()
2199 const struct niu_phy_ops *ops = np->phy_ops; in niu_link_status()
2203 if (ops->link_status) in niu_link_status()
2204 err = ops->link_status(np, link_up_p); in niu_link_status()
2219 if (netif_carrier_ok(np->dev)) in niu_timer()
2223 np->timer.expires = jiffies + off; in niu_timer()
2225 add_timer(&np->timer); in niu_timer()
2354 struct niu_link_config *lp = &np->link_config; in serdes_init_10g_serdes()
2358 switch (np->port) { in serdes_init_10g_serdes()
2371 return -EINVAL; in serdes_init_10g_serdes()
2387 if (lp->loopback_mode == LOOPBACK_PHY) { in serdes_init_10g_serdes()
2438 switch (np->port) { in serdes_init_10g_serdes()
2462 return -EINVAL; in serdes_init_10g_serdes()
2469 np->flags &= ~NIU_FLAGS_10G; in serdes_init_10g_serdes()
2470 np->mac_xcvr = MAC_XCVR_PCS; in serdes_init_10g_serdes()
2472 netdev_err(np->dev, "Port %u 10G/1G SERDES Link Failed\n", in serdes_init_10g_serdes()
2473 np->port); in serdes_init_10g_serdes()
2474 return -ENODEV; in serdes_init_10g_serdes()
2483 struct niu_parent *parent = np->parent; in niu_determine_phy_disposition()
2484 u8 plat_type = parent->plat_type; in niu_determine_phy_disposition()
2489 switch (np->flags & in niu_determine_phy_disposition()
2504 if (np->flags & NIU_FLAGS_HOTPLUG_PHY) { in niu_determine_phy_disposition()
2506 if (np->port == 0) in niu_determine_phy_disposition()
2508 if (np->port == 1) in niu_determine_phy_disposition()
2512 phy_addr_off += np->port; in niu_determine_phy_disposition()
2517 switch (np->flags & in niu_determine_phy_disposition()
2529 phy_addr_off += (np->port ^ 0x3); in niu_determine_phy_disposition()
2548 phy_addr_off += np->port; in niu_determine_phy_disposition()
2549 if (np->flags & NIU_FLAGS_HOTPLUG_PHY) { in niu_determine_phy_disposition()
2551 if (np->port == 0) in niu_determine_phy_disposition()
2553 if (np->port == 1) in niu_determine_phy_disposition()
2561 switch(np->port) { in niu_determine_phy_disposition()
2571 return -EINVAL; in niu_determine_phy_disposition()
2573 phy_addr_off = niu_atca_port_num[np->port]; in niu_determine_phy_disposition()
2577 return -EINVAL; in niu_determine_phy_disposition()
2581 np->phy_ops = tp->ops; in niu_determine_phy_disposition()
2582 np->phy_addr = tp->phy_addr_base + phy_addr_off; in niu_determine_phy_disposition()
2589 struct niu_parent *parent = np->parent; in niu_init_link()
2592 if (parent->plat_type == PLAT_TYPE_NIU) { in niu_init_link()
2599 if (err && !(np->flags & NIU_FLAGS_HOTPLUG_PHY)) in niu_init_link()
2603 if (!err || (np->flags & NIU_FLAGS_HOTPLUG_PHY)) in niu_init_link()
2614 if (np->flags & NIU_FLAGS_XMAC) { in niu_set_primary_mac()
2627 if (np->flags & NIU_FLAGS_XMAC) in niu_num_alt_addr()
2640 return -EINVAL; in niu_set_alt_mac()
2642 if (np->flags & NIU_FLAGS_XMAC) { in niu_set_alt_mac()
2661 return -EINVAL; in niu_enable_alt_mac()
2663 if (np->flags & NIU_FLAGS_XMAC) { in niu_enable_alt_mac()
2699 return -EINVAL; in __set_rdc_table_num()
2700 if (np->flags & NIU_FLAGS_XMAC) in __set_rdc_table_num()
2724 return -EINVAL; in niu_set_alt_mac_rdc_table()
2779 while (--limit > 0) { in tcam_wait_bit()
2785 return -ENODEV; in tcam_wait_bit()
2894 return -EINVAL; in tcam_user_eth_class_enable()
2896 reg = L2_CLS(class - CLASS_CODE_ETHERTYPE1); in tcam_user_eth_class_enable()
2917 return -EINVAL;
2919 reg = L2_CLS(class - CLASS_CODE_ETHERTYPE1);
2937 return -EINVAL; in tcam_user_ip_class_enable()
2939 reg = L3_CLS(class - CLASS_CODE_USER_PROG1); in tcam_user_ip_class_enable()
2962 return -EINVAL; in tcam_user_ip_class_set()
2964 reg = L3_CLS(class - CLASS_CODE_USER_PROG1); in tcam_user_ip_class_set()
3005 for (i = 0; i < np->parent->tcam_num_entries; i++) { in tcam_flush_all()
3028 return -EINVAL;
3047 return -EINVAL; in hash_write()
3096 return -EINVAL; in fflp_set_partition()
3170 parent = np->parent; in fflp_early_init()
3172 if (!(parent->flags & PARENT_FLGS_CLS_HWINIT)) { in fflp_early_init()
3173 if (np->parent->plat_type != PLAT_TYPE_NIU) { in fflp_early_init()
3178 netif_printk(np, probe, KERN_DEBUG, np->dev, in fflp_early_init()
3187 netif_printk(np, probe, KERN_DEBUG, np->dev, in fflp_early_init()
3198 netif_printk(np, probe, KERN_DEBUG, np->dev, in fflp_early_init()
3202 if (np->parent->plat_type != PLAT_TYPE_NIU) { in fflp_early_init()
3205 netif_printk(np, probe, KERN_DEBUG, np->dev, in fflp_early_init()
3214 parent->flags |= PARENT_FLGS_CLS_HWINIT; in fflp_early_init()
3225 return -EINVAL; in niu_set_flow_key()
3227 nw64(FLOW_KEY(class_code - CLASS_CODE_USER_PROG1), key); in niu_set_flow_key()
3235 return -EINVAL; in niu_set_tcam_key()
3237 nw64(TCAM_KEY(class_code - CLASS_CODE_USER_PROG1), key); in niu_set_tcam_key()
3245 if (idx >= (np->clas.tcam_sz - 1)) in tcam_get_index()
3247 return np->clas.tcam_top + ((idx+1) * np->parent->num_ports); in tcam_get_index()
3253 return np->clas.tcam_sz - 1; in tcam_get_size()
3259 return np->clas.tcam_valid_entries - 1; in tcam_get_valid_entry_cnt()
3265 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page, offset, size); in niu_rx_skb_append()
3267 skb->len += size; in niu_rx_skb_append()
3268 skb->data_len += size; in niu_rx_skb_append()
3269 skb->truesize += truesize; in niu_rx_skb_append()
3277 return a & (MAX_RBR_RING_SIZE - 1); in niu_hash_rxaddr()
3287 pp = &rp->rxhash[h]; in niu_find_rxpage()
3288 for (; (p = *pp) != NULL; pp = (struct page **) &p->mapping) { in niu_find_rxpage()
3289 if (p->index == addr) { in niu_find_rxpage()
3304 page->index = base; in niu_hash_page()
3305 page->mapping = (struct address_space *) rp->rxhash[h]; in niu_hash_page()
3306 rp->rxhash[h] = page; in niu_hash_page()
3318 return -ENOMEM; in niu_rbr_add_page()
3320 addr = np->ops->map_page(np->device, page, 0, in niu_rbr_add_page()
3324 return -ENOMEM; in niu_rbr_add_page()
3328 if (rp->rbr_blocks_per_page > 1) in niu_rbr_add_page()
3329 page_ref_add(page, rp->rbr_blocks_per_page - 1); in niu_rbr_add_page()
3331 for (i = 0; i < rp->rbr_blocks_per_page; i++) { in niu_rbr_add_page()
3332 __le32 *rbr = &rp->rbr[start_index + i]; in niu_rbr_add_page()
3335 addr += rp->rbr_block_size; in niu_rbr_add_page()
3343 int index = rp->rbr_index; in niu_rbr_refill()
3345 rp->rbr_pending++; in niu_rbr_refill()
3346 if ((rp->rbr_pending % rp->rbr_blocks_per_page) == 0) { in niu_rbr_refill()
3350 rp->rbr_pending--; in niu_rbr_refill()
3354 rp->rbr_index += rp->rbr_blocks_per_page; in niu_rbr_refill()
3355 BUG_ON(rp->rbr_index > rp->rbr_table_size); in niu_rbr_refill()
3356 if (rp->rbr_index == rp->rbr_table_size) in niu_rbr_refill()
3357 rp->rbr_index = 0; in niu_rbr_refill()
3359 if (rp->rbr_pending >= rp->rbr_kick_thresh) { in niu_rbr_refill()
3360 nw64(RBR_KICK(rp->rx_channel), rp->rbr_pending); in niu_rbr_refill()
3361 rp->rbr_pending = 0; in niu_rbr_refill()
3368 unsigned int index = rp->rcr_index; in niu_rx_pkt_ignore()
3371 rp->rx_dropped++; in niu_rx_pkt_ignore()
3379 val = le64_to_cpup(&rp->rcr[index]); in niu_rx_pkt_ignore()
3384 rcr_size = rp->rbr_sizes[(val & RCR_ENTRY_PKTBUFSZ) >> in niu_rx_pkt_ignore()
3386 if ((page->index + PAGE_SIZE) - rcr_size == addr) { in niu_rx_pkt_ignore()
3387 *link = (struct page *) page->mapping; in niu_rx_pkt_ignore()
3388 np->ops->unmap_page(np->device, page->index, in niu_rx_pkt_ignore()
3390 page->index = 0; in niu_rx_pkt_ignore()
3391 page->mapping = NULL; in niu_rx_pkt_ignore()
3393 rp->rbr_refill_pending++; in niu_rx_pkt_ignore()
3401 rp->rcr_index = index; in niu_rx_pkt_ignore()
3409 unsigned int index = rp->rcr_index; in niu_process_rx_pkt()
3414 skb = netdev_alloc_skb(np->dev, RX_SKB_ALLOC_SIZE); in niu_process_rx_pkt()
3426 val = le64_to_cpup(&rp->rcr[index]); in niu_process_rx_pkt()
3436 rcr_size = rp->rbr_sizes[(val & RCR_ENTRY_PKTBUFSZ) >> in niu_process_rx_pkt()
3448 skb->ip_summed = CHECKSUM_UNNECESSARY; in niu_process_rx_pkt()
3452 append_size = append_size - skb->len; in niu_process_rx_pkt()
3455 if ((page->index + rp->rbr_block_size) - rcr_size == addr) { in niu_process_rx_pkt()
3456 *link = (struct page *) page->mapping; in niu_process_rx_pkt()
3457 np->ops->unmap_page(np->device, page->index, in niu_process_rx_pkt()
3459 page->index = 0; in niu_process_rx_pkt()
3460 page->mapping = NULL; in niu_process_rx_pkt()
3461 rp->rbr_refill_pending++; in niu_process_rx_pkt()
3470 rp->rcr_index = index; in niu_process_rx_pkt()
3476 rh = (struct rx_pkt_hdr1 *) skb->data; in niu_process_rx_pkt()
3477 if (np->dev->features & NETIF_F_RXHASH) in niu_process_rx_pkt()
3479 ((u32)rh->hashval2_0 << 24 | in niu_process_rx_pkt()
3480 (u32)rh->hashval2_1 << 16 | in niu_process_rx_pkt()
3481 (u32)rh->hashval1_1 << 8 | in niu_process_rx_pkt()
3482 (u32)rh->hashval1_2 << 0), in niu_process_rx_pkt()
3486 rp->rx_packets++; in niu_process_rx_pkt()
3487 rp->rx_bytes += skb->len; in niu_process_rx_pkt()
3489 skb->protocol = eth_type_trans(skb, np->dev); in niu_process_rx_pkt()
3490 skb_record_rx_queue(skb, rp->rx_channel); in niu_process_rx_pkt()
3498 int blocks_per_page = rp->rbr_blocks_per_page; in niu_rbr_fill()
3499 int err, index = rp->rbr_index; in niu_rbr_fill()
3502 while (index < (rp->rbr_table_size - blocks_per_page)) { in niu_rbr_fill()
3510 rp->rbr_index = index; in niu_rbr_fill()
3521 page = rp->rxhash[i]; in niu_rbr_free()
3523 struct page *next = (struct page *) page->mapping; in niu_rbr_free()
3524 u64 base = page->index; in niu_rbr_free()
3526 np->ops->unmap_page(np->device, base, PAGE_SIZE, in niu_rbr_free()
3528 page->index = 0; in niu_rbr_free()
3529 page->mapping = NULL; in niu_rbr_free()
3537 for (i = 0; i < rp->rbr_table_size; i++) in niu_rbr_free()
3538 rp->rbr[i] = cpu_to_le32(0); in niu_rbr_free()
3539 rp->rbr_index = 0; in niu_rbr_free()
3544 struct tx_buff_info *tb = &rp->tx_buffs[idx]; in release_tx_packet()
3545 struct sk_buff *skb = tb->skb; in release_tx_packet()
3550 tp = (struct tx_pkt_hdr *) skb->data; in release_tx_packet()
3551 tx_flags = le64_to_cpup(&tp->flags); in release_tx_packet()
3553 rp->tx_packets++; in release_tx_packet()
3554 rp->tx_bytes += (((tx_flags & TXHDR_LEN) >> TXHDR_LEN_SHIFT) - in release_tx_packet()
3558 np->ops->unmap_single(np->device, tb->mapping, in release_tx_packet()
3561 if (le64_to_cpu(rp->descr[idx]) & TX_DESC_MARK) in release_tx_packet()
3562 rp->mark_pending--; in release_tx_packet()
3564 tb->skb = NULL; in release_tx_packet()
3567 len -= MAX_TX_DESC_LEN; in release_tx_packet()
3570 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in release_tx_packet()
3571 tb = &rp->tx_buffs[idx]; in release_tx_packet()
3572 BUG_ON(tb->skb != NULL); in release_tx_packet()
3573 np->ops->unmap_page(np->device, tb->mapping, in release_tx_packet()
3574 skb_frag_size(&skb_shinfo(skb)->frags[i]), in release_tx_packet()
3584 #define NIU_TX_WAKEUP_THRESH(rp) ((rp)->pending / 4)
3593 index = (rp - np->tx_rings); in niu_tx_work()
3594 txq = netdev_get_tx_queue(np->dev, index); in niu_tx_work()
3596 cs = rp->tx_cs; in niu_tx_work()
3601 pkt_cnt = (pkt_cnt - rp->last_pkt_cnt) & in niu_tx_work()
3604 rp->last_pkt_cnt = tmp; in niu_tx_work()
3606 cons = rp->cons; in niu_tx_work()
3608 netif_printk(np, tx_done, KERN_DEBUG, np->dev, in niu_tx_work()
3611 while (pkt_cnt--) in niu_tx_work()
3614 rp->cons = cons; in niu_tx_work()
3633 * counters, as they are only 16-bit and can overflow quickly, in niu_sync_rx_discard_stats()
3643 int rx_channel = rp->rx_channel; in niu_sync_rx_discard_stats()
3654 rp->rx_errors += misc & RXMISC_COUNT; in niu_sync_rx_discard_stats()
3657 dev_err(np->device, "rx-%d: Counter overflow RXMISC discard\n", in niu_sync_rx_discard_stats()
3660 netif_printk(np, rx_err, KERN_DEBUG, np->dev, in niu_sync_rx_discard_stats()
3661 "rx-%d: MISC drop=%u over=%u\n", in niu_sync_rx_discard_stats()
3662 rx_channel, misc, misc-limit); in niu_sync_rx_discard_stats()
3669 rp->rx_dropped += wred & RED_DIS_CNT_COUNT; in niu_sync_rx_discard_stats()
3672 dev_err(np->device, "rx-%d: Counter overflow WRED discard\n", rx_channel); in niu_sync_rx_discard_stats()
3674 netif_printk(np, rx_err, KERN_DEBUG, np->dev, in niu_sync_rx_discard_stats()
3675 "rx-%d: WRED drop=%u over=%u\n", in niu_sync_rx_discard_stats()
3676 rx_channel, wred, wred-limit); in niu_sync_rx_discard_stats()
3684 struct rxdma_mailbox *mbox = rp->mbox; in niu_rx_work()
3688 stat = nr64(RX_DMA_CTL_STAT(rp->rx_channel)); in niu_rx_work()
3689 qlen = nr64(RCRSTAT_A(rp->rx_channel)) & RCRSTAT_A_QLEN; in niu_rx_work()
3691 stat = le64_to_cpup(&mbox->rx_dma_ctl_stat); in niu_rx_work()
3692 qlen = (le64_to_cpup(&mbox->rcrstat_a) & RCRSTAT_A_QLEN); in niu_rx_work()
3694 mbox->rx_dma_ctl_stat = 0; in niu_rx_work()
3695 mbox->rcrstat_a = 0; in niu_rx_work()
3697 netif_printk(np, rx_status, KERN_DEBUG, np->dev, in niu_rx_work()
3699 __func__, rp->rx_channel, (unsigned long long)stat, qlen); in niu_rx_work()
3708 if (rp->rbr_refill_pending >= rp->rbr_kick_thresh) { in niu_rx_work()
3711 for (i = 0; i < rp->rbr_refill_pending; i++) in niu_rx_work()
3713 rp->rbr_refill_pending = 0; in niu_rx_work()
3720 nw64(RX_DMA_CTL_STAT(rp->rx_channel), stat); in niu_rx_work()
3731 u64 v0 = lp->v0; in niu_poll_core()
3736 netif_printk(np, intr, KERN_DEBUG, np->dev, in niu_poll_core()
3739 for (i = 0; i < np->num_tx_rings; i++) { in niu_poll_core()
3740 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_poll_core()
3741 if (tx_vec & (1 << rp->tx_channel)) in niu_poll_core()
3743 nw64(LD_IM0(LDN_TXDMA(rp->tx_channel)), 0); in niu_poll_core()
3746 for (i = 0; i < np->num_rx_rings; i++) { in niu_poll_core()
3747 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_poll_core()
3749 if (rx_vec & (1 << rp->rx_channel)) { in niu_poll_core()
3752 this_work_done = niu_rx_work(&lp->napi, np, rp, in niu_poll_core()
3755 budget -= this_work_done; in niu_poll_core()
3758 nw64(LD_IM0(LDN_RXDMA(rp->rx_channel)), 0); in niu_poll_core()
3767 struct niu *np = lp->np; in niu_poll()
3782 netdev_err(np->dev, "RX channel %u errors ( ", rp->rx_channel); in niu_log_rxchan_errors()
3818 u64 stat = nr64(RX_DMA_CTL_STAT(rp->rx_channel)); in niu_rx_error()
3824 err = -EINVAL; in niu_rx_error()
3827 netdev_err(np->dev, "RX channel %u error, stat[%llx]\n", in niu_rx_error()
3828 rp->rx_channel, in niu_rx_error()
3834 nw64(RX_DMA_CTL_STAT(rp->rx_channel), in niu_rx_error()
3843 netdev_err(np->dev, "TX channel %u errors ( ", rp->tx_channel); in niu_log_txchan_errors()
3869 cs = nr64(TX_CS(rp->tx_channel)); in niu_tx_error()
3870 logh = nr64(TX_RNG_ERR_LOGH(rp->tx_channel)); in niu_tx_error()
3871 logl = nr64(TX_RNG_ERR_LOGL(rp->tx_channel)); in niu_tx_error()
3873 netdev_err(np->dev, "TX channel %u error, cs[%llx] logh[%llx] logl[%llx]\n", in niu_tx_error()
3874 rp->tx_channel, in niu_tx_error()
3881 return -ENODEV; in niu_tx_error()
3889 if (np->flags & NIU_FLAGS_XMAC) { in niu_mif_interrupt()
3896 netdev_err(np->dev, "MIF interrupt, stat[%llx] phy_mdint(%d)\n", in niu_mif_interrupt()
3899 return -ENODEV; in niu_mif_interrupt()
3904 struct niu_xmac_stats *mp = &np->mac_stats.xmac; in niu_xmac_interrupt()
3909 mp->tx_frames += TXMAC_FRM_CNT_COUNT; in niu_xmac_interrupt()
3911 mp->tx_bytes += TXMAC_BYTE_CNT_COUNT; in niu_xmac_interrupt()
3913 mp->tx_fifo_errors++; in niu_xmac_interrupt()
3915 mp->tx_overflow_errors++; in niu_xmac_interrupt()
3917 mp->tx_max_pkt_size_errors++; in niu_xmac_interrupt()
3919 mp->tx_underflow_errors++; in niu_xmac_interrupt()
3923 mp->rx_local_faults++; in niu_xmac_interrupt()
3925 mp->rx_remote_faults++; in niu_xmac_interrupt()
3927 mp->rx_link_faults += LINK_FAULT_CNT_COUNT; in niu_xmac_interrupt()
3929 mp->rx_align_errors += RXMAC_ALIGN_ERR_CNT_COUNT; in niu_xmac_interrupt()
3931 mp->rx_frags += RXMAC_FRAG_CNT_COUNT; in niu_xmac_interrupt()
3933 mp->rx_mcasts += RXMAC_MC_FRM_CNT_COUNT; in niu_xmac_interrupt()
3935 mp->rx_bcasts += RXMAC_BC_FRM_CNT_COUNT; in niu_xmac_interrupt()
3937 mp->rx_bcasts += RXMAC_BC_FRM_CNT_COUNT; in niu_xmac_interrupt()
3939 mp->rx_hist_cnt1 += RXMAC_HIST_CNT1_COUNT; in niu_xmac_interrupt()
3941 mp->rx_hist_cnt2 += RXMAC_HIST_CNT2_COUNT; in niu_xmac_interrupt()
3943 mp->rx_hist_cnt3 += RXMAC_HIST_CNT3_COUNT; in niu_xmac_interrupt()
3945 mp->rx_hist_cnt4 += RXMAC_HIST_CNT4_COUNT; in niu_xmac_interrupt()
3947 mp->rx_hist_cnt5 += RXMAC_HIST_CNT5_COUNT; in niu_xmac_interrupt()
3949 mp->rx_hist_cnt6 += RXMAC_HIST_CNT6_COUNT; in niu_xmac_interrupt()
3951 mp->rx_hist_cnt7 += RXMAC_HIST_CNT7_COUNT; in niu_xmac_interrupt()
3953 mp->rx_octets += RXMAC_BT_CNT_COUNT; in niu_xmac_interrupt()
3955 mp->rx_code_violations += RXMAC_CD_VIO_CNT_COUNT; in niu_xmac_interrupt()
3957 mp->rx_len_errors += RXMAC_MPSZER_CNT_COUNT; in niu_xmac_interrupt()
3959 mp->rx_crc_errors += RXMAC_CRC_ER_CNT_COUNT; in niu_xmac_interrupt()
3961 mp->rx_underflows++; in niu_xmac_interrupt()
3963 mp->rx_overflows++; in niu_xmac_interrupt()
3967 mp->pause_off_state++; in niu_xmac_interrupt()
3969 mp->pause_on_state++; in niu_xmac_interrupt()
3971 mp->pause_received++; in niu_xmac_interrupt()
3976 struct niu_bmac_stats *mp = &np->mac_stats.bmac; in niu_bmac_interrupt()
3981 mp->tx_underflow_errors++; in niu_bmac_interrupt()
3983 mp->tx_max_pkt_size_errors++; in niu_bmac_interrupt()
3985 mp->tx_bytes += BTXMAC_BYTE_CNT_COUNT; in niu_bmac_interrupt()
3987 mp->tx_frames += BTXMAC_FRM_CNT_COUNT; in niu_bmac_interrupt()
3991 mp->rx_overflows++; in niu_bmac_interrupt()
3993 mp->rx_frames += BRXMAC_FRAME_CNT_COUNT; in niu_bmac_interrupt()
3995 mp->rx_align_errors += BRXMAC_ALIGN_ERR_CNT_COUNT; in niu_bmac_interrupt()
3997 mp->rx_crc_errors += BRXMAC_ALIGN_ERR_CNT_COUNT; in niu_bmac_interrupt()
3999 mp->rx_len_errors += BRXMAC_CODE_VIOL_ERR_CNT_COUNT; in niu_bmac_interrupt()
4003 mp->pause_off_state++; in niu_bmac_interrupt()
4005 mp->pause_on_state++; in niu_bmac_interrupt()
4007 mp->pause_received++; in niu_bmac_interrupt()
4012 if (np->flags & NIU_FLAGS_XMAC) in niu_mac_interrupt()
4022 netdev_err(np->dev, "Core device errors ( "); in niu_log_device_error()
4054 netdev_err(np->dev, "Core device error, stat[%llx]\n", in niu_device_error()
4059 return -ENODEV; in niu_device_error()
4068 lp->v0 = v0; in niu_slowpath_interrupt()
4069 lp->v1 = v1; in niu_slowpath_interrupt()
4070 lp->v2 = v2; in niu_slowpath_interrupt()
4075 for (i = 0; i < np->num_rx_rings; i++) { in niu_slowpath_interrupt()
4076 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_slowpath_interrupt()
4078 if (rx_vec & (1 << rp->rx_channel)) { in niu_slowpath_interrupt()
4084 nw64(RX_DMA_CTL_STAT(rp->rx_channel), in niu_slowpath_interrupt()
4093 for (i = 0; i < np->num_tx_rings; i++) { in niu_slowpath_interrupt()
4094 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_slowpath_interrupt()
4096 if (tx_vec & (1 << rp->tx_channel)) { in niu_slowpath_interrupt()
4130 struct rxdma_mailbox *mbox = rp->mbox; in niu_rxchan_intr()
4131 u64 stat_write, stat = le64_to_cpup(&mbox->rx_dma_ctl_stat); in niu_rxchan_intr()
4135 nw64(RX_DMA_CTL_STAT(rp->rx_channel), stat_write); in niu_rxchan_intr()
4137 netif_printk(np, intr, KERN_DEBUG, np->dev, in niu_rxchan_intr()
4144 rp->tx_cs = nr64(TX_CS(rp->tx_channel)); in niu_txchan_intr()
4146 netif_printk(np, intr, KERN_DEBUG, np->dev, in niu_txchan_intr()
4147 "%s() cs[%llx]\n", __func__, (unsigned long long)rp->tx_cs); in niu_txchan_intr()
4152 struct niu_parent *parent = np->parent; in __niu_fastpath_interrupt()
4159 for (i = 0; i < np->num_rx_rings; i++) { in __niu_fastpath_interrupt()
4160 struct rx_ring_info *rp = &np->rx_rings[i]; in __niu_fastpath_interrupt()
4161 int ldn = LDN_RXDMA(rp->rx_channel); in __niu_fastpath_interrupt()
4163 if (parent->ldg_map[ldn] != ldg) in __niu_fastpath_interrupt()
4167 if (rx_vec & (1 << rp->rx_channel)) in __niu_fastpath_interrupt()
4171 for (i = 0; i < np->num_tx_rings; i++) { in __niu_fastpath_interrupt()
4172 struct tx_ring_info *rp = &np->tx_rings[i]; in __niu_fastpath_interrupt()
4173 int ldn = LDN_TXDMA(rp->tx_channel); in __niu_fastpath_interrupt()
4175 if (parent->ldg_map[ldn] != ldg) in __niu_fastpath_interrupt()
4179 if (tx_vec & (1 << rp->tx_channel)) in __niu_fastpath_interrupt()
4187 if (likely(napi_schedule_prep(&lp->napi))) { in niu_schedule_napi()
4188 lp->v0 = v0; in niu_schedule_napi()
4189 lp->v1 = v1; in niu_schedule_napi()
4190 lp->v2 = v2; in niu_schedule_napi()
4191 __niu_fastpath_interrupt(np, lp->ldg_num, v0); in niu_schedule_napi()
4192 __napi_schedule(&lp->napi); in niu_schedule_napi()
4199 struct niu *np = lp->np; in niu_interrupt()
4200 int ldg = lp->ldg_num; in niu_interrupt()
4208 spin_lock_irqsave(&np->lock, flags); in niu_interrupt()
4221 spin_unlock_irqrestore(&np->lock, flags); in niu_interrupt()
4235 spin_unlock_irqrestore(&np->lock, flags); in niu_interrupt()
4242 if (rp->mbox) { in niu_free_rx_ring_info()
4243 np->ops->free_coherent(np->device, in niu_free_rx_ring_info()
4245 rp->mbox, rp->mbox_dma); in niu_free_rx_ring_info()
4246 rp->mbox = NULL; in niu_free_rx_ring_info()
4248 if (rp->rcr) { in niu_free_rx_ring_info()
4249 np->ops->free_coherent(np->device, in niu_free_rx_ring_info()
4251 rp->rcr, rp->rcr_dma); in niu_free_rx_ring_info()
4252 rp->rcr = NULL; in niu_free_rx_ring_info()
4253 rp->rcr_table_size = 0; in niu_free_rx_ring_info()
4254 rp->rcr_index = 0; in niu_free_rx_ring_info()
4256 if (rp->rbr) { in niu_free_rx_ring_info()
4259 np->ops->free_coherent(np->device, in niu_free_rx_ring_info()
4261 rp->rbr, rp->rbr_dma); in niu_free_rx_ring_info()
4262 rp->rbr = NULL; in niu_free_rx_ring_info()
4263 rp->rbr_table_size = 0; in niu_free_rx_ring_info()
4264 rp->rbr_index = 0; in niu_free_rx_ring_info()
4266 kfree(rp->rxhash); in niu_free_rx_ring_info()
4267 rp->rxhash = NULL; in niu_free_rx_ring_info()
4272 if (rp->mbox) { in niu_free_tx_ring_info()
4273 np->ops->free_coherent(np->device, in niu_free_tx_ring_info()
4275 rp->mbox, rp->mbox_dma); in niu_free_tx_ring_info()
4276 rp->mbox = NULL; in niu_free_tx_ring_info()
4278 if (rp->descr) { in niu_free_tx_ring_info()
4282 if (rp->tx_buffs[i].skb) in niu_free_tx_ring_info()
4286 np->ops->free_coherent(np->device, in niu_free_tx_ring_info()
4288 rp->descr, rp->descr_dma); in niu_free_tx_ring_info()
4289 rp->descr = NULL; in niu_free_tx_ring_info()
4290 rp->pending = 0; in niu_free_tx_ring_info()
4291 rp->prod = 0; in niu_free_tx_ring_info()
4292 rp->cons = 0; in niu_free_tx_ring_info()
4293 rp->wrap_bit = 0; in niu_free_tx_ring_info()
4301 if (np->rx_rings) { in niu_free_channels()
4302 for (i = 0; i < np->num_rx_rings; i++) { in niu_free_channels()
4303 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_free_channels()
4307 kfree(np->rx_rings); in niu_free_channels()
4308 np->rx_rings = NULL; in niu_free_channels()
4309 np->num_rx_rings = 0; in niu_free_channels()
4312 if (np->tx_rings) { in niu_free_channels()
4313 for (i = 0; i < np->num_tx_rings; i++) { in niu_free_channels()
4314 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_free_channels()
4318 kfree(np->tx_rings); in niu_free_channels()
4319 np->tx_rings = NULL; in niu_free_channels()
4320 np->num_tx_rings = 0; in niu_free_channels()
4329 rp->rxhash = kcalloc(MAX_RBR_RING_SIZE, sizeof(struct page *), in niu_alloc_rx_ring_info()
4331 if (!rp->rxhash) in niu_alloc_rx_ring_info()
4332 return -ENOMEM; in niu_alloc_rx_ring_info()
4334 rp->mbox = np->ops->alloc_coherent(np->device, in niu_alloc_rx_ring_info()
4336 &rp->mbox_dma, GFP_KERNEL); in niu_alloc_rx_ring_info()
4337 if (!rp->mbox) in niu_alloc_rx_ring_info()
4338 return -ENOMEM; in niu_alloc_rx_ring_info()
4339 if ((unsigned long)rp->mbox & (64UL - 1)) { in niu_alloc_rx_ring_info()
4340 netdev_err(np->dev, "Coherent alloc gives misaligned RXDMA mailbox %p\n", in niu_alloc_rx_ring_info()
4341 rp->mbox); in niu_alloc_rx_ring_info()
4342 return -EINVAL; in niu_alloc_rx_ring_info()
4345 rp->rcr = np->ops->alloc_coherent(np->device, in niu_alloc_rx_ring_info()
4347 &rp->rcr_dma, GFP_KERNEL); in niu_alloc_rx_ring_info()
4348 if (!rp->rcr) in niu_alloc_rx_ring_info()
4349 return -ENOMEM; in niu_alloc_rx_ring_info()
4350 if ((unsigned long)rp->rcr & (64UL - 1)) { in niu_alloc_rx_ring_info()
4351 netdev_err(np->dev, "Coherent alloc gives misaligned RXDMA RCR table %p\n", in niu_alloc_rx_ring_info()
4352 rp->rcr); in niu_alloc_rx_ring_info()
4353 return -EINVAL; in niu_alloc_rx_ring_info()
4355 rp->rcr_table_size = MAX_RCR_RING_SIZE; in niu_alloc_rx_ring_info()
4356 rp->rcr_index = 0; in niu_alloc_rx_ring_info()
4358 rp->rbr = np->ops->alloc_coherent(np->device, in niu_alloc_rx_ring_info()
4360 &rp->rbr_dma, GFP_KERNEL); in niu_alloc_rx_ring_info()
4361 if (!rp->rbr) in niu_alloc_rx_ring_info()
4362 return -ENOMEM; in niu_alloc_rx_ring_info()
4363 if ((unsigned long)rp->rbr & (64UL - 1)) { in niu_alloc_rx_ring_info()
4364 netdev_err(np->dev, "Coherent alloc gives misaligned RXDMA RBR table %p\n", in niu_alloc_rx_ring_info()
4365 rp->rbr); in niu_alloc_rx_ring_info()
4366 return -EINVAL; in niu_alloc_rx_ring_info()
4368 rp->rbr_table_size = MAX_RBR_RING_SIZE; in niu_alloc_rx_ring_info()
4369 rp->rbr_index = 0; in niu_alloc_rx_ring_info()
4370 rp->rbr_pending = 0; in niu_alloc_rx_ring_info()
4377 int mtu = np->dev->mtu; in niu_set_max_burst()
4382 rp->max_burst = mtu + 32; in niu_set_max_burst()
4383 if (rp->max_burst > 4096) in niu_set_max_burst()
4384 rp->max_burst = 4096; in niu_set_max_burst()
4392 rp->mbox = np->ops->alloc_coherent(np->device, in niu_alloc_tx_ring_info()
4394 &rp->mbox_dma, GFP_KERNEL); in niu_alloc_tx_ring_info()
4395 if (!rp->mbox) in niu_alloc_tx_ring_info()
4396 return -ENOMEM; in niu_alloc_tx_ring_info()
4397 if ((unsigned long)rp->mbox & (64UL - 1)) { in niu_alloc_tx_ring_info()
4398 netdev_err(np->dev, "Coherent alloc gives misaligned TXDMA mailbox %p\n", in niu_alloc_tx_ring_info()
4399 rp->mbox); in niu_alloc_tx_ring_info()
4400 return -EINVAL; in niu_alloc_tx_ring_info()
4403 rp->descr = np->ops->alloc_coherent(np->device, in niu_alloc_tx_ring_info()
4405 &rp->descr_dma, GFP_KERNEL); in niu_alloc_tx_ring_info()
4406 if (!rp->descr) in niu_alloc_tx_ring_info()
4407 return -ENOMEM; in niu_alloc_tx_ring_info()
4408 if ((unsigned long)rp->descr & (64UL - 1)) { in niu_alloc_tx_ring_info()
4409 netdev_err(np->dev, "Coherent alloc gives misaligned TXDMA descr table %p\n", in niu_alloc_tx_ring_info()
4410 rp->descr); in niu_alloc_tx_ring_info()
4411 return -EINVAL; in niu_alloc_tx_ring_info()
4414 rp->pending = MAX_TX_RING_SIZE; in niu_alloc_tx_ring_info()
4415 rp->prod = 0; in niu_alloc_tx_ring_info()
4416 rp->cons = 0; in niu_alloc_tx_ring_info()
4417 rp->wrap_bit = 0; in niu_alloc_tx_ring_info()
4420 rp->mark_freq = rp->pending / 4; in niu_alloc_tx_ring_info()
4433 rp->rbr_block_size = 1 << bss; in niu_size_rbr()
4434 rp->rbr_blocks_per_page = 1 << (PAGE_SHIFT-bss); in niu_size_rbr()
4436 rp->rbr_sizes[0] = 256; in niu_size_rbr()
4437 rp->rbr_sizes[1] = 1024; in niu_size_rbr()
4438 if (np->dev->mtu > ETH_DATA_LEN) { in niu_size_rbr()
4441 rp->rbr_sizes[2] = 4096; in niu_size_rbr()
4445 rp->rbr_sizes[2] = 8192; in niu_size_rbr()
4449 rp->rbr_sizes[2] = 2048; in niu_size_rbr()
4451 rp->rbr_sizes[3] = rp->rbr_block_size; in niu_size_rbr()
4456 struct niu_parent *parent = np->parent; in niu_alloc_channels()
4463 port = np->port; in niu_alloc_channels()
4466 first_rx_channel += parent->rxchan_per_port[i]; in niu_alloc_channels()
4467 first_tx_channel += parent->txchan_per_port[i]; in niu_alloc_channels()
4470 num_rx_rings = parent->rxchan_per_port[port]; in niu_alloc_channels()
4471 num_tx_rings = parent->txchan_per_port[port]; in niu_alloc_channels()
4475 err = -ENOMEM; in niu_alloc_channels()
4479 np->num_rx_rings = num_rx_rings; in niu_alloc_channels()
4481 np->rx_rings = rx_rings; in niu_alloc_channels()
4483 netif_set_real_num_rx_queues(np->dev, num_rx_rings); in niu_alloc_channels()
4485 for (i = 0; i < np->num_rx_rings; i++) { in niu_alloc_channels()
4486 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_alloc_channels()
4488 rp->np = np; in niu_alloc_channels()
4489 rp->rx_channel = first_rx_channel + i; in niu_alloc_channels()
4498 rp->nonsyn_window = 64; in niu_alloc_channels()
4499 rp->nonsyn_threshold = rp->rcr_table_size - 64; in niu_alloc_channels()
4500 rp->syn_window = 64; in niu_alloc_channels()
4501 rp->syn_threshold = rp->rcr_table_size - 64; in niu_alloc_channels()
4502 rp->rcr_pkt_threshold = 16; in niu_alloc_channels()
4503 rp->rcr_timeout = 8; in niu_alloc_channels()
4504 rp->rbr_kick_thresh = RBR_REFILL_MIN; in niu_alloc_channels()
4505 if (rp->rbr_kick_thresh < rp->rbr_blocks_per_page) in niu_alloc_channels()
4506 rp->rbr_kick_thresh = rp->rbr_blocks_per_page; in niu_alloc_channels()
4515 err = -ENOMEM; in niu_alloc_channels()
4519 np->num_tx_rings = num_tx_rings; in niu_alloc_channels()
4521 np->tx_rings = tx_rings; in niu_alloc_channels()
4523 netif_set_real_num_tx_queues(np->dev, num_tx_rings); in niu_alloc_channels()
4525 for (i = 0; i < np->num_tx_rings; i++) { in niu_alloc_channels()
4526 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_alloc_channels()
4528 rp->np = np; in niu_alloc_channels()
4529 rp->tx_channel = first_tx_channel + i; in niu_alloc_channels()
4547 while (--limit > 0) { in niu_tx_cs_sng_poll()
4552 return -ENODEV; in niu_tx_cs_sng_poll()
4569 while (--limit > 0) { in niu_tx_cs_reset_poll()
4574 return -ENODEV; in niu_tx_cs_reset_poll()
4604 val = (u64)np->port << TX_LOG_PAGE_VLD_FUNC_SHIFT; in niu_tx_channel_lpage_init()
4620 mask = (u64)1 << np->port; in niu_txc_enable_port()
4639 val &= ~TXC_INT_MASK_VAL(np->port); in niu_txc_set_imask()
4640 val |= (imask << TXC_INT_MASK_VAL_SHIFT(np->port)); in niu_txc_set_imask()
4651 for (i = 0; i < np->num_tx_rings; i++) in niu_txc_port_dma_enable()
4652 val |= (1 << np->tx_rings[i].tx_channel); in niu_txc_port_dma_enable()
4654 nw64(TXC_PORT_DMA(np->port), val); in niu_txc_port_dma_enable()
4659 int err, channel = rp->tx_channel; in niu_init_one_tx_channel()
4674 nw64(TXC_DMA_MAX(channel), rp->max_burst); in niu_init_one_tx_channel()
4677 if (rp->descr_dma & ~(TX_RNG_CFIG_STADDR_BASE | in niu_init_one_tx_channel()
4679 netdev_err(np->dev, "TX ring channel %d DMA addr (%llx) is not aligned\n", in niu_init_one_tx_channel()
4680 channel, (unsigned long long)rp->descr_dma); in niu_init_one_tx_channel()
4681 return -EINVAL; in niu_init_one_tx_channel()
4684 /* The length field in TX_RNG_CFIG is measured in 64-byte in niu_init_one_tx_channel()
4685 * blocks. rp->pending is the number of TX descriptors in in niu_init_one_tx_channel()
4689 ring_len = (rp->pending / 8); in niu_init_one_tx_channel()
4692 rp->descr_dma); in niu_init_one_tx_channel()
4695 if (((rp->mbox_dma >> 32) & ~TXDMA_MBH_MBADDR) || in niu_init_one_tx_channel()
4696 ((u32)rp->mbox_dma & ~TXDMA_MBL_MBADDR)) { in niu_init_one_tx_channel()
4697 netdev_err(np->dev, "TX ring channel %d MBOX addr (%llx) has invalid bits\n", in niu_init_one_tx_channel()
4698 channel, (unsigned long long)rp->mbox_dma); in niu_init_one_tx_channel()
4699 return -EINVAL; in niu_init_one_tx_channel()
4701 nw64(TXDMA_MBH(channel), rp->mbox_dma >> 32); in niu_init_one_tx_channel()
4702 nw64(TXDMA_MBL(channel), rp->mbox_dma & TXDMA_MBL_MBADDR); in niu_init_one_tx_channel()
4706 rp->last_pkt_cnt = 0; in niu_init_one_tx_channel()
4713 struct niu_rdc_tables *tp = &np->parent->rdc_group_cfg[np->port]; in niu_init_rdc_groups()
4714 int i, first_table_num = tp->first_table_num; in niu_init_rdc_groups()
4716 for (i = 0; i < tp->num_tables; i++) { in niu_init_rdc_groups()
4717 struct rdc_table *tbl = &tp->tables[i]; in niu_init_rdc_groups()
4723 tbl->rxdma_channel[slot]); in niu_init_rdc_groups()
4726 nw64(DEF_RDC(np->port), np->parent->rdc_default[np->port]); in niu_init_rdc_groups()
4731 int type = phy_decode(np->parent->port_phy, np->port); in niu_init_drr_weight()
4744 nw64(PT_DRR_WT(np->port), val); in niu_init_drr_weight()
4749 struct niu_parent *parent = np->parent; in niu_init_hostinfo()
4750 struct niu_rdc_tables *tp = &parent->rdc_group_cfg[np->port]; in niu_init_hostinfo()
4752 int first_rdc_table = tp->first_table_num; in niu_init_hostinfo()
4790 val = (u64)np->port << RX_LOG_PAGE_VLD_FUNC_SHIFT; in niu_rx_channel_lpage_init()
4801 val = (((u64)rp->nonsyn_window << RDC_RED_PARA_WIN_SHIFT) | in niu_rx_channel_wred_init()
4802 ((u64)rp->nonsyn_threshold << RDC_RED_PARA_THRE_SHIFT) | in niu_rx_channel_wred_init()
4803 ((u64)rp->syn_window << RDC_RED_PARA_WIN_SYN_SHIFT) | in niu_rx_channel_wred_init()
4804 ((u64)rp->syn_threshold << RDC_RED_PARA_THRE_SYN_SHIFT)); in niu_rx_channel_wred_init()
4805 nw64(RDC_RED_PARA(rp->rx_channel), val); in niu_rx_channel_wred_init()
4813 switch (rp->rbr_block_size) { in niu_compute_rbr_cfig_b()
4827 return -EINVAL; in niu_compute_rbr_cfig_b()
4830 switch (rp->rbr_sizes[2]) { in niu_compute_rbr_cfig_b()
4845 return -EINVAL; in niu_compute_rbr_cfig_b()
4848 switch (rp->rbr_sizes[1]) { in niu_compute_rbr_cfig_b()
4863 return -EINVAL; in niu_compute_rbr_cfig_b()
4866 switch (rp->rbr_sizes[0]) { in niu_compute_rbr_cfig_b()
4881 return -EINVAL; in niu_compute_rbr_cfig_b()
4900 while (--limit > 0) { in niu_enable_rx_channel()
4906 return -ENODEV; in niu_enable_rx_channel()
4912 int err, channel = rp->rx_channel; in niu_init_one_rx_channel()
4931 nw64(RXDMA_CFIG1(channel), rp->mbox_dma >> 32); in niu_init_one_rx_channel()
4933 ((rp->mbox_dma & RXDMA_CFIG2_MBADDR_L) | in niu_init_one_rx_channel()
4936 ((u64)rp->rbr_table_size << RBR_CFIG_A_LEN_SHIFT) | in niu_init_one_rx_channel()
4937 (rp->rbr_dma & (RBR_CFIG_A_STADDR_BASE | RBR_CFIG_A_STADDR))); in niu_init_one_rx_channel()
4943 ((u64)rp->rcr_table_size << RCRCFIG_A_LEN_SHIFT) | in niu_init_one_rx_channel()
4944 (rp->rcr_dma & (RCRCFIG_A_STADDR_BASE | RCRCFIG_A_STADDR))); in niu_init_one_rx_channel()
4946 ((u64)rp->rcr_pkt_threshold << RCRCFIG_B_PTHRES_SHIFT) | in niu_init_one_rx_channel()
4948 ((u64)rp->rcr_timeout << RCRCFIG_B_TIMEOUT_SHIFT)); in niu_init_one_rx_channel()
4954 nw64(RBR_KICK(channel), rp->rbr_index); in niu_init_one_rx_channel()
4970 nw64(RX_DMA_CK_DIV, np->parent->rxdma_clock_divider); in niu_init_rx_channels()
4983 for (i = 0; i < np->num_rx_rings; i++) { in niu_init_rx_channels()
4984 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_init_rx_channels()
4996 struct niu_parent *parent = np->parent; in niu_set_ip_frag_rule()
4997 struct niu_classifier *cp = &np->clas; in niu_set_ip_frag_rule()
5001 index = cp->tcam_top; in niu_set_ip_frag_rule()
5002 tp = &parent->tcam[index]; in niu_set_ip_frag_rule()
5008 tp->key[1] = TCAM_V4KEY1_NOPORT; in niu_set_ip_frag_rule()
5009 tp->key_mask[1] = TCAM_V4KEY1_NOPORT; in niu_set_ip_frag_rule()
5010 tp->assoc_data = (TCAM_ASSOCDATA_TRES_USE_OFFSET | in niu_set_ip_frag_rule()
5012 err = tcam_write(np, index, tp->key, tp->key_mask); in niu_set_ip_frag_rule()
5015 err = tcam_assoc_write(np, index, tp->assoc_data); in niu_set_ip_frag_rule()
5018 tp->valid = 1; in niu_set_ip_frag_rule()
5019 cp->tcam_valid_entries++; in niu_set_ip_frag_rule()
5026 struct niu_parent *parent = np->parent; in niu_init_classifier_hw()
5027 struct niu_classifier *cp = &np->clas; in niu_init_classifier_hw()
5030 nw64(H1POLY, cp->h1_init); in niu_init_classifier_hw()
5031 nw64(H2POLY, cp->h2_init); in niu_init_classifier_hw()
5038 struct niu_vlan_rdc *vp = &cp->vlan_mappings[i]; in niu_init_classifier_hw()
5040 vlan_tbl_write(np, i, np->port, in niu_init_classifier_hw()
5041 vp->vlan_pref, vp->rdc_num); in niu_init_classifier_hw()
5044 for (i = 0; i < cp->num_alt_mac_mappings; i++) { in niu_init_classifier_hw()
5045 struct niu_altmac_rdc *ap = &cp->alt_mac_mappings[i]; in niu_init_classifier_hw()
5047 err = niu_set_alt_mac_rdc_table(np, ap->alt_mac_num, in niu_init_classifier_hw()
5048 ap->rdc_num, ap->mac_pref); in niu_init_classifier_hw()
5054 int index = i - CLASS_CODE_USER_PROG1; in niu_init_classifier_hw()
5056 err = niu_set_tcam_key(np, i, parent->tcam_key[index]); in niu_init_classifier_hw()
5059 err = niu_set_flow_key(np, i, parent->flow_key[index]); in niu_init_classifier_hw()
5084 (ZCP_RAM_SEL_CFIFO(np->port) << ZCP_RAM_ACC_RAM_SEL_SHIFT))); in niu_zcp_write()
5097 netdev_err(np->dev, "ZCP read busy won't clear, ZCP_RAM_ACC[%llx]\n", in niu_zcp_read()
5105 (ZCP_RAM_SEL_CFIFO(np->port) << ZCP_RAM_ACC_RAM_SEL_SHIFT))); in niu_zcp_read()
5110 netdev_err(np->dev, "ZCP read busy2 won't clear, ZCP_RAM_ACC[%llx]\n", in niu_zcp_read()
5128 val |= RESET_CFIFO_RST(np->port); in niu_zcp_cfifo_reset()
5132 val &= ~RESET_CFIFO_RST(np->port); in niu_zcp_cfifo_reset()
5141 if (np->parent->plat_type != PLAT_TYPE_NIU) { in niu_init_zcp()
5142 if (np->port == 0 || np->port == 1) in niu_init_zcp()
5165 nw64(CFIFO_ECC(np->port), 0); in niu_init_zcp()
5208 if (np->parent->plat_type != PLAT_TYPE_NIU) { in niu_init_ipp()
5209 if (np->port == 0 || np->port == 1) in niu_init_ipp()
5259 if ((np->flags & NIU_FLAGS_10G) != 0 && in niu_handle_led()
5260 (np->flags & NIU_FLAGS_FIBER) != 0) { in niu_handle_led()
5275 struct niu_link_config *lp = &np->link_config; in niu_init_xif_xmac()
5278 if (np->flags & NIU_FLAGS_XCVR_SERDES) { in niu_init_xif_xmac()
5289 if (lp->loopback_mode == LOOPBACK_MAC) { in niu_init_xif_xmac()
5296 if (np->flags & NIU_FLAGS_10G) { in niu_init_xif_xmac()
5300 if (!(np->flags & NIU_FLAGS_FIBER) && in niu_init_xif_xmac()
5301 !(np->flags & NIU_FLAGS_XCVR_SERDES)) in niu_init_xif_xmac()
5309 if (lp->active_speed == SPEED_100) in niu_init_xif_xmac()
5318 if (np->flags & NIU_FLAGS_10G) { in niu_init_xif_xmac()
5321 if (lp->active_speed == SPEED_1000) in niu_init_xif_xmac()
5332 struct niu_link_config *lp = &np->link_config; in niu_init_xif_bmac()
5337 if (lp->loopback_mode == LOOPBACK_MAC) in niu_init_xif_bmac()
5342 if (lp->active_speed == SPEED_1000) in niu_init_xif_bmac()
5350 if (!(np->flags & NIU_FLAGS_10G) && in niu_init_xif_bmac()
5351 !(np->flags & NIU_FLAGS_FIBER) && in niu_init_xif_bmac()
5352 lp->active_speed == SPEED_100) in niu_init_xif_bmac()
5362 if (np->flags & NIU_FLAGS_XMAC) in niu_init_xif()
5374 while ((--limit >= 0) && (val & PCS_MII_CTL_RST)) { in niu_pcs_mii_reset()
5386 while ((--limit >= 0) && (val & XPCS_CONTROL1_RESET)) { in niu_xpcs_reset()
5394 struct niu_link_config *lp = &np->link_config; in niu_init_pcs()
5397 switch (np->flags & (NIU_FLAGS_10G | in niu_init_pcs()
5411 if (!(np->flags & NIU_FLAGS_XMAC)) in niu_init_pcs()
5412 return -EINVAL; in niu_init_pcs()
5422 if (lp->loopback_mode == LOOPBACK_PHY) in niu_init_pcs()
5450 return -EINVAL; in niu_init_pcs()
5470 while (--limit >= 0) { in niu_reset_tx_bmac()
5476 dev_err(np->device, "Port %u TX BMAC would not reset, BTXMAC_SW_RST[%llx]\n", in niu_reset_tx_bmac()
5477 np->port, in niu_reset_tx_bmac()
5479 return -ENODEV; in niu_reset_tx_bmac()
5487 if (np->flags & NIU_FLAGS_XMAC) in niu_reset_tx_mac()
5509 if (np->flags & NIU_FLAGS_10G) { in niu_init_tx_xmac()
5551 if (np->dev->mtu > ETH_DATA_LEN) in niu_init_tx_mac()
5561 if (np->flags & NIU_FLAGS_XMAC) in niu_init_tx_mac()
5574 while (--limit >= 0) { in niu_reset_rx_xmac()
5581 dev_err(np->device, "Port %u RX XMAC would not reset, XRXMAC_SW_RST[%llx]\n", in niu_reset_rx_xmac()
5582 np->port, in niu_reset_rx_xmac()
5584 return -ENODEV; in niu_reset_rx_xmac()
5596 while (--limit >= 0) { in niu_reset_rx_bmac()
5602 dev_err(np->device, "Port %u RX BMAC would not reset, BRXMAC_SW_RST[%llx]\n", in niu_reset_rx_bmac()
5603 np->port, in niu_reset_rx_bmac()
5605 return -ENODEV; in niu_reset_rx_bmac()
5613 if (np->flags & NIU_FLAGS_XMAC) in niu_reset_rx_mac()
5621 struct niu_parent *parent = np->parent; in niu_init_rx_xmac()
5622 struct niu_rdc_tables *tp = &parent->rdc_group_cfg[np->port]; in niu_init_rx_xmac()
5623 int first_rdc_table = tp->first_table_num; in niu_init_rx_xmac()
5673 struct niu_parent *parent = np->parent; in niu_init_rx_bmac()
5674 struct niu_rdc_tables *tp = &parent->rdc_group_cfg[np->port]; in niu_init_rx_bmac()
5675 int first_rdc_table = tp->first_table_num; in niu_init_rx_bmac()
5708 niu_set_primary_mac(np, np->dev->dev_addr); in niu_init_rx_mac()
5710 if (np->flags & NIU_FLAGS_XMAC) in niu_init_rx_mac()
5740 if (np->flags & NIU_FLAGS_XMAC) in niu_enable_tx_mac()
5753 if (np->flags & NIU_FLAGS_MCAST) in niu_enable_rx_xmac()
5755 if (np->flags & NIU_FLAGS_PROMISC) in niu_enable_rx_xmac()
5772 if (np->flags & NIU_FLAGS_MCAST) in niu_enable_rx_bmac()
5774 if (np->flags & NIU_FLAGS_PROMISC) in niu_enable_rx_bmac()
5786 if (np->flags & NIU_FLAGS_XMAC) in niu_enable_rx_mac()
5825 (void) niu_tx_channel_stop(np, rp->tx_channel); in niu_stop_one_tx_channel()
5832 for (i = 0; i < np->num_tx_rings; i++) { in niu_stop_tx_channels()
5833 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_stop_tx_channels()
5841 (void) niu_tx_channel_reset(np, rp->tx_channel); in niu_reset_one_tx_channel()
5848 for (i = 0; i < np->num_tx_rings; i++) { in niu_reset_tx_channels()
5849 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_reset_tx_channels()
5857 (void) niu_enable_rx_channel(np, rp->rx_channel, 0); in niu_stop_one_rx_channel()
5864 for (i = 0; i < np->num_rx_rings; i++) { in niu_stop_rx_channels()
5865 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_stop_rx_channels()
5873 int channel = rp->rx_channel; in niu_reset_one_rx_channel()
5885 for (i = 0; i < np->num_rx_rings; i++) { in niu_reset_rx_channels()
5886 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_reset_rx_channels()
5900 while (--limit >= 0 && (rd != wr)) { in niu_disable_ipp()
5906 netdev_err(np->dev, "IPP would not quiesce, rd_ptr[%llx] wr_ptr[%llx]\n", in niu_disable_ipp()
5925 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize TXC\n"); in niu_init_hw()
5930 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize TX channels\n"); in niu_init_hw()
5931 for (i = 0; i < np->num_tx_rings; i++) { in niu_init_hw()
5932 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_init_hw()
5939 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize RX channels\n"); in niu_init_hw()
5944 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize classifier\n"); in niu_init_hw()
5949 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize ZCP\n"); in niu_init_hw()
5954 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize IPP\n"); in niu_init_hw()
5959 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize MAC\n"); in niu_init_hw()
5967 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Uninit IPP\n"); in niu_init_hw()
5971 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Uninit RX channels\n"); in niu_init_hw()
5976 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Uninit TX channels\n"); in niu_init_hw()
5985 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Disable interrupts\n"); in niu_stop_hw()
5988 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Disable RX MAC\n"); in niu_stop_hw()
5991 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Disable IPP\n"); in niu_stop_hw()
5994 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Stop TX channels\n"); in niu_stop_hw()
5997 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Stop RX channels\n"); in niu_stop_hw()
6000 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Reset TX channels\n"); in niu_stop_hw()
6003 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Reset RX channels\n"); in niu_stop_hw()
6009 int port = np->port; in niu_set_irq_name()
6012 sprintf(np->irq_name[0], "%s:MAC", np->dev->name); in niu_set_irq_name()
6015 sprintf(np->irq_name[1], "%s:MIF", np->dev->name); in niu_set_irq_name()
6016 sprintf(np->irq_name[2], "%s:SYSERR", np->dev->name); in niu_set_irq_name()
6020 for (i = 0; i < np->num_ldg - j; i++) { in niu_set_irq_name()
6021 if (i < np->num_rx_rings) in niu_set_irq_name()
6022 sprintf(np->irq_name[i+j], "%s-rx-%d", in niu_set_irq_name()
6023 np->dev->name, i); in niu_set_irq_name()
6024 else if (i < np->num_tx_rings + np->num_rx_rings) in niu_set_irq_name()
6025 sprintf(np->irq_name[i+j], "%s-tx-%d", np->dev->name, in niu_set_irq_name()
6026 i - np->num_rx_rings); in niu_set_irq_name()
6037 for (i = 0; i < np->num_ldg; i++) { in niu_request_irq()
6038 struct niu_ldg *lp = &np->ldg[i]; in niu_request_irq()
6040 err = request_irq(lp->irq, niu_interrupt, IRQF_SHARED, in niu_request_irq()
6041 np->irq_name[i], lp); in niu_request_irq()
6051 struct niu_ldg *lp = &np->ldg[j]; in niu_request_irq()
6053 free_irq(lp->irq, lp); in niu_request_irq()
6062 for (i = 0; i < np->num_ldg; i++) { in niu_free_irq()
6063 struct niu_ldg *lp = &np->ldg[i]; in niu_free_irq()
6065 free_irq(lp->irq, lp); in niu_free_irq()
6073 for (i = 0; i < np->num_ldg; i++) in niu_enable_napi()
6074 napi_enable(&np->ldg[i].napi); in niu_enable_napi()
6081 for (i = 0; i < np->num_ldg; i++) in niu_disable_napi()
6082 napi_disable(&np->ldg[i].napi); in niu_disable_napi()
6106 spin_lock_irq(&np->lock); in niu_open()
6110 timer_setup(&np->timer, niu_timer, 0); in niu_open()
6111 np->timer.expires = jiffies + HZ; in niu_open()
6118 spin_unlock_irq(&np->lock); in niu_open()
6127 if (np->link_config.loopback_mode != LOOPBACK_DISABLED) in niu_open()
6130 add_timer(&np->timer); in niu_open()
6146 cancel_work_sync(&np->reset_task); in niu_full_shutdown()
6151 del_timer_sync(&np->timer); in niu_full_shutdown()
6153 spin_lock_irq(&np->lock); in niu_full_shutdown()
6157 spin_unlock_irq(&np->lock); in niu_full_shutdown()
6177 struct niu_xmac_stats *mp = &np->mac_stats.xmac; in niu_sync_xmac_stats()
6179 mp->tx_frames += nr64_mac(TXMAC_FRM_CNT); in niu_sync_xmac_stats()
6180 mp->tx_bytes += nr64_mac(TXMAC_BYTE_CNT); in niu_sync_xmac_stats()
6182 mp->rx_link_faults += nr64_mac(LINK_FAULT_CNT); in niu_sync_xmac_stats()
6183 mp->rx_align_errors += nr64_mac(RXMAC_ALIGN_ERR_CNT); in niu_sync_xmac_stats()
6184 mp->rx_frags += nr64_mac(RXMAC_FRAG_CNT); in niu_sync_xmac_stats()
6185 mp->rx_mcasts += nr64_mac(RXMAC_MC_FRM_CNT); in niu_sync_xmac_stats()
6186 mp->rx_bcasts += nr64_mac(RXMAC_BC_FRM_CNT); in niu_sync_xmac_stats()
6187 mp->rx_hist_cnt1 += nr64_mac(RXMAC_HIST_CNT1); in niu_sync_xmac_stats()
6188 mp->rx_hist_cnt2 += nr64_mac(RXMAC_HIST_CNT2); in niu_sync_xmac_stats()
6189 mp->rx_hist_cnt3 += nr64_mac(RXMAC_HIST_CNT3); in niu_sync_xmac_stats()
6190 mp->rx_hist_cnt4 += nr64_mac(RXMAC_HIST_CNT4); in niu_sync_xmac_stats()
6191 mp->rx_hist_cnt5 += nr64_mac(RXMAC_HIST_CNT5); in niu_sync_xmac_stats()
6192 mp->rx_hist_cnt6 += nr64_mac(RXMAC_HIST_CNT6); in niu_sync_xmac_stats()
6193 mp->rx_hist_cnt7 += nr64_mac(RXMAC_HIST_CNT7); in niu_sync_xmac_stats()
6194 mp->rx_octets += nr64_mac(RXMAC_BT_CNT); in niu_sync_xmac_stats()
6195 mp->rx_code_violations += nr64_mac(RXMAC_CD_VIO_CNT); in niu_sync_xmac_stats()
6196 mp->rx_len_errors += nr64_mac(RXMAC_MPSZER_CNT); in niu_sync_xmac_stats()
6197 mp->rx_crc_errors += nr64_mac(RXMAC_CRC_ER_CNT); in niu_sync_xmac_stats()
6202 struct niu_bmac_stats *mp = &np->mac_stats.bmac; in niu_sync_bmac_stats()
6204 mp->tx_bytes += nr64_mac(BTXMAC_BYTE_CNT); in niu_sync_bmac_stats()
6205 mp->tx_frames += nr64_mac(BTXMAC_FRM_CNT); in niu_sync_bmac_stats()
6207 mp->rx_frames += nr64_mac(BRXMAC_FRAME_CNT); in niu_sync_bmac_stats()
6208 mp->rx_align_errors += nr64_mac(BRXMAC_ALIGN_ERR_CNT); in niu_sync_bmac_stats()
6209 mp->rx_crc_errors += nr64_mac(BRXMAC_ALIGN_ERR_CNT); in niu_sync_bmac_stats()
6210 mp->rx_len_errors += nr64_mac(BRXMAC_CODE_VIOL_ERR_CNT); in niu_sync_bmac_stats()
6215 if (np->flags & NIU_FLAGS_XMAC) in niu_sync_mac_stats()
6230 rx_rings = READ_ONCE(np->rx_rings); in niu_get_rx_stats()
6234 for (i = 0; i < np->num_rx_rings; i++) { in niu_get_rx_stats()
6239 pkts += rp->rx_packets; in niu_get_rx_stats()
6240 bytes += rp->rx_bytes; in niu_get_rx_stats()
6241 dropped += rp->rx_dropped; in niu_get_rx_stats()
6242 errors += rp->rx_errors; in niu_get_rx_stats()
6246 stats->rx_packets = pkts; in niu_get_rx_stats()
6247 stats->rx_bytes = bytes; in niu_get_rx_stats()
6248 stats->rx_dropped = dropped; in niu_get_rx_stats()
6249 stats->rx_errors = errors; in niu_get_rx_stats()
6261 tx_rings = READ_ONCE(np->tx_rings); in niu_get_tx_stats()
6265 for (i = 0; i < np->num_tx_rings; i++) { in niu_get_tx_stats()
6268 pkts += rp->tx_packets; in niu_get_tx_stats()
6269 bytes += rp->tx_bytes; in niu_get_tx_stats()
6270 errors += rp->tx_errors; in niu_get_tx_stats()
6274 stats->tx_packets = pkts; in niu_get_tx_stats()
6275 stats->tx_bytes = bytes; in niu_get_tx_stats()
6276 stats->tx_errors = errors; in niu_get_tx_stats()
6308 if (np->flags & NIU_FLAGS_XMAC) in niu_load_hash()
6322 spin_lock_irqsave(&np->lock, flags); in niu_set_rx_mode()
6325 np->flags &= ~(NIU_FLAGS_MCAST | NIU_FLAGS_PROMISC); in niu_set_rx_mode()
6326 if (dev->flags & IFF_PROMISC) in niu_set_rx_mode()
6327 np->flags |= NIU_FLAGS_PROMISC; in niu_set_rx_mode()
6328 if ((dev->flags & IFF_ALLMULTI) || (!netdev_mc_empty(dev))) in niu_set_rx_mode()
6329 np->flags |= NIU_FLAGS_MCAST; in niu_set_rx_mode()
6334 np->flags |= NIU_FLAGS_PROMISC; in niu_set_rx_mode()
6341 err = niu_set_alt_mac(np, index, ha->addr); in niu_set_rx_mode()
6354 if (np->flags & NIU_FLAGS_XMAC) in niu_set_rx_mode()
6365 if (dev->flags & IFF_ALLMULTI) { in niu_set_rx_mode()
6370 u32 crc = ether_crc_le(ETH_ALEN, ha->addr); in niu_set_rx_mode()
6373 hash[crc >> 4] |= (1 << (15 - (crc & 0xf))); in niu_set_rx_mode()
6377 if (np->flags & NIU_FLAGS_MCAST) in niu_set_rx_mode()
6381 spin_unlock_irqrestore(&np->lock, flags); in niu_set_rx_mode()
6390 if (!is_valid_ether_addr(addr->sa_data)) in niu_set_mac_addr()
6391 return -EADDRNOTAVAIL; in niu_set_mac_addr()
6393 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); in niu_set_mac_addr()
6398 spin_lock_irqsave(&np->lock, flags); in niu_set_mac_addr()
6400 niu_set_primary_mac(np, dev->dev_addr); in niu_set_mac_addr()
6402 spin_unlock_irqrestore(&np->lock, flags); in niu_set_mac_addr()
6409 return -EOPNOTSUPP; in niu_ioctl()
6414 netif_trans_update(np->dev); /* prevent tx timeout */ in niu_netif_stop()
6418 netif_tx_disable(np->dev); in niu_netif_stop()
6427 netif_tx_wake_all_queues(np->dev); in niu_netif_start()
6438 if (np->rx_rings) { in niu_reset_buffers()
6439 for (i = 0; i < np->num_rx_rings; i++) { in niu_reset_buffers()
6440 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_reset_buffers()
6445 page = rp->rxhash[j]; in niu_reset_buffers()
6448 (struct page *) page->mapping; in niu_reset_buffers()
6449 u64 base = page->index; in niu_reset_buffers()
6451 rp->rbr[k++] = cpu_to_le32(base); in niu_reset_buffers()
6461 rp->rbr_index = rp->rbr_table_size - 1; in niu_reset_buffers()
6462 rp->rcr_index = 0; in niu_reset_buffers()
6463 rp->rbr_pending = 0; in niu_reset_buffers()
6464 rp->rbr_refill_pending = 0; in niu_reset_buffers()
6467 if (np->tx_rings) { in niu_reset_buffers()
6468 for (i = 0; i < np->num_tx_rings; i++) { in niu_reset_buffers()
6469 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_reset_buffers()
6472 if (rp->tx_buffs[j].skb) in niu_reset_buffers()
6476 rp->pending = MAX_TX_RING_SIZE; in niu_reset_buffers()
6477 rp->prod = 0; in niu_reset_buffers()
6478 rp->cons = 0; in niu_reset_buffers()
6479 rp->wrap_bit = 0; in niu_reset_buffers()
6490 spin_lock_irqsave(&np->lock, flags); in niu_reset_task()
6491 if (!netif_running(np->dev)) { in niu_reset_task()
6492 spin_unlock_irqrestore(&np->lock, flags); in niu_reset_task()
6496 spin_unlock_irqrestore(&np->lock, flags); in niu_reset_task()
6498 del_timer_sync(&np->timer); in niu_reset_task()
6502 spin_lock_irqsave(&np->lock, flags); in niu_reset_task()
6506 spin_unlock_irqrestore(&np->lock, flags); in niu_reset_task()
6510 spin_lock_irqsave(&np->lock, flags); in niu_reset_task()
6514 np->timer.expires = jiffies + HZ; in niu_reset_task()
6515 add_timer(&np->timer); in niu_reset_task()
6519 spin_unlock_irqrestore(&np->lock, flags); in niu_reset_task()
6526 dev_err(np->device, "%s: Transmit timed out, resetting\n", in niu_tx_timeout()
6527 dev->name); in niu_tx_timeout()
6529 schedule_work(&np->reset_task); in niu_tx_timeout()
6536 __le64 *desc = &rp->descr[index]; in niu_set_txd()
6552 eth_proto = be16_to_cpu(ehdr->h_proto); in niu_compute_tx_flags()
6556 __be16 val = vp->h_vlan_encapsulated_proto; in niu_compute_tx_flags()
6562 switch (skb->protocol) { in niu_compute_tx_flags()
6564 ip_proto = ip_hdr(skb)->protocol; in niu_compute_tx_flags()
6565 ihl = ip_hdr(skb)->ihl; in niu_compute_tx_flags()
6568 ip_proto = ipv6_hdr(skb)->nexthdr; in niu_compute_tx_flags()
6578 if (skb->ip_summed == CHECKSUM_PARTIAL) { in niu_compute_tx_flags()
6586 start = skb_checksum_start_offset(skb) - in niu_compute_tx_flags()
6588 stuff = start + skb->csum_offset; in niu_compute_tx_flags()
6594 l3off = skb_network_offset(skb) - in niu_compute_tx_flags()
6623 rp = &np->tx_rings[i]; in niu_start_xmit()
6626 if (niu_tx_avail(rp) <= (skb_shinfo(skb)->nr_frags + 1)) { in niu_start_xmit()
6628 dev_err(np->device, "%s: BUG! Tx ring full when queue awake!\n", dev->name); in niu_start_xmit()
6629 rp->tx_errors++; in niu_start_xmit()
6648 align = ((unsigned long) skb->data & (16 - 1)); in niu_start_xmit()
6651 ehdr = (struct ethhdr *) skb->data; in niu_start_xmit()
6654 len = skb->len - sizeof(struct tx_pkt_hdr); in niu_start_xmit()
6655 tp->flags = cpu_to_le64(niu_compute_tx_flags(skb, ehdr, align, len)); in niu_start_xmit()
6656 tp->resv = 0; in niu_start_xmit()
6659 mapping = np->ops->map_single(np->device, skb->data, in niu_start_xmit()
6662 prod = rp->prod; in niu_start_xmit()
6664 rp->tx_buffs[prod].skb = skb; in niu_start_xmit()
6665 rp->tx_buffs[prod].mapping = mapping; in niu_start_xmit()
6668 if (++rp->mark_counter == rp->mark_freq) { in niu_start_xmit()
6669 rp->mark_counter = 0; in niu_start_xmit()
6671 rp->mark_pending++; in niu_start_xmit()
6675 nfg = skb_shinfo(skb)->nr_frags; in niu_start_xmit()
6677 tlen -= MAX_TX_DESC_LEN; in niu_start_xmit()
6692 len -= this_len; in niu_start_xmit()
6695 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in niu_start_xmit()
6696 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; in niu_start_xmit()
6699 mapping = np->ops->map_page(np->device, skb_frag_page(frag), in niu_start_xmit()
6700 frag->page_offset, len, in niu_start_xmit()
6703 rp->tx_buffs[prod].skb = NULL; in niu_start_xmit()
6704 rp->tx_buffs[prod].mapping = mapping; in niu_start_xmit()
6711 if (prod < rp->prod) in niu_start_xmit()
6712 rp->wrap_bit ^= TX_RING_KICK_WRAP; in niu_start_xmit()
6713 rp->prod = prod; in niu_start_xmit()
6715 nw64(TX_RING_KICK(rp->tx_channel), rp->wrap_bit | (prod << 3)); in niu_start_xmit()
6727 rp->tx_errors++; in niu_start_xmit()
6737 orig_jumbo = (dev->mtu > ETH_DATA_LEN); in niu_change_mtu()
6740 dev->mtu = new_mtu; in niu_change_mtu()
6756 spin_lock_irq(&np->lock); in niu_change_mtu()
6760 timer_setup(&np->timer, niu_timer, 0); in niu_change_mtu()
6761 np->timer.expires = jiffies + HZ; in niu_change_mtu()
6768 spin_unlock_irq(&np->lock); in niu_change_mtu()
6772 if (np->link_config.loopback_mode != LOOPBACK_DISABLED) in niu_change_mtu()
6775 add_timer(&np->timer); in niu_change_mtu()
6785 struct niu_vpd *vpd = &np->vpd; in niu_get_drvinfo()
6787 strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); in niu_get_drvinfo()
6788 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); in niu_get_drvinfo()
6789 snprintf(info->fw_version, sizeof(info->fw_version), "%d.%d", in niu_get_drvinfo()
6790 vpd->fcode_major, vpd->fcode_minor); in niu_get_drvinfo()
6791 if (np->parent->plat_type != PLAT_TYPE_NIU) in niu_get_drvinfo()
6792 strlcpy(info->bus_info, pci_name(np->pdev), in niu_get_drvinfo()
6793 sizeof(info->bus_info)); in niu_get_drvinfo()
6802 lp = &np->link_config; in niu_get_link_ksettings()
6805 cmd->base.phy_address = np->phy_addr; in niu_get_link_ksettings()
6806 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, in niu_get_link_ksettings()
6807 lp->supported); in niu_get_link_ksettings()
6808 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, in niu_get_link_ksettings()
6809 lp->active_advertising); in niu_get_link_ksettings()
6810 cmd->base.autoneg = lp->active_autoneg; in niu_get_link_ksettings()
6811 cmd->base.speed = lp->active_speed; in niu_get_link_ksettings()
6812 cmd->base.duplex = lp->active_duplex; in niu_get_link_ksettings()
6813 cmd->base.port = (np->flags & NIU_FLAGS_FIBER) ? PORT_FIBRE : PORT_TP; in niu_get_link_ksettings()
6822 struct niu_link_config *lp = &np->link_config; in niu_set_link_ksettings()
6824 ethtool_convert_link_mode_to_legacy_u32(&lp->advertising, in niu_set_link_ksettings()
6825 cmd->link_modes.advertising); in niu_set_link_ksettings()
6826 lp->speed = cmd->base.speed; in niu_set_link_ksettings()
6827 lp->duplex = cmd->base.duplex; in niu_set_link_ksettings()
6828 lp->autoneg = cmd->base.autoneg; in niu_set_link_ksettings()
6835 return np->msg_enable; in niu_get_msglevel()
6841 np->msg_enable = value; in niu_set_msglevel()
6848 if (np->link_config.autoneg) in niu_nway_reset()
6858 return np->eeprom_len; in niu_get_eeprom_len()
6867 offset = eeprom->offset; in niu_get_eeprom()
6868 len = eeprom->len; in niu_get_eeprom()
6871 return -EINVAL; in niu_get_eeprom()
6872 if (offset >= np->eeprom_len) in niu_get_eeprom()
6873 return -EINVAL; in niu_get_eeprom()
6874 if (offset + len > np->eeprom_len) in niu_get_eeprom()
6875 len = eeprom->len = np->eeprom_len - offset; in niu_get_eeprom()
6881 b_count = 4 - b_offset; in niu_get_eeprom()
6885 val = nr64(ESPC_NCR((offset - b_offset) / 4)); in niu_get_eeprom()
6888 len -= b_count; in niu_get_eeprom()
6895 len -= 4; in niu_get_eeprom()
6968 return -EINVAL; in niu_class_to_ethflow()
7064 nfc->data = 0; in niu_get_hash_opts()
7066 if (!niu_ethflow_to_class(nfc->flow_type, &class)) in niu_get_hash_opts()
7067 return -EINVAL; in niu_get_hash_opts()
7069 if (np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] & in niu_get_hash_opts()
7071 nfc->data = RXH_DISCARD; in niu_get_hash_opts()
7073 nfc->data = niu_flowkey_to_ethflow(np->parent->flow_key[class - in niu_get_hash_opts()
7084 tmp = (tp->key[3] & TCAM_V4KEY3_SADDR) >> TCAM_V4KEY3_SADDR_SHIFT; in niu_get_ip4fs_from_tcam_key()
7085 fsp->h_u.tcp_ip4_spec.ip4src = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7087 tmp = (tp->key[3] & TCAM_V4KEY3_DADDR) >> TCAM_V4KEY3_DADDR_SHIFT; in niu_get_ip4fs_from_tcam_key()
7088 fsp->h_u.tcp_ip4_spec.ip4dst = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7090 tmp = (tp->key_mask[3] & TCAM_V4KEY3_SADDR) >> TCAM_V4KEY3_SADDR_SHIFT; in niu_get_ip4fs_from_tcam_key()
7091 fsp->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7093 tmp = (tp->key_mask[3] & TCAM_V4KEY3_DADDR) >> TCAM_V4KEY3_DADDR_SHIFT; in niu_get_ip4fs_from_tcam_key()
7094 fsp->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7096 fsp->h_u.tcp_ip4_spec.tos = (tp->key[2] & TCAM_V4KEY2_TOS) >> in niu_get_ip4fs_from_tcam_key()
7098 fsp->m_u.tcp_ip4_spec.tos = (tp->key_mask[2] & TCAM_V4KEY2_TOS) >> in niu_get_ip4fs_from_tcam_key()
7101 switch (fsp->flow_type) { in niu_get_ip4fs_from_tcam_key()
7105 prt = ((tp->key[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7107 fsp->h_u.tcp_ip4_spec.psrc = cpu_to_be16(prt); in niu_get_ip4fs_from_tcam_key()
7109 prt = ((tp->key[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7111 fsp->h_u.tcp_ip4_spec.pdst = cpu_to_be16(prt); in niu_get_ip4fs_from_tcam_key()
7113 prt = ((tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7115 fsp->m_u.tcp_ip4_spec.psrc = cpu_to_be16(prt); in niu_get_ip4fs_from_tcam_key()
7117 prt = ((tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7119 fsp->m_u.tcp_ip4_spec.pdst = cpu_to_be16(prt); in niu_get_ip4fs_from_tcam_key()
7123 tmp = (tp->key[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7125 fsp->h_u.ah_ip4_spec.spi = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7127 tmp = (tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7129 fsp->m_u.ah_ip4_spec.spi = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7132 tmp = (tp->key[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7134 fsp->h_u.usr_ip4_spec.l4_4_bytes = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7136 tmp = (tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7138 fsp->m_u.usr_ip4_spec.l4_4_bytes = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7140 fsp->h_u.usr_ip4_spec.proto = in niu_get_ip4fs_from_tcam_key()
7141 (tp->key[2] & TCAM_V4KEY2_PROTO) >> in niu_get_ip4fs_from_tcam_key()
7143 fsp->m_u.usr_ip4_spec.proto = in niu_get_ip4fs_from_tcam_key()
7144 (tp->key_mask[2] & TCAM_V4KEY2_PROTO) >> in niu_get_ip4fs_from_tcam_key()
7147 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; in niu_get_ip4fs_from_tcam_key()
7157 struct niu_parent *parent = np->parent; in niu_get_ethtool_tcam_entry()
7159 struct ethtool_rx_flow_spec *fsp = &nfc->fs; in niu_get_ethtool_tcam_entry()
7164 idx = tcam_get_index(np, (u16)nfc->fs.location); in niu_get_ethtool_tcam_entry()
7166 tp = &parent->tcam[idx]; in niu_get_ethtool_tcam_entry()
7167 if (!tp->valid) { in niu_get_ethtool_tcam_entry()
7168 netdev_info(np->dev, "niu%d: entry [%d] invalid for idx[%d]\n", in niu_get_ethtool_tcam_entry()
7169 parent->index, (u16)nfc->fs.location, idx); in niu_get_ethtool_tcam_entry()
7170 return -EINVAL; in niu_get_ethtool_tcam_entry()
7174 class = (tp->key[0] & TCAM_V4KEY0_CLASS_CODE) >> in niu_get_ethtool_tcam_entry()
7176 ret = niu_class_to_ethflow(class, &fsp->flow_type); in niu_get_ethtool_tcam_entry()
7178 netdev_info(np->dev, "niu%d: niu_class_to_ethflow failed\n", in niu_get_ethtool_tcam_entry()
7179 parent->index); in niu_get_ethtool_tcam_entry()
7183 if (fsp->flow_type == AH_V4_FLOW || fsp->flow_type == AH_V6_FLOW) { in niu_get_ethtool_tcam_entry()
7184 u32 proto = (tp->key[2] & TCAM_V4KEY2_PROTO) >> in niu_get_ethtool_tcam_entry()
7187 if (fsp->flow_type == AH_V4_FLOW) in niu_get_ethtool_tcam_entry()
7188 fsp->flow_type = ESP_V4_FLOW; in niu_get_ethtool_tcam_entry()
7190 fsp->flow_type = ESP_V6_FLOW; in niu_get_ethtool_tcam_entry()
7194 switch (fsp->flow_type) { in niu_get_ethtool_tcam_entry()
7208 ret = -EINVAL; in niu_get_ethtool_tcam_entry()
7214 ret = -EINVAL; in niu_get_ethtool_tcam_entry()
7221 if (tp->assoc_data & TCAM_ASSOCDATA_DISC) in niu_get_ethtool_tcam_entry()
7222 fsp->ring_cookie = RX_CLS_FLOW_DISC; in niu_get_ethtool_tcam_entry()
7224 fsp->ring_cookie = (tp->assoc_data & TCAM_ASSOCDATA_OFFSET) >> in niu_get_ethtool_tcam_entry()
7228 nfc->data = tcam_get_size(np); in niu_get_ethtool_tcam_entry()
7237 struct niu_parent *parent = np->parent; in niu_get_ethtool_tcam_all()
7244 nfc->data = tcam_get_size(np); in niu_get_ethtool_tcam_all()
7247 for (cnt = 0, i = 0; i < nfc->data; i++) { in niu_get_ethtool_tcam_all()
7249 tp = &parent->tcam[idx]; in niu_get_ethtool_tcam_all()
7250 if (!tp->valid) in niu_get_ethtool_tcam_all()
7252 if (cnt == nfc->rule_cnt) { in niu_get_ethtool_tcam_all()
7253 ret = -EMSGSIZE; in niu_get_ethtool_tcam_all()
7261 nfc->rule_cnt = cnt; in niu_get_ethtool_tcam_all()
7272 switch (cmd->cmd) { in niu_get_nfc()
7277 cmd->data = np->num_rx_rings; in niu_get_nfc()
7280 cmd->rule_cnt = tcam_get_valid_entry_cnt(np); in niu_get_nfc()
7289 ret = -EINVAL; in niu_get_nfc()
7302 if (!niu_ethflow_to_class(nfc->flow_type, &class)) in niu_set_hash_opts()
7303 return -EINVAL; in niu_set_hash_opts()
7307 return -EINVAL; in niu_set_hash_opts()
7309 if (nfc->data & RXH_DISCARD) { in niu_set_hash_opts()
7311 flow_key = np->parent->tcam_key[class - in niu_set_hash_opts()
7314 nw64(TCAM_KEY(class - CLASS_CODE_USER_PROG1), flow_key); in niu_set_hash_opts()
7315 np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] = flow_key; in niu_set_hash_opts()
7320 if (np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] & in niu_set_hash_opts()
7323 flow_key = np->parent->tcam_key[class - in niu_set_hash_opts()
7326 nw64(TCAM_KEY(class - CLASS_CODE_USER_PROG1), in niu_set_hash_opts()
7328 np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] = in niu_set_hash_opts()
7334 if (!niu_ethflow_to_flowkey(nfc->data, &flow_key)) in niu_set_hash_opts()
7335 return -EINVAL; in niu_set_hash_opts()
7338 nw64(FLOW_KEY(class - CLASS_CODE_USER_PROG1), flow_key); in niu_set_hash_opts()
7339 np->parent->flow_key[class - CLASS_CODE_USER_PROG1] = flow_key; in niu_set_hash_opts()
7353 sip = be32_to_cpu(fsp->h_u.tcp_ip4_spec.ip4src); in niu_get_tcamkey_from_ip4fs()
7354 sipm = be32_to_cpu(fsp->m_u.tcp_ip4_spec.ip4src); in niu_get_tcamkey_from_ip4fs()
7355 dip = be32_to_cpu(fsp->h_u.tcp_ip4_spec.ip4dst); in niu_get_tcamkey_from_ip4fs()
7356 dipm = be32_to_cpu(fsp->m_u.tcp_ip4_spec.ip4dst); in niu_get_tcamkey_from_ip4fs()
7358 tp->key[0] = class << TCAM_V4KEY0_CLASS_CODE_SHIFT; in niu_get_tcamkey_from_ip4fs()
7359 tp->key_mask[0] = TCAM_V4KEY0_CLASS_CODE; in niu_get_tcamkey_from_ip4fs()
7360 tp->key[1] = (u64)l2_rdc_tab << TCAM_V4KEY1_L2RDCNUM_SHIFT; in niu_get_tcamkey_from_ip4fs()
7361 tp->key_mask[1] = TCAM_V4KEY1_L2RDCNUM; in niu_get_tcamkey_from_ip4fs()
7363 tp->key[3] = (u64)sip << TCAM_V4KEY3_SADDR_SHIFT; in niu_get_tcamkey_from_ip4fs()
7364 tp->key[3] |= dip; in niu_get_tcamkey_from_ip4fs()
7366 tp->key_mask[3] = (u64)sipm << TCAM_V4KEY3_SADDR_SHIFT; in niu_get_tcamkey_from_ip4fs()
7367 tp->key_mask[3] |= dipm; in niu_get_tcamkey_from_ip4fs()
7369 tp->key[2] |= ((u64)fsp->h_u.tcp_ip4_spec.tos << in niu_get_tcamkey_from_ip4fs()
7371 tp->key_mask[2] |= ((u64)fsp->m_u.tcp_ip4_spec.tos << in niu_get_tcamkey_from_ip4fs()
7373 switch (fsp->flow_type) { in niu_get_tcamkey_from_ip4fs()
7377 sport = be16_to_cpu(fsp->h_u.tcp_ip4_spec.psrc); in niu_get_tcamkey_from_ip4fs()
7378 spm = be16_to_cpu(fsp->m_u.tcp_ip4_spec.psrc); in niu_get_tcamkey_from_ip4fs()
7379 dport = be16_to_cpu(fsp->h_u.tcp_ip4_spec.pdst); in niu_get_tcamkey_from_ip4fs()
7380 dpm = be16_to_cpu(fsp->m_u.tcp_ip4_spec.pdst); in niu_get_tcamkey_from_ip4fs()
7382 tp->key[2] |= (((u64)sport << 16) | dport); in niu_get_tcamkey_from_ip4fs()
7383 tp->key_mask[2] |= (((u64)spm << 16) | dpm); in niu_get_tcamkey_from_ip4fs()
7384 niu_ethflow_to_l3proto(fsp->flow_type, &pid); in niu_get_tcamkey_from_ip4fs()
7388 spi = be32_to_cpu(fsp->h_u.ah_ip4_spec.spi); in niu_get_tcamkey_from_ip4fs()
7389 spim = be32_to_cpu(fsp->m_u.ah_ip4_spec.spi); in niu_get_tcamkey_from_ip4fs()
7391 tp->key[2] |= spi; in niu_get_tcamkey_from_ip4fs()
7392 tp->key_mask[2] |= spim; in niu_get_tcamkey_from_ip4fs()
7393 niu_ethflow_to_l3proto(fsp->flow_type, &pid); in niu_get_tcamkey_from_ip4fs()
7396 spi = be32_to_cpu(fsp->h_u.usr_ip4_spec.l4_4_bytes); in niu_get_tcamkey_from_ip4fs()
7397 spim = be32_to_cpu(fsp->m_u.usr_ip4_spec.l4_4_bytes); in niu_get_tcamkey_from_ip4fs()
7399 tp->key[2] |= spi; in niu_get_tcamkey_from_ip4fs()
7400 tp->key_mask[2] |= spim; in niu_get_tcamkey_from_ip4fs()
7401 pid = fsp->h_u.usr_ip4_spec.proto; in niu_get_tcamkey_from_ip4fs()
7407 tp->key[2] |= ((u64)pid << TCAM_V4KEY2_PROTO_SHIFT); in niu_get_tcamkey_from_ip4fs()
7409 tp->key_mask[2] |= TCAM_V4KEY2_PROTO; in niu_get_tcamkey_from_ip4fs()
7416 struct niu_parent *parent = np->parent; in niu_add_ethtool_tcam_entry()
7418 struct ethtool_rx_flow_spec *fsp = &nfc->fs; in niu_add_ethtool_tcam_entry()
7419 struct niu_rdc_tables *rdc_table = &parent->rdc_group_cfg[np->port]; in niu_add_ethtool_tcam_entry()
7420 int l2_rdc_table = rdc_table->first_table_num; in niu_add_ethtool_tcam_entry()
7428 idx = nfc->fs.location; in niu_add_ethtool_tcam_entry()
7430 return -EINVAL; in niu_add_ethtool_tcam_entry()
7432 if (fsp->flow_type == IP_USER_FLOW) { in niu_add_ethtool_tcam_entry()
7435 struct ethtool_usrip4_spec *uspec = &fsp->h_u.usr_ip4_spec; in niu_add_ethtool_tcam_entry()
7436 struct ethtool_usrip4_spec *umask = &fsp->m_u.usr_ip4_spec; in niu_add_ethtool_tcam_entry()
7438 if (uspec->ip_ver != ETH_RX_NFC_IP4) in niu_add_ethtool_tcam_entry()
7439 return -EINVAL; in niu_add_ethtool_tcam_entry()
7444 if (parent->l3_cls[i]) { in niu_add_ethtool_tcam_entry()
7445 if (uspec->proto == parent->l3_cls_pid[i]) { in niu_add_ethtool_tcam_entry()
7446 class = parent->l3_cls[i]; in niu_add_ethtool_tcam_entry()
7447 parent->l3_cls_refcnt[i]++; in niu_add_ethtool_tcam_entry()
7470 uspec->proto, in niu_add_ethtool_tcam_entry()
7471 uspec->tos, in niu_add_ethtool_tcam_entry()
7472 umask->tos); in niu_add_ethtool_tcam_entry()
7479 parent->l3_cls[i] = class; in niu_add_ethtool_tcam_entry()
7480 parent->l3_cls_pid[i] = uspec->proto; in niu_add_ethtool_tcam_entry()
7481 parent->l3_cls_refcnt[i]++; in niu_add_ethtool_tcam_entry()
7487 netdev_info(np->dev, "niu%d: %s(): Could not find/insert class for pid %d\n", in niu_add_ethtool_tcam_entry()
7488 parent->index, __func__, uspec->proto); in niu_add_ethtool_tcam_entry()
7489 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7494 if (!niu_ethflow_to_class(fsp->flow_type, &class)) { in niu_add_ethtool_tcam_entry()
7495 return -EINVAL; in niu_add_ethtool_tcam_entry()
7502 tp = &parent->tcam[idx]; in niu_add_ethtool_tcam_entry()
7507 switch (fsp->flow_type) { in niu_add_ethtool_tcam_entry()
7521 netdev_info(np->dev, "niu%d: In %s(): flow %d for IPv6 not implemented\n", in niu_add_ethtool_tcam_entry()
7522 parent->index, __func__, fsp->flow_type); in niu_add_ethtool_tcam_entry()
7523 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7529 netdev_info(np->dev, "niu%d: In %s(): Unknown flow type %d\n", in niu_add_ethtool_tcam_entry()
7530 parent->index, __func__, fsp->flow_type); in niu_add_ethtool_tcam_entry()
7531 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7536 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) { in niu_add_ethtool_tcam_entry()
7537 tp->assoc_data = TCAM_ASSOCDATA_DISC; in niu_add_ethtool_tcam_entry()
7539 if (fsp->ring_cookie >= np->num_rx_rings) { in niu_add_ethtool_tcam_entry()
7540 netdev_info(np->dev, "niu%d: In %s(): Invalid RX ring %lld\n", in niu_add_ethtool_tcam_entry()
7541 parent->index, __func__, in niu_add_ethtool_tcam_entry()
7542 (long long)fsp->ring_cookie); in niu_add_ethtool_tcam_entry()
7543 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7546 tp->assoc_data = (TCAM_ASSOCDATA_TRES_USE_OFFSET | in niu_add_ethtool_tcam_entry()
7547 (fsp->ring_cookie << in niu_add_ethtool_tcam_entry()
7551 err = tcam_write(np, idx, tp->key, tp->key_mask); in niu_add_ethtool_tcam_entry()
7553 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7556 err = tcam_assoc_write(np, idx, tp->assoc_data); in niu_add_ethtool_tcam_entry()
7558 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7563 tp->valid = 1; in niu_add_ethtool_tcam_entry()
7564 np->clas.tcam_valid_entries++; in niu_add_ethtool_tcam_entry()
7573 struct niu_parent *parent = np->parent; in niu_del_ethtool_tcam_entry()
7581 return -EINVAL; in niu_del_ethtool_tcam_entry()
7586 tp = &parent->tcam[idx]; in niu_del_ethtool_tcam_entry()
7589 class = (tp->key[0] & TCAM_V4KEY0_CLASS_CODE) >> in niu_del_ethtool_tcam_entry()
7595 if (parent->l3_cls[i] == class) { in niu_del_ethtool_tcam_entry()
7596 parent->l3_cls_refcnt[i]--; in niu_del_ethtool_tcam_entry()
7597 if (!parent->l3_cls_refcnt[i]) { in niu_del_ethtool_tcam_entry()
7604 parent->l3_cls[i] = 0; in niu_del_ethtool_tcam_entry()
7605 parent->l3_cls_pid[i] = 0; in niu_del_ethtool_tcam_entry()
7611 netdev_info(np->dev, "niu%d: In %s(): Usr class 0x%llx not found\n", in niu_del_ethtool_tcam_entry()
7612 parent->index, __func__, in niu_del_ethtool_tcam_entry()
7614 ret = -EINVAL; in niu_del_ethtool_tcam_entry()
7624 tp->valid = 0; in niu_del_ethtool_tcam_entry()
7625 np->clas.tcam_valid_entries--; in niu_del_ethtool_tcam_entry()
7637 switch (cmd->cmd) { in niu_set_nfc()
7645 ret = niu_del_ethtool_tcam_entry(np, cmd->fs.location); in niu_set_nfc()
7648 ret = -EINVAL; in niu_set_nfc()
7741 if (np->flags & NIU_FLAGS_XMAC) { in niu_get_strings()
7750 for (i = 0; i < np->num_rx_rings; i++) { in niu_get_strings()
7755 for (i = 0; i < np->num_tx_rings; i++) { in niu_get_strings()
7767 return -EINVAL; in niu_get_sset_count()
7769 return (np->flags & NIU_FLAGS_XMAC ? in niu_get_sset_count()
7772 (np->num_rx_rings * NUM_RXCHAN_STAT_KEYS) + in niu_get_sset_count()
7773 (np->num_tx_rings * NUM_TXCHAN_STAT_KEYS); in niu_get_sset_count()
7783 if (np->flags & NIU_FLAGS_XMAC) { in niu_get_ethtool_stats()
7784 memcpy(data, &np->mac_stats.xmac, in niu_get_ethtool_stats()
7788 memcpy(data, &np->mac_stats.bmac, in niu_get_ethtool_stats()
7792 for (i = 0; i < np->num_rx_rings; i++) { in niu_get_ethtool_stats()
7793 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_get_ethtool_stats()
7797 data[0] = rp->rx_channel; in niu_get_ethtool_stats()
7798 data[1] = rp->rx_packets; in niu_get_ethtool_stats()
7799 data[2] = rp->rx_bytes; in niu_get_ethtool_stats()
7800 data[3] = rp->rx_dropped; in niu_get_ethtool_stats()
7801 data[4] = rp->rx_errors; in niu_get_ethtool_stats()
7804 for (i = 0; i < np->num_tx_rings; i++) { in niu_get_ethtool_stats()
7805 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_get_ethtool_stats()
7807 data[0] = rp->tx_channel; in niu_get_ethtool_stats()
7808 data[1] = rp->tx_packets; in niu_get_ethtool_stats()
7809 data[2] = rp->tx_bytes; in niu_get_ethtool_stats()
7810 data[3] = rp->tx_errors; in niu_get_ethtool_stats()
7817 if (np->flags & NIU_FLAGS_XMAC) in niu_led_state_save()
7825 if (np->flags & NIU_FLAGS_XMAC) in niu_led_state_restore()
7835 if (np->flags & NIU_FLAGS_XMAC) { in niu_force_led()
7858 return -EAGAIN; in niu_set_phys_id()
7862 np->orig_led_state = niu_led_state_save(np); in niu_set_phys_id()
7874 niu_led_state_restore(np, np->orig_led_state); in niu_set_phys_id()
7902 return -EINVAL; in niu_ldg_assign_ldn()
7904 return -EINVAL; in niu_ldg_assign_ldn()
7906 parent->ldg_map[ldn] = ldg; in niu_ldg_assign_ldn()
7908 if (np->parent->plat_type == PLAT_TYPE_NIU) { in niu_ldg_assign_ldn()
7909 /* On N2 NIU, the ldn-->ldg assignments are setup and fixed by in niu_ldg_assign_ldn()
7915 dev_err(np->device, "Port %u, mis-matched LDG assignment for ldn %d, should be %d is %llu\n", in niu_ldg_assign_ldn()
7916 np->port, ldn, ldg, in niu_ldg_assign_ldn()
7918 return -EINVAL; in niu_ldg_assign_ldn()
7929 return -EINVAL; in niu_set_ldg_timer_res()
7942 return -EINVAL; in niu_set_ldg_sid()
7956 return -EINVAL; in niu_pci_eeprom_read()
7966 } while (limit--); in niu_pci_eeprom_read()
7968 dev_err(np->device, "EEPROM read timeout frame[%llx]\n", in niu_pci_eeprom_read()
7970 return -ENODEV; in niu_pci_eeprom_read()
7981 } while (limit--); in niu_pci_eeprom_read()
7983 dev_err(np->device, "EEPROM read timeout frame[%llx]\n", in niu_pci_eeprom_read()
7985 return -ENODEV; in niu_pci_eeprom_read()
8040 return -EINVAL; in niu_pci_vpd_get_propname()
8047 struct niu_vpd *vpd = &np->vpd; in niu_vpd_parse_version()
8048 int len = strlen(vpd->version) + 1; in niu_vpd_parse_version()
8049 const char *s = vpd->version; in niu_vpd_parse_version()
8052 for (i = 0; i < len - 5; i++) { in niu_vpd_parse_version()
8056 if (i >= len - 5) in niu_vpd_parse_version()
8060 sscanf(s, "%d.%d", &vpd->fcode_major, &vpd->fcode_minor); in niu_vpd_parse_version()
8062 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_vpd_parse_version()
8064 vpd->fcode_major, vpd->fcode_minor); in niu_vpd_parse_version()
8065 if (vpd->fcode_major > NIU_VPD_MIN_MAJOR || in niu_vpd_parse_version()
8066 (vpd->fcode_major == NIU_VPD_MIN_MAJOR && in niu_vpd_parse_version()
8067 vpd->fcode_minor >= NIU_VPD_MIN_MINOR)) in niu_vpd_parse_version()
8068 np->flags |= NIU_FLAGS_VPD_VALID; in niu_vpd_parse_version()
8083 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_vpd_scan_props()
8112 prop_buf = np->vpd.model; in niu_pci_vpd_scan_props()
8115 } else if (!strcmp(namebuf, "board-model")) { in niu_pci_vpd_scan_props()
8116 prop_buf = np->vpd.board_model; in niu_pci_vpd_scan_props()
8120 prop_buf = np->vpd.version; in niu_pci_vpd_scan_props()
8123 } else if (!strcmp(namebuf, "local-mac-address")) { in niu_pci_vpd_scan_props()
8124 prop_buf = np->vpd.local_mac; in niu_pci_vpd_scan_props()
8127 } else if (!strcmp(namebuf, "num-mac-addresses")) { in niu_pci_vpd_scan_props()
8128 prop_buf = &np->vpd.mac_num; in niu_pci_vpd_scan_props()
8131 } else if (!strcmp(namebuf, "phy-type")) { in niu_pci_vpd_scan_props()
8132 prop_buf = np->vpd.phy_type; in niu_pci_vpd_scan_props()
8138 dev_err(np->device, "Property '%s' length (%d) is too long\n", namebuf, prop_len); in niu_pci_vpd_scan_props()
8139 return -EINVAL; in niu_pci_vpd_scan_props()
8146 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_vpd_scan_props()
8257 /* 1G copper, MII */ in niu_phy_type_prop_decode()
8258 np->flags &= ~(NIU_FLAGS_FIBER | in niu_phy_type_prop_decode()
8260 np->mac_xcvr = MAC_XCVR_MII; in niu_phy_type_prop_decode()
8263 np->flags |= (NIU_FLAGS_10G | in niu_phy_type_prop_decode()
8265 np->mac_xcvr = MAC_XCVR_XPCS; in niu_phy_type_prop_decode()
8268 np->flags &= ~NIU_FLAGS_10G; in niu_phy_type_prop_decode()
8269 np->flags |= NIU_FLAGS_FIBER; in niu_phy_type_prop_decode()
8270 np->mac_xcvr = MAC_XCVR_PCS; in niu_phy_type_prop_decode()
8273 np->flags |= NIU_FLAGS_10G; in niu_phy_type_prop_decode()
8274 np->flags &= ~NIU_FLAGS_FIBER; in niu_phy_type_prop_decode()
8275 np->mac_xcvr = MAC_XCVR_XPCS; in niu_phy_type_prop_decode()
8278 np->flags |= NIU_FLAGS_10G; in niu_phy_type_prop_decode()
8279 np->flags &= ~NIU_FLAGS_FIBER; in niu_phy_type_prop_decode()
8280 np->flags |= NIU_FLAGS_XCVR_SERDES; in niu_phy_type_prop_decode()
8281 np->mac_xcvr = MAC_XCVR_XPCS; in niu_phy_type_prop_decode()
8283 return -EINVAL; in niu_phy_type_prop_decode()
8292 if ((!strcmp(np->vpd.model, NIU_QGC_LP_MDL_STR)) || in niu_pci_vpd_get_nports()
8293 (!strcmp(np->vpd.model, NIU_QGC_PEM_MDL_STR)) || in niu_pci_vpd_get_nports()
8294 (!strcmp(np->vpd.model, NIU_MARAMBA_MDL_STR)) || in niu_pci_vpd_get_nports()
8295 (!strcmp(np->vpd.model, NIU_KIMI_MDL_STR)) || in niu_pci_vpd_get_nports()
8296 (!strcmp(np->vpd.model, NIU_ALONSO_MDL_STR))) { in niu_pci_vpd_get_nports()
8298 } else if ((!strcmp(np->vpd.model, NIU_2XGF_LP_MDL_STR)) || in niu_pci_vpd_get_nports()
8299 (!strcmp(np->vpd.model, NIU_2XGF_PEM_MDL_STR)) || in niu_pci_vpd_get_nports()
8300 (!strcmp(np->vpd.model, NIU_FOXXY_MDL_STR)) || in niu_pci_vpd_get_nports()
8301 (!strcmp(np->vpd.model, NIU_2XGF_MRVL_MDL_STR))) { in niu_pci_vpd_get_nports()
8310 struct net_device *dev = np->dev; in niu_pci_vpd_validate()
8311 struct niu_vpd *vpd = &np->vpd; in niu_pci_vpd_validate()
8314 if (!is_valid_ether_addr(&vpd->local_mac[0])) { in niu_pci_vpd_validate()
8315 dev_err(np->device, "VPD MAC invalid, falling back to SPROM\n"); in niu_pci_vpd_validate()
8317 np->flags &= ~NIU_FLAGS_VPD_VALID; in niu_pci_vpd_validate()
8321 if (!strcmp(np->vpd.model, NIU_ALONSO_MDL_STR) || in niu_pci_vpd_validate()
8322 !strcmp(np->vpd.model, NIU_KIMI_MDL_STR)) { in niu_pci_vpd_validate()
8323 np->flags |= NIU_FLAGS_10G; in niu_pci_vpd_validate()
8324 np->flags &= ~NIU_FLAGS_FIBER; in niu_pci_vpd_validate()
8325 np->flags |= NIU_FLAGS_XCVR_SERDES; in niu_pci_vpd_validate()
8326 np->mac_xcvr = MAC_XCVR_PCS; in niu_pci_vpd_validate()
8327 if (np->port > 1) { in niu_pci_vpd_validate()
8328 np->flags |= NIU_FLAGS_FIBER; in niu_pci_vpd_validate()
8329 np->flags &= ~NIU_FLAGS_10G; in niu_pci_vpd_validate()
8331 if (np->flags & NIU_FLAGS_10G) in niu_pci_vpd_validate()
8332 np->mac_xcvr = MAC_XCVR_XPCS; in niu_pci_vpd_validate()
8333 } else if (!strcmp(np->vpd.model, NIU_FOXXY_MDL_STR)) { in niu_pci_vpd_validate()
8334 np->flags |= (NIU_FLAGS_10G | NIU_FLAGS_FIBER | in niu_pci_vpd_validate()
8336 } else if (niu_phy_type_prop_decode(np, np->vpd.phy_type)) { in niu_pci_vpd_validate()
8337 dev_err(np->device, "Illegal phy string [%s]\n", in niu_pci_vpd_validate()
8338 np->vpd.phy_type); in niu_pci_vpd_validate()
8339 dev_err(np->device, "Falling back to SPROM\n"); in niu_pci_vpd_validate()
8340 np->flags &= ~NIU_FLAGS_VPD_VALID; in niu_pci_vpd_validate()
8344 memcpy(dev->dev_addr, vpd->local_mac, ETH_ALEN); in niu_pci_vpd_validate()
8346 val8 = dev->dev_addr[5]; in niu_pci_vpd_validate()
8347 dev->dev_addr[5] += np->port; in niu_pci_vpd_validate()
8348 if (dev->dev_addr[5] < val8) in niu_pci_vpd_validate()
8349 dev->dev_addr[4]++; in niu_pci_vpd_validate()
8354 struct net_device *dev = np->dev; in niu_pci_probe_sprom()
8363 np->eeprom_len = len; in niu_pci_probe_sprom()
8365 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8376 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8379 dev_err(np->device, "Bad SPROM checksum (%x, should be 0xab)\n", (int)(sum & 0xff)); in niu_pci_probe_sprom()
8380 return -EINVAL; in niu_pci_probe_sprom()
8384 switch (np->port) { in niu_pci_probe_sprom()
8402 dev_err(np->device, "Bogus port number %u\n", in niu_pci_probe_sprom()
8403 np->port); in niu_pci_probe_sprom()
8404 return -EINVAL; in niu_pci_probe_sprom()
8406 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8411 /* 1G copper, MII */ in niu_pci_probe_sprom()
8412 np->flags &= ~(NIU_FLAGS_FIBER | in niu_pci_probe_sprom()
8414 np->mac_xcvr = MAC_XCVR_MII; in niu_pci_probe_sprom()
8419 np->flags &= ~NIU_FLAGS_10G; in niu_pci_probe_sprom()
8420 np->flags |= NIU_FLAGS_FIBER; in niu_pci_probe_sprom()
8421 np->mac_xcvr = MAC_XCVR_PCS; in niu_pci_probe_sprom()
8426 np->flags |= NIU_FLAGS_10G; in niu_pci_probe_sprom()
8427 np->flags &= ~NIU_FLAGS_FIBER; in niu_pci_probe_sprom()
8428 np->mac_xcvr = MAC_XCVR_XPCS; in niu_pci_probe_sprom()
8433 np->flags |= (NIU_FLAGS_10G | in niu_pci_probe_sprom()
8435 np->mac_xcvr = MAC_XCVR_XPCS; in niu_pci_probe_sprom()
8439 dev_err(np->device, "Bogus SPROM phy type %u\n", val8); in niu_pci_probe_sprom()
8440 return -EINVAL; in niu_pci_probe_sprom()
8444 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8446 dev->dev_addr[0] = (val >> 0) & 0xff; in niu_pci_probe_sprom()
8447 dev->dev_addr[1] = (val >> 8) & 0xff; in niu_pci_probe_sprom()
8448 dev->dev_addr[2] = (val >> 16) & 0xff; in niu_pci_probe_sprom()
8449 dev->dev_addr[3] = (val >> 24) & 0xff; in niu_pci_probe_sprom()
8452 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8454 dev->dev_addr[4] = (val >> 0) & 0xff; in niu_pci_probe_sprom()
8455 dev->dev_addr[5] = (val >> 8) & 0xff; in niu_pci_probe_sprom()
8457 if (!is_valid_ether_addr(&dev->dev_addr[0])) { in niu_pci_probe_sprom()
8458 dev_err(np->device, "SPROM MAC address invalid [ %pM ]\n", in niu_pci_probe_sprom()
8459 dev->dev_addr); in niu_pci_probe_sprom()
8460 return -EINVAL; in niu_pci_probe_sprom()
8463 val8 = dev->dev_addr[5]; in niu_pci_probe_sprom()
8464 dev->dev_addr[5] += np->port; in niu_pci_probe_sprom()
8465 if (dev->dev_addr[5] < val8) in niu_pci_probe_sprom()
8466 dev->dev_addr[4]++; in niu_pci_probe_sprom()
8469 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8472 return -EINVAL; in niu_pci_probe_sprom()
8477 np->vpd.model[i + 3] = (tmp >> 0) & 0xff; in niu_pci_probe_sprom()
8478 np->vpd.model[i + 2] = (tmp >> 8) & 0xff; in niu_pci_probe_sprom()
8479 np->vpd.model[i + 1] = (tmp >> 16) & 0xff; in niu_pci_probe_sprom()
8480 np->vpd.model[i + 0] = (tmp >> 24) & 0xff; in niu_pci_probe_sprom()
8482 np->vpd.model[val] = '\0'; in niu_pci_probe_sprom()
8485 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8488 return -EINVAL; in niu_pci_probe_sprom()
8493 np->vpd.board_model[i + 3] = (tmp >> 0) & 0xff; in niu_pci_probe_sprom()
8494 np->vpd.board_model[i + 2] = (tmp >> 8) & 0xff; in niu_pci_probe_sprom()
8495 np->vpd.board_model[i + 1] = (tmp >> 16) & 0xff; in niu_pci_probe_sprom()
8496 np->vpd.board_model[i + 0] = (tmp >> 24) & 0xff; in niu_pci_probe_sprom()
8498 np->vpd.board_model[val] = '\0'; in niu_pci_probe_sprom()
8500 np->vpd.mac_num = in niu_pci_probe_sprom()
8502 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8503 "SPROM: NUM_PORTS_MACS[%d]\n", np->vpd.mac_num); in niu_pci_probe_sprom()
8510 struct niu_parent *parent = np->parent; in niu_get_and_validate_port()
8512 if (np->port <= 1) in niu_get_and_validate_port()
8513 np->flags |= NIU_FLAGS_XMAC; in niu_get_and_validate_port()
8515 if (!parent->num_ports) { in niu_get_and_validate_port()
8516 if (parent->plat_type == PLAT_TYPE_NIU) { in niu_get_and_validate_port()
8517 parent->num_ports = 2; in niu_get_and_validate_port()
8519 parent->num_ports = niu_pci_vpd_get_nports(np); in niu_get_and_validate_port()
8520 if (!parent->num_ports) { in niu_get_and_validate_port()
8524 parent->num_ports = nr64(ESPC_NUM_PORTS_MACS) & in niu_get_and_validate_port()
8528 * Maramba on-board parts. in niu_get_and_validate_port()
8530 if (!parent->num_ports) in niu_get_and_validate_port()
8531 parent->num_ports = 4; in niu_get_and_validate_port()
8536 if (np->port >= parent->num_ports) in niu_get_and_validate_port()
8537 return -ENODEV; in niu_get_and_validate_port()
8563 parent->index, id, in phy_record()
8565 type == PHY_TYPE_PCS ? "PCS" : "MII", in phy_record()
8568 if (p->cur[type] >= NIU_MAX_PORTS) { in phy_record()
8570 return -EINVAL; in phy_record()
8572 idx = p->cur[type]; in phy_record()
8573 p->phy_id[type][idx] = id; in phy_record()
8574 p->phy_port[type][idx] = phy_port; in phy_record()
8575 p->cur[type] = idx + 1; in phy_record()
8583 for (i = 0; i < p->cur[PHY_TYPE_PMA_PMD]; i++) { in port_has_10g()
8584 if (p->phy_port[PHY_TYPE_PMA_PMD][i] == port) in port_has_10g()
8587 for (i = 0; i < p->cur[PHY_TYPE_PCS]; i++) { in port_has_10g()
8588 if (p->phy_port[PHY_TYPE_PCS][i] == port) in port_has_10g()
8615 if (p->cur[PHY_TYPE_MII]) in count_1g_ports()
8616 *lowest = p->phy_port[PHY_TYPE_MII][0]; in count_1g_ports()
8618 return p->cur[PHY_TYPE_MII]; in count_1g_ports()
8623 int num_ports = parent->num_ports; in niu_n2_divide_channels()
8627 parent->rxchan_per_port[i] = (16 / num_ports); in niu_n2_divide_channels()
8628 parent->txchan_per_port[i] = (16 / num_ports); in niu_n2_divide_channels()
8631 parent->index, i, in niu_n2_divide_channels()
8632 parent->rxchan_per_port[i], in niu_n2_divide_channels()
8633 parent->txchan_per_port[i]); in niu_n2_divide_channels()
8640 int num_ports = parent->num_ports; in niu_divide_channels()
8652 rx_chans_per_10g = (NIU_NUM_RXCHAN - in niu_divide_channels()
8657 tx_chans_per_10g = (NIU_NUM_TXCHAN - in niu_divide_channels()
8664 int type = phy_decode(parent->port_phy, i); in niu_divide_channels()
8667 parent->rxchan_per_port[i] = rx_chans_per_10g; in niu_divide_channels()
8668 parent->txchan_per_port[i] = tx_chans_per_10g; in niu_divide_channels()
8670 parent->rxchan_per_port[i] = rx_chans_per_1g; in niu_divide_channels()
8671 parent->txchan_per_port[i] = tx_chans_per_1g; in niu_divide_channels()
8674 parent->index, i, in niu_divide_channels()
8675 parent->rxchan_per_port[i], in niu_divide_channels()
8676 parent->txchan_per_port[i]); in niu_divide_channels()
8677 tot_rx += parent->rxchan_per_port[i]; in niu_divide_channels()
8678 tot_tx += parent->txchan_per_port[i]; in niu_divide_channels()
8683 parent->index, tot_rx); in niu_divide_channels()
8685 parent->rxchan_per_port[i] = 1; in niu_divide_channels()
8689 parent->index, tot_tx); in niu_divide_channels()
8691 parent->txchan_per_port[i] = 1; in niu_divide_channels()
8695 parent->index, tot_rx, tot_tx); in niu_divide_channels()
8702 int i, num_ports = parent->num_ports; in niu_divide_rdc_groups()
8712 struct niu_rdc_tables *tp = &parent->rdc_group_cfg[i]; in niu_divide_rdc_groups()
8713 int grp, num_channels = parent->rxchan_per_port[i]; in niu_divide_rdc_groups()
8716 tp->first_table_num = rdc_group; in niu_divide_rdc_groups()
8717 tp->num_tables = rdc_groups_per_port; in niu_divide_rdc_groups()
8719 for (grp = 0; grp < tp->num_tables; grp++) { in niu_divide_rdc_groups()
8720 struct rdc_table *rt = &tp->tables[grp]; in niu_divide_rdc_groups() local
8724 parent->index, i, tp->first_table_num + grp); in niu_divide_rdc_groups()
8726 rt->rxdma_channel[slot] = in niu_divide_rdc_groups()
8729 pr_cont("%d ", rt->rxdma_channel[slot]); in niu_divide_rdc_groups()
8737 parent->rdc_default[i] = rdc_channel_base; in niu_divide_rdc_groups()
8788 struct phy_probe_info *info = &parent->phy_probe_info; in walk_phys()
8796 if (!strcmp(np->vpd.model, NIU_ALONSO_MDL_STR) || in walk_phys()
8797 !strcmp(np->vpd.model, NIU_KIMI_MDL_STR)) { in walk_phys()
8800 parent->plat_type = PLAT_TYPE_ATCA_CP3220; in walk_phys()
8801 parent->num_ports = 4; in walk_phys()
8806 } else if (!strcmp(np->vpd.model, NIU_FOXXY_MDL_STR)) { in walk_phys()
8809 parent->num_ports = 2; in walk_phys()
8812 } else if ((np->flags & NIU_FLAGS_XCVR_SERDES) && in walk_phys()
8813 (parent->plat_type == PLAT_TYPE_NIU)) { in walk_phys()
8815 if (np->flags & NIU_FLAGS_10G) { in walk_phys()
8833 parent->plat_type = PLAT_TYPE_VF_P0; in walk_phys()
8835 parent->plat_type = PLAT_TYPE_VF_P1; in walk_phys()
8853 val = phy_encode(PORT_TYPE_10G, np->port); in walk_phys()
8858 parent->plat_type = PLAT_TYPE_VF_P0; in walk_phys()
8860 parent->plat_type = PLAT_TYPE_VF_P1; in walk_phys()
8880 parent->plat_type = PLAT_TYPE_VF_P0; in walk_phys()
8882 parent->plat_type = PLAT_TYPE_VF_P1; in walk_phys()
8895 return -EINVAL; in walk_phys()
8899 parent->port_phy = val; in walk_phys()
8901 if (parent->plat_type == PLAT_TYPE_NIU) in walk_phys()
8912 return -EINVAL; in walk_phys()
8917 struct niu_parent *parent = np->parent; in niu_probe_ports()
8920 if (parent->port_phy == PORT_PHY_UNKNOWN) { in niu_probe_ports()
8930 if (parent->port_phy == PORT_PHY_INVALID) in niu_probe_ports()
8931 return -EINVAL; in niu_probe_ports()
8938 struct niu_classifier *cp = &np->clas; in niu_classifier_swstate_init()
8940 cp->tcam_top = (u16) np->port; in niu_classifier_swstate_init()
8941 cp->tcam_sz = np->parent->tcam_num_entries / np->parent->num_ports; in niu_classifier_swstate_init()
8942 cp->h1_init = 0xffffffff; in niu_classifier_swstate_init()
8943 cp->h2_init = 0xffff; in niu_classifier_swstate_init()
8950 struct niu_link_config *lp = &np->link_config; in niu_link_config_init()
8952 lp->advertising = (ADVERTISED_10baseT_Half | in niu_link_config_init()
8960 lp->speed = lp->active_speed = SPEED_INVALID; in niu_link_config_init()
8961 lp->duplex = DUPLEX_FULL; in niu_link_config_init()
8962 lp->active_duplex = DUPLEX_INVALID; in niu_link_config_init()
8963 lp->autoneg = 1; in niu_link_config_init()
8965 lp->loopback_mode = LOOPBACK_MAC; in niu_link_config_init()
8966 lp->active_speed = SPEED_10000; in niu_link_config_init()
8967 lp->active_duplex = DUPLEX_FULL; in niu_link_config_init()
8969 lp->loopback_mode = LOOPBACK_DISABLED; in niu_link_config_init()
8975 switch (np->port) { in niu_init_mac_ipp_pcs_base()
8977 np->mac_regs = np->regs + XMAC_PORT0_OFF; in niu_init_mac_ipp_pcs_base()
8978 np->ipp_off = 0x00000; in niu_init_mac_ipp_pcs_base()
8979 np->pcs_off = 0x04000; in niu_init_mac_ipp_pcs_base()
8980 np->xpcs_off = 0x02000; in niu_init_mac_ipp_pcs_base()
8984 np->mac_regs = np->regs + XMAC_PORT1_OFF; in niu_init_mac_ipp_pcs_base()
8985 np->ipp_off = 0x08000; in niu_init_mac_ipp_pcs_base()
8986 np->pcs_off = 0x0a000; in niu_init_mac_ipp_pcs_base()
8987 np->xpcs_off = 0x08000; in niu_init_mac_ipp_pcs_base()
8991 np->mac_regs = np->regs + BMAC_PORT2_OFF; in niu_init_mac_ipp_pcs_base()
8992 np->ipp_off = 0x04000; in niu_init_mac_ipp_pcs_base()
8993 np->pcs_off = 0x0e000; in niu_init_mac_ipp_pcs_base()
8994 np->xpcs_off = ~0UL; in niu_init_mac_ipp_pcs_base()
8998 np->mac_regs = np->regs + BMAC_PORT3_OFF; in niu_init_mac_ipp_pcs_base()
8999 np->ipp_off = 0x0c000; in niu_init_mac_ipp_pcs_base()
9000 np->pcs_off = 0x12000; in niu_init_mac_ipp_pcs_base()
9001 np->xpcs_off = ~0UL; in niu_init_mac_ipp_pcs_base()
9005 dev_err(np->device, "Port %u is invalid, cannot compute MAC block offset\n", np->port); in niu_init_mac_ipp_pcs_base()
9006 return -EINVAL; in niu_init_mac_ipp_pcs_base()
9015 struct niu_parent *parent = np->parent; in niu_try_msix()
9016 struct pci_dev *pdev = np->pdev; in niu_try_msix()
9020 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port; in niu_try_msix()
9021 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++) in niu_try_msix()
9024 num_irqs = (parent->rxchan_per_port[np->port] + in niu_try_msix()
9025 parent->txchan_per_port[np->port] + in niu_try_msix()
9026 (np->port == 0 ? 3 : 1)); in niu_try_msix()
9027 BUG_ON(num_irqs > (NIU_NUM_LDG / parent->num_ports)); in niu_try_msix()
9036 np->flags &= ~NIU_FLAGS_MSIX; in niu_try_msix()
9040 np->flags |= NIU_FLAGS_MSIX; in niu_try_msix()
9042 np->ldg[i].irq = msi_vec[i].vector; in niu_try_msix()
9043 np->num_ldg = num_irqs; in niu_try_msix()
9049 struct platform_device *op = np->op; in niu_n2_irq_init()
9053 int_prop = of_get_property(op->dev.of_node, "interrupts", NULL); in niu_n2_irq_init()
9055 return -ENODEV; in niu_n2_irq_init()
9057 for (i = 0; i < op->archdata.num_irqs; i++) { in niu_n2_irq_init()
9059 np->ldg[i].irq = op->archdata.irqs[i]; in niu_n2_irq_init()
9062 np->num_ldg = op->archdata.num_irqs; in niu_n2_irq_init()
9066 return -EINVAL; in niu_n2_irq_init()
9072 struct niu_parent *parent = np->parent; in niu_ldg_init()
9078 np->num_ldg = 1; in niu_ldg_init()
9079 np->ldg[0].irq = np->dev->irq; in niu_ldg_init()
9080 if (parent->plat_type == PLAT_TYPE_NIU) { in niu_ldg_init()
9087 port = np->port; in niu_ldg_init()
9088 for (i = 0; i < np->num_ldg; i++) { in niu_ldg_init()
9089 struct niu_ldg *lp = &np->ldg[i]; in niu_ldg_init()
9091 netif_napi_add(np->dev, &lp->napi, niu_poll, 64); in niu_ldg_init()
9093 lp->np = np; in niu_ldg_init()
9094 lp->ldg_num = ldg_num_map[i]; in niu_ldg_init()
9095 lp->timer = 2; /* XXX */ in niu_ldg_init()
9101 if (np->parent->plat_type != PLAT_TYPE_NIU) { in niu_ldg_init()
9102 err = niu_set_ldg_sid(np, lp->ldg_num, port, i); in niu_ldg_init()
9127 if (ldg_rotor == np->num_ldg) in niu_ldg_init()
9138 if (ldg_rotor == np->num_ldg) in niu_ldg_init()
9148 if (ldg_rotor == np->num_ldg) in niu_ldg_init()
9155 first_chan += parent->rxchan_per_port[i]; in niu_ldg_init()
9156 num_chan = parent->rxchan_per_port[port]; in niu_ldg_init()
9165 if (ldg_rotor == np->num_ldg) in niu_ldg_init()
9171 first_chan += parent->txchan_per_port[i]; in niu_ldg_init()
9172 num_chan = parent->txchan_per_port[port]; in niu_ldg_init()
9180 if (ldg_rotor == np->num_ldg) in niu_ldg_init()
9189 if (np->flags & NIU_FLAGS_MSIX) in niu_ldg_free()
9190 pci_disable_msix(np->pdev); in niu_ldg_free()
9196 struct net_device *dev = np->dev; in niu_get_of_props()
9203 if (np->parent->plat_type == PLAT_TYPE_NIU) in niu_get_of_props()
9204 dp = np->op->dev.of_node; in niu_get_of_props()
9206 dp = pci_device_to_OF_node(np->pdev); in niu_get_of_props()
9208 phy_type = of_get_property(dp, "phy-type", &prop_len); in niu_get_of_props()
9210 netdev_err(dev, "%pOF: OF node lacks phy-type property\n", dp); in niu_get_of_props()
9211 return -EINVAL; in niu_get_of_props()
9215 return -ENODEV; in niu_get_of_props()
9217 strcpy(np->vpd.phy_type, phy_type); in niu_get_of_props()
9219 if (niu_phy_type_prop_decode(np, np->vpd.phy_type)) { in niu_get_of_props()
9221 dp, np->vpd.phy_type); in niu_get_of_props()
9222 return -EINVAL; in niu_get_of_props()
9225 mac_addr = of_get_property(dp, "local-mac-address", &prop_len); in niu_get_of_props()
9227 netdev_err(dev, "%pOF: OF node lacks local-mac-address property\n", in niu_get_of_props()
9229 return -EINVAL; in niu_get_of_props()
9231 if (prop_len != dev->addr_len) { in niu_get_of_props()
9235 memcpy(dev->dev_addr, mac_addr, dev->addr_len); in niu_get_of_props()
9236 if (!is_valid_ether_addr(&dev->dev_addr[0])) { in niu_get_of_props()
9238 netdev_err(dev, "%pOF: [ %pM ]\n", dp, dev->dev_addr); in niu_get_of_props()
9239 return -EINVAL; in niu_get_of_props()
9245 strcpy(np->vpd.model, model); in niu_get_of_props()
9247 if (of_find_property(dp, "hot-swappable-phy", &prop_len)) { in niu_get_of_props()
9248 np->flags |= (NIU_FLAGS_10G | NIU_FLAGS_FIBER | in niu_get_of_props()
9254 return -EINVAL; in niu_get_of_props()
9264 if (err == -ENODEV) in niu_get_invariants()
9279 if (np->parent->plat_type == PLAT_TYPE_NIU) in niu_get_invariants()
9280 return -EINVAL; in niu_get_invariants()
9284 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_get_invariants()
9290 if (np->flags & NIU_FLAGS_VPD_VALID) { in niu_get_invariants()
9297 if (!(np->flags & NIU_FLAGS_VPD_VALID)) { in niu_get_invariants()
9331 struct niu_parent *p = dev_get_platdata(&plat_dev->dev); in show_port_phy()
9332 u32 port_phy = p->port_phy; in show_port_phy()
9340 for (i = 0; i < p->num_ports; i++) { in show_port_phy()
9354 return buf - orig_buf; in show_port_phy()
9361 struct niu_parent *p = dev_get_platdata(&plat_dev->dev); in show_plat_type()
9364 switch (p->plat_type) { in show_plat_type()
9390 struct niu_parent *p = dev_get_platdata(&plat_dev->dev); in __show_chan_per_port()
9395 arr = (rx ? p->rxchan_per_port : p->txchan_per_port); in __show_chan_per_port()
9397 for (i = 0; i < p->num_ports; i++) { in __show_chan_per_port()
9404 return buf - orig_buf; in __show_chan_per_port()
9423 struct niu_parent *p = dev_get_platdata(&plat_dev->dev); in show_num_ports()
9425 return sprintf(buf, "%d\n", p->num_ports); in show_num_ports()
9444 plat_dev = platform_device_register_simple("niu-board", niu_parent_index, in niu_new_parent()
9450 int err = device_create_file(&plat_dev->dev, in niu_new_parent()
9460 p->index = niu_parent_index++; in niu_new_parent()
9462 plat_dev->dev.platform_data = p; in niu_new_parent()
9463 p->plat_dev = plat_dev; in niu_new_parent()
9465 memcpy(&p->id, id, sizeof(*id)); in niu_new_parent()
9466 p->plat_type = ptype; in niu_new_parent()
9467 INIT_LIST_HEAD(&p->list); in niu_new_parent()
9468 atomic_set(&p->refcnt, 0); in niu_new_parent()
9469 list_add(&p->list, &niu_parent_list); in niu_new_parent()
9470 spin_lock_init(&p->lock); in niu_new_parent()
9472 p->rxdma_clock_divider = 7500; in niu_new_parent()
9474 p->tcam_num_entries = NIU_PCI_TCAM_ENTRIES; in niu_new_parent()
9475 if (p->plat_type == PLAT_TYPE_NIU) in niu_new_parent()
9476 p->tcam_num_entries = NIU_NONPCI_TCAM_ENTRIES; in niu_new_parent()
9479 int index = i - CLASS_CODE_USER_PROG1; in niu_new_parent()
9481 p->tcam_key[index] = TCAM_KEY_TSEL; in niu_new_parent()
9482 p->flow_key[index] = (FLOW_KEY_IPSA | in niu_new_parent()
9492 p->ldg_map[i] = LDG_INVALID; in niu_new_parent()
9505 int port = np->port; in niu_get_parent()
9510 if (!memcmp(id, &tmp->id, sizeof(*id))) { in niu_get_parent()
9523 err = sysfs_create_link(&p->plat_dev->dev.kobj, in niu_get_parent()
9524 &np->device->kobj, in niu_get_parent()
9527 p->ports[port] = np; in niu_get_parent()
9528 atomic_inc(&p->refcnt); in niu_get_parent()
9538 struct niu_parent *p = np->parent; in niu_put_parent()
9539 u8 port = np->port; in niu_put_parent()
9542 BUG_ON(!p || p->ports[port] != np); in niu_put_parent()
9544 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_put_parent()
9551 sysfs_remove_link(&p->plat_dev->dev.kobj, port_name); in niu_put_parent()
9553 p->ports[port] = NULL; in niu_put_parent()
9554 np->parent = NULL; in niu_put_parent()
9556 if (atomic_dec_and_test(&p->refcnt)) { in niu_put_parent()
9557 list_del(&p->list); in niu_put_parent()
9558 platform_device_unregister(p->plat_dev); in niu_put_parent()
9641 np->dev = dev; in niu_alloc_and_init()
9642 np->pdev = pdev; in niu_alloc_and_init()
9643 np->op = op; in niu_alloc_and_init()
9644 np->device = gen_dev; in niu_alloc_and_init()
9645 np->ops = ops; in niu_alloc_and_init()
9647 np->msg_enable = niu_debug; in niu_alloc_and_init()
9649 spin_lock_init(&np->lock); in niu_alloc_and_init()
9650 INIT_WORK(&np->reset_task, niu_reset_task); in niu_alloc_and_init()
9652 np->port = port; in niu_alloc_and_init()
9672 dev->netdev_ops = &niu_netdev_ops; in niu_assign_netdev_ops()
9673 dev->ethtool_ops = &niu_ethtool_ops; in niu_assign_netdev_ops()
9674 dev->watchdog_timeo = NIU_TX_TIMEOUT; in niu_assign_netdev_ops()
9679 struct net_device *dev = np->dev; in niu_device_announce()
9681 pr_info("%s: NIU Ethernet %pM\n", dev->name, dev->dev_addr); in niu_device_announce()
9683 if (np->parent->plat_type == PLAT_TYPE_ATCA_CP3220) { in niu_device_announce()
9685 dev->name, in niu_device_announce()
9686 (np->flags & NIU_FLAGS_XMAC ? "XMAC" : "BMAC"), in niu_device_announce()
9687 (np->flags & NIU_FLAGS_10G ? "10G" : "1G"), in niu_device_announce()
9688 (np->flags & NIU_FLAGS_FIBER ? "RGMII FIBER" : "SERDES"), in niu_device_announce()
9689 (np->mac_xcvr == MAC_XCVR_MII ? "MII" : in niu_device_announce()
9690 (np->mac_xcvr == MAC_XCVR_PCS ? "PCS" : "XPCS")), in niu_device_announce()
9691 np->vpd.phy_type); in niu_device_announce()
9694 dev->name, in niu_device_announce()
9695 (np->flags & NIU_FLAGS_XMAC ? "XMAC" : "BMAC"), in niu_device_announce()
9696 (np->flags & NIU_FLAGS_10G ? "10G" : "1G"), in niu_device_announce()
9697 (np->flags & NIU_FLAGS_FIBER ? "FIBER" : in niu_device_announce()
9698 (np->flags & NIU_FLAGS_XCVR_SERDES ? "SERDES" : in niu_device_announce()
9700 (np->mac_xcvr == MAC_XCVR_MII ? "MII" : in niu_device_announce()
9701 (np->mac_xcvr == MAC_XCVR_PCS ? "PCS" : "XPCS")), in niu_device_announce()
9702 np->vpd.phy_type); in niu_device_announce()
9708 dev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_RXHASH; in niu_set_basic_features()
9709 dev->features |= dev->hw_features | NETIF_F_RXCSUM; in niu_set_basic_features()
9725 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); in niu_pci_init_one()
9731 dev_err(&pdev->dev, "Cannot find proper PCI device base addresses, aborting\n"); in niu_pci_init_one()
9732 err = -ENODEV; in niu_pci_init_one()
9738 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); in niu_pci_init_one()
9743 dev_err(&pdev->dev, "Cannot find PCI Express capability, aborting\n"); in niu_pci_init_one()
9744 err = -ENODEV; in niu_pci_init_one()
9748 dev = niu_alloc_and_init(&pdev->dev, pdev, NULL, in niu_pci_init_one()
9749 &niu_pci_ops, PCI_FUNC(pdev->devfn)); in niu_pci_init_one()
9751 err = -ENOMEM; in niu_pci_init_one()
9757 parent_id.pci.domain = pci_domain_nr(pdev->bus); in niu_pci_init_one()
9758 parent_id.pci.bus = pdev->bus->number; in niu_pci_init_one()
9759 parent_id.pci.device = PCI_SLOT(pdev->devfn); in niu_pci_init_one()
9761 np->parent = niu_get_parent(np, &parent_id, in niu_pci_init_one()
9763 if (!np->parent) { in niu_pci_init_one()
9764 err = -ENOMEM; in niu_pci_init_one()
9777 dev->features |= NETIF_F_HIGHDMA; in niu_pci_init_one()
9780 dev_err(&pdev->dev, "Unable to obtain 44 bit DMA for consistent allocations, aborting\n"); in niu_pci_init_one()
9787 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); in niu_pci_init_one()
9794 dev->priv_flags |= IFF_UNICAST_FLT; in niu_pci_init_one()
9796 np->regs = pci_ioremap_bar(pdev, 0); in niu_pci_init_one()
9797 if (!np->regs) { in niu_pci_init_one()
9798 dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); in niu_pci_init_one()
9799 err = -ENOMEM; in niu_pci_init_one()
9806 dev->irq = pdev->irq; in niu_pci_init_one()
9808 /* MTU range: 68 - 9216 */ in niu_pci_init_one()
9809 dev->min_mtu = ETH_MIN_MTU; in niu_pci_init_one()
9810 dev->max_mtu = NIU_MAX_MTU; in niu_pci_init_one()
9816 if (err != -ENODEV) in niu_pci_init_one()
9817 dev_err(&pdev->dev, "Problem fetching invariants of chip, aborting\n"); in niu_pci_init_one()
9823 dev_err(&pdev->dev, "Cannot register net device, aborting\n"); in niu_pci_init_one()
9834 if (np->regs) { in niu_pci_init_one()
9835 iounmap(np->regs); in niu_pci_init_one()
9836 np->regs = NULL; in niu_pci_init_one()
9862 if (np->regs) { in niu_pci_remove_one()
9863 iounmap(np->regs); in niu_pci_remove_one()
9864 np->regs = NULL; in niu_pci_remove_one()
9886 flush_work(&np->reset_task); in niu_suspend()
9889 del_timer_sync(&np->timer); in niu_suspend()
9891 spin_lock_irqsave(&np->lock, flags); in niu_suspend()
9893 spin_unlock_irqrestore(&np->lock, flags); in niu_suspend()
9897 spin_lock_irqsave(&np->lock, flags); in niu_suspend()
9899 spin_unlock_irqrestore(&np->lock, flags); in niu_suspend()
9920 spin_lock_irqsave(&np->lock, flags); in niu_resume()
9924 np->timer.expires = jiffies + HZ; in niu_resume()
9925 add_timer(&np->timer); in niu_resume()
9929 spin_unlock_irqrestore(&np->lock, flags); in niu_resume()
10012 reg = of_get_property(op->dev.of_node, "reg", NULL); in niu_of_probe()
10014 dev_err(&op->dev, "%pOF: No 'reg' property, aborting\n", in niu_of_probe()
10015 op->dev.of_node); in niu_of_probe()
10016 return -ENODEV; in niu_of_probe()
10019 dev = niu_alloc_and_init(&op->dev, NULL, op, in niu_of_probe()
10022 err = -ENOMEM; in niu_of_probe()
10028 parent_id.of = of_get_parent(op->dev.of_node); in niu_of_probe()
10030 np->parent = niu_get_parent(np, &parent_id, in niu_of_probe()
10032 if (!np->parent) { in niu_of_probe()
10033 err = -ENOMEM; in niu_of_probe()
10039 np->regs = of_ioremap(&op->resource[1], 0, in niu_of_probe()
10040 resource_size(&op->resource[1]), in niu_of_probe()
10042 if (!np->regs) { in niu_of_probe()
10043 dev_err(&op->dev, "Cannot map device registers, aborting\n"); in niu_of_probe()
10044 err = -ENOMEM; in niu_of_probe()
10048 np->vir_regs_1 = of_ioremap(&op->resource[2], 0, in niu_of_probe()
10049 resource_size(&op->resource[2]), in niu_of_probe()
10050 "niu vregs-1"); in niu_of_probe()
10051 if (!np->vir_regs_1) { in niu_of_probe()
10052 dev_err(&op->dev, "Cannot map device vir registers 1, aborting\n"); in niu_of_probe()
10053 err = -ENOMEM; in niu_of_probe()
10057 np->vir_regs_2 = of_ioremap(&op->resource[3], 0, in niu_of_probe()
10058 resource_size(&op->resource[3]), in niu_of_probe()
10059 "niu vregs-2"); in niu_of_probe()
10060 if (!np->vir_regs_2) { in niu_of_probe()
10061 dev_err(&op->dev, "Cannot map device vir registers 2, aborting\n"); in niu_of_probe()
10062 err = -ENOMEM; in niu_of_probe()
10070 if (err != -ENODEV) in niu_of_probe()
10071 dev_err(&op->dev, "Problem fetching invariants of chip, aborting\n"); in niu_of_probe()
10077 dev_err(&op->dev, "Cannot register net device, aborting\n"); in niu_of_probe()
10088 if (np->vir_regs_1) { in niu_of_probe()
10089 of_iounmap(&op->resource[2], np->vir_regs_1, in niu_of_probe()
10090 resource_size(&op->resource[2])); in niu_of_probe()
10091 np->vir_regs_1 = NULL; in niu_of_probe()
10094 if (np->vir_regs_2) { in niu_of_probe()
10095 of_iounmap(&op->resource[3], np->vir_regs_2, in niu_of_probe()
10096 resource_size(&op->resource[3])); in niu_of_probe()
10097 np->vir_regs_2 = NULL; in niu_of_probe()
10100 if (np->regs) { in niu_of_probe()
10101 of_iounmap(&op->resource[1], np->regs, in niu_of_probe()
10102 resource_size(&op->resource[1])); in niu_of_probe()
10103 np->regs = NULL; in niu_of_probe()
10125 if (np->vir_regs_1) { in niu_of_remove()
10126 of_iounmap(&op->resource[2], np->vir_regs_1, in niu_of_remove()
10127 resource_size(&op->resource[2])); in niu_of_remove()
10128 np->vir_regs_1 = NULL; in niu_of_remove()
10131 if (np->vir_regs_2) { in niu_of_remove()
10132 of_iounmap(&op->resource[3], np->vir_regs_2, in niu_of_remove()
10133 resource_size(&op->resource[3])); in niu_of_remove()
10134 np->vir_regs_2 = NULL; in niu_of_remove()
10137 if (np->regs) { in niu_of_remove()
10138 of_iounmap(&op->resource[1], np->regs, in niu_of_remove()
10139 resource_size(&op->resource[1])); in niu_of_remove()
10140 np->regs = NULL; in niu_of_remove()