]> err.no Git - linux-2.6/blobdiff - drivers/net/pasemi_mac.c
pasemi_mac: Fix local-mac-address parsing
[linux-2.6] / drivers / net / pasemi_mac.c
index 78b127c404e9364f0b2c92fad1240047d47b80cf..8d38425e46c3cba389aaee76bada0765be257c3e 100644 (file)
@@ -85,6 +85,7 @@ static int pasemi_get_mac_addr(struct pasemi_mac *mac)
 {
        struct pci_dev *pdev = mac->pdev;
        struct device_node *dn = pci_device_to_OF_node(pdev);
+       int len;
        const u8 *maddr;
        u8 addr[6];
 
@@ -94,13 +95,27 @@ static int pasemi_get_mac_addr(struct pasemi_mac *mac)
                return -ENOENT;
        }
 
-       maddr = get_property(dn, "mac-address", NULL);
+       maddr = of_get_property(dn, "local-mac-address", &len);
+
+       if (maddr && len == 6) {
+               memcpy(mac->mac_addr, maddr, 6);
+               return 0;
+       }
+
+       /* Some old versions of firmware mistakenly uses mac-address
+        * (and as a string) instead of a byte array in local-mac-address.
+        */
+
+       if (maddr == NULL)
+               maddr = of_get_property(dn, "mac-address", NULL);
+
        if (maddr == NULL) {
                dev_warn(&pdev->dev,
                         "no mac address in device tree, not configuring\n");
                return -ENOENT;
        }
 
+
        if (sscanf(maddr, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &addr[0],
                   &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]) != 6) {
                dev_warn(&pdev->dev,
@@ -108,7 +123,8 @@ static int pasemi_get_mac_addr(struct pasemi_mac *mac)
                return -EINVAL;
        }
 
-       memcpy(mac->mac_addr, addr, sizeof(addr));
+       memcpy(mac->mac_addr, addr, 6);
+
        return 0;
 }
 
@@ -379,17 +395,14 @@ static void pasemi_mac_replenish_rx_ring(struct net_device *dev)
 
 static void pasemi_mac_restart_rx_intr(struct pasemi_mac *mac)
 {
-       unsigned int reg, stat;
+       unsigned int reg, pcnt;
        /* Re-enable packet count interrupts: finally
         * ack the packet count interrupt we got in rx_intr.
         */
 
-       pci_read_config_dword(mac->iob_pdev,
-                             PAS_IOB_DMA_RXCH_STAT(mac->dma_rxch),
-                             &stat);
+       pcnt = *mac->rx_status & PAS_STATUS_PCNT_M;
 
-       reg = PAS_IOB_DMA_RXCH_RESET_PCNT(stat & PAS_IOB_DMA_RXCH_STAT_CNTDEL_M)
-               | PAS_IOB_DMA_RXCH_RESET_PINTC;
+       reg = PAS_IOB_DMA_RXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_RXCH_RESET_PINTC;
 
        pci_write_config_dword(mac->iob_pdev,
                               PAS_IOB_DMA_RXCH_RESET(mac->dma_rxch),
@@ -398,14 +411,12 @@ static void pasemi_mac_restart_rx_intr(struct pasemi_mac *mac)
 
 static void pasemi_mac_restart_tx_intr(struct pasemi_mac *mac)
 {
-       unsigned int reg, stat;
+       unsigned int reg, pcnt;
 
        /* Re-enable packet count interrupts */
-       pci_read_config_dword(mac->iob_pdev,
-                             PAS_IOB_DMA_TXCH_STAT(mac->dma_txch), &stat);
+       pcnt = *mac->tx_status & PAS_STATUS_PCNT_M;
 
-       reg = PAS_IOB_DMA_TXCH_RESET_PCNT(stat & PAS_IOB_DMA_TXCH_STAT_CNTDEL_M)
-               | PAS_IOB_DMA_TXCH_RESET_PINTC;
+       reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
 
        pci_write_config_dword(mac->iob_pdev,
                               PAS_IOB_DMA_TXCH_RESET(mac->dma_txch), reg);
@@ -586,21 +597,24 @@ static irqreturn_t pasemi_mac_tx_intr(int irq, void *data)
 {
        struct net_device *dev = data;
        struct pasemi_mac *mac = netdev_priv(dev);
-       unsigned int reg;
+       unsigned int reg, pcnt;
 
        if (!(*mac->tx_status & PAS_STATUS_CAUSE_M))
                return IRQ_NONE;
 
        pasemi_mac_clean_tx(mac);
 
-       reg = PAS_IOB_DMA_TXCH_RESET_PINTC;
+       pcnt = *mac->tx_status & PAS_STATUS_PCNT_M;
+
+       reg = PAS_IOB_DMA_TXCH_RESET_PCNT(pcnt) | PAS_IOB_DMA_TXCH_RESET_PINTC;
 
        if (*mac->tx_status & PAS_STATUS_SOFT)
                reg |= PAS_IOB_DMA_TXCH_RESET_SINTC;
        if (*mac->tx_status & PAS_STATUS_ERROR)
                reg |= PAS_IOB_DMA_TXCH_RESET_DINTC;
 
-       pci_write_config_dword(mac->iob_pdev, PAS_IOB_DMA_TXCH_RESET(mac->dma_txch),
+       pci_write_config_dword(mac->iob_pdev,
+                              PAS_IOB_DMA_TXCH_RESET(mac->dma_txch),
                               reg);
 
        return IRQ_HANDLED;
@@ -678,12 +692,12 @@ static int pasemi_mac_phy_init(struct net_device *dev)
        int ret;
 
        dn = pci_device_to_OF_node(mac->pdev);
-       ph = get_property(dn, "phy-handle", NULL);
+       ph = of_get_property(dn, "phy-handle", NULL);
        if (!ph)
                return -ENODEV;
        phy_dn = of_find_node_by_phandle(*ph);
 
-       prop = get_property(phy_dn, "reg", NULL);
+       prop = of_get_property(phy_dn, "reg", NULL);
        ret = of_address_to_resource(phy_dn->parent, 0, &r);
        if (ret)
                goto err;
@@ -969,6 +983,7 @@ static int pasemi_mac_start_tx(struct sk_buff *skb, struct net_device *dev)
        if (txring->next_to_clean - txring->next_to_use == TX_RING_SIZE) {
                spin_unlock_irqrestore(&txring->lock, flags);
                pasemi_mac_clean_tx(mac);
+               pasemi_mac_restart_tx_intr(mac);
                spin_lock_irqsave(&txring->lock, flags);
 
                if (txring->next_to_clean - txring->next_to_use ==
@@ -1205,6 +1220,7 @@ static void __devexit pasemi_mac_remove(struct pci_dev *pdev)
 static struct pci_device_id pasemi_mac_pci_tbl[] = {
        { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa005) },
        { PCI_DEVICE(PCI_VENDOR_ID_PASEMI, 0xa006) },
+       { },
 };
 
 MODULE_DEVICE_TABLE(pci, pasemi_mac_pci_tbl);