Lines Matching +full:mii +full:- +full:g +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()
389 /* Mode is always 10G fiber. */
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()
456 /* Initialize PLL for 1G */ 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()
548 /* Initialize PLL for 10G */ 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()
622 pr_info("NIU Port %u signal bits [%08x] are not [%08x] for 10G...trying 1G\n", in serdes_init_niu_10g_serdes()
623 np->port, (int)(sig & mask), (int)val); in serdes_init_niu_10g_serdes()
625 /* 10G failed, try initializing at 1G */ 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 = mii_read(np, np->phy_addr, MII_BMSR); in link_status_1g_rgmii()
1230 lp->active_speed = current_speed; in link_status_1g_rgmii()
1231 lp->active_duplex = current_duplex; in link_status_1g_rgmii()
1235 spin_unlock_irqrestore(&np->lock, flags); in link_status_1g_rgmii()
1243 struct niu_link_config *lp = &np->link_config; in link_status_1g()
1247 spin_lock_irqsave(&np->lock, flags); in link_status_1g()
1250 lp->supported |= SUPPORTED_TP; in link_status_1g()
1251 lp->active_advertising |= ADVERTISED_TP; in link_status_1g()
1253 spin_unlock_irqrestore(&np->lock, flags); in link_status_1g()
1261 err = mdio_read(np, np->phy_addr, in bcm8704_reset()
1266 err = mdio_write(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR, in bcm8704_reset()
1272 while (--limit >= 0) { in bcm8704_reset()
1273 err = mdio_read(np, np->phy_addr, in bcm8704_reset()
1281 netdev_err(np->dev, "Port %u PHY will not reset (bmcr=%04x)\n", in bcm8704_reset()
1282 np->port, (err & 0xffff)); in bcm8704_reset()
1283 return -ENODEV; in bcm8704_reset()
1293 int err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, reg); in bcm8704_user_dev3_readback()
1296 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, reg); in bcm8704_user_dev3_readback()
1307 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in bcm8706_init_user_dev3()
1314 err = mdio_write(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in bcm8706_init_user_dev3()
1328 err = mdio_write(np, np->phy_addr, in bcm8704_init_user_dev3()
1342 err = mdio_write(np, np->phy_addr, in bcm8704_init_user_dev3()
1358 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in bcm8704_init_user_dev3()
1364 err = mdio_write(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in bcm8704_init_user_dev3()
1378 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV2_ADDR, in mrvl88x2011_act_led()
1386 return mdio_write(np, np->phy_addr, MRVL88X2011_USER_DEV2_ADDR, in mrvl88x2011_act_led()
1394 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV2_ADDR, in mrvl88x2011_led_blink_rate()
1400 err = mdio_write(np, np->phy_addr, MRVL88X2011_USER_DEV2_ADDR, in mrvl88x2011_led_blink_rate()
1421 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV3_ADDR, in xcvr_init_10g_mrvl88x2011()
1428 err = mdio_write(np, np->phy_addr, MRVL88X2011_USER_DEV3_ADDR, in xcvr_init_10g_mrvl88x2011()
1433 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV1_ADDR, in xcvr_init_10g_mrvl88x2011()
1438 if (np->link_config.loopback_mode == LOOPBACK_MAC) in xcvr_init_10g_mrvl88x2011()
1443 err = mdio_write(np, np->phy_addr, MRVL88X2011_USER_DEV1_ADDR, in xcvr_init_10g_mrvl88x2011()
1449 return mdio_write(np, np->phy_addr, MRVL88X2011_USER_DEV1_ADDR, in xcvr_init_10g_mrvl88x2011()
1460 err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR, in xcvr_diag_bcm870x()
1464 pr_info("Port %u PMA_PMD(MII_STAT1000) [%04x]\n", np->port, err); in xcvr_diag_bcm870x()
1466 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, 0x20); in xcvr_diag_bcm870x()
1469 pr_info("Port %u USER_DEV3(0x20) [%04x]\n", np->port, err); in xcvr_diag_bcm870x()
1471 err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR, in xcvr_diag_bcm870x()
1475 pr_info("Port %u PHYXS(MII_NWAYTEST) [%04x]\n", np->port, err); in xcvr_diag_bcm870x()
1479 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in xcvr_diag_bcm870x()
1483 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in xcvr_diag_bcm870x()
1489 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in xcvr_diag_bcm870x()
1493 err = mdio_read(np, np->phy_addr, BCM8704_USER_DEV3_ADDR, in xcvr_diag_bcm870x()
1502 np->port); in xcvr_diag_bcm870x()
1505 np->port); in xcvr_diag_bcm870x()
1514 struct niu_link_config *lp = &np->link_config; in xcvr_10g_set_lb_bcm870x()
1517 err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR, in xcvr_10g_set_lb_bcm870x()
1524 if (lp->loopback_mode == LOOPBACK_MAC) in xcvr_10g_set_lb_bcm870x()
1527 err = mdio_write(np, np->phy_addr, BCM8704_PCS_DEV_ADDR, in xcvr_10g_set_lb_bcm870x()
1540 if ((np->flags & NIU_FLAGS_HOTPLUG_PHY) && in xcvr_init_10g_bcm8706()
1541 (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT) == 0) in xcvr_init_10g_bcm8706()
1610 phy_id = phy_decode(np->parent->port_phy, np->port); in xcvr_init_10g()
1611 phy_id = np->parent->phy_probe_info.phy_id[phy_id][np->port]; in xcvr_init_10g()
1631 err = mii_write(np, np->phy_addr, MII_BMCR, BMCR_RESET); in mii_reset()
1636 while (--limit >= 0) { in mii_reset()
1638 err = mii_read(np, np->phy_addr, MII_BMCR); in mii_reset()
1645 netdev_err(np->dev, "Port %u MII would not reset, bmcr[%04x]\n", in mii_reset()
1646 np->port, err); in mii_reset()
1647 return -ENODEV; in mii_reset()
1667 err = mii_read(np, np->phy_addr, MII_BMSR); in xcvr_init_1g_rgmii()
1674 err = mii_read(np, np->phy_addr, MII_ESTATUS); in xcvr_init_1g_rgmii()
1681 err = mii_write(np, np->phy_addr, MII_BMCR, bmcr); in xcvr_init_1g_rgmii()
1690 err = mii_write(np, np->phy_addr, MII_CTRL1000, ctrl1000); in xcvr_init_1g_rgmii()
1697 err = mii_write(np, np->phy_addr, MII_BMCR, bmcr); in xcvr_init_1g_rgmii()
1701 err = mii_read(np, np->phy_addr, MII_BMCR); in xcvr_init_1g_rgmii()
1704 bmcr = mii_read(np, np->phy_addr, MII_BMCR); in xcvr_init_1g_rgmii()
1706 err = mii_read(np, np->phy_addr, MII_BMSR); in xcvr_init_1g_rgmii()
1715 struct niu_link_config *lp = &np->link_config; in mii_init_common()
1723 err = mii_read(np, np->phy_addr, MII_BMSR); in mii_init_common()
1730 err = mii_read(np, np->phy_addr, MII_ESTATUS); in mii_init_common()
1737 err = mii_write(np, np->phy_addr, MII_BMCR, bmcr); in mii_init_common()
1741 if (lp->loopback_mode == LOOPBACK_MAC) { in mii_init_common()
1743 if (lp->active_speed == SPEED_1000) in mii_init_common()
1745 if (lp->active_duplex == DUPLEX_FULL) in mii_init_common()
1749 if (lp->loopback_mode == LOOPBACK_PHY) { in mii_init_common()
1754 err = mii_write(np, np->phy_addr, BCM5464R_AUX_CTL, aux); in mii_init_common()
1759 if (lp->autoneg) { in mii_init_common()
1764 (lp->advertising & ADVERTISED_10baseT_Half)) in mii_init_common()
1767 (lp->advertising & ADVERTISED_10baseT_Full)) in mii_init_common()
1770 (lp->advertising & ADVERTISED_100baseT_Half)) in mii_init_common()
1773 (lp->advertising & ADVERTISED_100baseT_Full)) in mii_init_common()
1775 err = mii_write(np, np->phy_addr, MII_ADVERTISE, adv); in mii_init_common()
1782 (lp->advertising & ADVERTISED_1000baseT_Half)) in mii_init_common()
1785 (lp->advertising & ADVERTISED_1000baseT_Full)) in mii_init_common()
1787 err = mii_write(np, np->phy_addr, in mii_init_common()
1795 /* !lp->autoneg */ in mii_init_common()
1798 if (lp->duplex == DUPLEX_FULL) { in mii_init_common()
1801 } else if (lp->duplex == DUPLEX_HALF) in mii_init_common()
1804 return -EINVAL; in mii_init_common()
1806 if (lp->speed == SPEED_1000) { in mii_init_common()
1807 /* if X-full requested while not supported, or in mii_init_common()
1808 X-half requested while not supported... */ in mii_init_common()
1811 return -EINVAL; in mii_init_common()
1813 } else if (lp->speed == SPEED_100) { in mii_init_common()
1816 return -EINVAL; in mii_init_common()
1818 } else if (lp->speed == SPEED_10) { in mii_init_common()
1821 return -EINVAL; in mii_init_common()
1823 return -EINVAL; in mii_init_common()
1826 err = mii_write(np, np->phy_addr, MII_BMCR, bmcr); in mii_init_common()
1831 err = mii_read(np, np->phy_addr, MII_BMCR); in mii_init_common()
1836 err = mii_read(np, np->phy_addr, MII_BMSR); in mii_init_common()
1841 pr_info("Port %u after MII init bmcr[%04x] bmsr[%04x]\n", in mii_init_common()
1842 np->port, bmcr, bmsr); in mii_init_common()
1862 const struct niu_phy_ops *ops = np->phy_ops; in niu_xcvr_init()
1866 if (ops->xcvr_init) in niu_xcvr_init()
1867 err = ops->xcvr_init(np); in niu_xcvr_init()
1874 const struct niu_phy_ops *ops = np->phy_ops; in niu_serdes_init()
1878 if (ops->serdes_init) in niu_serdes_init()
1879 err = ops->serdes_init(np); in niu_serdes_init()
1889 struct niu_link_config *lp = &np->link_config; in niu_link_status_common()
1890 struct net_device *dev = np->dev; in niu_link_status_common()
1895 lp->active_speed == SPEED_10000 ? "10Gb/sec" : in niu_link_status_common()
1896 lp->active_speed == SPEED_1000 ? "1Gb/sec" : in niu_link_status_common()
1897 lp->active_speed == SPEED_100 ? "100Mbit/sec" : in niu_link_status_common()
1899 lp->active_duplex == DUPLEX_FULL ? "full" : "half"); in niu_link_status_common()
1901 spin_lock_irqsave(&np->lock, flags); in niu_link_status_common()
1904 spin_unlock_irqrestore(&np->lock, flags); in niu_link_status_common()
1909 spin_lock_irqsave(&np->lock, flags); in niu_link_status_common()
1911 spin_unlock_irqrestore(&np->lock, flags); in niu_link_status_common()
1924 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV1_ADDR, in link_status_10g_mrvl()
1930 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV1_ADDR, in link_status_10g_mrvl()
1938 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV3_ADDR, in link_status_10g_mrvl()
1943 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV3_ADDR, in link_status_10g_mrvl()
1950 /* Check XGXS Register : 4.0018.[0-3,12] */ in link_status_10g_mrvl()
1951 err = mdio_read(np, np->phy_addr, MRVL88X2011_USER_DEV4_ADDR, in link_status_10g_mrvl()
1962 np->link_config.active_speed = SPEED_10000; in link_status_10g_mrvl()
1963 np->link_config.active_duplex = DUPLEX_FULL; in link_status_10g_mrvl()
1979 err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR, in link_status_10g_bcm8706()
1988 err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR, in link_status_10g_bcm8706()
1998 err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR, in link_status_10g_bcm8706()
2010 np->link_config.active_speed = SPEED_INVALID; in link_status_10g_bcm8706()
2011 np->link_config.active_duplex = DUPLEX_INVALID; in link_status_10g_bcm8706()
2016 np->link_config.active_speed = SPEED_10000; in link_status_10g_bcm8706()
2017 np->link_config.active_duplex = DUPLEX_FULL; in link_status_10g_bcm8706()
2031 err = mdio_read(np, np->phy_addr, BCM8704_PMA_PMD_DEV_ADDR, in link_status_10g_bcom()
2040 err = mdio_read(np, np->phy_addr, BCM8704_PCS_DEV_ADDR, in link_status_10g_bcom()
2049 err = mdio_read(np, np->phy_addr, BCM8704_PHYXS_DEV_ADDR, in link_status_10g_bcom()
2065 np->link_config.active_speed = SPEED_10000; in link_status_10g_bcom()
2066 np->link_config.active_duplex = DUPLEX_FULL; in link_status_10g_bcom()
2077 int err = -EINVAL; in link_status_10g()
2079 spin_lock_irqsave(&np->lock, flags); in link_status_10g()
2081 if (np->link_config.loopback_mode == LOOPBACK_DISABLED) { in link_status_10g()
2084 phy_id = phy_decode(np->parent->port_phy, np->port); in link_status_10g()
2085 phy_id = np->parent->phy_probe_info.phy_id[phy_id][np->port]; in link_status_10g()
2099 spin_unlock_irqrestore(&np->lock, flags); in link_status_10g()
2109 switch (np->port) { in niu_10g_phy_present()
2148 spin_lock_irqsave(&np->lock, flags); in link_status_10g_hotplug()
2150 if (np->link_config.loopback_mode == LOOPBACK_DISABLED) { in link_status_10g_hotplug()
2151 phy_present_prev = (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT) ? in link_status_10g_hotplug()
2158 np->flags |= NIU_FLAGS_HOTPLUG_PHY_PRESENT; in link_status_10g_hotplug()
2159 if (np->phy_ops->xcvr_init) in link_status_10g_hotplug()
2160 err = np->phy_ops->xcvr_init(np); in link_status_10g_hotplug()
2162 err = mdio_read(np, np->phy_addr, in link_status_10g_hotplug()
2165 /* No mdio, back-to-back XAUI */ in link_status_10g_hotplug()
2169 np->flags &= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT; in link_status_10g_hotplug()
2172 np->flags &= ~NIU_FLAGS_HOTPLUG_PHY_PRESENT; in link_status_10g_hotplug()
2174 netif_warn(np, link, np->dev, in link_status_10g_hotplug()
2179 if (np->flags & NIU_FLAGS_HOTPLUG_PHY_PRESENT) { in link_status_10g_hotplug()
2182 /* No mdio, back-to-back XAUI: it is C10NEM */ in link_status_10g_hotplug()
2184 np->link_config.active_speed = SPEED_10000; in link_status_10g_hotplug()
2185 np->link_config.active_duplex = DUPLEX_FULL; in link_status_10g_hotplug()
2190 spin_unlock_irqrestore(&np->lock, flags); in link_status_10g_hotplug()
2197 const struct niu_phy_ops *ops = np->phy_ops; in niu_link_status()
2201 if (ops->link_status) in niu_link_status()
2202 err = ops->link_status(np, link_up_p); in niu_link_status()
2217 if (netif_carrier_ok(np->dev)) in niu_timer()
2221 np->timer.expires = jiffies + off; in niu_timer()
2223 add_timer(&np->timer); in niu_timer()
2352 struct niu_link_config *lp = &np->link_config; in serdes_init_10g_serdes()
2356 switch (np->port) { in serdes_init_10g_serdes()
2369 return -EINVAL; in serdes_init_10g_serdes()
2385 if (lp->loopback_mode == LOOPBACK_PHY) { in serdes_init_10g_serdes()
2436 switch (np->port) { in serdes_init_10g_serdes()
2460 return -EINVAL; in serdes_init_10g_serdes()
2467 np->flags &= ~NIU_FLAGS_10G; in serdes_init_10g_serdes()
2468 np->mac_xcvr = MAC_XCVR_PCS; in serdes_init_10g_serdes()
2470 netdev_err(np->dev, "Port %u 10G/1G SERDES Link Failed\n", in serdes_init_10g_serdes()
2471 np->port); in serdes_init_10g_serdes()
2472 return -ENODEV; in serdes_init_10g_serdes()
2481 struct niu_parent *parent = np->parent; in niu_determine_phy_disposition()
2482 u8 plat_type = parent->plat_type; in niu_determine_phy_disposition()
2487 switch (np->flags & in niu_determine_phy_disposition()
2492 /* 10G Serdes */ in niu_determine_phy_disposition()
2496 /* 1G Serdes */ in niu_determine_phy_disposition()
2500 /* 10G Fiber */ in niu_determine_phy_disposition()
2502 if (np->flags & NIU_FLAGS_HOTPLUG_PHY) { in niu_determine_phy_disposition()
2504 if (np->port == 0) in niu_determine_phy_disposition()
2506 if (np->port == 1) in niu_determine_phy_disposition()
2510 phy_addr_off += np->port; in niu_determine_phy_disposition()
2515 switch (np->flags & in niu_determine_phy_disposition()
2520 /* 1G copper */ in niu_determine_phy_disposition()
2527 phy_addr_off += (np->port ^ 0x3); in niu_determine_phy_disposition()
2531 /* 10G copper */ in niu_determine_phy_disposition()
2536 /* 1G fiber */ in niu_determine_phy_disposition()
2541 /* 10G fiber */ in niu_determine_phy_disposition()
2546 phy_addr_off += np->port; in niu_determine_phy_disposition()
2547 if (np->flags & NIU_FLAGS_HOTPLUG_PHY) { in niu_determine_phy_disposition()
2549 if (np->port == 0) in niu_determine_phy_disposition()
2551 if (np->port == 1) in niu_determine_phy_disposition()
2559 switch(np->port) { in niu_determine_phy_disposition()
2569 return -EINVAL; in niu_determine_phy_disposition()
2571 phy_addr_off = niu_atca_port_num[np->port]; in niu_determine_phy_disposition()
2575 return -EINVAL; in niu_determine_phy_disposition()
2579 np->phy_ops = tp->ops; in niu_determine_phy_disposition()
2580 np->phy_addr = tp->phy_addr_base + phy_addr_off; in niu_determine_phy_disposition()
2587 struct niu_parent *parent = np->parent; in niu_init_link()
2590 if (parent->plat_type == PLAT_TYPE_NIU) { in niu_init_link()
2597 if (err && !(np->flags & NIU_FLAGS_HOTPLUG_PHY)) in niu_init_link()
2601 if (!err || (np->flags & NIU_FLAGS_HOTPLUG_PHY)) in niu_init_link()
2612 if (np->flags & NIU_FLAGS_XMAC) { in niu_set_primary_mac()
2625 if (np->flags & NIU_FLAGS_XMAC) in niu_num_alt_addr()
2638 return -EINVAL; in niu_set_alt_mac()
2640 if (np->flags & NIU_FLAGS_XMAC) { in niu_set_alt_mac()
2659 return -EINVAL; in niu_enable_alt_mac()
2661 if (np->flags & NIU_FLAGS_XMAC) { in niu_enable_alt_mac()
2697 return -EINVAL; in __set_rdc_table_num()
2698 if (np->flags & NIU_FLAGS_XMAC) in __set_rdc_table_num()
2722 return -EINVAL; in niu_set_alt_mac_rdc_table()
2777 while (--limit > 0) { in tcam_wait_bit()
2783 return -ENODEV; in tcam_wait_bit()
2892 return -EINVAL; in tcam_user_eth_class_enable()
2894 reg = L2_CLS(class - CLASS_CODE_ETHERTYPE1); in tcam_user_eth_class_enable()
2915 return -EINVAL;
2917 reg = L2_CLS(class - CLASS_CODE_ETHERTYPE1);
2935 return -EINVAL; in tcam_user_ip_class_enable()
2937 reg = L3_CLS(class - CLASS_CODE_USER_PROG1); in tcam_user_ip_class_enable()
2960 return -EINVAL; in tcam_user_ip_class_set()
2962 reg = L3_CLS(class - CLASS_CODE_USER_PROG1); in tcam_user_ip_class_set()
3003 for (i = 0; i < np->parent->tcam_num_entries; i++) { in tcam_flush_all()
3026 return -EINVAL;
3045 return -EINVAL; in hash_write()
3094 return -EINVAL; in fflp_set_partition()
3168 parent = np->parent; in fflp_early_init()
3170 if (!(parent->flags & PARENT_FLGS_CLS_HWINIT)) { in fflp_early_init()
3171 if (np->parent->plat_type != PLAT_TYPE_NIU) { in fflp_early_init()
3176 netif_printk(np, probe, KERN_DEBUG, np->dev, in fflp_early_init()
3185 netif_printk(np, probe, KERN_DEBUG, np->dev, in fflp_early_init()
3196 netif_printk(np, probe, KERN_DEBUG, np->dev, in fflp_early_init()
3200 if (np->parent->plat_type != PLAT_TYPE_NIU) { in fflp_early_init()
3203 netif_printk(np, probe, KERN_DEBUG, np->dev, in fflp_early_init()
3212 parent->flags |= PARENT_FLGS_CLS_HWINIT; in fflp_early_init()
3223 return -EINVAL; in niu_set_flow_key()
3225 nw64(FLOW_KEY(class_code - CLASS_CODE_USER_PROG1), key); in niu_set_flow_key()
3233 return -EINVAL; in niu_set_tcam_key()
3235 nw64(TCAM_KEY(class_code - CLASS_CODE_USER_PROG1), key); in niu_set_tcam_key()
3243 if (idx >= (np->clas.tcam_sz - 1)) in tcam_get_index()
3245 return np->clas.tcam_top + ((idx+1) * np->parent->num_ports); in tcam_get_index()
3251 return np->clas.tcam_sz - 1; in tcam_get_size()
3257 return np->clas.tcam_valid_entries - 1; in tcam_get_valid_entry_cnt()
3263 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, page, offset, size); in niu_rx_skb_append()
3265 skb->len += size; in niu_rx_skb_append()
3266 skb->data_len += size; in niu_rx_skb_append()
3267 skb->truesize += truesize; in niu_rx_skb_append()
3275 return a & (MAX_RBR_RING_SIZE - 1); in niu_hash_rxaddr()
3285 pp = &rp->rxhash[h]; in niu_find_rxpage()
3286 for (; (p = *pp) != NULL; pp = (struct page **) &p->mapping) { in niu_find_rxpage()
3287 if (p->index == addr) { in niu_find_rxpage()
3302 page->index = base; in niu_hash_page()
3303 page->mapping = (struct address_space *) rp->rxhash[h]; in niu_hash_page()
3304 rp->rxhash[h] = page; in niu_hash_page()
3316 return -ENOMEM; in niu_rbr_add_page()
3318 addr = np->ops->map_page(np->device, page, 0, in niu_rbr_add_page()
3322 return -ENOMEM; in niu_rbr_add_page()
3326 if (rp->rbr_blocks_per_page > 1) in niu_rbr_add_page()
3327 page_ref_add(page, rp->rbr_blocks_per_page - 1); in niu_rbr_add_page()
3329 for (i = 0; i < rp->rbr_blocks_per_page; i++) { in niu_rbr_add_page()
3330 __le32 *rbr = &rp->rbr[start_index + i]; in niu_rbr_add_page()
3333 addr += rp->rbr_block_size; in niu_rbr_add_page()
3341 int index = rp->rbr_index; in niu_rbr_refill()
3343 rp->rbr_pending++; in niu_rbr_refill()
3344 if ((rp->rbr_pending % rp->rbr_blocks_per_page) == 0) { in niu_rbr_refill()
3348 rp->rbr_pending--; in niu_rbr_refill()
3352 rp->rbr_index += rp->rbr_blocks_per_page; in niu_rbr_refill()
3353 BUG_ON(rp->rbr_index > rp->rbr_table_size); in niu_rbr_refill()
3354 if (rp->rbr_index == rp->rbr_table_size) in niu_rbr_refill()
3355 rp->rbr_index = 0; in niu_rbr_refill()
3357 if (rp->rbr_pending >= rp->rbr_kick_thresh) { in niu_rbr_refill()
3358 nw64(RBR_KICK(rp->rx_channel), rp->rbr_pending); in niu_rbr_refill()
3359 rp->rbr_pending = 0; in niu_rbr_refill()
3366 unsigned int index = rp->rcr_index; in niu_rx_pkt_ignore()
3369 rp->rx_dropped++; in niu_rx_pkt_ignore()
3377 val = le64_to_cpup(&rp->rcr[index]); in niu_rx_pkt_ignore()
3382 rcr_size = rp->rbr_sizes[(val & RCR_ENTRY_PKTBUFSZ) >> in niu_rx_pkt_ignore()
3384 if ((page->index + PAGE_SIZE) - rcr_size == addr) { in niu_rx_pkt_ignore()
3385 *link = (struct page *) page->mapping; in niu_rx_pkt_ignore()
3386 np->ops->unmap_page(np->device, page->index, in niu_rx_pkt_ignore()
3388 page->index = 0; in niu_rx_pkt_ignore()
3389 page->mapping = NULL; in niu_rx_pkt_ignore()
3391 rp->rbr_refill_pending++; in niu_rx_pkt_ignore()
3399 rp->rcr_index = index; in niu_rx_pkt_ignore()
3407 unsigned int index = rp->rcr_index; in niu_process_rx_pkt()
3412 skb = netdev_alloc_skb(np->dev, RX_SKB_ALLOC_SIZE); in niu_process_rx_pkt()
3424 val = le64_to_cpup(&rp->rcr[index]); in niu_process_rx_pkt()
3434 rcr_size = rp->rbr_sizes[(val & RCR_ENTRY_PKTBUFSZ) >> in niu_process_rx_pkt()
3446 skb->ip_summed = CHECKSUM_UNNECESSARY; in niu_process_rx_pkt()
3450 append_size = append_size - skb->len; in niu_process_rx_pkt()
3453 if ((page->index + rp->rbr_block_size) - rcr_size == addr) { in niu_process_rx_pkt()
3454 *link = (struct page *) page->mapping; in niu_process_rx_pkt()
3455 np->ops->unmap_page(np->device, page->index, in niu_process_rx_pkt()
3457 page->index = 0; in niu_process_rx_pkt()
3458 page->mapping = NULL; in niu_process_rx_pkt()
3459 rp->rbr_refill_pending++; in niu_process_rx_pkt()
3468 rp->rcr_index = index; in niu_process_rx_pkt()
3474 rh = (struct rx_pkt_hdr1 *) skb->data; in niu_process_rx_pkt()
3475 if (np->dev->features & NETIF_F_RXHASH) in niu_process_rx_pkt()
3477 ((u32)rh->hashval2_0 << 24 | in niu_process_rx_pkt()
3478 (u32)rh->hashval2_1 << 16 | in niu_process_rx_pkt()
3479 (u32)rh->hashval1_1 << 8 | in niu_process_rx_pkt()
3480 (u32)rh->hashval1_2 << 0), in niu_process_rx_pkt()
3484 rp->rx_packets++; in niu_process_rx_pkt()
3485 rp->rx_bytes += skb->len; in niu_process_rx_pkt()
3487 skb->protocol = eth_type_trans(skb, np->dev); in niu_process_rx_pkt()
3488 skb_record_rx_queue(skb, rp->rx_channel); in niu_process_rx_pkt()
3496 int blocks_per_page = rp->rbr_blocks_per_page; in niu_rbr_fill()
3497 int err, index = rp->rbr_index; in niu_rbr_fill()
3500 while (index < (rp->rbr_table_size - blocks_per_page)) { in niu_rbr_fill()
3508 rp->rbr_index = index; in niu_rbr_fill()
3519 page = rp->rxhash[i]; in niu_rbr_free()
3521 struct page *next = (struct page *) page->mapping; in niu_rbr_free()
3522 u64 base = page->index; in niu_rbr_free()
3524 np->ops->unmap_page(np->device, base, PAGE_SIZE, in niu_rbr_free()
3526 page->index = 0; in niu_rbr_free()
3527 page->mapping = NULL; in niu_rbr_free()
3535 for (i = 0; i < rp->rbr_table_size; i++) in niu_rbr_free()
3536 rp->rbr[i] = cpu_to_le32(0); in niu_rbr_free()
3537 rp->rbr_index = 0; in niu_rbr_free()
3542 struct tx_buff_info *tb = &rp->tx_buffs[idx]; in release_tx_packet()
3543 struct sk_buff *skb = tb->skb; in release_tx_packet()
3548 tp = (struct tx_pkt_hdr *) skb->data; in release_tx_packet()
3549 tx_flags = le64_to_cpup(&tp->flags); in release_tx_packet()
3551 rp->tx_packets++; in release_tx_packet()
3552 rp->tx_bytes += (((tx_flags & TXHDR_LEN) >> TXHDR_LEN_SHIFT) - in release_tx_packet()
3556 np->ops->unmap_single(np->device, tb->mapping, in release_tx_packet()
3559 if (le64_to_cpu(rp->descr[idx]) & TX_DESC_MARK) in release_tx_packet()
3560 rp->mark_pending--; in release_tx_packet()
3562 tb->skb = NULL; in release_tx_packet()
3565 len -= MAX_TX_DESC_LEN; in release_tx_packet()
3568 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in release_tx_packet()
3569 tb = &rp->tx_buffs[idx]; in release_tx_packet()
3570 BUG_ON(tb->skb != NULL); in release_tx_packet()
3571 np->ops->unmap_page(np->device, tb->mapping, in release_tx_packet()
3572 skb_frag_size(&skb_shinfo(skb)->frags[i]), in release_tx_packet()
3582 #define NIU_TX_WAKEUP_THRESH(rp) ((rp)->pending / 4)
3591 index = (rp - np->tx_rings); in niu_tx_work()
3592 txq = netdev_get_tx_queue(np->dev, index); in niu_tx_work()
3594 cs = rp->tx_cs; in niu_tx_work()
3599 pkt_cnt = (pkt_cnt - rp->last_pkt_cnt) & in niu_tx_work()
3602 rp->last_pkt_cnt = tmp; in niu_tx_work()
3604 cons = rp->cons; in niu_tx_work()
3606 netif_printk(np, tx_done, KERN_DEBUG, np->dev, in niu_tx_work()
3609 while (pkt_cnt--) in niu_tx_work()
3612 rp->cons = cons; in niu_tx_work()
3631 * counters, as they are only 16-bit and can overflow quickly, in niu_sync_rx_discard_stats()
3641 int rx_channel = rp->rx_channel; in niu_sync_rx_discard_stats()
3652 rp->rx_errors += misc & RXMISC_COUNT; in niu_sync_rx_discard_stats()
3655 dev_err(np->device, "rx-%d: Counter overflow RXMISC discard\n", in niu_sync_rx_discard_stats()
3658 netif_printk(np, rx_err, KERN_DEBUG, np->dev, in niu_sync_rx_discard_stats()
3659 "rx-%d: MISC drop=%u over=%u\n", in niu_sync_rx_discard_stats()
3660 rx_channel, misc, misc-limit); in niu_sync_rx_discard_stats()
3667 rp->rx_dropped += wred & RED_DIS_CNT_COUNT; in niu_sync_rx_discard_stats()
3670 dev_err(np->device, "rx-%d: Counter overflow WRED discard\n", rx_channel); in niu_sync_rx_discard_stats()
3672 netif_printk(np, rx_err, KERN_DEBUG, np->dev, in niu_sync_rx_discard_stats()
3673 "rx-%d: WRED drop=%u over=%u\n", in niu_sync_rx_discard_stats()
3674 rx_channel, wred, wred-limit); in niu_sync_rx_discard_stats()
3682 struct rxdma_mailbox *mbox = rp->mbox; in niu_rx_work()
3686 stat = nr64(RX_DMA_CTL_STAT(rp->rx_channel)); in niu_rx_work()
3687 qlen = nr64(RCRSTAT_A(rp->rx_channel)) & RCRSTAT_A_QLEN; in niu_rx_work()
3689 stat = le64_to_cpup(&mbox->rx_dma_ctl_stat); in niu_rx_work()
3690 qlen = (le64_to_cpup(&mbox->rcrstat_a) & RCRSTAT_A_QLEN); in niu_rx_work()
3692 mbox->rx_dma_ctl_stat = 0; in niu_rx_work()
3693 mbox->rcrstat_a = 0; in niu_rx_work()
3695 netif_printk(np, rx_status, KERN_DEBUG, np->dev, in niu_rx_work()
3697 __func__, rp->rx_channel, (unsigned long long)stat, qlen); in niu_rx_work()
3706 if (rp->rbr_refill_pending >= rp->rbr_kick_thresh) { in niu_rx_work()
3709 for (i = 0; i < rp->rbr_refill_pending; i++) in niu_rx_work()
3711 rp->rbr_refill_pending = 0; in niu_rx_work()
3718 nw64(RX_DMA_CTL_STAT(rp->rx_channel), stat); in niu_rx_work()
3729 u64 v0 = lp->v0; in niu_poll_core()
3734 netif_printk(np, intr, KERN_DEBUG, np->dev, in niu_poll_core()
3737 for (i = 0; i < np->num_tx_rings; i++) { in niu_poll_core()
3738 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_poll_core()
3739 if (tx_vec & (1 << rp->tx_channel)) in niu_poll_core()
3741 nw64(LD_IM0(LDN_TXDMA(rp->tx_channel)), 0); in niu_poll_core()
3744 for (i = 0; i < np->num_rx_rings; i++) { in niu_poll_core()
3745 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_poll_core()
3747 if (rx_vec & (1 << rp->rx_channel)) { in niu_poll_core()
3750 this_work_done = niu_rx_work(&lp->napi, np, rp, in niu_poll_core()
3753 budget -= this_work_done; in niu_poll_core()
3756 nw64(LD_IM0(LDN_RXDMA(rp->rx_channel)), 0); in niu_poll_core()
3765 struct niu *np = lp->np; in niu_poll()
3780 netdev_err(np->dev, "RX channel %u errors ( ", rp->rx_channel); in niu_log_rxchan_errors()
3816 u64 stat = nr64(RX_DMA_CTL_STAT(rp->rx_channel)); in niu_rx_error()
3822 err = -EINVAL; in niu_rx_error()
3825 netdev_err(np->dev, "RX channel %u error, stat[%llx]\n", in niu_rx_error()
3826 rp->rx_channel, in niu_rx_error()
3832 nw64(RX_DMA_CTL_STAT(rp->rx_channel), in niu_rx_error()
3841 netdev_err(np->dev, "TX channel %u errors ( ", rp->tx_channel); in niu_log_txchan_errors()
3867 cs = nr64(TX_CS(rp->tx_channel)); in niu_tx_error()
3868 logh = nr64(TX_RNG_ERR_LOGH(rp->tx_channel)); in niu_tx_error()
3869 logl = nr64(TX_RNG_ERR_LOGL(rp->tx_channel)); in niu_tx_error()
3871 netdev_err(np->dev, "TX channel %u error, cs[%llx] logh[%llx] logl[%llx]\n", in niu_tx_error()
3872 rp->tx_channel, in niu_tx_error()
3879 return -ENODEV; in niu_tx_error()
3887 if (np->flags & NIU_FLAGS_XMAC) { in niu_mif_interrupt()
3894 netdev_err(np->dev, "MIF interrupt, stat[%llx] phy_mdint(%d)\n", in niu_mif_interrupt()
3897 return -ENODEV; in niu_mif_interrupt()
3902 struct niu_xmac_stats *mp = &np->mac_stats.xmac; in niu_xmac_interrupt()
3907 mp->tx_frames += TXMAC_FRM_CNT_COUNT; in niu_xmac_interrupt()
3909 mp->tx_bytes += TXMAC_BYTE_CNT_COUNT; in niu_xmac_interrupt()
3911 mp->tx_fifo_errors++; in niu_xmac_interrupt()
3913 mp->tx_overflow_errors++; in niu_xmac_interrupt()
3915 mp->tx_max_pkt_size_errors++; in niu_xmac_interrupt()
3917 mp->tx_underflow_errors++; in niu_xmac_interrupt()
3921 mp->rx_local_faults++; in niu_xmac_interrupt()
3923 mp->rx_remote_faults++; in niu_xmac_interrupt()
3925 mp->rx_link_faults += LINK_FAULT_CNT_COUNT; in niu_xmac_interrupt()
3927 mp->rx_align_errors += RXMAC_ALIGN_ERR_CNT_COUNT; in niu_xmac_interrupt()
3929 mp->rx_frags += RXMAC_FRAG_CNT_COUNT; in niu_xmac_interrupt()
3931 mp->rx_mcasts += RXMAC_MC_FRM_CNT_COUNT; in niu_xmac_interrupt()
3933 mp->rx_bcasts += RXMAC_BC_FRM_CNT_COUNT; in niu_xmac_interrupt()
3935 mp->rx_bcasts += RXMAC_BC_FRM_CNT_COUNT; in niu_xmac_interrupt()
3937 mp->rx_hist_cnt1 += RXMAC_HIST_CNT1_COUNT; in niu_xmac_interrupt()
3939 mp->rx_hist_cnt2 += RXMAC_HIST_CNT2_COUNT; in niu_xmac_interrupt()
3941 mp->rx_hist_cnt3 += RXMAC_HIST_CNT3_COUNT; in niu_xmac_interrupt()
3943 mp->rx_hist_cnt4 += RXMAC_HIST_CNT4_COUNT; in niu_xmac_interrupt()
3945 mp->rx_hist_cnt5 += RXMAC_HIST_CNT5_COUNT; in niu_xmac_interrupt()
3947 mp->rx_hist_cnt6 += RXMAC_HIST_CNT6_COUNT; in niu_xmac_interrupt()
3949 mp->rx_hist_cnt7 += RXMAC_HIST_CNT7_COUNT; in niu_xmac_interrupt()
3951 mp->rx_octets += RXMAC_BT_CNT_COUNT; in niu_xmac_interrupt()
3953 mp->rx_code_violations += RXMAC_CD_VIO_CNT_COUNT; in niu_xmac_interrupt()
3955 mp->rx_len_errors += RXMAC_MPSZER_CNT_COUNT; in niu_xmac_interrupt()
3957 mp->rx_crc_errors += RXMAC_CRC_ER_CNT_COUNT; in niu_xmac_interrupt()
3959 mp->rx_underflows++; in niu_xmac_interrupt()
3961 mp->rx_overflows++; in niu_xmac_interrupt()
3965 mp->pause_off_state++; in niu_xmac_interrupt()
3967 mp->pause_on_state++; in niu_xmac_interrupt()
3969 mp->pause_received++; in niu_xmac_interrupt()
3974 struct niu_bmac_stats *mp = &np->mac_stats.bmac; in niu_bmac_interrupt()
3979 mp->tx_underflow_errors++; in niu_bmac_interrupt()
3981 mp->tx_max_pkt_size_errors++; in niu_bmac_interrupt()
3983 mp->tx_bytes += BTXMAC_BYTE_CNT_COUNT; in niu_bmac_interrupt()
3985 mp->tx_frames += BTXMAC_FRM_CNT_COUNT; in niu_bmac_interrupt()
3989 mp->rx_overflows++; in niu_bmac_interrupt()
3991 mp->rx_frames += BRXMAC_FRAME_CNT_COUNT; in niu_bmac_interrupt()
3993 mp->rx_align_errors += BRXMAC_ALIGN_ERR_CNT_COUNT; in niu_bmac_interrupt()
3995 mp->rx_crc_errors += BRXMAC_ALIGN_ERR_CNT_COUNT; in niu_bmac_interrupt()
3997 mp->rx_len_errors += BRXMAC_CODE_VIOL_ERR_CNT_COUNT; in niu_bmac_interrupt()
4001 mp->pause_off_state++; in niu_bmac_interrupt()
4003 mp->pause_on_state++; in niu_bmac_interrupt()
4005 mp->pause_received++; in niu_bmac_interrupt()
4010 if (np->flags & NIU_FLAGS_XMAC) in niu_mac_interrupt()
4020 netdev_err(np->dev, "Core device errors ( "); in niu_log_device_error()
4052 netdev_err(np->dev, "Core device error, stat[%llx]\n", in niu_device_error()
4057 return -ENODEV; in niu_device_error()
4066 lp->v0 = v0; in niu_slowpath_interrupt()
4067 lp->v1 = v1; in niu_slowpath_interrupt()
4068 lp->v2 = v2; in niu_slowpath_interrupt()
4073 for (i = 0; i < np->num_rx_rings; i++) { in niu_slowpath_interrupt()
4074 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_slowpath_interrupt()
4076 if (rx_vec & (1 << rp->rx_channel)) { in niu_slowpath_interrupt()
4082 nw64(RX_DMA_CTL_STAT(rp->rx_channel), in niu_slowpath_interrupt()
4091 for (i = 0; i < np->num_tx_rings; i++) { in niu_slowpath_interrupt()
4092 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_slowpath_interrupt()
4094 if (tx_vec & (1 << rp->tx_channel)) { in niu_slowpath_interrupt()
4128 struct rxdma_mailbox *mbox = rp->mbox; in niu_rxchan_intr()
4129 u64 stat_write, stat = le64_to_cpup(&mbox->rx_dma_ctl_stat); in niu_rxchan_intr()
4133 nw64(RX_DMA_CTL_STAT(rp->rx_channel), stat_write); in niu_rxchan_intr()
4135 netif_printk(np, intr, KERN_DEBUG, np->dev, in niu_rxchan_intr()
4142 rp->tx_cs = nr64(TX_CS(rp->tx_channel)); in niu_txchan_intr()
4144 netif_printk(np, intr, KERN_DEBUG, np->dev, in niu_txchan_intr()
4145 "%s() cs[%llx]\n", __func__, (unsigned long long)rp->tx_cs); in niu_txchan_intr()
4150 struct niu_parent *parent = np->parent; in __niu_fastpath_interrupt()
4157 for (i = 0; i < np->num_rx_rings; i++) { in __niu_fastpath_interrupt()
4158 struct rx_ring_info *rp = &np->rx_rings[i]; in __niu_fastpath_interrupt()
4159 int ldn = LDN_RXDMA(rp->rx_channel); in __niu_fastpath_interrupt()
4161 if (parent->ldg_map[ldn] != ldg) in __niu_fastpath_interrupt()
4165 if (rx_vec & (1 << rp->rx_channel)) in __niu_fastpath_interrupt()
4169 for (i = 0; i < np->num_tx_rings; i++) { in __niu_fastpath_interrupt()
4170 struct tx_ring_info *rp = &np->tx_rings[i]; in __niu_fastpath_interrupt()
4171 int ldn = LDN_TXDMA(rp->tx_channel); in __niu_fastpath_interrupt()
4173 if (parent->ldg_map[ldn] != ldg) in __niu_fastpath_interrupt()
4177 if (tx_vec & (1 << rp->tx_channel)) in __niu_fastpath_interrupt()
4185 if (likely(napi_schedule_prep(&lp->napi))) { in niu_schedule_napi()
4186 lp->v0 = v0; in niu_schedule_napi()
4187 lp->v1 = v1; in niu_schedule_napi()
4188 lp->v2 = v2; in niu_schedule_napi()
4189 __niu_fastpath_interrupt(np, lp->ldg_num, v0); in niu_schedule_napi()
4190 __napi_schedule(&lp->napi); in niu_schedule_napi()
4197 struct niu *np = lp->np; in niu_interrupt()
4198 int ldg = lp->ldg_num; in niu_interrupt()
4206 spin_lock_irqsave(&np->lock, flags); in niu_interrupt()
4219 spin_unlock_irqrestore(&np->lock, flags); in niu_interrupt()
4233 spin_unlock_irqrestore(&np->lock, flags); in niu_interrupt()
4240 if (rp->mbox) { in niu_free_rx_ring_info()
4241 np->ops->free_coherent(np->device, in niu_free_rx_ring_info()
4243 rp->mbox, rp->mbox_dma); in niu_free_rx_ring_info()
4244 rp->mbox = NULL; in niu_free_rx_ring_info()
4246 if (rp->rcr) { in niu_free_rx_ring_info()
4247 np->ops->free_coherent(np->device, in niu_free_rx_ring_info()
4249 rp->rcr, rp->rcr_dma); in niu_free_rx_ring_info()
4250 rp->rcr = NULL; in niu_free_rx_ring_info()
4251 rp->rcr_table_size = 0; in niu_free_rx_ring_info()
4252 rp->rcr_index = 0; in niu_free_rx_ring_info()
4254 if (rp->rbr) { in niu_free_rx_ring_info()
4257 np->ops->free_coherent(np->device, in niu_free_rx_ring_info()
4259 rp->rbr, rp->rbr_dma); in niu_free_rx_ring_info()
4260 rp->rbr = NULL; in niu_free_rx_ring_info()
4261 rp->rbr_table_size = 0; in niu_free_rx_ring_info()
4262 rp->rbr_index = 0; in niu_free_rx_ring_info()
4264 kfree(rp->rxhash); in niu_free_rx_ring_info()
4265 rp->rxhash = NULL; in niu_free_rx_ring_info()
4270 if (rp->mbox) { in niu_free_tx_ring_info()
4271 np->ops->free_coherent(np->device, in niu_free_tx_ring_info()
4273 rp->mbox, rp->mbox_dma); in niu_free_tx_ring_info()
4274 rp->mbox = NULL; in niu_free_tx_ring_info()
4276 if (rp->descr) { in niu_free_tx_ring_info()
4280 if (rp->tx_buffs[i].skb) in niu_free_tx_ring_info()
4284 np->ops->free_coherent(np->device, in niu_free_tx_ring_info()
4286 rp->descr, rp->descr_dma); in niu_free_tx_ring_info()
4287 rp->descr = NULL; in niu_free_tx_ring_info()
4288 rp->pending = 0; in niu_free_tx_ring_info()
4289 rp->prod = 0; in niu_free_tx_ring_info()
4290 rp->cons = 0; in niu_free_tx_ring_info()
4291 rp->wrap_bit = 0; in niu_free_tx_ring_info()
4299 if (np->rx_rings) { in niu_free_channels()
4300 for (i = 0; i < np->num_rx_rings; i++) { in niu_free_channels()
4301 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_free_channels()
4305 kfree(np->rx_rings); in niu_free_channels()
4306 np->rx_rings = NULL; in niu_free_channels()
4307 np->num_rx_rings = 0; in niu_free_channels()
4310 if (np->tx_rings) { in niu_free_channels()
4311 for (i = 0; i < np->num_tx_rings; i++) { in niu_free_channels()
4312 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_free_channels()
4316 kfree(np->tx_rings); in niu_free_channels()
4317 np->tx_rings = NULL; in niu_free_channels()
4318 np->num_tx_rings = 0; in niu_free_channels()
4327 rp->rxhash = kcalloc(MAX_RBR_RING_SIZE, sizeof(struct page *), in niu_alloc_rx_ring_info()
4329 if (!rp->rxhash) in niu_alloc_rx_ring_info()
4330 return -ENOMEM; in niu_alloc_rx_ring_info()
4332 rp->mbox = np->ops->alloc_coherent(np->device, in niu_alloc_rx_ring_info()
4334 &rp->mbox_dma, GFP_KERNEL); in niu_alloc_rx_ring_info()
4335 if (!rp->mbox) in niu_alloc_rx_ring_info()
4336 return -ENOMEM; in niu_alloc_rx_ring_info()
4337 if ((unsigned long)rp->mbox & (64UL - 1)) { in niu_alloc_rx_ring_info()
4338 netdev_err(np->dev, "Coherent alloc gives misaligned RXDMA mailbox %p\n", in niu_alloc_rx_ring_info()
4339 rp->mbox); in niu_alloc_rx_ring_info()
4340 return -EINVAL; in niu_alloc_rx_ring_info()
4343 rp->rcr = np->ops->alloc_coherent(np->device, in niu_alloc_rx_ring_info()
4345 &rp->rcr_dma, GFP_KERNEL); in niu_alloc_rx_ring_info()
4346 if (!rp->rcr) in niu_alloc_rx_ring_info()
4347 return -ENOMEM; in niu_alloc_rx_ring_info()
4348 if ((unsigned long)rp->rcr & (64UL - 1)) { in niu_alloc_rx_ring_info()
4349 netdev_err(np->dev, "Coherent alloc gives misaligned RXDMA RCR table %p\n", in niu_alloc_rx_ring_info()
4350 rp->rcr); in niu_alloc_rx_ring_info()
4351 return -EINVAL; in niu_alloc_rx_ring_info()
4353 rp->rcr_table_size = MAX_RCR_RING_SIZE; in niu_alloc_rx_ring_info()
4354 rp->rcr_index = 0; in niu_alloc_rx_ring_info()
4356 rp->rbr = np->ops->alloc_coherent(np->device, in niu_alloc_rx_ring_info()
4358 &rp->rbr_dma, GFP_KERNEL); in niu_alloc_rx_ring_info()
4359 if (!rp->rbr) in niu_alloc_rx_ring_info()
4360 return -ENOMEM; in niu_alloc_rx_ring_info()
4361 if ((unsigned long)rp->rbr & (64UL - 1)) { in niu_alloc_rx_ring_info()
4362 netdev_err(np->dev, "Coherent alloc gives misaligned RXDMA RBR table %p\n", in niu_alloc_rx_ring_info()
4363 rp->rbr); in niu_alloc_rx_ring_info()
4364 return -EINVAL; in niu_alloc_rx_ring_info()
4366 rp->rbr_table_size = MAX_RBR_RING_SIZE; in niu_alloc_rx_ring_info()
4367 rp->rbr_index = 0; in niu_alloc_rx_ring_info()
4368 rp->rbr_pending = 0; in niu_alloc_rx_ring_info()
4375 int mtu = np->dev->mtu; in niu_set_max_burst()
4380 rp->max_burst = mtu + 32; in niu_set_max_burst()
4381 if (rp->max_burst > 4096) in niu_set_max_burst()
4382 rp->max_burst = 4096; in niu_set_max_burst()
4390 rp->mbox = np->ops->alloc_coherent(np->device, in niu_alloc_tx_ring_info()
4392 &rp->mbox_dma, GFP_KERNEL); in niu_alloc_tx_ring_info()
4393 if (!rp->mbox) in niu_alloc_tx_ring_info()
4394 return -ENOMEM; in niu_alloc_tx_ring_info()
4395 if ((unsigned long)rp->mbox & (64UL - 1)) { in niu_alloc_tx_ring_info()
4396 netdev_err(np->dev, "Coherent alloc gives misaligned TXDMA mailbox %p\n", in niu_alloc_tx_ring_info()
4397 rp->mbox); in niu_alloc_tx_ring_info()
4398 return -EINVAL; in niu_alloc_tx_ring_info()
4401 rp->descr = np->ops->alloc_coherent(np->device, in niu_alloc_tx_ring_info()
4403 &rp->descr_dma, GFP_KERNEL); in niu_alloc_tx_ring_info()
4404 if (!rp->descr) in niu_alloc_tx_ring_info()
4405 return -ENOMEM; in niu_alloc_tx_ring_info()
4406 if ((unsigned long)rp->descr & (64UL - 1)) { in niu_alloc_tx_ring_info()
4407 netdev_err(np->dev, "Coherent alloc gives misaligned TXDMA descr table %p\n", in niu_alloc_tx_ring_info()
4408 rp->descr); in niu_alloc_tx_ring_info()
4409 return -EINVAL; in niu_alloc_tx_ring_info()
4412 rp->pending = MAX_TX_RING_SIZE; in niu_alloc_tx_ring_info()
4413 rp->prod = 0; in niu_alloc_tx_ring_info()
4414 rp->cons = 0; in niu_alloc_tx_ring_info()
4415 rp->wrap_bit = 0; in niu_alloc_tx_ring_info()
4418 rp->mark_freq = rp->pending / 4; in niu_alloc_tx_ring_info()
4431 rp->rbr_block_size = 1 << bss; in niu_size_rbr()
4432 rp->rbr_blocks_per_page = 1 << (PAGE_SHIFT-bss); in niu_size_rbr()
4434 rp->rbr_sizes[0] = 256; in niu_size_rbr()
4435 rp->rbr_sizes[1] = 1024; in niu_size_rbr()
4436 if (np->dev->mtu > ETH_DATA_LEN) { in niu_size_rbr()
4439 rp->rbr_sizes[2] = 4096; in niu_size_rbr()
4443 rp->rbr_sizes[2] = 8192; in niu_size_rbr()
4447 rp->rbr_sizes[2] = 2048; in niu_size_rbr()
4449 rp->rbr_sizes[3] = rp->rbr_block_size; in niu_size_rbr()
4454 struct niu_parent *parent = np->parent; in niu_alloc_channels()
4461 port = np->port; in niu_alloc_channels()
4464 first_rx_channel += parent->rxchan_per_port[i]; in niu_alloc_channels()
4465 first_tx_channel += parent->txchan_per_port[i]; in niu_alloc_channels()
4468 num_rx_rings = parent->rxchan_per_port[port]; in niu_alloc_channels()
4469 num_tx_rings = parent->txchan_per_port[port]; in niu_alloc_channels()
4473 err = -ENOMEM; in niu_alloc_channels()
4477 np->num_rx_rings = num_rx_rings; in niu_alloc_channels()
4479 np->rx_rings = rx_rings; in niu_alloc_channels()
4481 netif_set_real_num_rx_queues(np->dev, num_rx_rings); in niu_alloc_channels()
4483 for (i = 0; i < np->num_rx_rings; i++) { in niu_alloc_channels()
4484 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_alloc_channels()
4486 rp->np = np; in niu_alloc_channels()
4487 rp->rx_channel = first_rx_channel + i; in niu_alloc_channels()
4496 rp->nonsyn_window = 64; in niu_alloc_channels()
4497 rp->nonsyn_threshold = rp->rcr_table_size - 64; in niu_alloc_channels()
4498 rp->syn_window = 64; in niu_alloc_channels()
4499 rp->syn_threshold = rp->rcr_table_size - 64; in niu_alloc_channels()
4500 rp->rcr_pkt_threshold = 16; in niu_alloc_channels()
4501 rp->rcr_timeout = 8; in niu_alloc_channels()
4502 rp->rbr_kick_thresh = RBR_REFILL_MIN; in niu_alloc_channels()
4503 if (rp->rbr_kick_thresh < rp->rbr_blocks_per_page) in niu_alloc_channels()
4504 rp->rbr_kick_thresh = rp->rbr_blocks_per_page; in niu_alloc_channels()
4513 err = -ENOMEM; in niu_alloc_channels()
4517 np->num_tx_rings = num_tx_rings; in niu_alloc_channels()
4519 np->tx_rings = tx_rings; in niu_alloc_channels()
4521 netif_set_real_num_tx_queues(np->dev, num_tx_rings); in niu_alloc_channels()
4523 for (i = 0; i < np->num_tx_rings; i++) { in niu_alloc_channels()
4524 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_alloc_channels()
4526 rp->np = np; in niu_alloc_channels()
4527 rp->tx_channel = first_tx_channel + i; in niu_alloc_channels()
4545 while (--limit > 0) { in niu_tx_cs_sng_poll()
4550 return -ENODEV; in niu_tx_cs_sng_poll()
4567 while (--limit > 0) { in niu_tx_cs_reset_poll()
4572 return -ENODEV; in niu_tx_cs_reset_poll()
4602 val = (u64)np->port << TX_LOG_PAGE_VLD_FUNC_SHIFT; in niu_tx_channel_lpage_init()
4618 mask = (u64)1 << np->port; in niu_txc_enable_port()
4637 val &= ~TXC_INT_MASK_VAL(np->port); in niu_txc_set_imask()
4638 val |= (imask << TXC_INT_MASK_VAL_SHIFT(np->port)); in niu_txc_set_imask()
4649 for (i = 0; i < np->num_tx_rings; i++) in niu_txc_port_dma_enable()
4650 val |= (1 << np->tx_rings[i].tx_channel); in niu_txc_port_dma_enable()
4652 nw64(TXC_PORT_DMA(np->port), val); in niu_txc_port_dma_enable()
4657 int err, channel = rp->tx_channel; in niu_init_one_tx_channel()
4672 nw64(TXC_DMA_MAX(channel), rp->max_burst); in niu_init_one_tx_channel()
4675 if (rp->descr_dma & ~(TX_RNG_CFIG_STADDR_BASE | in niu_init_one_tx_channel()
4677 netdev_err(np->dev, "TX ring channel %d DMA addr (%llx) is not aligned\n", in niu_init_one_tx_channel()
4678 channel, (unsigned long long)rp->descr_dma); in niu_init_one_tx_channel()
4679 return -EINVAL; in niu_init_one_tx_channel()
4682 /* The length field in TX_RNG_CFIG is measured in 64-byte in niu_init_one_tx_channel()
4683 * blocks. rp->pending is the number of TX descriptors in in niu_init_one_tx_channel()
4687 ring_len = (rp->pending / 8); in niu_init_one_tx_channel()
4690 rp->descr_dma); in niu_init_one_tx_channel()
4693 if (((rp->mbox_dma >> 32) & ~TXDMA_MBH_MBADDR) || in niu_init_one_tx_channel()
4694 ((u32)rp->mbox_dma & ~TXDMA_MBL_MBADDR)) { in niu_init_one_tx_channel()
4695 netdev_err(np->dev, "TX ring channel %d MBOX addr (%llx) has invalid bits\n", in niu_init_one_tx_channel()
4696 channel, (unsigned long long)rp->mbox_dma); in niu_init_one_tx_channel()
4697 return -EINVAL; in niu_init_one_tx_channel()
4699 nw64(TXDMA_MBH(channel), rp->mbox_dma >> 32); in niu_init_one_tx_channel()
4700 nw64(TXDMA_MBL(channel), rp->mbox_dma & TXDMA_MBL_MBADDR); in niu_init_one_tx_channel()
4704 rp->last_pkt_cnt = 0; in niu_init_one_tx_channel()
4711 struct niu_rdc_tables *tp = &np->parent->rdc_group_cfg[np->port]; in niu_init_rdc_groups()
4712 int i, first_table_num = tp->first_table_num; in niu_init_rdc_groups()
4714 for (i = 0; i < tp->num_tables; i++) { in niu_init_rdc_groups()
4715 struct rdc_table *tbl = &tp->tables[i]; in niu_init_rdc_groups()
4721 tbl->rxdma_channel[slot]); in niu_init_rdc_groups()
4724 nw64(DEF_RDC(np->port), np->parent->rdc_default[np->port]); in niu_init_rdc_groups()
4729 int type = phy_decode(np->parent->port_phy, np->port); in niu_init_drr_weight()
4742 nw64(PT_DRR_WT(np->port), val); in niu_init_drr_weight()
4747 struct niu_parent *parent = np->parent; in niu_init_hostinfo()
4748 struct niu_rdc_tables *tp = &parent->rdc_group_cfg[np->port]; in niu_init_hostinfo()
4750 int first_rdc_table = tp->first_table_num; in niu_init_hostinfo()
4788 val = (u64)np->port << RX_LOG_PAGE_VLD_FUNC_SHIFT; in niu_rx_channel_lpage_init()
4799 val = (((u64)rp->nonsyn_window << RDC_RED_PARA_WIN_SHIFT) | in niu_rx_channel_wred_init()
4800 ((u64)rp->nonsyn_threshold << RDC_RED_PARA_THRE_SHIFT) | in niu_rx_channel_wred_init()
4801 ((u64)rp->syn_window << RDC_RED_PARA_WIN_SYN_SHIFT) | in niu_rx_channel_wred_init()
4802 ((u64)rp->syn_threshold << RDC_RED_PARA_THRE_SYN_SHIFT)); in niu_rx_channel_wred_init()
4803 nw64(RDC_RED_PARA(rp->rx_channel), val); in niu_rx_channel_wred_init()
4811 switch (rp->rbr_block_size) { in niu_compute_rbr_cfig_b()
4825 return -EINVAL; in niu_compute_rbr_cfig_b()
4828 switch (rp->rbr_sizes[2]) { in niu_compute_rbr_cfig_b()
4843 return -EINVAL; in niu_compute_rbr_cfig_b()
4846 switch (rp->rbr_sizes[1]) { in niu_compute_rbr_cfig_b()
4861 return -EINVAL; in niu_compute_rbr_cfig_b()
4864 switch (rp->rbr_sizes[0]) { in niu_compute_rbr_cfig_b()
4879 return -EINVAL; in niu_compute_rbr_cfig_b()
4898 while (--limit > 0) { in niu_enable_rx_channel()
4904 return -ENODEV; in niu_enable_rx_channel()
4910 int err, channel = rp->rx_channel; in niu_init_one_rx_channel()
4929 nw64(RXDMA_CFIG1(channel), rp->mbox_dma >> 32); in niu_init_one_rx_channel()
4931 ((rp->mbox_dma & RXDMA_CFIG2_MBADDR_L) | in niu_init_one_rx_channel()
4934 ((u64)rp->rbr_table_size << RBR_CFIG_A_LEN_SHIFT) | in niu_init_one_rx_channel()
4935 (rp->rbr_dma & (RBR_CFIG_A_STADDR_BASE | RBR_CFIG_A_STADDR))); in niu_init_one_rx_channel()
4941 ((u64)rp->rcr_table_size << RCRCFIG_A_LEN_SHIFT) | in niu_init_one_rx_channel()
4942 (rp->rcr_dma & (RCRCFIG_A_STADDR_BASE | RCRCFIG_A_STADDR))); in niu_init_one_rx_channel()
4944 ((u64)rp->rcr_pkt_threshold << RCRCFIG_B_PTHRES_SHIFT) | in niu_init_one_rx_channel()
4946 ((u64)rp->rcr_timeout << RCRCFIG_B_TIMEOUT_SHIFT)); in niu_init_one_rx_channel()
4952 nw64(RBR_KICK(channel), rp->rbr_index); in niu_init_one_rx_channel()
4968 nw64(RX_DMA_CK_DIV, np->parent->rxdma_clock_divider); in niu_init_rx_channels()
4981 for (i = 0; i < np->num_rx_rings; i++) { in niu_init_rx_channels()
4982 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_init_rx_channels()
4994 struct niu_parent *parent = np->parent; in niu_set_ip_frag_rule()
4995 struct niu_classifier *cp = &np->clas; in niu_set_ip_frag_rule()
4999 index = cp->tcam_top; in niu_set_ip_frag_rule()
5000 tp = &parent->tcam[index]; in niu_set_ip_frag_rule()
5006 tp->key[1] = TCAM_V4KEY1_NOPORT; in niu_set_ip_frag_rule()
5007 tp->key_mask[1] = TCAM_V4KEY1_NOPORT; in niu_set_ip_frag_rule()
5008 tp->assoc_data = (TCAM_ASSOCDATA_TRES_USE_OFFSET | in niu_set_ip_frag_rule()
5010 err = tcam_write(np, index, tp->key, tp->key_mask); in niu_set_ip_frag_rule()
5013 err = tcam_assoc_write(np, index, tp->assoc_data); in niu_set_ip_frag_rule()
5016 tp->valid = 1; in niu_set_ip_frag_rule()
5017 cp->tcam_valid_entries++; in niu_set_ip_frag_rule()
5024 struct niu_parent *parent = np->parent; in niu_init_classifier_hw()
5025 struct niu_classifier *cp = &np->clas; in niu_init_classifier_hw()
5028 nw64(H1POLY, cp->h1_init); in niu_init_classifier_hw()
5029 nw64(H2POLY, cp->h2_init); in niu_init_classifier_hw()
5036 struct niu_vlan_rdc *vp = &cp->vlan_mappings[i]; in niu_init_classifier_hw()
5038 vlan_tbl_write(np, i, np->port, in niu_init_classifier_hw()
5039 vp->vlan_pref, vp->rdc_num); in niu_init_classifier_hw()
5042 for (i = 0; i < cp->num_alt_mac_mappings; i++) { in niu_init_classifier_hw()
5043 struct niu_altmac_rdc *ap = &cp->alt_mac_mappings[i]; in niu_init_classifier_hw()
5045 err = niu_set_alt_mac_rdc_table(np, ap->alt_mac_num, in niu_init_classifier_hw()
5046 ap->rdc_num, ap->mac_pref); in niu_init_classifier_hw()
5052 int index = i - CLASS_CODE_USER_PROG1; in niu_init_classifier_hw()
5054 err = niu_set_tcam_key(np, i, parent->tcam_key[index]); in niu_init_classifier_hw()
5057 err = niu_set_flow_key(np, i, parent->flow_key[index]); in niu_init_classifier_hw()
5082 (ZCP_RAM_SEL_CFIFO(np->port) << ZCP_RAM_ACC_RAM_SEL_SHIFT))); in niu_zcp_write()
5095 netdev_err(np->dev, "ZCP read busy won't clear, ZCP_RAM_ACC[%llx]\n", in niu_zcp_read()
5103 (ZCP_RAM_SEL_CFIFO(np->port) << ZCP_RAM_ACC_RAM_SEL_SHIFT))); in niu_zcp_read()
5108 netdev_err(np->dev, "ZCP read busy2 won't clear, ZCP_RAM_ACC[%llx]\n", in niu_zcp_read()
5126 val |= RESET_CFIFO_RST(np->port); in niu_zcp_cfifo_reset()
5130 val &= ~RESET_CFIFO_RST(np->port); in niu_zcp_cfifo_reset()
5139 if (np->parent->plat_type != PLAT_TYPE_NIU) { in niu_init_zcp()
5140 if (np->port == 0 || np->port == 1) in niu_init_zcp()
5163 nw64(CFIFO_ECC(np->port), 0); in niu_init_zcp()
5206 if (np->parent->plat_type != PLAT_TYPE_NIU) { in niu_init_ipp()
5207 if (np->port == 0 || np->port == 1) in niu_init_ipp()
5257 if ((np->flags & NIU_FLAGS_10G) != 0 && in niu_handle_led()
5258 (np->flags & NIU_FLAGS_FIBER) != 0) { in niu_handle_led()
5273 struct niu_link_config *lp = &np->link_config; in niu_init_xif_xmac()
5276 if (np->flags & NIU_FLAGS_XCVR_SERDES) { in niu_init_xif_xmac()
5287 if (lp->loopback_mode == LOOPBACK_MAC) { in niu_init_xif_xmac()
5294 if (np->flags & NIU_FLAGS_10G) { in niu_init_xif_xmac()
5298 if (!(np->flags & NIU_FLAGS_FIBER) && in niu_init_xif_xmac()
5299 !(np->flags & NIU_FLAGS_XCVR_SERDES)) in niu_init_xif_xmac()
5307 if (lp->active_speed == SPEED_100) in niu_init_xif_xmac()
5316 if (np->flags & NIU_FLAGS_10G) { in niu_init_xif_xmac()
5319 if (lp->active_speed == SPEED_1000) in niu_init_xif_xmac()
5330 struct niu_link_config *lp = &np->link_config; in niu_init_xif_bmac()
5335 if (lp->loopback_mode == LOOPBACK_MAC) in niu_init_xif_bmac()
5340 if (lp->active_speed == SPEED_1000) in niu_init_xif_bmac()
5348 if (!(np->flags & NIU_FLAGS_10G) && in niu_init_xif_bmac()
5349 !(np->flags & NIU_FLAGS_FIBER) && in niu_init_xif_bmac()
5350 lp->active_speed == SPEED_100) in niu_init_xif_bmac()
5360 if (np->flags & NIU_FLAGS_XMAC) in niu_init_xif()
5372 while ((--limit >= 0) && (val & PCS_MII_CTL_RST)) { in niu_pcs_mii_reset()
5384 while ((--limit >= 0) && (val & XPCS_CONTROL1_RESET)) { in niu_xpcs_reset()
5392 struct niu_link_config *lp = &np->link_config; in niu_init_pcs()
5395 switch (np->flags & (NIU_FLAGS_10G | in niu_init_pcs()
5399 /* 1G fiber */ in niu_init_pcs()
5408 /* 10G SERDES */ in niu_init_pcs()
5409 if (!(np->flags & NIU_FLAGS_XMAC)) in niu_init_pcs()
5410 return -EINVAL; in niu_init_pcs()
5412 /* 10G copper or fiber */ in niu_init_pcs()
5420 if (lp->loopback_mode == LOOPBACK_PHY) in niu_init_pcs()
5433 /* 1G SERDES */ in niu_init_pcs()
5440 /* 1G copper */ in niu_init_pcs()
5442 /* 1G RGMII FIBER */ in niu_init_pcs()
5448 return -EINVAL; in niu_init_pcs()
5468 while (--limit >= 0) { in niu_reset_tx_bmac()
5474 dev_err(np->device, "Port %u TX BMAC would not reset, BTXMAC_SW_RST[%llx]\n", in niu_reset_tx_bmac()
5475 np->port, in niu_reset_tx_bmac()
5477 return -ENODEV; in niu_reset_tx_bmac()
5485 if (np->flags & NIU_FLAGS_XMAC) in niu_reset_tx_mac()
5507 if (np->flags & NIU_FLAGS_10G) { in niu_init_tx_xmac()
5549 if (np->dev->mtu > ETH_DATA_LEN) in niu_init_tx_mac()
5559 if (np->flags & NIU_FLAGS_XMAC) in niu_init_tx_mac()
5572 while (--limit >= 0) { in niu_reset_rx_xmac()
5579 dev_err(np->device, "Port %u RX XMAC would not reset, XRXMAC_SW_RST[%llx]\n", in niu_reset_rx_xmac()
5580 np->port, in niu_reset_rx_xmac()
5582 return -ENODEV; in niu_reset_rx_xmac()
5594 while (--limit >= 0) { in niu_reset_rx_bmac()
5600 dev_err(np->device, "Port %u RX BMAC would not reset, BRXMAC_SW_RST[%llx]\n", in niu_reset_rx_bmac()
5601 np->port, in niu_reset_rx_bmac()
5603 return -ENODEV; in niu_reset_rx_bmac()
5611 if (np->flags & NIU_FLAGS_XMAC) in niu_reset_rx_mac()
5619 struct niu_parent *parent = np->parent; in niu_init_rx_xmac()
5620 struct niu_rdc_tables *tp = &parent->rdc_group_cfg[np->port]; in niu_init_rx_xmac()
5621 int first_rdc_table = tp->first_table_num; in niu_init_rx_xmac()
5671 struct niu_parent *parent = np->parent; in niu_init_rx_bmac()
5672 struct niu_rdc_tables *tp = &parent->rdc_group_cfg[np->port]; in niu_init_rx_bmac()
5673 int first_rdc_table = tp->first_table_num; in niu_init_rx_bmac()
5706 niu_set_primary_mac(np, np->dev->dev_addr); in niu_init_rx_mac()
5708 if (np->flags & NIU_FLAGS_XMAC) in niu_init_rx_mac()
5738 if (np->flags & NIU_FLAGS_XMAC) in niu_enable_tx_mac()
5751 if (np->flags & NIU_FLAGS_MCAST) in niu_enable_rx_xmac()
5753 if (np->flags & NIU_FLAGS_PROMISC) in niu_enable_rx_xmac()
5770 if (np->flags & NIU_FLAGS_MCAST) in niu_enable_rx_bmac()
5772 if (np->flags & NIU_FLAGS_PROMISC) in niu_enable_rx_bmac()
5784 if (np->flags & NIU_FLAGS_XMAC) in niu_enable_rx_mac()
5823 (void) niu_tx_channel_stop(np, rp->tx_channel); in niu_stop_one_tx_channel()
5830 for (i = 0; i < np->num_tx_rings; i++) { in niu_stop_tx_channels()
5831 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_stop_tx_channels()
5839 (void) niu_tx_channel_reset(np, rp->tx_channel); in niu_reset_one_tx_channel()
5846 for (i = 0; i < np->num_tx_rings; i++) { in niu_reset_tx_channels()
5847 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_reset_tx_channels()
5855 (void) niu_enable_rx_channel(np, rp->rx_channel, 0); in niu_stop_one_rx_channel()
5862 for (i = 0; i < np->num_rx_rings; i++) { in niu_stop_rx_channels()
5863 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_stop_rx_channels()
5871 int channel = rp->rx_channel; in niu_reset_one_rx_channel()
5883 for (i = 0; i < np->num_rx_rings; i++) { in niu_reset_rx_channels()
5884 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_reset_rx_channels()
5898 while (--limit >= 0 && (rd != wr)) { in niu_disable_ipp()
5904 netdev_err(np->dev, "IPP would not quiesce, rd_ptr[%llx] wr_ptr[%llx]\n", in niu_disable_ipp()
5923 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize TXC\n"); in niu_init_hw()
5928 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize TX channels\n"); in niu_init_hw()
5929 for (i = 0; i < np->num_tx_rings; i++) { in niu_init_hw()
5930 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_init_hw()
5937 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize RX channels\n"); in niu_init_hw()
5942 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize classifier\n"); in niu_init_hw()
5947 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize ZCP\n"); in niu_init_hw()
5952 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize IPP\n"); in niu_init_hw()
5957 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Initialize MAC\n"); in niu_init_hw()
5965 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Uninit IPP\n"); in niu_init_hw()
5969 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Uninit RX channels\n"); in niu_init_hw()
5974 netif_printk(np, ifup, KERN_DEBUG, np->dev, "Uninit TX channels\n"); in niu_init_hw()
5983 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Disable interrupts\n"); in niu_stop_hw()
5986 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Disable RX MAC\n"); in niu_stop_hw()
5989 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Disable IPP\n"); in niu_stop_hw()
5992 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Stop TX channels\n"); in niu_stop_hw()
5995 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Stop RX channels\n"); in niu_stop_hw()
5998 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Reset TX channels\n"); in niu_stop_hw()
6001 netif_printk(np, ifdown, KERN_DEBUG, np->dev, "Reset RX channels\n"); in niu_stop_hw()
6007 int port = np->port; in niu_set_irq_name()
6010 sprintf(np->irq_name[0], "%s:MAC", np->dev->name); in niu_set_irq_name()
6013 sprintf(np->irq_name[1], "%s:MIF", np->dev->name); in niu_set_irq_name()
6014 sprintf(np->irq_name[2], "%s:SYSERR", np->dev->name); in niu_set_irq_name()
6018 for (i = 0; i < np->num_ldg - j; i++) { in niu_set_irq_name()
6019 if (i < np->num_rx_rings) in niu_set_irq_name()
6020 sprintf(np->irq_name[i+j], "%s-rx-%d", in niu_set_irq_name()
6021 np->dev->name, i); in niu_set_irq_name()
6022 else if (i < np->num_tx_rings + np->num_rx_rings) in niu_set_irq_name()
6023 sprintf(np->irq_name[i+j], "%s-tx-%d", np->dev->name, in niu_set_irq_name()
6024 i - np->num_rx_rings); in niu_set_irq_name()
6035 for (i = 0; i < np->num_ldg; i++) { in niu_request_irq()
6036 struct niu_ldg *lp = &np->ldg[i]; in niu_request_irq()
6038 err = request_irq(lp->irq, niu_interrupt, IRQF_SHARED, in niu_request_irq()
6039 np->irq_name[i], lp); in niu_request_irq()
6049 struct niu_ldg *lp = &np->ldg[j]; in niu_request_irq()
6051 free_irq(lp->irq, lp); in niu_request_irq()
6060 for (i = 0; i < np->num_ldg; i++) { in niu_free_irq()
6061 struct niu_ldg *lp = &np->ldg[i]; in niu_free_irq()
6063 free_irq(lp->irq, lp); in niu_free_irq()
6071 for (i = 0; i < np->num_ldg; i++) in niu_enable_napi()
6072 napi_enable(&np->ldg[i].napi); in niu_enable_napi()
6079 for (i = 0; i < np->num_ldg; i++) in niu_disable_napi()
6080 napi_disable(&np->ldg[i].napi); in niu_disable_napi()
6104 spin_lock_irq(&np->lock); in niu_open()
6108 timer_setup(&np->timer, niu_timer, 0); in niu_open()
6109 np->timer.expires = jiffies + HZ; in niu_open()
6116 spin_unlock_irq(&np->lock); in niu_open()
6125 if (np->link_config.loopback_mode != LOOPBACK_DISABLED) in niu_open()
6128 add_timer(&np->timer); in niu_open()
6144 cancel_work_sync(&np->reset_task); in niu_full_shutdown()
6149 del_timer_sync(&np->timer); in niu_full_shutdown()
6151 spin_lock_irq(&np->lock); in niu_full_shutdown()
6155 spin_unlock_irq(&np->lock); in niu_full_shutdown()
6175 struct niu_xmac_stats *mp = &np->mac_stats.xmac; in niu_sync_xmac_stats()
6177 mp->tx_frames += nr64_mac(TXMAC_FRM_CNT); in niu_sync_xmac_stats()
6178 mp->tx_bytes += nr64_mac(TXMAC_BYTE_CNT); in niu_sync_xmac_stats()
6180 mp->rx_link_faults += nr64_mac(LINK_FAULT_CNT); in niu_sync_xmac_stats()
6181 mp->rx_align_errors += nr64_mac(RXMAC_ALIGN_ERR_CNT); in niu_sync_xmac_stats()
6182 mp->rx_frags += nr64_mac(RXMAC_FRAG_CNT); in niu_sync_xmac_stats()
6183 mp->rx_mcasts += nr64_mac(RXMAC_MC_FRM_CNT); in niu_sync_xmac_stats()
6184 mp->rx_bcasts += nr64_mac(RXMAC_BC_FRM_CNT); in niu_sync_xmac_stats()
6185 mp->rx_hist_cnt1 += nr64_mac(RXMAC_HIST_CNT1); in niu_sync_xmac_stats()
6186 mp->rx_hist_cnt2 += nr64_mac(RXMAC_HIST_CNT2); in niu_sync_xmac_stats()
6187 mp->rx_hist_cnt3 += nr64_mac(RXMAC_HIST_CNT3); in niu_sync_xmac_stats()
6188 mp->rx_hist_cnt4 += nr64_mac(RXMAC_HIST_CNT4); in niu_sync_xmac_stats()
6189 mp->rx_hist_cnt5 += nr64_mac(RXMAC_HIST_CNT5); in niu_sync_xmac_stats()
6190 mp->rx_hist_cnt6 += nr64_mac(RXMAC_HIST_CNT6); in niu_sync_xmac_stats()
6191 mp->rx_hist_cnt7 += nr64_mac(RXMAC_HIST_CNT7); in niu_sync_xmac_stats()
6192 mp->rx_octets += nr64_mac(RXMAC_BT_CNT); in niu_sync_xmac_stats()
6193 mp->rx_code_violations += nr64_mac(RXMAC_CD_VIO_CNT); in niu_sync_xmac_stats()
6194 mp->rx_len_errors += nr64_mac(RXMAC_MPSZER_CNT); in niu_sync_xmac_stats()
6195 mp->rx_crc_errors += nr64_mac(RXMAC_CRC_ER_CNT); in niu_sync_xmac_stats()
6200 struct niu_bmac_stats *mp = &np->mac_stats.bmac; in niu_sync_bmac_stats()
6202 mp->tx_bytes += nr64_mac(BTXMAC_BYTE_CNT); in niu_sync_bmac_stats()
6203 mp->tx_frames += nr64_mac(BTXMAC_FRM_CNT); in niu_sync_bmac_stats()
6205 mp->rx_frames += nr64_mac(BRXMAC_FRAME_CNT); in niu_sync_bmac_stats()
6206 mp->rx_align_errors += nr64_mac(BRXMAC_ALIGN_ERR_CNT); in niu_sync_bmac_stats()
6207 mp->rx_crc_errors += nr64_mac(BRXMAC_ALIGN_ERR_CNT); in niu_sync_bmac_stats()
6208 mp->rx_len_errors += nr64_mac(BRXMAC_CODE_VIOL_ERR_CNT); in niu_sync_bmac_stats()
6213 if (np->flags & NIU_FLAGS_XMAC) in niu_sync_mac_stats()
6228 rx_rings = READ_ONCE(np->rx_rings); in niu_get_rx_stats()
6232 for (i = 0; i < np->num_rx_rings; i++) { in niu_get_rx_stats()
6237 pkts += rp->rx_packets; in niu_get_rx_stats()
6238 bytes += rp->rx_bytes; in niu_get_rx_stats()
6239 dropped += rp->rx_dropped; in niu_get_rx_stats()
6240 errors += rp->rx_errors; in niu_get_rx_stats()
6244 stats->rx_packets = pkts; in niu_get_rx_stats()
6245 stats->rx_bytes = bytes; in niu_get_rx_stats()
6246 stats->rx_dropped = dropped; in niu_get_rx_stats()
6247 stats->rx_errors = errors; in niu_get_rx_stats()
6259 tx_rings = READ_ONCE(np->tx_rings); in niu_get_tx_stats()
6263 for (i = 0; i < np->num_tx_rings; i++) { in niu_get_tx_stats()
6266 pkts += rp->tx_packets; in niu_get_tx_stats()
6267 bytes += rp->tx_bytes; in niu_get_tx_stats()
6268 errors += rp->tx_errors; in niu_get_tx_stats()
6272 stats->tx_packets = pkts; in niu_get_tx_stats()
6273 stats->tx_bytes = bytes; in niu_get_tx_stats()
6274 stats->tx_errors = errors; in niu_get_tx_stats()
6306 if (np->flags & NIU_FLAGS_XMAC) in niu_load_hash()
6320 spin_lock_irqsave(&np->lock, flags); in niu_set_rx_mode()
6323 np->flags &= ~(NIU_FLAGS_MCAST | NIU_FLAGS_PROMISC); in niu_set_rx_mode()
6324 if (dev->flags & IFF_PROMISC) in niu_set_rx_mode()
6325 np->flags |= NIU_FLAGS_PROMISC; in niu_set_rx_mode()
6326 if ((dev->flags & IFF_ALLMULTI) || (!netdev_mc_empty(dev))) in niu_set_rx_mode()
6327 np->flags |= NIU_FLAGS_MCAST; in niu_set_rx_mode()
6332 np->flags |= NIU_FLAGS_PROMISC; in niu_set_rx_mode()
6339 err = niu_set_alt_mac(np, index, ha->addr); in niu_set_rx_mode()
6352 if (np->flags & NIU_FLAGS_XMAC) in niu_set_rx_mode()
6363 if (dev->flags & IFF_ALLMULTI) { in niu_set_rx_mode()
6368 u32 crc = ether_crc_le(ETH_ALEN, ha->addr); in niu_set_rx_mode()
6371 hash[crc >> 4] |= (1 << (15 - (crc & 0xf))); in niu_set_rx_mode()
6375 if (np->flags & NIU_FLAGS_MCAST) in niu_set_rx_mode()
6379 spin_unlock_irqrestore(&np->lock, flags); in niu_set_rx_mode()
6388 if (!is_valid_ether_addr(addr->sa_data)) in niu_set_mac_addr()
6389 return -EADDRNOTAVAIL; in niu_set_mac_addr()
6391 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); in niu_set_mac_addr()
6396 spin_lock_irqsave(&np->lock, flags); in niu_set_mac_addr()
6398 niu_set_primary_mac(np, dev->dev_addr); in niu_set_mac_addr()
6400 spin_unlock_irqrestore(&np->lock, flags); in niu_set_mac_addr()
6407 return -EOPNOTSUPP; in niu_ioctl()
6412 netif_trans_update(np->dev); /* prevent tx timeout */ in niu_netif_stop()
6416 netif_tx_disable(np->dev); in niu_netif_stop()
6425 netif_tx_wake_all_queues(np->dev); in niu_netif_start()
6436 if (np->rx_rings) { in niu_reset_buffers()
6437 for (i = 0; i < np->num_rx_rings; i++) { in niu_reset_buffers()
6438 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_reset_buffers()
6443 page = rp->rxhash[j]; in niu_reset_buffers()
6446 (struct page *) page->mapping; in niu_reset_buffers()
6447 u64 base = page->index; in niu_reset_buffers()
6449 rp->rbr[k++] = cpu_to_le32(base); in niu_reset_buffers()
6459 rp->rbr_index = rp->rbr_table_size - 1; in niu_reset_buffers()
6460 rp->rcr_index = 0; in niu_reset_buffers()
6461 rp->rbr_pending = 0; in niu_reset_buffers()
6462 rp->rbr_refill_pending = 0; in niu_reset_buffers()
6465 if (np->tx_rings) { in niu_reset_buffers()
6466 for (i = 0; i < np->num_tx_rings; i++) { in niu_reset_buffers()
6467 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_reset_buffers()
6470 if (rp->tx_buffs[j].skb) in niu_reset_buffers()
6474 rp->pending = MAX_TX_RING_SIZE; in niu_reset_buffers()
6475 rp->prod = 0; in niu_reset_buffers()
6476 rp->cons = 0; in niu_reset_buffers()
6477 rp->wrap_bit = 0; in niu_reset_buffers()
6488 spin_lock_irqsave(&np->lock, flags); in niu_reset_task()
6489 if (!netif_running(np->dev)) { in niu_reset_task()
6490 spin_unlock_irqrestore(&np->lock, flags); in niu_reset_task()
6494 spin_unlock_irqrestore(&np->lock, flags); in niu_reset_task()
6496 del_timer_sync(&np->timer); in niu_reset_task()
6500 spin_lock_irqsave(&np->lock, flags); in niu_reset_task()
6504 spin_unlock_irqrestore(&np->lock, flags); in niu_reset_task()
6508 spin_lock_irqsave(&np->lock, flags); in niu_reset_task()
6512 np->timer.expires = jiffies + HZ; in niu_reset_task()
6513 add_timer(&np->timer); in niu_reset_task()
6517 spin_unlock_irqrestore(&np->lock, flags); in niu_reset_task()
6524 dev_err(np->device, "%s: Transmit timed out, resetting\n", in niu_tx_timeout()
6525 dev->name); in niu_tx_timeout()
6527 schedule_work(&np->reset_task); in niu_tx_timeout()
6534 __le64 *desc = &rp->descr[index]; in niu_set_txd()
6550 eth_proto = be16_to_cpu(ehdr->h_proto); in niu_compute_tx_flags()
6554 __be16 val = vp->h_vlan_encapsulated_proto; in niu_compute_tx_flags()
6560 switch (skb->protocol) { in niu_compute_tx_flags()
6562 ip_proto = ip_hdr(skb)->protocol; in niu_compute_tx_flags()
6563 ihl = ip_hdr(skb)->ihl; in niu_compute_tx_flags()
6566 ip_proto = ipv6_hdr(skb)->nexthdr; in niu_compute_tx_flags()
6576 if (skb->ip_summed == CHECKSUM_PARTIAL) { in niu_compute_tx_flags()
6584 start = skb_checksum_start_offset(skb) - in niu_compute_tx_flags()
6586 stuff = start + skb->csum_offset; in niu_compute_tx_flags()
6592 l3off = skb_network_offset(skb) - in niu_compute_tx_flags()
6621 rp = &np->tx_rings[i]; in niu_start_xmit()
6624 if (niu_tx_avail(rp) <= (skb_shinfo(skb)->nr_frags + 1)) { in niu_start_xmit()
6626 dev_err(np->device, "%s: BUG! Tx ring full when queue awake!\n", dev->name); in niu_start_xmit()
6627 rp->tx_errors++; in niu_start_xmit()
6646 align = ((unsigned long) skb->data & (16 - 1)); in niu_start_xmit()
6649 ehdr = (struct ethhdr *) skb->data; in niu_start_xmit()
6652 len = skb->len - sizeof(struct tx_pkt_hdr); in niu_start_xmit()
6653 tp->flags = cpu_to_le64(niu_compute_tx_flags(skb, ehdr, align, len)); in niu_start_xmit()
6654 tp->resv = 0; in niu_start_xmit()
6657 mapping = np->ops->map_single(np->device, skb->data, in niu_start_xmit()
6660 prod = rp->prod; in niu_start_xmit()
6662 rp->tx_buffs[prod].skb = skb; in niu_start_xmit()
6663 rp->tx_buffs[prod].mapping = mapping; in niu_start_xmit()
6666 if (++rp->mark_counter == rp->mark_freq) { in niu_start_xmit()
6667 rp->mark_counter = 0; in niu_start_xmit()
6669 rp->mark_pending++; in niu_start_xmit()
6673 nfg = skb_shinfo(skb)->nr_frags; in niu_start_xmit()
6675 tlen -= MAX_TX_DESC_LEN; in niu_start_xmit()
6690 len -= this_len; in niu_start_xmit()
6693 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { in niu_start_xmit()
6694 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; in niu_start_xmit()
6697 mapping = np->ops->map_page(np->device, skb_frag_page(frag), in niu_start_xmit()
6701 rp->tx_buffs[prod].skb = NULL; in niu_start_xmit()
6702 rp->tx_buffs[prod].mapping = mapping; in niu_start_xmit()
6709 if (prod < rp->prod) in niu_start_xmit()
6710 rp->wrap_bit ^= TX_RING_KICK_WRAP; in niu_start_xmit()
6711 rp->prod = prod; in niu_start_xmit()
6713 nw64(TX_RING_KICK(rp->tx_channel), rp->wrap_bit | (prod << 3)); in niu_start_xmit()
6725 rp->tx_errors++; in niu_start_xmit()
6735 orig_jumbo = (dev->mtu > ETH_DATA_LEN); in niu_change_mtu()
6738 dev->mtu = new_mtu; in niu_change_mtu()
6754 spin_lock_irq(&np->lock); in niu_change_mtu()
6758 timer_setup(&np->timer, niu_timer, 0); in niu_change_mtu()
6759 np->timer.expires = jiffies + HZ; in niu_change_mtu()
6766 spin_unlock_irq(&np->lock); in niu_change_mtu()
6770 if (np->link_config.loopback_mode != LOOPBACK_DISABLED) in niu_change_mtu()
6773 add_timer(&np->timer); in niu_change_mtu()
6783 struct niu_vpd *vpd = &np->vpd; in niu_get_drvinfo()
6785 strlcpy(info->driver, DRV_MODULE_NAME, sizeof(info->driver)); in niu_get_drvinfo()
6786 strlcpy(info->version, DRV_MODULE_VERSION, sizeof(info->version)); in niu_get_drvinfo()
6787 snprintf(info->fw_version, sizeof(info->fw_version), "%d.%d", in niu_get_drvinfo()
6788 vpd->fcode_major, vpd->fcode_minor); in niu_get_drvinfo()
6789 if (np->parent->plat_type != PLAT_TYPE_NIU) in niu_get_drvinfo()
6790 strlcpy(info->bus_info, pci_name(np->pdev), in niu_get_drvinfo()
6791 sizeof(info->bus_info)); in niu_get_drvinfo()
6800 lp = &np->link_config; in niu_get_link_ksettings()
6803 cmd->base.phy_address = np->phy_addr; in niu_get_link_ksettings()
6804 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, in niu_get_link_ksettings()
6805 lp->supported); in niu_get_link_ksettings()
6806 ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, in niu_get_link_ksettings()
6807 lp->active_advertising); in niu_get_link_ksettings()
6808 cmd->base.autoneg = lp->active_autoneg; in niu_get_link_ksettings()
6809 cmd->base.speed = lp->active_speed; in niu_get_link_ksettings()
6810 cmd->base.duplex = lp->active_duplex; in niu_get_link_ksettings()
6811 cmd->base.port = (np->flags & NIU_FLAGS_FIBER) ? PORT_FIBRE : PORT_TP; in niu_get_link_ksettings()
6820 struct niu_link_config *lp = &np->link_config; in niu_set_link_ksettings()
6822 ethtool_convert_link_mode_to_legacy_u32(&lp->advertising, in niu_set_link_ksettings()
6823 cmd->link_modes.advertising); in niu_set_link_ksettings()
6824 lp->speed = cmd->base.speed; in niu_set_link_ksettings()
6825 lp->duplex = cmd->base.duplex; in niu_set_link_ksettings()
6826 lp->autoneg = cmd->base.autoneg; in niu_set_link_ksettings()
6833 return np->msg_enable; in niu_get_msglevel()
6839 np->msg_enable = value; in niu_set_msglevel()
6846 if (np->link_config.autoneg) in niu_nway_reset()
6856 return np->eeprom_len; in niu_get_eeprom_len()
6865 offset = eeprom->offset; in niu_get_eeprom()
6866 len = eeprom->len; in niu_get_eeprom()
6869 return -EINVAL; in niu_get_eeprom()
6870 if (offset >= np->eeprom_len) in niu_get_eeprom()
6871 return -EINVAL; in niu_get_eeprom()
6872 if (offset + len > np->eeprom_len) in niu_get_eeprom()
6873 len = eeprom->len = np->eeprom_len - offset; in niu_get_eeprom()
6879 b_count = 4 - b_offset; in niu_get_eeprom()
6883 val = nr64(ESPC_NCR((offset - b_offset) / 4)); in niu_get_eeprom()
6886 len -= b_count; in niu_get_eeprom()
6893 len -= 4; in niu_get_eeprom()
6966 return -EINVAL; in niu_class_to_ethflow()
7062 nfc->data = 0; in niu_get_hash_opts()
7064 if (!niu_ethflow_to_class(nfc->flow_type, &class)) in niu_get_hash_opts()
7065 return -EINVAL; in niu_get_hash_opts()
7067 if (np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] & in niu_get_hash_opts()
7069 nfc->data = RXH_DISCARD; in niu_get_hash_opts()
7071 nfc->data = niu_flowkey_to_ethflow(np->parent->flow_key[class - in niu_get_hash_opts()
7082 tmp = (tp->key[3] & TCAM_V4KEY3_SADDR) >> TCAM_V4KEY3_SADDR_SHIFT; in niu_get_ip4fs_from_tcam_key()
7083 fsp->h_u.tcp_ip4_spec.ip4src = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7085 tmp = (tp->key[3] & TCAM_V4KEY3_DADDR) >> TCAM_V4KEY3_DADDR_SHIFT; in niu_get_ip4fs_from_tcam_key()
7086 fsp->h_u.tcp_ip4_spec.ip4dst = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7088 tmp = (tp->key_mask[3] & TCAM_V4KEY3_SADDR) >> TCAM_V4KEY3_SADDR_SHIFT; in niu_get_ip4fs_from_tcam_key()
7089 fsp->m_u.tcp_ip4_spec.ip4src = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7091 tmp = (tp->key_mask[3] & TCAM_V4KEY3_DADDR) >> TCAM_V4KEY3_DADDR_SHIFT; in niu_get_ip4fs_from_tcam_key()
7092 fsp->m_u.tcp_ip4_spec.ip4dst = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7094 fsp->h_u.tcp_ip4_spec.tos = (tp->key[2] & TCAM_V4KEY2_TOS) >> in niu_get_ip4fs_from_tcam_key()
7096 fsp->m_u.tcp_ip4_spec.tos = (tp->key_mask[2] & TCAM_V4KEY2_TOS) >> in niu_get_ip4fs_from_tcam_key()
7099 switch (fsp->flow_type) { in niu_get_ip4fs_from_tcam_key()
7103 prt = ((tp->key[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7105 fsp->h_u.tcp_ip4_spec.psrc = cpu_to_be16(prt); in niu_get_ip4fs_from_tcam_key()
7107 prt = ((tp->key[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7109 fsp->h_u.tcp_ip4_spec.pdst = cpu_to_be16(prt); in niu_get_ip4fs_from_tcam_key()
7111 prt = ((tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7113 fsp->m_u.tcp_ip4_spec.psrc = cpu_to_be16(prt); in niu_get_ip4fs_from_tcam_key()
7115 prt = ((tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7117 fsp->m_u.tcp_ip4_spec.pdst = cpu_to_be16(prt); in niu_get_ip4fs_from_tcam_key()
7121 tmp = (tp->key[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7123 fsp->h_u.ah_ip4_spec.spi = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7125 tmp = (tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7127 fsp->m_u.ah_ip4_spec.spi = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7130 tmp = (tp->key[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7132 fsp->h_u.usr_ip4_spec.l4_4_bytes = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7134 tmp = (tp->key_mask[2] & TCAM_V4KEY2_PORT_SPI) >> in niu_get_ip4fs_from_tcam_key()
7136 fsp->m_u.usr_ip4_spec.l4_4_bytes = cpu_to_be32(tmp); in niu_get_ip4fs_from_tcam_key()
7138 fsp->h_u.usr_ip4_spec.proto = in niu_get_ip4fs_from_tcam_key()
7139 (tp->key[2] & TCAM_V4KEY2_PROTO) >> in niu_get_ip4fs_from_tcam_key()
7141 fsp->m_u.usr_ip4_spec.proto = in niu_get_ip4fs_from_tcam_key()
7142 (tp->key_mask[2] & TCAM_V4KEY2_PROTO) >> in niu_get_ip4fs_from_tcam_key()
7145 fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; in niu_get_ip4fs_from_tcam_key()
7155 struct niu_parent *parent = np->parent; in niu_get_ethtool_tcam_entry()
7157 struct ethtool_rx_flow_spec *fsp = &nfc->fs; in niu_get_ethtool_tcam_entry()
7162 idx = tcam_get_index(np, (u16)nfc->fs.location); in niu_get_ethtool_tcam_entry()
7164 tp = &parent->tcam[idx]; in niu_get_ethtool_tcam_entry()
7165 if (!tp->valid) { in niu_get_ethtool_tcam_entry()
7166 netdev_info(np->dev, "niu%d: entry [%d] invalid for idx[%d]\n", in niu_get_ethtool_tcam_entry()
7167 parent->index, (u16)nfc->fs.location, idx); in niu_get_ethtool_tcam_entry()
7168 return -EINVAL; in niu_get_ethtool_tcam_entry()
7172 class = (tp->key[0] & TCAM_V4KEY0_CLASS_CODE) >> in niu_get_ethtool_tcam_entry()
7174 ret = niu_class_to_ethflow(class, &fsp->flow_type); in niu_get_ethtool_tcam_entry()
7176 netdev_info(np->dev, "niu%d: niu_class_to_ethflow failed\n", in niu_get_ethtool_tcam_entry()
7177 parent->index); in niu_get_ethtool_tcam_entry()
7181 if (fsp->flow_type == AH_V4_FLOW || fsp->flow_type == AH_V6_FLOW) { in niu_get_ethtool_tcam_entry()
7182 u32 proto = (tp->key[2] & TCAM_V4KEY2_PROTO) >> in niu_get_ethtool_tcam_entry()
7185 if (fsp->flow_type == AH_V4_FLOW) in niu_get_ethtool_tcam_entry()
7186 fsp->flow_type = ESP_V4_FLOW; in niu_get_ethtool_tcam_entry()
7188 fsp->flow_type = ESP_V6_FLOW; in niu_get_ethtool_tcam_entry()
7192 switch (fsp->flow_type) { in niu_get_ethtool_tcam_entry()
7206 ret = -EINVAL; in niu_get_ethtool_tcam_entry()
7212 ret = -EINVAL; in niu_get_ethtool_tcam_entry()
7219 if (tp->assoc_data & TCAM_ASSOCDATA_DISC) in niu_get_ethtool_tcam_entry()
7220 fsp->ring_cookie = RX_CLS_FLOW_DISC; in niu_get_ethtool_tcam_entry()
7222 fsp->ring_cookie = (tp->assoc_data & TCAM_ASSOCDATA_OFFSET) >> in niu_get_ethtool_tcam_entry()
7226 nfc->data = tcam_get_size(np); in niu_get_ethtool_tcam_entry()
7235 struct niu_parent *parent = np->parent; in niu_get_ethtool_tcam_all()
7242 nfc->data = tcam_get_size(np); in niu_get_ethtool_tcam_all()
7245 for (cnt = 0, i = 0; i < nfc->data; i++) { in niu_get_ethtool_tcam_all()
7247 tp = &parent->tcam[idx]; in niu_get_ethtool_tcam_all()
7248 if (!tp->valid) in niu_get_ethtool_tcam_all()
7250 if (cnt == nfc->rule_cnt) { in niu_get_ethtool_tcam_all()
7251 ret = -EMSGSIZE; in niu_get_ethtool_tcam_all()
7259 nfc->rule_cnt = cnt; in niu_get_ethtool_tcam_all()
7270 switch (cmd->cmd) { in niu_get_nfc()
7275 cmd->data = np->num_rx_rings; in niu_get_nfc()
7278 cmd->rule_cnt = tcam_get_valid_entry_cnt(np); in niu_get_nfc()
7287 ret = -EINVAL; in niu_get_nfc()
7300 if (!niu_ethflow_to_class(nfc->flow_type, &class)) in niu_set_hash_opts()
7301 return -EINVAL; in niu_set_hash_opts()
7305 return -EINVAL; in niu_set_hash_opts()
7307 if (nfc->data & RXH_DISCARD) { in niu_set_hash_opts()
7309 flow_key = np->parent->tcam_key[class - in niu_set_hash_opts()
7312 nw64(TCAM_KEY(class - CLASS_CODE_USER_PROG1), flow_key); in niu_set_hash_opts()
7313 np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] = flow_key; in niu_set_hash_opts()
7318 if (np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] & in niu_set_hash_opts()
7321 flow_key = np->parent->tcam_key[class - in niu_set_hash_opts()
7324 nw64(TCAM_KEY(class - CLASS_CODE_USER_PROG1), in niu_set_hash_opts()
7326 np->parent->tcam_key[class - CLASS_CODE_USER_PROG1] = in niu_set_hash_opts()
7332 if (!niu_ethflow_to_flowkey(nfc->data, &flow_key)) in niu_set_hash_opts()
7333 return -EINVAL; in niu_set_hash_opts()
7336 nw64(FLOW_KEY(class - CLASS_CODE_USER_PROG1), flow_key); in niu_set_hash_opts()
7337 np->parent->flow_key[class - CLASS_CODE_USER_PROG1] = flow_key; in niu_set_hash_opts()
7351 sip = be32_to_cpu(fsp->h_u.tcp_ip4_spec.ip4src); in niu_get_tcamkey_from_ip4fs()
7352 sipm = be32_to_cpu(fsp->m_u.tcp_ip4_spec.ip4src); in niu_get_tcamkey_from_ip4fs()
7353 dip = be32_to_cpu(fsp->h_u.tcp_ip4_spec.ip4dst); in niu_get_tcamkey_from_ip4fs()
7354 dipm = be32_to_cpu(fsp->m_u.tcp_ip4_spec.ip4dst); in niu_get_tcamkey_from_ip4fs()
7356 tp->key[0] = class << TCAM_V4KEY0_CLASS_CODE_SHIFT; in niu_get_tcamkey_from_ip4fs()
7357 tp->key_mask[0] = TCAM_V4KEY0_CLASS_CODE; in niu_get_tcamkey_from_ip4fs()
7358 tp->key[1] = (u64)l2_rdc_tab << TCAM_V4KEY1_L2RDCNUM_SHIFT; in niu_get_tcamkey_from_ip4fs()
7359 tp->key_mask[1] = TCAM_V4KEY1_L2RDCNUM; in niu_get_tcamkey_from_ip4fs()
7361 tp->key[3] = (u64)sip << TCAM_V4KEY3_SADDR_SHIFT; in niu_get_tcamkey_from_ip4fs()
7362 tp->key[3] |= dip; in niu_get_tcamkey_from_ip4fs()
7364 tp->key_mask[3] = (u64)sipm << TCAM_V4KEY3_SADDR_SHIFT; in niu_get_tcamkey_from_ip4fs()
7365 tp->key_mask[3] |= dipm; in niu_get_tcamkey_from_ip4fs()
7367 tp->key[2] |= ((u64)fsp->h_u.tcp_ip4_spec.tos << in niu_get_tcamkey_from_ip4fs()
7369 tp->key_mask[2] |= ((u64)fsp->m_u.tcp_ip4_spec.tos << in niu_get_tcamkey_from_ip4fs()
7371 switch (fsp->flow_type) { in niu_get_tcamkey_from_ip4fs()
7375 sport = be16_to_cpu(fsp->h_u.tcp_ip4_spec.psrc); in niu_get_tcamkey_from_ip4fs()
7376 spm = be16_to_cpu(fsp->m_u.tcp_ip4_spec.psrc); in niu_get_tcamkey_from_ip4fs()
7377 dport = be16_to_cpu(fsp->h_u.tcp_ip4_spec.pdst); in niu_get_tcamkey_from_ip4fs()
7378 dpm = be16_to_cpu(fsp->m_u.tcp_ip4_spec.pdst); in niu_get_tcamkey_from_ip4fs()
7380 tp->key[2] |= (((u64)sport << 16) | dport); in niu_get_tcamkey_from_ip4fs()
7381 tp->key_mask[2] |= (((u64)spm << 16) | dpm); in niu_get_tcamkey_from_ip4fs()
7382 niu_ethflow_to_l3proto(fsp->flow_type, &pid); in niu_get_tcamkey_from_ip4fs()
7386 spi = be32_to_cpu(fsp->h_u.ah_ip4_spec.spi); in niu_get_tcamkey_from_ip4fs()
7387 spim = be32_to_cpu(fsp->m_u.ah_ip4_spec.spi); in niu_get_tcamkey_from_ip4fs()
7389 tp->key[2] |= spi; in niu_get_tcamkey_from_ip4fs()
7390 tp->key_mask[2] |= spim; in niu_get_tcamkey_from_ip4fs()
7391 niu_ethflow_to_l3proto(fsp->flow_type, &pid); in niu_get_tcamkey_from_ip4fs()
7394 spi = be32_to_cpu(fsp->h_u.usr_ip4_spec.l4_4_bytes); in niu_get_tcamkey_from_ip4fs()
7395 spim = be32_to_cpu(fsp->m_u.usr_ip4_spec.l4_4_bytes); in niu_get_tcamkey_from_ip4fs()
7397 tp->key[2] |= spi; in niu_get_tcamkey_from_ip4fs()
7398 tp->key_mask[2] |= spim; in niu_get_tcamkey_from_ip4fs()
7399 pid = fsp->h_u.usr_ip4_spec.proto; in niu_get_tcamkey_from_ip4fs()
7405 tp->key[2] |= ((u64)pid << TCAM_V4KEY2_PROTO_SHIFT); in niu_get_tcamkey_from_ip4fs()
7407 tp->key_mask[2] |= TCAM_V4KEY2_PROTO; in niu_get_tcamkey_from_ip4fs()
7414 struct niu_parent *parent = np->parent; in niu_add_ethtool_tcam_entry()
7416 struct ethtool_rx_flow_spec *fsp = &nfc->fs; in niu_add_ethtool_tcam_entry()
7417 struct niu_rdc_tables *rdc_table = &parent->rdc_group_cfg[np->port]; in niu_add_ethtool_tcam_entry()
7418 int l2_rdc_table = rdc_table->first_table_num; in niu_add_ethtool_tcam_entry()
7426 idx = nfc->fs.location; in niu_add_ethtool_tcam_entry()
7428 return -EINVAL; in niu_add_ethtool_tcam_entry()
7430 if (fsp->flow_type == IP_USER_FLOW) { in niu_add_ethtool_tcam_entry()
7433 struct ethtool_usrip4_spec *uspec = &fsp->h_u.usr_ip4_spec; in niu_add_ethtool_tcam_entry()
7434 struct ethtool_usrip4_spec *umask = &fsp->m_u.usr_ip4_spec; in niu_add_ethtool_tcam_entry()
7436 if (uspec->ip_ver != ETH_RX_NFC_IP4) in niu_add_ethtool_tcam_entry()
7437 return -EINVAL; in niu_add_ethtool_tcam_entry()
7442 if (parent->l3_cls[i]) { in niu_add_ethtool_tcam_entry()
7443 if (uspec->proto == parent->l3_cls_pid[i]) { in niu_add_ethtool_tcam_entry()
7444 class = parent->l3_cls[i]; in niu_add_ethtool_tcam_entry()
7445 parent->l3_cls_refcnt[i]++; in niu_add_ethtool_tcam_entry()
7469 uspec->proto, in niu_add_ethtool_tcam_entry()
7470 uspec->tos, in niu_add_ethtool_tcam_entry()
7471 umask->tos); in niu_add_ethtool_tcam_entry()
7478 parent->l3_cls[i] = class; in niu_add_ethtool_tcam_entry()
7479 parent->l3_cls_pid[i] = uspec->proto; in niu_add_ethtool_tcam_entry()
7480 parent->l3_cls_refcnt[i]++; in niu_add_ethtool_tcam_entry()
7486 netdev_info(np->dev, "niu%d: %s(): Could not find/insert class for pid %d\n", in niu_add_ethtool_tcam_entry()
7487 parent->index, __func__, uspec->proto); in niu_add_ethtool_tcam_entry()
7488 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7493 if (!niu_ethflow_to_class(fsp->flow_type, &class)) { in niu_add_ethtool_tcam_entry()
7494 return -EINVAL; in niu_add_ethtool_tcam_entry()
7501 tp = &parent->tcam[idx]; in niu_add_ethtool_tcam_entry()
7506 switch (fsp->flow_type) { in niu_add_ethtool_tcam_entry()
7520 netdev_info(np->dev, "niu%d: In %s(): flow %d for IPv6 not implemented\n", in niu_add_ethtool_tcam_entry()
7521 parent->index, __func__, fsp->flow_type); in niu_add_ethtool_tcam_entry()
7522 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7528 netdev_info(np->dev, "niu%d: In %s(): Unknown flow type %d\n", in niu_add_ethtool_tcam_entry()
7529 parent->index, __func__, fsp->flow_type); in niu_add_ethtool_tcam_entry()
7530 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7535 if (fsp->ring_cookie == RX_CLS_FLOW_DISC) { in niu_add_ethtool_tcam_entry()
7536 tp->assoc_data = TCAM_ASSOCDATA_DISC; in niu_add_ethtool_tcam_entry()
7538 if (fsp->ring_cookie >= np->num_rx_rings) { in niu_add_ethtool_tcam_entry()
7539 netdev_info(np->dev, "niu%d: In %s(): Invalid RX ring %lld\n", in niu_add_ethtool_tcam_entry()
7540 parent->index, __func__, in niu_add_ethtool_tcam_entry()
7541 (long long)fsp->ring_cookie); in niu_add_ethtool_tcam_entry()
7542 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7545 tp->assoc_data = (TCAM_ASSOCDATA_TRES_USE_OFFSET | in niu_add_ethtool_tcam_entry()
7546 (fsp->ring_cookie << in niu_add_ethtool_tcam_entry()
7550 err = tcam_write(np, idx, tp->key, tp->key_mask); in niu_add_ethtool_tcam_entry()
7552 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7555 err = tcam_assoc_write(np, idx, tp->assoc_data); in niu_add_ethtool_tcam_entry()
7557 ret = -EINVAL; in niu_add_ethtool_tcam_entry()
7562 tp->valid = 1; in niu_add_ethtool_tcam_entry()
7563 np->clas.tcam_valid_entries++; in niu_add_ethtool_tcam_entry()
7572 struct niu_parent *parent = np->parent; in niu_del_ethtool_tcam_entry()
7580 return -EINVAL; in niu_del_ethtool_tcam_entry()
7585 tp = &parent->tcam[idx]; in niu_del_ethtool_tcam_entry()
7588 class = (tp->key[0] & TCAM_V4KEY0_CLASS_CODE) >> in niu_del_ethtool_tcam_entry()
7594 if (parent->l3_cls[i] == class) { in niu_del_ethtool_tcam_entry()
7595 parent->l3_cls_refcnt[i]--; in niu_del_ethtool_tcam_entry()
7596 if (!parent->l3_cls_refcnt[i]) { in niu_del_ethtool_tcam_entry()
7603 parent->l3_cls[i] = 0; in niu_del_ethtool_tcam_entry()
7604 parent->l3_cls_pid[i] = 0; in niu_del_ethtool_tcam_entry()
7610 netdev_info(np->dev, "niu%d: In %s(): Usr class 0x%llx not found\n", in niu_del_ethtool_tcam_entry()
7611 parent->index, __func__, in niu_del_ethtool_tcam_entry()
7613 ret = -EINVAL; in niu_del_ethtool_tcam_entry()
7623 tp->valid = 0; in niu_del_ethtool_tcam_entry()
7624 np->clas.tcam_valid_entries--; in niu_del_ethtool_tcam_entry()
7636 switch (cmd->cmd) { in niu_set_nfc()
7644 ret = niu_del_ethtool_tcam_entry(np, cmd->fs.location); in niu_set_nfc()
7647 ret = -EINVAL; in niu_set_nfc()
7740 if (np->flags & NIU_FLAGS_XMAC) { in niu_get_strings()
7749 for (i = 0; i < np->num_rx_rings; i++) { in niu_get_strings()
7754 for (i = 0; i < np->num_tx_rings; i++) { in niu_get_strings()
7766 return -EINVAL; in niu_get_sset_count()
7768 return (np->flags & NIU_FLAGS_XMAC ? in niu_get_sset_count()
7771 (np->num_rx_rings * NUM_RXCHAN_STAT_KEYS) + in niu_get_sset_count()
7772 (np->num_tx_rings * NUM_TXCHAN_STAT_KEYS); in niu_get_sset_count()
7782 if (np->flags & NIU_FLAGS_XMAC) { in niu_get_ethtool_stats()
7783 memcpy(data, &np->mac_stats.xmac, in niu_get_ethtool_stats()
7787 memcpy(data, &np->mac_stats.bmac, in niu_get_ethtool_stats()
7791 for (i = 0; i < np->num_rx_rings; i++) { in niu_get_ethtool_stats()
7792 struct rx_ring_info *rp = &np->rx_rings[i]; in niu_get_ethtool_stats()
7796 data[0] = rp->rx_channel; in niu_get_ethtool_stats()
7797 data[1] = rp->rx_packets; in niu_get_ethtool_stats()
7798 data[2] = rp->rx_bytes; in niu_get_ethtool_stats()
7799 data[3] = rp->rx_dropped; in niu_get_ethtool_stats()
7800 data[4] = rp->rx_errors; in niu_get_ethtool_stats()
7803 for (i = 0; i < np->num_tx_rings; i++) { in niu_get_ethtool_stats()
7804 struct tx_ring_info *rp = &np->tx_rings[i]; in niu_get_ethtool_stats()
7806 data[0] = rp->tx_channel; in niu_get_ethtool_stats()
7807 data[1] = rp->tx_packets; in niu_get_ethtool_stats()
7808 data[2] = rp->tx_bytes; in niu_get_ethtool_stats()
7809 data[3] = rp->tx_errors; in niu_get_ethtool_stats()
7816 if (np->flags & NIU_FLAGS_XMAC) in niu_led_state_save()
7824 if (np->flags & NIU_FLAGS_XMAC) in niu_led_state_restore()
7834 if (np->flags & NIU_FLAGS_XMAC) { in niu_force_led()
7857 return -EAGAIN; in niu_set_phys_id()
7861 np->orig_led_state = niu_led_state_save(np); in niu_set_phys_id()
7873 niu_led_state_restore(np, np->orig_led_state); in niu_set_phys_id()
7901 return -EINVAL; in niu_ldg_assign_ldn()
7903 return -EINVAL; in niu_ldg_assign_ldn()
7905 parent->ldg_map[ldn] = ldg; in niu_ldg_assign_ldn()
7907 if (np->parent->plat_type == PLAT_TYPE_NIU) { in niu_ldg_assign_ldn()
7908 /* On N2 NIU, the ldn-->ldg assignments are setup and fixed by in niu_ldg_assign_ldn()
7914 dev_err(np->device, "Port %u, mis-matched LDG assignment for ldn %d, should be %d is %llu\n", in niu_ldg_assign_ldn()
7915 np->port, ldn, ldg, in niu_ldg_assign_ldn()
7917 return -EINVAL; in niu_ldg_assign_ldn()
7928 return -EINVAL; in niu_set_ldg_timer_res()
7941 return -EINVAL; in niu_set_ldg_sid()
7955 return -EINVAL; in niu_pci_eeprom_read()
7965 } while (limit--); in niu_pci_eeprom_read()
7967 dev_err(np->device, "EEPROM read timeout frame[%llx]\n", in niu_pci_eeprom_read()
7969 return -ENODEV; in niu_pci_eeprom_read()
7980 } while (limit--); in niu_pci_eeprom_read()
7982 dev_err(np->device, "EEPROM read timeout frame[%llx]\n", in niu_pci_eeprom_read()
7984 return -ENODEV; in niu_pci_eeprom_read()
8039 return -EINVAL; in niu_pci_vpd_get_propname()
8046 struct niu_vpd *vpd = &np->vpd; in niu_vpd_parse_version()
8047 int len = strlen(vpd->version) + 1; in niu_vpd_parse_version()
8048 const char *s = vpd->version; in niu_vpd_parse_version()
8051 for (i = 0; i < len - 5; i++) { in niu_vpd_parse_version()
8055 if (i >= len - 5) in niu_vpd_parse_version()
8059 sscanf(s, "%d.%d", &vpd->fcode_major, &vpd->fcode_minor); in niu_vpd_parse_version()
8061 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_vpd_parse_version()
8063 vpd->fcode_major, vpd->fcode_minor); in niu_vpd_parse_version()
8064 if (vpd->fcode_major > NIU_VPD_MIN_MAJOR || in niu_vpd_parse_version()
8065 (vpd->fcode_major == NIU_VPD_MIN_MAJOR && in niu_vpd_parse_version()
8066 vpd->fcode_minor >= NIU_VPD_MIN_MINOR)) in niu_vpd_parse_version()
8067 np->flags |= NIU_FLAGS_VPD_VALID; in niu_vpd_parse_version()
8082 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_vpd_scan_props()
8111 prop_buf = np->vpd.model; in niu_pci_vpd_scan_props()
8114 } else if (!strcmp(namebuf, "board-model")) { in niu_pci_vpd_scan_props()
8115 prop_buf = np->vpd.board_model; in niu_pci_vpd_scan_props()
8119 prop_buf = np->vpd.version; in niu_pci_vpd_scan_props()
8122 } else if (!strcmp(namebuf, "local-mac-address")) { in niu_pci_vpd_scan_props()
8123 prop_buf = np->vpd.local_mac; in niu_pci_vpd_scan_props()
8126 } else if (!strcmp(namebuf, "num-mac-addresses")) { in niu_pci_vpd_scan_props()
8127 prop_buf = &np->vpd.mac_num; in niu_pci_vpd_scan_props()
8130 } else if (!strcmp(namebuf, "phy-type")) { in niu_pci_vpd_scan_props()
8131 prop_buf = np->vpd.phy_type; in niu_pci_vpd_scan_props()
8137 dev_err(np->device, "Property '%s' length (%d) is too long\n", namebuf, prop_len); in niu_pci_vpd_scan_props()
8138 return -EINVAL; in niu_pci_vpd_scan_props()
8145 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_vpd_scan_props()
8256 /* 1G copper, MII */ in niu_phy_type_prop_decode()
8257 np->flags &= ~(NIU_FLAGS_FIBER | in niu_phy_type_prop_decode()
8259 np->mac_xcvr = MAC_XCVR_MII; in niu_phy_type_prop_decode()
8261 /* 10G fiber, XPCS */ in niu_phy_type_prop_decode()
8262 np->flags |= (NIU_FLAGS_10G | in niu_phy_type_prop_decode()
8264 np->mac_xcvr = MAC_XCVR_XPCS; in niu_phy_type_prop_decode()
8266 /* 1G fiber, PCS */ in niu_phy_type_prop_decode()
8267 np->flags &= ~NIU_FLAGS_10G; in niu_phy_type_prop_decode()
8268 np->flags |= NIU_FLAGS_FIBER; in niu_phy_type_prop_decode()
8269 np->mac_xcvr = MAC_XCVR_PCS; in niu_phy_type_prop_decode()
8271 /* 10G copper, XPCS */ in niu_phy_type_prop_decode()
8272 np->flags |= NIU_FLAGS_10G; in niu_phy_type_prop_decode()
8273 np->flags &= ~NIU_FLAGS_FIBER; in niu_phy_type_prop_decode()
8274 np->mac_xcvr = MAC_XCVR_XPCS; in niu_phy_type_prop_decode()
8276 /* 10G Serdes or 1G Serdes, default to 10G */ in niu_phy_type_prop_decode()
8277 np->flags |= NIU_FLAGS_10G; in niu_phy_type_prop_decode()
8278 np->flags &= ~NIU_FLAGS_FIBER; in niu_phy_type_prop_decode()
8279 np->flags |= NIU_FLAGS_XCVR_SERDES; in niu_phy_type_prop_decode()
8280 np->mac_xcvr = MAC_XCVR_XPCS; in niu_phy_type_prop_decode()
8282 return -EINVAL; in niu_phy_type_prop_decode()
8291 if ((!strcmp(np->vpd.model, NIU_QGC_LP_MDL_STR)) || in niu_pci_vpd_get_nports()
8292 (!strcmp(np->vpd.model, NIU_QGC_PEM_MDL_STR)) || in niu_pci_vpd_get_nports()
8293 (!strcmp(np->vpd.model, NIU_MARAMBA_MDL_STR)) || in niu_pci_vpd_get_nports()
8294 (!strcmp(np->vpd.model, NIU_KIMI_MDL_STR)) || in niu_pci_vpd_get_nports()
8295 (!strcmp(np->vpd.model, NIU_ALONSO_MDL_STR))) { in niu_pci_vpd_get_nports()
8297 } else if ((!strcmp(np->vpd.model, NIU_2XGF_LP_MDL_STR)) || in niu_pci_vpd_get_nports()
8298 (!strcmp(np->vpd.model, NIU_2XGF_PEM_MDL_STR)) || in niu_pci_vpd_get_nports()
8299 (!strcmp(np->vpd.model, NIU_FOXXY_MDL_STR)) || in niu_pci_vpd_get_nports()
8300 (!strcmp(np->vpd.model, NIU_2XGF_MRVL_MDL_STR))) { in niu_pci_vpd_get_nports()
8309 struct net_device *dev = np->dev; in niu_pci_vpd_validate()
8310 struct niu_vpd *vpd = &np->vpd; in niu_pci_vpd_validate()
8313 if (!is_valid_ether_addr(&vpd->local_mac[0])) { in niu_pci_vpd_validate()
8314 dev_err(np->device, "VPD MAC invalid, falling back to SPROM\n"); in niu_pci_vpd_validate()
8316 np->flags &= ~NIU_FLAGS_VPD_VALID; in niu_pci_vpd_validate()
8320 if (!strcmp(np->vpd.model, NIU_ALONSO_MDL_STR) || in niu_pci_vpd_validate()
8321 !strcmp(np->vpd.model, NIU_KIMI_MDL_STR)) { in niu_pci_vpd_validate()
8322 np->flags |= NIU_FLAGS_10G; in niu_pci_vpd_validate()
8323 np->flags &= ~NIU_FLAGS_FIBER; in niu_pci_vpd_validate()
8324 np->flags |= NIU_FLAGS_XCVR_SERDES; in niu_pci_vpd_validate()
8325 np->mac_xcvr = MAC_XCVR_PCS; in niu_pci_vpd_validate()
8326 if (np->port > 1) { in niu_pci_vpd_validate()
8327 np->flags |= NIU_FLAGS_FIBER; in niu_pci_vpd_validate()
8328 np->flags &= ~NIU_FLAGS_10G; in niu_pci_vpd_validate()
8330 if (np->flags & NIU_FLAGS_10G) in niu_pci_vpd_validate()
8331 np->mac_xcvr = MAC_XCVR_XPCS; in niu_pci_vpd_validate()
8332 } else if (!strcmp(np->vpd.model, NIU_FOXXY_MDL_STR)) { in niu_pci_vpd_validate()
8333 np->flags |= (NIU_FLAGS_10G | NIU_FLAGS_FIBER | in niu_pci_vpd_validate()
8335 } else if (niu_phy_type_prop_decode(np, np->vpd.phy_type)) { in niu_pci_vpd_validate()
8336 dev_err(np->device, "Illegal phy string [%s]\n", in niu_pci_vpd_validate()
8337 np->vpd.phy_type); in niu_pci_vpd_validate()
8338 dev_err(np->device, "Falling back to SPROM\n"); in niu_pci_vpd_validate()
8339 np->flags &= ~NIU_FLAGS_VPD_VALID; in niu_pci_vpd_validate()
8343 memcpy(dev->dev_addr, vpd->local_mac, ETH_ALEN); in niu_pci_vpd_validate()
8345 val8 = dev->dev_addr[5]; in niu_pci_vpd_validate()
8346 dev->dev_addr[5] += np->port; in niu_pci_vpd_validate()
8347 if (dev->dev_addr[5] < val8) in niu_pci_vpd_validate()
8348 dev->dev_addr[4]++; in niu_pci_vpd_validate()
8353 struct net_device *dev = np->dev; in niu_pci_probe_sprom()
8362 np->eeprom_len = len; in niu_pci_probe_sprom()
8364 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8375 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8378 dev_err(np->device, "Bad SPROM checksum (%x, should be 0xab)\n", (int)(sum & 0xff)); in niu_pci_probe_sprom()
8379 return -EINVAL; in niu_pci_probe_sprom()
8383 switch (np->port) { in niu_pci_probe_sprom()
8401 dev_err(np->device, "Bogus port number %u\n", in niu_pci_probe_sprom()
8402 np->port); in niu_pci_probe_sprom()
8403 return -EINVAL; in niu_pci_probe_sprom()
8405 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8410 /* 1G copper, MII */ in niu_pci_probe_sprom()
8411 np->flags &= ~(NIU_FLAGS_FIBER | in niu_pci_probe_sprom()
8413 np->mac_xcvr = MAC_XCVR_MII; in niu_pci_probe_sprom()
8417 /* 1G fiber, PCS */ in niu_pci_probe_sprom()
8418 np->flags &= ~NIU_FLAGS_10G; in niu_pci_probe_sprom()
8419 np->flags |= NIU_FLAGS_FIBER; in niu_pci_probe_sprom()
8420 np->mac_xcvr = MAC_XCVR_PCS; in niu_pci_probe_sprom()
8424 /* 10G copper, XPCS */ in niu_pci_probe_sprom()
8425 np->flags |= NIU_FLAGS_10G; in niu_pci_probe_sprom()
8426 np->flags &= ~NIU_FLAGS_FIBER; in niu_pci_probe_sprom()
8427 np->mac_xcvr = MAC_XCVR_XPCS; in niu_pci_probe_sprom()
8431 /* 10G fiber, XPCS */ in niu_pci_probe_sprom()
8432 np->flags |= (NIU_FLAGS_10G | in niu_pci_probe_sprom()
8434 np->mac_xcvr = MAC_XCVR_XPCS; in niu_pci_probe_sprom()
8438 dev_err(np->device, "Bogus SPROM phy type %u\n", val8); in niu_pci_probe_sprom()
8439 return -EINVAL; in niu_pci_probe_sprom()
8443 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8445 dev->dev_addr[0] = (val >> 0) & 0xff; in niu_pci_probe_sprom()
8446 dev->dev_addr[1] = (val >> 8) & 0xff; in niu_pci_probe_sprom()
8447 dev->dev_addr[2] = (val >> 16) & 0xff; in niu_pci_probe_sprom()
8448 dev->dev_addr[3] = (val >> 24) & 0xff; in niu_pci_probe_sprom()
8451 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8453 dev->dev_addr[4] = (val >> 0) & 0xff; in niu_pci_probe_sprom()
8454 dev->dev_addr[5] = (val >> 8) & 0xff; in niu_pci_probe_sprom()
8456 if (!is_valid_ether_addr(&dev->dev_addr[0])) { in niu_pci_probe_sprom()
8457 dev_err(np->device, "SPROM MAC address invalid [ %pM ]\n", in niu_pci_probe_sprom()
8458 dev->dev_addr); in niu_pci_probe_sprom()
8459 return -EINVAL; in niu_pci_probe_sprom()
8462 val8 = dev->dev_addr[5]; in niu_pci_probe_sprom()
8463 dev->dev_addr[5] += np->port; in niu_pci_probe_sprom()
8464 if (dev->dev_addr[5] < val8) in niu_pci_probe_sprom()
8465 dev->dev_addr[4]++; in niu_pci_probe_sprom()
8468 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8471 return -EINVAL; in niu_pci_probe_sprom()
8476 np->vpd.model[i + 3] = (tmp >> 0) & 0xff; in niu_pci_probe_sprom()
8477 np->vpd.model[i + 2] = (tmp >> 8) & 0xff; in niu_pci_probe_sprom()
8478 np->vpd.model[i + 1] = (tmp >> 16) & 0xff; in niu_pci_probe_sprom()
8479 np->vpd.model[i + 0] = (tmp >> 24) & 0xff; in niu_pci_probe_sprom()
8481 np->vpd.model[val] = '\0'; in niu_pci_probe_sprom()
8484 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8487 return -EINVAL; in niu_pci_probe_sprom()
8492 np->vpd.board_model[i + 3] = (tmp >> 0) & 0xff; in niu_pci_probe_sprom()
8493 np->vpd.board_model[i + 2] = (tmp >> 8) & 0xff; in niu_pci_probe_sprom()
8494 np->vpd.board_model[i + 1] = (tmp >> 16) & 0xff; in niu_pci_probe_sprom()
8495 np->vpd.board_model[i + 0] = (tmp >> 24) & 0xff; in niu_pci_probe_sprom()
8497 np->vpd.board_model[val] = '\0'; in niu_pci_probe_sprom()
8499 np->vpd.mac_num = in niu_pci_probe_sprom()
8501 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_pci_probe_sprom()
8502 "SPROM: NUM_PORTS_MACS[%d]\n", np->vpd.mac_num); in niu_pci_probe_sprom()
8509 struct niu_parent *parent = np->parent; in niu_get_and_validate_port()
8511 if (np->port <= 1) in niu_get_and_validate_port()
8512 np->flags |= NIU_FLAGS_XMAC; in niu_get_and_validate_port()
8514 if (!parent->num_ports) { in niu_get_and_validate_port()
8515 if (parent->plat_type == PLAT_TYPE_NIU) { in niu_get_and_validate_port()
8516 parent->num_ports = 2; in niu_get_and_validate_port()
8518 parent->num_ports = niu_pci_vpd_get_nports(np); in niu_get_and_validate_port()
8519 if (!parent->num_ports) { in niu_get_and_validate_port()
8523 parent->num_ports = nr64(ESPC_NUM_PORTS_MACS) & in niu_get_and_validate_port()
8527 * Maramba on-board parts. in niu_get_and_validate_port()
8529 if (!parent->num_ports) in niu_get_and_validate_port()
8530 parent->num_ports = 4; in niu_get_and_validate_port()
8535 if (np->port >= parent->num_ports) in niu_get_and_validate_port()
8536 return -ENODEV; in niu_get_and_validate_port()
8562 parent->index, id, in phy_record()
8564 type == PHY_TYPE_PCS ? "PCS" : "MII", in phy_record()
8567 if (p->cur[type] >= NIU_MAX_PORTS) { in phy_record()
8569 return -EINVAL; in phy_record()
8571 idx = p->cur[type]; in phy_record()
8572 p->phy_id[type][idx] = id; in phy_record()
8573 p->phy_port[type][idx] = phy_port; in phy_record()
8574 p->cur[type] = idx + 1; in phy_record()
8582 for (i = 0; i < p->cur[PHY_TYPE_PMA_PMD]; i++) { in port_has_10g()
8583 if (p->phy_port[PHY_TYPE_PMA_PMD][i] == port) in port_has_10g()
8586 for (i = 0; i < p->cur[PHY_TYPE_PCS]; i++) { in port_has_10g()
8587 if (p->phy_port[PHY_TYPE_PCS][i] == port) in port_has_10g()
8614 if (p->cur[PHY_TYPE_MII]) in count_1g_ports()
8615 *lowest = p->phy_port[PHY_TYPE_MII][0]; in count_1g_ports()
8617 return p->cur[PHY_TYPE_MII]; in count_1g_ports()
8622 int num_ports = parent->num_ports; in niu_n2_divide_channels()
8626 parent->rxchan_per_port[i] = (16 / num_ports); in niu_n2_divide_channels()
8627 parent->txchan_per_port[i] = (16 / num_ports); in niu_n2_divide_channels()
8630 parent->index, i, in niu_n2_divide_channels()
8631 parent->rxchan_per_port[i], in niu_n2_divide_channels()
8632 parent->txchan_per_port[i]); in niu_n2_divide_channels()
8639 int num_ports = parent->num_ports; in niu_divide_channels()
8651 rx_chans_per_10g = (NIU_NUM_RXCHAN - in niu_divide_channels()
8656 tx_chans_per_10g = (NIU_NUM_TXCHAN - in niu_divide_channels()
8663 int type = phy_decode(parent->port_phy, i); in niu_divide_channels()
8666 parent->rxchan_per_port[i] = rx_chans_per_10g; in niu_divide_channels()
8667 parent->txchan_per_port[i] = tx_chans_per_10g; in niu_divide_channels()
8669 parent->rxchan_per_port[i] = rx_chans_per_1g; in niu_divide_channels()
8670 parent->txchan_per_port[i] = tx_chans_per_1g; in niu_divide_channels()
8673 parent->index, i, in niu_divide_channels()
8674 parent->rxchan_per_port[i], in niu_divide_channels()
8675 parent->txchan_per_port[i]); in niu_divide_channels()
8676 tot_rx += parent->rxchan_per_port[i]; in niu_divide_channels()
8677 tot_tx += parent->txchan_per_port[i]; in niu_divide_channels()
8682 parent->index, tot_rx); in niu_divide_channels()
8684 parent->rxchan_per_port[i] = 1; in niu_divide_channels()
8688 parent->index, tot_tx); in niu_divide_channels()
8690 parent->txchan_per_port[i] = 1; in niu_divide_channels()
8694 parent->index, tot_rx, tot_tx); in niu_divide_channels()
8701 int i, num_ports = parent->num_ports; in niu_divide_rdc_groups()
8711 struct niu_rdc_tables *tp = &parent->rdc_group_cfg[i]; in niu_divide_rdc_groups()
8712 int grp, num_channels = parent->rxchan_per_port[i]; in niu_divide_rdc_groups()
8715 tp->first_table_num = rdc_group; in niu_divide_rdc_groups()
8716 tp->num_tables = rdc_groups_per_port; in niu_divide_rdc_groups()
8718 for (grp = 0; grp < tp->num_tables; grp++) { in niu_divide_rdc_groups()
8719 struct rdc_table *rt = &tp->tables[grp]; in niu_divide_rdc_groups() local
8723 parent->index, i, tp->first_table_num + grp); in niu_divide_rdc_groups()
8725 rt->rxdma_channel[slot] = in niu_divide_rdc_groups()
8728 pr_cont("%d ", rt->rxdma_channel[slot]); in niu_divide_rdc_groups()
8736 parent->rdc_default[i] = rdc_channel_base; in niu_divide_rdc_groups()
8787 struct phy_probe_info *info = &parent->phy_probe_info; in walk_phys()
8795 if (!strcmp(np->vpd.model, NIU_ALONSO_MDL_STR) || in walk_phys()
8796 !strcmp(np->vpd.model, NIU_KIMI_MDL_STR)) { in walk_phys()
8799 parent->plat_type = PLAT_TYPE_ATCA_CP3220; in walk_phys()
8800 parent->num_ports = 4; in walk_phys()
8805 } else if (!strcmp(np->vpd.model, NIU_FOXXY_MDL_STR)) { in walk_phys()
8808 parent->num_ports = 2; in walk_phys()
8811 } else if ((np->flags & NIU_FLAGS_XCVR_SERDES) && in walk_phys()
8812 (parent->plat_type == PLAT_TYPE_NIU)) { in walk_phys()
8814 if (np->flags & NIU_FLAGS_10G) { in walk_phys()
8832 parent->plat_type = PLAT_TYPE_VF_P0; in walk_phys()
8834 parent->plat_type = PLAT_TYPE_VF_P1; in walk_phys()
8852 val = phy_encode(PORT_TYPE_10G, np->port); in walk_phys()
8857 parent->plat_type = PLAT_TYPE_VF_P0; in walk_phys()
8859 parent->plat_type = PLAT_TYPE_VF_P1; in walk_phys()
8879 parent->plat_type = PLAT_TYPE_VF_P0; in walk_phys()
8881 parent->plat_type = PLAT_TYPE_VF_P1; in walk_phys()
8892 pr_err("Unsupported port config 10G[%d] 1G[%d]\n", in walk_phys()
8894 return -EINVAL; in walk_phys()
8898 parent->port_phy = val; in walk_phys()
8900 if (parent->plat_type == PLAT_TYPE_NIU) in walk_phys()
8911 return -EINVAL; in walk_phys()
8916 struct niu_parent *parent = np->parent; in niu_probe_ports()
8919 if (parent->port_phy == PORT_PHY_UNKNOWN) { in niu_probe_ports()
8929 if (parent->port_phy == PORT_PHY_INVALID) in niu_probe_ports()
8930 return -EINVAL; in niu_probe_ports()
8937 struct niu_classifier *cp = &np->clas; in niu_classifier_swstate_init()
8939 cp->tcam_top = (u16) np->port; in niu_classifier_swstate_init()
8940 cp->tcam_sz = np->parent->tcam_num_entries / np->parent->num_ports; in niu_classifier_swstate_init()
8941 cp->h1_init = 0xffffffff; in niu_classifier_swstate_init()
8942 cp->h2_init = 0xffff; in niu_classifier_swstate_init()
8949 struct niu_link_config *lp = &np->link_config; in niu_link_config_init()
8951 lp->advertising = (ADVERTISED_10baseT_Half | in niu_link_config_init()
8959 lp->speed = lp->active_speed = SPEED_INVALID; in niu_link_config_init()
8960 lp->duplex = DUPLEX_FULL; in niu_link_config_init()
8961 lp->active_duplex = DUPLEX_INVALID; in niu_link_config_init()
8962 lp->autoneg = 1; in niu_link_config_init()
8964 lp->loopback_mode = LOOPBACK_MAC; in niu_link_config_init()
8965 lp->active_speed = SPEED_10000; in niu_link_config_init()
8966 lp->active_duplex = DUPLEX_FULL; in niu_link_config_init()
8968 lp->loopback_mode = LOOPBACK_DISABLED; in niu_link_config_init()
8974 switch (np->port) { in niu_init_mac_ipp_pcs_base()
8976 np->mac_regs = np->regs + XMAC_PORT0_OFF; in niu_init_mac_ipp_pcs_base()
8977 np->ipp_off = 0x00000; in niu_init_mac_ipp_pcs_base()
8978 np->pcs_off = 0x04000; in niu_init_mac_ipp_pcs_base()
8979 np->xpcs_off = 0x02000; in niu_init_mac_ipp_pcs_base()
8983 np->mac_regs = np->regs + XMAC_PORT1_OFF; in niu_init_mac_ipp_pcs_base()
8984 np->ipp_off = 0x08000; in niu_init_mac_ipp_pcs_base()
8985 np->pcs_off = 0x0a000; in niu_init_mac_ipp_pcs_base()
8986 np->xpcs_off = 0x08000; in niu_init_mac_ipp_pcs_base()
8990 np->mac_regs = np->regs + BMAC_PORT2_OFF; in niu_init_mac_ipp_pcs_base()
8991 np->ipp_off = 0x04000; in niu_init_mac_ipp_pcs_base()
8992 np->pcs_off = 0x0e000; in niu_init_mac_ipp_pcs_base()
8993 np->xpcs_off = ~0UL; in niu_init_mac_ipp_pcs_base()
8997 np->mac_regs = np->regs + BMAC_PORT3_OFF; in niu_init_mac_ipp_pcs_base()
8998 np->ipp_off = 0x0c000; in niu_init_mac_ipp_pcs_base()
8999 np->pcs_off = 0x12000; in niu_init_mac_ipp_pcs_base()
9000 np->xpcs_off = ~0UL; in niu_init_mac_ipp_pcs_base()
9004 dev_err(np->device, "Port %u is invalid, cannot compute MAC block offset\n", np->port); in niu_init_mac_ipp_pcs_base()
9005 return -EINVAL; in niu_init_mac_ipp_pcs_base()
9014 struct niu_parent *parent = np->parent; in niu_try_msix()
9015 struct pci_dev *pdev = np->pdev; in niu_try_msix()
9019 first_ldg = (NIU_NUM_LDG / parent->num_ports) * np->port; in niu_try_msix()
9020 for (i = 0; i < (NIU_NUM_LDG / parent->num_ports); i++) in niu_try_msix()
9023 num_irqs = (parent->rxchan_per_port[np->port] + in niu_try_msix()
9024 parent->txchan_per_port[np->port] + in niu_try_msix()
9025 (np->port == 0 ? 3 : 1)); in niu_try_msix()
9026 BUG_ON(num_irqs > (NIU_NUM_LDG / parent->num_ports)); in niu_try_msix()
9035 np->flags &= ~NIU_FLAGS_MSIX; in niu_try_msix()
9039 np->flags |= NIU_FLAGS_MSIX; in niu_try_msix()
9041 np->ldg[i].irq = msi_vec[i].vector; in niu_try_msix()
9042 np->num_ldg = num_irqs; in niu_try_msix()
9048 struct platform_device *op = np->op; in niu_n2_irq_init()
9052 int_prop = of_get_property(op->dev.of_node, "interrupts", NULL); in niu_n2_irq_init()
9054 return -ENODEV; in niu_n2_irq_init()
9056 for (i = 0; i < op->archdata.num_irqs; i++) { in niu_n2_irq_init()
9058 np->ldg[i].irq = op->archdata.irqs[i]; in niu_n2_irq_init()
9061 np->num_ldg = op->archdata.num_irqs; in niu_n2_irq_init()
9065 return -EINVAL; in niu_n2_irq_init()
9071 struct niu_parent *parent = np->parent; in niu_ldg_init()
9077 np->num_ldg = 1; in niu_ldg_init()
9078 np->ldg[0].irq = np->dev->irq; in niu_ldg_init()
9079 if (parent->plat_type == PLAT_TYPE_NIU) { in niu_ldg_init()
9086 port = np->port; in niu_ldg_init()
9087 for (i = 0; i < np->num_ldg; i++) { in niu_ldg_init()
9088 struct niu_ldg *lp = &np->ldg[i]; in niu_ldg_init()
9090 netif_napi_add(np->dev, &lp->napi, niu_poll, 64); in niu_ldg_init()
9092 lp->np = np; in niu_ldg_init()
9093 lp->ldg_num = ldg_num_map[i]; in niu_ldg_init()
9094 lp->timer = 2; /* XXX */ in niu_ldg_init()
9100 if (np->parent->plat_type != PLAT_TYPE_NIU) { in niu_ldg_init()
9101 err = niu_set_ldg_sid(np, lp->ldg_num, port, i); in niu_ldg_init()
9126 if (ldg_rotor == np->num_ldg) in niu_ldg_init()
9137 if (ldg_rotor == np->num_ldg) in niu_ldg_init()
9147 if (ldg_rotor == np->num_ldg) in niu_ldg_init()
9154 first_chan += parent->rxchan_per_port[i]; in niu_ldg_init()
9155 num_chan = parent->rxchan_per_port[port]; in niu_ldg_init()
9164 if (ldg_rotor == np->num_ldg) in niu_ldg_init()
9170 first_chan += parent->txchan_per_port[i]; in niu_ldg_init()
9171 num_chan = parent->txchan_per_port[port]; in niu_ldg_init()
9179 if (ldg_rotor == np->num_ldg) in niu_ldg_init()
9188 if (np->flags & NIU_FLAGS_MSIX) in niu_ldg_free()
9189 pci_disable_msix(np->pdev); in niu_ldg_free()
9195 struct net_device *dev = np->dev; in niu_get_of_props()
9202 if (np->parent->plat_type == PLAT_TYPE_NIU) in niu_get_of_props()
9203 dp = np->op->dev.of_node; in niu_get_of_props()
9205 dp = pci_device_to_OF_node(np->pdev); in niu_get_of_props()
9207 phy_type = of_get_property(dp, "phy-type", &prop_len); in niu_get_of_props()
9209 netdev_err(dev, "%pOF: OF node lacks phy-type property\n", dp); in niu_get_of_props()
9210 return -EINVAL; in niu_get_of_props()
9214 return -ENODEV; in niu_get_of_props()
9216 strcpy(np->vpd.phy_type, phy_type); in niu_get_of_props()
9218 if (niu_phy_type_prop_decode(np, np->vpd.phy_type)) { in niu_get_of_props()
9220 dp, np->vpd.phy_type); in niu_get_of_props()
9221 return -EINVAL; in niu_get_of_props()
9224 mac_addr = of_get_property(dp, "local-mac-address", &prop_len); in niu_get_of_props()
9226 netdev_err(dev, "%pOF: OF node lacks local-mac-address property\n", in niu_get_of_props()
9228 return -EINVAL; in niu_get_of_props()
9230 if (prop_len != dev->addr_len) { in niu_get_of_props()
9234 memcpy(dev->dev_addr, mac_addr, dev->addr_len); in niu_get_of_props()
9235 if (!is_valid_ether_addr(&dev->dev_addr[0])) { in niu_get_of_props()
9237 netdev_err(dev, "%pOF: [ %pM ]\n", dp, dev->dev_addr); in niu_get_of_props()
9238 return -EINVAL; in niu_get_of_props()
9244 strcpy(np->vpd.model, model); in niu_get_of_props()
9246 if (of_find_property(dp, "hot-swappable-phy", &prop_len)) { in niu_get_of_props()
9247 np->flags |= (NIU_FLAGS_10G | NIU_FLAGS_FIBER | in niu_get_of_props()
9253 return -EINVAL; in niu_get_of_props()
9263 if (err == -ENODEV) in niu_get_invariants()
9278 if (np->parent->plat_type == PLAT_TYPE_NIU) in niu_get_invariants()
9279 return -EINVAL; in niu_get_invariants()
9283 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_get_invariants()
9289 if (np->flags & NIU_FLAGS_VPD_VALID) { in niu_get_invariants()
9296 if (!(np->flags & NIU_FLAGS_VPD_VALID)) { in niu_get_invariants()
9330 struct niu_parent *p = dev_get_platdata(&plat_dev->dev); in show_port_phy()
9331 u32 port_phy = p->port_phy; in show_port_phy()
9339 for (i = 0; i < p->num_ports; i++) { in show_port_phy()
9345 type_str = "10G"; in show_port_phy()
9347 type_str = "1G"; in show_port_phy()
9353 return buf - orig_buf; in show_port_phy()
9360 struct niu_parent *p = dev_get_platdata(&plat_dev->dev); in show_plat_type()
9363 switch (p->plat_type) { in show_plat_type()
9389 struct niu_parent *p = dev_get_platdata(&plat_dev->dev); in __show_chan_per_port()
9394 arr = (rx ? p->rxchan_per_port : p->txchan_per_port); in __show_chan_per_port()
9396 for (i = 0; i < p->num_ports; i++) { in __show_chan_per_port()
9403 return buf - orig_buf; in __show_chan_per_port()
9422 struct niu_parent *p = dev_get_platdata(&plat_dev->dev); in show_num_ports()
9424 return sprintf(buf, "%d\n", p->num_ports); in show_num_ports()
9443 plat_dev = platform_device_register_simple("niu-board", niu_parent_index, in niu_new_parent()
9449 int err = device_create_file(&plat_dev->dev, in niu_new_parent()
9459 p->index = niu_parent_index++; in niu_new_parent()
9461 plat_dev->dev.platform_data = p; in niu_new_parent()
9462 p->plat_dev = plat_dev; in niu_new_parent()
9464 memcpy(&p->id, id, sizeof(*id)); in niu_new_parent()
9465 p->plat_type = ptype; in niu_new_parent()
9466 INIT_LIST_HEAD(&p->list); in niu_new_parent()
9467 atomic_set(&p->refcnt, 0); in niu_new_parent()
9468 list_add(&p->list, &niu_parent_list); in niu_new_parent()
9469 spin_lock_init(&p->lock); in niu_new_parent()
9471 p->rxdma_clock_divider = 7500; in niu_new_parent()
9473 p->tcam_num_entries = NIU_PCI_TCAM_ENTRIES; in niu_new_parent()
9474 if (p->plat_type == PLAT_TYPE_NIU) in niu_new_parent()
9475 p->tcam_num_entries = NIU_NONPCI_TCAM_ENTRIES; in niu_new_parent()
9478 int index = i - CLASS_CODE_USER_PROG1; in niu_new_parent()
9480 p->tcam_key[index] = TCAM_KEY_TSEL; in niu_new_parent()
9481 p->flow_key[index] = (FLOW_KEY_IPSA | in niu_new_parent()
9491 p->ldg_map[i] = LDG_INVALID; in niu_new_parent()
9504 int port = np->port; in niu_get_parent()
9509 if (!memcmp(id, &tmp->id, sizeof(*id))) { in niu_get_parent()
9522 err = sysfs_create_link(&p->plat_dev->dev.kobj, in niu_get_parent()
9523 &np->device->kobj, in niu_get_parent()
9526 p->ports[port] = np; in niu_get_parent()
9527 atomic_inc(&p->refcnt); in niu_get_parent()
9537 struct niu_parent *p = np->parent; in niu_put_parent()
9538 u8 port = np->port; in niu_put_parent()
9541 BUG_ON(!p || p->ports[port] != np); in niu_put_parent()
9543 netif_printk(np, probe, KERN_DEBUG, np->dev, in niu_put_parent()
9550 sysfs_remove_link(&p->plat_dev->dev.kobj, port_name); in niu_put_parent()
9552 p->ports[port] = NULL; in niu_put_parent()
9553 np->parent = NULL; in niu_put_parent()
9555 if (atomic_dec_and_test(&p->refcnt)) { in niu_put_parent()
9556 list_del(&p->list); in niu_put_parent()
9557 platform_device_unregister(p->plat_dev); in niu_put_parent()
9640 np->dev = dev; in niu_alloc_and_init()
9641 np->pdev = pdev; in niu_alloc_and_init()
9642 np->op = op; in niu_alloc_and_init()
9643 np->device = gen_dev; in niu_alloc_and_init()
9644 np->ops = ops; in niu_alloc_and_init()
9646 np->msg_enable = niu_debug; in niu_alloc_and_init()
9648 spin_lock_init(&np->lock); in niu_alloc_and_init()
9649 INIT_WORK(&np->reset_task, niu_reset_task); in niu_alloc_and_init()
9651 np->port = port; in niu_alloc_and_init()
9671 dev->netdev_ops = &niu_netdev_ops; in niu_assign_netdev_ops()
9672 dev->ethtool_ops = &niu_ethtool_ops; in niu_assign_netdev_ops()
9673 dev->watchdog_timeo = NIU_TX_TIMEOUT; in niu_assign_netdev_ops()
9678 struct net_device *dev = np->dev; in niu_device_announce()
9680 pr_info("%s: NIU Ethernet %pM\n", dev->name, dev->dev_addr); in niu_device_announce()
9682 if (np->parent->plat_type == PLAT_TYPE_ATCA_CP3220) { in niu_device_announce()
9684 dev->name, in niu_device_announce()
9685 (np->flags & NIU_FLAGS_XMAC ? "XMAC" : "BMAC"), in niu_device_announce()
9686 (np->flags & NIU_FLAGS_10G ? "10G" : "1G"), in niu_device_announce()
9687 (np->flags & NIU_FLAGS_FIBER ? "RGMII FIBER" : "SERDES"), in niu_device_announce()
9688 (np->mac_xcvr == MAC_XCVR_MII ? "MII" : in niu_device_announce()
9689 (np->mac_xcvr == MAC_XCVR_PCS ? "PCS" : "XPCS")), in niu_device_announce()
9690 np->vpd.phy_type); in niu_device_announce()
9693 dev->name, in niu_device_announce()
9694 (np->flags & NIU_FLAGS_XMAC ? "XMAC" : "BMAC"), in niu_device_announce()
9695 (np->flags & NIU_FLAGS_10G ? "10G" : "1G"), in niu_device_announce()
9696 (np->flags & NIU_FLAGS_FIBER ? "FIBER" : in niu_device_announce()
9697 (np->flags & NIU_FLAGS_XCVR_SERDES ? "SERDES" : in niu_device_announce()
9699 (np->mac_xcvr == MAC_XCVR_MII ? "MII" : in niu_device_announce()
9700 (np->mac_xcvr == MAC_XCVR_PCS ? "PCS" : "XPCS")), in niu_device_announce()
9701 np->vpd.phy_type); in niu_device_announce()
9707 dev->hw_features = NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_RXHASH; in niu_set_basic_features()
9708 dev->features |= dev->hw_features | NETIF_F_RXCSUM; in niu_set_basic_features()
9724 dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); in niu_pci_init_one()
9730 dev_err(&pdev->dev, "Cannot find proper PCI device base addresses, aborting\n"); in niu_pci_init_one()
9731 err = -ENODEV; in niu_pci_init_one()
9737 dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); in niu_pci_init_one()
9742 dev_err(&pdev->dev, "Cannot find PCI Express capability, aborting\n"); in niu_pci_init_one()
9743 err = -ENODEV; in niu_pci_init_one()
9747 dev = niu_alloc_and_init(&pdev->dev, pdev, NULL, in niu_pci_init_one()
9748 &niu_pci_ops, PCI_FUNC(pdev->devfn)); in niu_pci_init_one()
9750 err = -ENOMEM; in niu_pci_init_one()
9756 parent_id.pci.domain = pci_domain_nr(pdev->bus); in niu_pci_init_one()
9757 parent_id.pci.bus = pdev->bus->number; in niu_pci_init_one()
9758 parent_id.pci.device = PCI_SLOT(pdev->devfn); in niu_pci_init_one()
9760 np->parent = niu_get_parent(np, &parent_id, in niu_pci_init_one()
9762 if (!np->parent) { in niu_pci_init_one()
9763 err = -ENOMEM; in niu_pci_init_one()
9776 dev->features |= NETIF_F_HIGHDMA; in niu_pci_init_one()
9779 dev_err(&pdev->dev, "Unable to obtain 44 bit DMA for consistent allocations, aborting\n"); in niu_pci_init_one()
9786 dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); in niu_pci_init_one()
9793 dev->priv_flags |= IFF_UNICAST_FLT; in niu_pci_init_one()
9795 np->regs = pci_ioremap_bar(pdev, 0); in niu_pci_init_one()
9796 if (!np->regs) { in niu_pci_init_one()
9797 dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); in niu_pci_init_one()
9798 err = -ENOMEM; in niu_pci_init_one()
9805 dev->irq = pdev->irq; in niu_pci_init_one()
9807 /* MTU range: 68 - 9216 */ in niu_pci_init_one()
9808 dev->min_mtu = ETH_MIN_MTU; in niu_pci_init_one()
9809 dev->max_mtu = NIU_MAX_MTU; in niu_pci_init_one()
9815 if (err != -ENODEV) in niu_pci_init_one()
9816 dev_err(&pdev->dev, "Problem fetching invariants of chip, aborting\n"); in niu_pci_init_one()
9822 dev_err(&pdev->dev, "Cannot register net device, aborting\n"); in niu_pci_init_one()
9833 if (np->regs) { in niu_pci_init_one()
9834 iounmap(np->regs); in niu_pci_init_one()
9835 np->regs = NULL; in niu_pci_init_one()
9861 if (np->regs) { in niu_pci_remove_one()
9862 iounmap(np->regs); in niu_pci_remove_one()
9863 np->regs = NULL; in niu_pci_remove_one()
9885 flush_work(&np->reset_task); in niu_suspend()
9888 del_timer_sync(&np->timer); in niu_suspend()
9890 spin_lock_irqsave(&np->lock, flags); in niu_suspend()
9892 spin_unlock_irqrestore(&np->lock, flags); in niu_suspend()
9896 spin_lock_irqsave(&np->lock, flags); in niu_suspend()
9898 spin_unlock_irqrestore(&np->lock, flags); in niu_suspend()
9915 spin_lock_irqsave(&np->lock, flags); in niu_resume()
9919 np->timer.expires = jiffies + HZ; in niu_resume()
9920 add_timer(&np->timer); in niu_resume()
9924 spin_unlock_irqrestore(&np->lock, flags); in niu_resume()
10008 reg = of_get_property(op->dev.of_node, "reg", NULL); in niu_of_probe()
10010 dev_err(&op->dev, "%pOF: No 'reg' property, aborting\n", in niu_of_probe()
10011 op->dev.of_node); in niu_of_probe()
10012 return -ENODEV; in niu_of_probe()
10015 dev = niu_alloc_and_init(&op->dev, NULL, op, in niu_of_probe()
10018 err = -ENOMEM; in niu_of_probe()
10024 parent_id.of = of_get_parent(op->dev.of_node); in niu_of_probe()
10026 np->parent = niu_get_parent(np, &parent_id, in niu_of_probe()
10028 if (!np->parent) { in niu_of_probe()
10029 err = -ENOMEM; in niu_of_probe()
10035 np->regs = of_ioremap(&op->resource[1], 0, in niu_of_probe()
10036 resource_size(&op->resource[1]), in niu_of_probe()
10038 if (!np->regs) { in niu_of_probe()
10039 dev_err(&op->dev, "Cannot map device registers, aborting\n"); in niu_of_probe()
10040 err = -ENOMEM; in niu_of_probe()
10044 np->vir_regs_1 = of_ioremap(&op->resource[2], 0, in niu_of_probe()
10045 resource_size(&op->resource[2]), in niu_of_probe()
10046 "niu vregs-1"); in niu_of_probe()
10047 if (!np->vir_regs_1) { in niu_of_probe()
10048 dev_err(&op->dev, "Cannot map device vir registers 1, aborting\n"); in niu_of_probe()
10049 err = -ENOMEM; in niu_of_probe()
10053 np->vir_regs_2 = of_ioremap(&op->resource[3], 0, in niu_of_probe()
10054 resource_size(&op->resource[3]), in niu_of_probe()
10055 "niu vregs-2"); in niu_of_probe()
10056 if (!np->vir_regs_2) { in niu_of_probe()
10057 dev_err(&op->dev, "Cannot map device vir registers 2, aborting\n"); in niu_of_probe()
10058 err = -ENOMEM; in niu_of_probe()
10066 if (err != -ENODEV) in niu_of_probe()
10067 dev_err(&op->dev, "Problem fetching invariants of chip, aborting\n"); in niu_of_probe()
10073 dev_err(&op->dev, "Cannot register net device, aborting\n"); in niu_of_probe()
10084 if (np->vir_regs_1) { in niu_of_probe()
10085 of_iounmap(&op->resource[2], np->vir_regs_1, in niu_of_probe()
10086 resource_size(&op->resource[2])); in niu_of_probe()
10087 np->vir_regs_1 = NULL; in niu_of_probe()
10090 if (np->vir_regs_2) { in niu_of_probe()
10091 of_iounmap(&op->resource[3], np->vir_regs_2, in niu_of_probe()
10092 resource_size(&op->resource[3])); in niu_of_probe()
10093 np->vir_regs_2 = NULL; in niu_of_probe()
10096 if (np->regs) { in niu_of_probe()
10097 of_iounmap(&op->resource[1], np->regs, in niu_of_probe()
10098 resource_size(&op->resource[1])); in niu_of_probe()
10099 np->regs = NULL; in niu_of_probe()
10121 if (np->vir_regs_1) { in niu_of_remove()
10122 of_iounmap(&op->resource[2], np->vir_regs_1, in niu_of_remove()
10123 resource_size(&op->resource[2])); in niu_of_remove()
10124 np->vir_regs_1 = NULL; in niu_of_remove()
10127 if (np->vir_regs_2) { in niu_of_remove()
10128 of_iounmap(&op->resource[3], np->vir_regs_2, in niu_of_remove()
10129 resource_size(&op->resource[3])); in niu_of_remove()
10130 np->vir_regs_2 = NULL; in niu_of_remove()
10133 if (np->regs) { in niu_of_remove()
10134 of_iounmap(&op->resource[1], np->regs, in niu_of_remove()
10135 resource_size(&op->resource[1])); in niu_of_remove()
10136 np->regs = NULL; in niu_of_remove()