sky2: revert to access PCI config via device space
[powerpc.git] / drivers / net / sky2.c
index 24cfb62..65071e4 100644 (file)
@@ -52,7 +52,7 @@
 #include "sky2.h"
 
 #define DRV_NAME               "sky2"
-#define DRV_VERSION            "1.19"
+#define DRV_VERSION            "1.20"
 #define PFX                    DRV_NAME " "
 
 /*
@@ -121,6 +121,7 @@ static const struct pci_device_id sky2_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4353) }, /* 88E8039 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4354) }, /* 88E8040 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4356) }, /* 88EC033 */
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4357) }, /* 88E8042 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x435A) }, /* 88E8048 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4360) }, /* 88E8052 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4361) }, /* 88E8050 */
@@ -134,6 +135,7 @@ static const struct pci_device_id sky2_id_table[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x4369) }, /* 88EC042 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436A) }, /* 88E8058 */
        { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436B) }, /* 88E8071 */
+       { PCI_DEVICE(PCI_VENDOR_ID_MARVELL, 0x436C) }, /* 88E8072 */
        { 0 }
 };
 
@@ -156,7 +158,7 @@ static const char *yukon2_name[] = {
 
 static void sky2_set_multicast(struct net_device *dev);
 
-/* Access to external PHY */
+/* Access to PHY via serial interconnect */
 static int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val)
 {
        int i;
@@ -166,13 +168,22 @@ static int gm_phy_write(struct sky2_hw *hw, unsigned port, u16 reg, u16 val)
                    GM_SMI_CT_PHY_AD(PHY_ADDR_MARV) | GM_SMI_CT_REG_AD(reg));
 
        for (i = 0; i < PHY_RETRIES; i++) {
-               if (!(gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_BUSY))
+               u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL);
+               if (ctrl == 0xffff)
+                       goto io_error;
+
+               if (!(ctrl & GM_SMI_CT_BUSY))
                        return 0;
-               udelay(1);
+
+               udelay(10);
        }
 
-       printk(KERN_WARNING PFX "%s: phy write timeout\n", hw->dev[port]->name);
+       dev_warn(&hw->pdev->dev,"%s: phy write timeout\n", hw->dev[port]->name);
        return -ETIMEDOUT;
+
+io_error:
+       dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name);
+       return -EIO;
 }
 
 static int __gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg, u16 *val)
@@ -183,23 +194,29 @@ static int __gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg, u16 *val)
                    | GM_SMI_CT_REG_AD(reg) | GM_SMI_CT_OP_RD);
 
        for (i = 0; i < PHY_RETRIES; i++) {
-               if (gma_read16(hw, port, GM_SMI_CTRL) & GM_SMI_CT_RD_VAL) {
+               u16 ctrl = gma_read16(hw, port, GM_SMI_CTRL);
+               if (ctrl == 0xffff)
+                       goto io_error;
+
+               if (ctrl & GM_SMI_CT_RD_VAL) {
                        *val = gma_read16(hw, port, GM_SMI_DATA);
                        return 0;
                }
 
-               udelay(1);
+               udelay(10);
        }
 
+       dev_warn(&hw->pdev->dev, "%s: phy read timeout\n", hw->dev[port]->name);
        return -ETIMEDOUT;
+io_error:
+       dev_err(&hw->pdev->dev, "%s: phy I/O error\n", hw->dev[port]->name);
+       return -EIO;
 }
 
-static u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg)
+static inline u16 gm_phy_read(struct sky2_hw *hw, unsigned port, u16 reg)
 {
        u16 v;
-
-       if (__gm_phy_read(hw, port, reg, &v) != 0)
-               printk(KERN_WARNING PFX "%s: phy read timeout\n", hw->dev[port]->name);
+       __gm_phy_read(hw, port, reg, &v);
        return v;
 }
 
@@ -223,22 +240,21 @@ static void sky2_power_on(struct sky2_hw *hw)
                sky2_write8(hw, B2_Y2_CLK_GATE, 0);
 
        if (hw->flags & SKY2_HW_ADV_POWER_CTL) {
-               struct pci_dev *pdev = hw->pdev;
                u32 reg;
 
-               pci_write_config_dword(pdev, PCI_DEV_REG3, 0);
+               sky2_pci_write32(hw, PCI_DEV_REG3, 0);
 
-               pci_read_config_dword(pdev, PCI_DEV_REG4, &reg);
+               reg = sky2_pci_read32(hw, PCI_DEV_REG4);
                /* set all bits to 0 except bits 15..12 and 8 */
                reg &= P_ASPM_CONTROL_MSK;
-               pci_write_config_dword(pdev, PCI_DEV_REG4, reg);
+               sky2_pci_write32(hw, PCI_DEV_REG4, reg);
 
-               pci_read_config_dword(pdev, PCI_DEV_REG5, &reg);
+               reg = sky2_pci_read32(hw, PCI_DEV_REG5);
                /* set all bits to 0 except bits 28 & 27 */
                reg &= P_CTL_TIM_VMAIN_AV_MSK;
-               pci_write_config_dword(pdev, PCI_DEV_REG5, reg);
+               sky2_pci_write32(hw, PCI_DEV_REG5, reg);
 
-               pci_write_config_dword(pdev, PCI_CFG_REG_1, 0);
+               sky2_pci_write32(hw, PCI_CFG_REG_1, 0);
 
                /* Enable workaround for dev 4.107 on Yukon-Ultra & Extreme */
                reg = sky2_read32(hw, B2_GP_IO);
@@ -273,8 +289,6 @@ static void sky2_gmac_reset(struct sky2_hw *hw, unsigned port)
 
        /* disable all GMAC IRQ's */
        sky2_write8(hw, SK_REG(port, GMAC_IRQ_MSK), 0);
-       /* disable PHY IRQs */
-       gm_phy_write(hw, port, PHY_MARV_INT_MASK, 0);
 
        gma_write16(hw, port, GM_MC_ADDR_H1, 0);        /* clear MC hash */
        gma_write16(hw, port, GM_MC_ADDR_H2, 0);
@@ -604,12 +618,11 @@ static void sky2_phy_init(struct sky2_hw *hw, unsigned port)
 
 static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
 {
-       struct pci_dev *pdev = hw->pdev;
        u32 reg1;
        static const u32 phy_power[] = { PCI_Y2_PHY1_POWD, PCI_Y2_PHY2_POWD };
        static const u32 coma_mode[] = { PCI_Y2_PHY1_COMA, PCI_Y2_PHY2_COMA };
 
-       pci_read_config_dword(pdev, PCI_DEV_REG1, &reg1);
+       reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
        /* Turn on/off phy power saving */
        if (onoff)
                reg1 &= ~phy_power[port];
@@ -619,8 +632,8 @@ static void sky2_phy_power(struct sky2_hw *hw, unsigned port, int onoff)
        if (onoff && hw->chip_id == CHIP_ID_YUKON_XL && hw->chip_rev > 1)
                reg1 |= coma_mode[port];
 
-       pci_write_config_dword(pdev, PCI_DEV_REG1, reg1);
-       pci_read_config_dword(pdev, PCI_DEV_REG1, &reg1);
+       sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
+       reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
 
        udelay(100);
 }
@@ -689,9 +702,9 @@ static void sky2_wol_init(struct sky2_port *sky2)
        sky2_write16(hw, WOL_REGS(port, WOL_CTRL_STAT), ctrl);
 
        /* Turn on legacy PCI-Express PME mode */
-       pci_read_config_dword(hw->pdev, PCI_DEV_REG1, &reg1);
+       reg1 = sky2_pci_read32(hw, PCI_DEV_REG1);
        reg1 |= PCI_Y2_PME_LEGACY;
-       pci_write_config_dword(hw->pdev, PCI_DEV_REG1, reg1);
+       sky2_pci_write32(hw, PCI_DEV_REG1, reg1);
 
        /* block receiver */
        sky2_write8(hw, SK_REG(port, RX_GMF_CTRL_T), GMF_RST_SET);
@@ -1305,15 +1318,12 @@ static int sky2_up(struct net_device *dev)
         */
        if (otherdev && netif_running(otherdev) &&
            (cap = pci_find_capability(hw->pdev, PCI_CAP_ID_PCIX))) {
-               struct sky2_port *osky2 = netdev_priv(otherdev);
                u16 cmd;
 
-               pci_read_config_word(hw->pdev, cap + PCI_X_CMD, &cmd);
+               cmd = sky2_pci_read16(hw, cap + PCI_X_CMD);
                cmd &= ~PCI_X_CMD_MAX_SPLIT;
-               pci_write_config_word(hw->pdev, cap + PCI_X_CMD, cmd);
+               sky2_pci_write16(hw, cap + PCI_X_CMD, cmd);
 
-               sky2->rx_csum = 0;
-               osky2->rx_csum = 0;
        }
 
        if (netif_msg_ifup(sky2))
@@ -1805,29 +1815,6 @@ static void sky2_link_up(struct sky2_port *sky2)
        sky2_write8(hw, SK_REG(port, LNK_LED_REG),
                    LINKLED_ON | LINKLED_BLINK_OFF | LINKLED_LINKSYNC_OFF);
 
-       if (hw->flags & SKY2_HW_NEWER_PHY) {
-               u16 pg = gm_phy_read(hw, port, PHY_MARV_EXT_ADR);
-               u16 led = PHY_M_LEDC_LOS_CTRL(1);       /* link active */
-
-               switch(sky2->speed) {
-               case SPEED_10:
-                       led |= PHY_M_LEDC_INIT_CTRL(7);
-                       break;
-
-               case SPEED_100:
-                       led |= PHY_M_LEDC_STA1_CTRL(7);
-                       break;
-
-               case SPEED_1000:
-                       led |= PHY_M_LEDC_STA0_CTRL(7);
-                       break;
-               }
-
-               gm_phy_write(hw, port, PHY_MARV_EXT_ADR, 3);
-               gm_phy_write(hw, port, PHY_MARV_PHY_CTRL, led);
-               gm_phy_write(hw, port, PHY_MARV_EXT_ADR, pg);
-       }
-
        if (netif_msg_link(sky2))
                printk(KERN_INFO PFX
                       "%s: Link is up at %d Mbps, %s duplex, flow control %s\n",
@@ -2247,20 +2234,26 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx)
        do {
                struct sky2_port *sky2;
                struct sky2_status_le *le  = hw->st_le + hw->st_idx;
-               unsigned port = le->css & CSS_LINK_BIT;
+               unsigned port;
                struct net_device *dev;
                struct sk_buff *skb;
                u32 status;
                u16 length;
+               u8 opcode = le->opcode;
+
+               if (!(opcode & HW_OWNER))
+                       break;
 
                hw->st_idx = RING_NEXT(hw->st_idx, STATUS_RING_SIZE);
 
+               port = le->css & CSS_LINK_BIT;
                dev = hw->dev[port];
                sky2 = netdev_priv(dev);
                length = le16_to_cpu(le->length);
                status = le32_to_cpu(le->status);
 
-               switch (le->opcode & ~HW_OWNER) {
+               le->opcode = 0;
+               switch (opcode & ~HW_OWNER) {
                case OP_RXSTAT:
                        ++rx[port];
                        skb = sky2_receive(dev, length, status);
@@ -2353,7 +2346,7 @@ static int sky2_status_intr(struct sky2_hw *hw, int to_do, u16 idx)
                default:
                        if (net_ratelimit())
                                printk(KERN_WARNING PFX
-                                      "unknown status opcode 0x%x\n", le->opcode);
+                                      "unknown status opcode 0x%x\n", opcode);
                }
        } while (hw->st_idx != idx);
 
@@ -2428,24 +2421,37 @@ static void sky2_hw_intr(struct sky2_hw *hw)
        if (status & (Y2_IS_MST_ERR | Y2_IS_IRQ_STAT)) {
                u16 pci_err;
 
-               pci_read_config_word(pdev, PCI_STATUS, &pci_err);
+               pci_err = sky2_pci_read16(hw, PCI_STATUS);
                if (net_ratelimit())
                        dev_err(&pdev->dev, "PCI hardware error (0x%x)\n",
                                pci_err);
 
-               pci_write_config_word(pdev, PCI_STATUS,
+               sky2_pci_write16(hw, PCI_STATUS,
                                      pci_err | PCI_STATUS_ERROR_BITS);
        }
 
        if (status & Y2_IS_PCI_EXP) {
                /* PCI-Express uncorrectable Error occurred */
-               int pos = pci_find_aer_capability(hw->pdev);
+               int aer = pci_find_aer_capability(hw->pdev);
                u32 err;
 
-               pci_read_config_dword(pdev, pos + PCI_ERR_UNCOR_STATUS, &err);
+               if (aer) {
+                       pci_read_config_dword(pdev, aer + PCI_ERR_UNCOR_STATUS,
+                                             &err);
+                       pci_cleanup_aer_uncorrect_error_status(pdev);
+               } else {
+                       /* Either AER not configured, or not working
+                        * because of bad MMCONFIG, so just do recover
+                        * manually.
+                        */
+                       err = sky2_read32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS);
+                       sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
+                                    0xfffffffful);
+               }
+
                if (net_ratelimit())
                        dev_err(&pdev->dev, "PCI Express error (0x%x)\n", err);
-               pci_cleanup_aer_uncorrect_error_status(pdev);
+
        }
 
        if (status & Y2_HWE_L1_MASK)
@@ -2692,13 +2698,10 @@ static inline u32 sky2_clk2us(const struct sky2_hw *hw, u32 clk)
 
 static int __devinit sky2_init(struct sky2_hw *hw)
 {
-       int rc;
        u8 t8;
 
        /* Enable all clocks and check for bad PCI access */
-       rc = pci_write_config_dword(hw->pdev, PCI_DEV_REG3, 0);
-       if (rc)
-               return rc;
+       sky2_pci_write32(hw, PCI_DEV_REG3, 0);
 
        sky2_write8(hw, B0_CTST, CS_RST_CLR);
 
@@ -2791,18 +2794,30 @@ static void sky2_reset(struct sky2_hw *hw)
        sky2_write8(hw, B0_CTST, CS_RST_SET);
        sky2_write8(hw, B0_CTST, CS_RST_CLR);
 
+       /* allow writes to PCI config */
+       sky2_write8(hw, B2_TST_CTRL1, TST_CFG_WRITE_ON);
+
        /* clear PCI errors, if any */
-       pci_read_config_word(pdev, PCI_STATUS, &status);
+       status = sky2_pci_read16(hw, PCI_STATUS);
        status |= PCI_STATUS_ERROR_BITS;
-       pci_write_config_word(pdev, PCI_STATUS, status);
+       sky2_pci_write16(hw, PCI_STATUS, status);
 
        sky2_write8(hw, B0_CTST, CS_MRST_CLR);
 
        cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
        if (cap) {
-               /* Check for advanced error reporting */
-               pci_cleanup_aer_uncorrect_error_status(pdev);
-               pci_cleanup_aer_correct_error_status(pdev);
+               if (pci_find_aer_capability(pdev)) {
+                       /* Check for advanced error reporting */
+                       pci_cleanup_aer_uncorrect_error_status(pdev);
+                       pci_cleanup_aer_correct_error_status(pdev);
+               } else {
+                       dev_warn(&pdev->dev,
+                               "PCI Express Advanced Error Reporting"
+                               " not configured or MMCONFIG problem?\n");
+
+                       sky2_write32(hw, Y2_CFG_AER + PCI_ERR_UNCOR_STATUS,
+                                    0xfffffffful);
+               }
 
                /* If error bit is stuck on ignore it */
                if (sky2_read32(hw, B0_HWE_ISRC) & Y2_IS_PCI_EXP)
@@ -3649,32 +3664,33 @@ static int sky2_set_tso(struct net_device *dev, u32 data)
 static int sky2_get_eeprom_len(struct net_device *dev)
 {
        struct sky2_port *sky2 = netdev_priv(dev);
+       struct sky2_hw *hw = sky2->hw;
        u16 reg2;
 
-       pci_read_config_word(sky2->hw->pdev, PCI_DEV_REG2, &reg2);
+       reg2 = sky2_pci_read16(hw, PCI_DEV_REG2);
        return 1 << ( ((reg2 & PCI_VPD_ROM_SZ) >> 14) + 8);
 }
 
-static u32 sky2_vpd_read(struct pci_dev *pdev, int cap, u16 offset)
+static u32 sky2_vpd_read(struct sky2_hw *hw, int cap, u16 offset)
 {
        u32 val;
 
-       pci_write_config_word(pdev, cap + PCI_VPD_ADDR, offset);
+       sky2_pci_write16(hw, cap + PCI_VPD_ADDR, offset);
 
        do {
-               pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
+               offset = sky2_pci_read16(hw, cap + PCI_VPD_ADDR);
        } while (!(offset & PCI_VPD_ADDR_F));
 
-       pci_read_config_dword(pdev, cap + PCI_VPD_DATA, &val);
+       val = sky2_pci_read32(hw, cap + PCI_VPD_DATA);
        return val;
 }
 
-static void sky2_vpd_write(struct pci_dev *pdev, int cap, u16 offset, u32 val)
+static void sky2_vpd_write(struct sky2_hw *hw, int cap, u16 offset, u32 val)
 {
-       pci_write_config_word(pdev, cap + PCI_VPD_DATA, val);
-       pci_write_config_dword(pdev, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F);
+       sky2_pci_write16(hw, cap + PCI_VPD_DATA, val);
+       sky2_pci_write32(hw, cap + PCI_VPD_ADDR, offset | PCI_VPD_ADDR_F);
        do {
-               pci_read_config_word(pdev, cap + PCI_VPD_ADDR, &offset);
+               offset = sky2_pci_read16(hw, cap + PCI_VPD_ADDR);
        } while (offset & PCI_VPD_ADDR_F);
 }
 
@@ -3692,7 +3708,7 @@ static int sky2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom
        eeprom->magic = SKY2_EEPROM_MAGIC;
 
        while (length > 0) {
-               u32 val = sky2_vpd_read(sky2->hw->pdev, cap, offset);
+               u32 val = sky2_vpd_read(sky2->hw, cap, offset);
                int n = min_t(int, length, sizeof(val));
 
                memcpy(data, &val, n);
@@ -3722,10 +3738,10 @@ static int sky2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom
                int n = min_t(int, length, sizeof(val));
 
                if (n < sizeof(val))
-                       val = sky2_vpd_read(sky2->hw->pdev, cap, offset);
+                       val = sky2_vpd_read(sky2->hw, cap, offset);
                memcpy(&val, data, n);
 
-               sky2_vpd_write(sky2->hw->pdev, cap, offset, val);
+               sky2_vpd_write(sky2->hw, cap, offset, val);
 
                length -= n;
                data += n;
@@ -3974,7 +3990,8 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
        dev->tx_timeout = sky2_tx_timeout;
        dev->watchdog_timeo = TX_WATCHDOG;
 #ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = sky2_netpoll;
+       if (port == 0)
+               dev->poll_controller = sky2_netpoll;
 #endif
 
        sky2 = netdev_priv(dev);
@@ -3989,7 +4006,7 @@ static __devinit struct net_device *sky2_init_netdev(struct sky2_hw *hw,
        sky2->duplex = -1;
        sky2->speed = -1;
        sky2->advertising = sky2_supported_modes(hw);
-       sky2->rx_csum = 1;
+       sky2->rx_csum = (hw->chip_id != CHIP_ID_YUKON_XL);
        sky2->wol = wol;
 
        spin_lock_init(&sky2->phy_lock);
@@ -4160,9 +4177,9 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
         */
        {
                u32 reg;
-               pci_read_config_dword(pdev,PCI_DEV_REG2, &reg);
+               reg = sky2_pci_read32(hw, PCI_DEV_REG2);
                reg &= ~PCI_REV_DESC;
-               pci_write_config_dword(pdev, PCI_DEV_REG2, reg);
+               sky2_pci_write32(hw, PCI_DEV_REG2, reg);
        }
 #endif
 
@@ -4271,7 +4288,7 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
        del_timer_sync(&hw->watchdog_timer);
        cancel_work_sync(&hw->restart_work);
 
-       for (i = hw->ports; i >= 0; --i)
+       for (i = hw->ports-1; i >= 0; --i)
                unregister_netdev(hw->dev[i]);
 
        sky2_write32(hw, B0_IMSK, 0);
@@ -4289,7 +4306,7 @@ static void __devexit sky2_remove(struct pci_dev *pdev)
        pci_release_regions(pdev);
        pci_disable_device(pdev);
 
-       for (i = hw->ports; i >= 0; --i)
+       for (i = hw->ports-1; i >= 0; --i)
                free_netdev(hw->dev[i]);
 
        iounmap(hw->regs);
@@ -4353,7 +4370,7 @@ static int sky2_resume(struct pci_dev *pdev)
        if (hw->chip_id == CHIP_ID_YUKON_EX ||
            hw->chip_id == CHIP_ID_YUKON_EC_U ||
            hw->chip_id == CHIP_ID_YUKON_FE_P)
-               pci_write_config_dword(pdev, PCI_DEV_REG3, 0);
+               sky2_pci_write32(hw, PCI_DEV_REG3, 0);
 
        sky2_reset(hw);
        sky2_write32(hw, B0_IMSK, Y2_IS_BASE);