mwl8k: simplify sequence number assignment
[safe/jmp/linux-2.6] / drivers / net / tulip / dmfe.c
index ca90566..ad63621 100644 (file)
@@ -23,7 +23,7 @@
     Marcelo Tosatti <marcelo@conectiva.com.br> :
     Made it compile in 2.3 (device to net_device)
 
-    Alan Cox <alan@redhat.com> :
+    Alan Cox <alan@lxorguk.ukuu.org.uk> :
     Cleaned up for kernel merge.
     Removed the back compatibility support
     Reformatted, fixing spelling etc as I went
@@ -49,7 +49,7 @@
     support.  Updated PCI resource allocation.  Do not
     forget to unmap PCI mapped skbs.
 
-    Alan Cox <alan@redhat.com>
+    Alan Cox <alan@lxorguk.ukuu.org.uk>
     Added new PCI identifiers provided by Clear Zhang at ALi
     for their 1563 ethernet device.
 
@@ -257,9 +257,6 @@ struct dmfe_board_info {
        u8 wol_mode;                    /* user WOL settings */
        struct timer_list timer;
 
-       /* System defined statistic counter */
-       struct net_device_stats stats;
-
        /* Driver defined statistic counter */
        unsigned long tx_fifo_underrun;
        unsigned long tx_loss_carrier;
@@ -291,7 +288,7 @@ enum dmfe_CR6_bits {
 
 /* Global variable declaration ----------------------------- */
 static int __devinitdata printed_version;
-static char version[] __devinitdata =
+static const char version[] __devinitconst =
        KERN_INFO DRV_NAME ": Davicom DM9xxx net driver, version "
        DRV_VERSION " (" DRV_RELDATE ")\n";
 
@@ -314,9 +311,8 @@ static u8 SF_mode;          /* Special Function: 1:VLAN, 2:RX Flow Control
 
 /* function declaration ------------------------------------- */
 static int dmfe_open(struct DEVICE *);
-static int dmfe_start_xmit(struct sk_buff *, struct DEVICE *);
+static netdev_tx_t dmfe_start_xmit(struct sk_buff *, struct DEVICE *);
 static int dmfe_stop(struct DEVICE *);
-static struct net_device_stats * dmfe_get_stats(struct DEVICE *);
 static void dmfe_set_filter_mode(struct DEVICE *);
 static const struct ethtool_ops netdev_ethtool_ops;
 static u16 read_srom_word(long ,int);
@@ -351,6 +347,19 @@ static void dmfe_set_phyxcer(struct dmfe_board_info *);
 
 /* DM910X network board routine ---------------------------- */
 
+static const struct net_device_ops netdev_ops = {
+       .ndo_open               = dmfe_open,
+       .ndo_stop               = dmfe_stop,
+       .ndo_start_xmit         = dmfe_start_xmit,
+       .ndo_set_multicast_list = dmfe_set_filter_mode,
+       .ndo_change_mtu         = eth_change_mtu,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_validate_addr      = eth_validate_addr,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller    = poll_dmfe,
+#endif
+};
+
 /*
  *     Search DM910X board ,allocate space and register it
  */
@@ -362,7 +371,6 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
        struct net_device *dev;
        u32 pci_pmr;
        int i, err;
-       DECLARE_MAC_BUF(mac);
 
        DMFE_DBUG(0, "dmfe_init_one()", 0);
 
@@ -375,7 +383,7 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
                return -ENOMEM;
        SET_NETDEV_DEV(dev, &pdev->dev);
 
-       if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
+       if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
                printk(KERN_WARNING DRV_NAME
                        ": 32-bit PCI DMA not available.\n");
                err = -ENODEV;
@@ -420,9 +428,13 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
        /* Allocate Tx/Rx descriptor memory */
        db->desc_pool_ptr = pci_alloc_consistent(pdev, sizeof(struct tx_desc) *
                        DESC_ALL_CNT + 0x20, &db->desc_pool_dma_ptr);
+       if (!db->desc_pool_ptr)
+               goto err_out_res;
 
        db->buf_pool_ptr = pci_alloc_consistent(pdev, TX_BUF_ALLOC *
                        TX_DESC_CNT + 4, &db->buf_pool_dma_ptr);
+       if (!db->buf_pool_ptr)
+               goto err_out_free_desc;
 
        db->first_tx_desc = (struct tx_desc *) db->desc_pool_ptr;
        db->first_tx_desc_dma = db->desc_pool_dma_ptr;
@@ -439,14 +451,7 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
        dev->base_addr = db->ioaddr;
        dev->irq = pdev->irq;
        pci_set_drvdata(pdev, dev);
-       dev->open = &dmfe_open;
-       dev->hard_start_xmit = &dmfe_start_xmit;
-       dev->stop = &dmfe_stop;
-       dev->get_stats = &dmfe_get_stats;
-       dev->set_multicast_list = &dmfe_set_filter_mode;
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = &poll_dmfe;
-#endif
+       dev->netdev_ops = &netdev_ops;
        dev->ethtool_ops = &netdev_ethtool_ops;
        netif_carrier_off(dev);
        spin_lock_init(&db->lock);
@@ -469,20 +474,25 @@ static int __devinit dmfe_init_one (struct pci_dev *pdev,
 
        err = register_netdev (dev);
        if (err)
-               goto err_out_res;
+               goto err_out_free_buf;
 
-       printk(KERN_INFO "%s: Davicom DM%04lx at pci%s, "
-              "%s, irq %d.\n",
+       printk(KERN_INFO "%s: Davicom DM%04lx at pci%s, %pM, irq %d.\n",
               dev->name,
               ent->driver_data >> 16,
               pci_name(pdev),
-              print_mac(mac, dev->dev_addr),
+              dev->dev_addr,
               dev->irq);
 
        pci_set_master(pdev);
 
        return 0;
 
+err_out_free_buf:
+       pci_free_consistent(pdev, TX_BUF_ALLOC * TX_DESC_CNT + 4,
+                           db->buf_pool_ptr, db->buf_pool_dma_ptr);
+err_out_free_desc:
+       pci_free_consistent(pdev, sizeof(struct tx_desc) * DESC_ALL_CNT + 0x20,
+                           db->desc_pool_ptr, db->desc_pool_dma_ptr);
 err_out_res:
        pci_release_regions(pdev);
 err_out_disable:
@@ -533,7 +543,7 @@ static int dmfe_open(struct DEVICE *dev)
 
        DMFE_DBUG(0, "dmfe_open", 0);
 
-       ret = request_irq(dev->irq, &dmfe_interrupt,
+       ret = request_irq(dev->irq, dmfe_interrupt,
                          IRQF_SHARED, dev->name, dev);
        if (ret)
                return ret;
@@ -651,7 +661,8 @@ static void dmfe_init_dm910x(struct DEVICE *dev)
  *     Send a packet to media from the upper layer.
  */
 
-static int dmfe_start_xmit(struct sk_buff *skb, struct DEVICE *dev)
+static netdev_tx_t dmfe_start_xmit(struct sk_buff *skb,
+                                        struct DEVICE *dev)
 {
        struct dmfe_board_info *db = netdev_priv(dev);
        struct tx_desc *txptr;
@@ -666,7 +677,7 @@ static int dmfe_start_xmit(struct sk_buff *skb, struct DEVICE *dev)
        if (skb->len > MAX_PACKET_SIZE) {
                printk(KERN_ERR DRV_NAME ": big packet = %d\n", (u16)skb->len);
                dev_kfree_skb(skb);
-               return 0;
+               return NETDEV_TX_OK;
        }
 
        spin_lock_irqsave(&db->lock, flags);
@@ -676,7 +687,7 @@ static int dmfe_start_xmit(struct sk_buff *skb, struct DEVICE *dev)
                spin_unlock_irqrestore(&db->lock, flags);
                printk(KERN_ERR DRV_NAME ": No Tx resource %ld\n",
                       db->tx_queue_cnt);
-               return 1;
+               return NETDEV_TX_BUSY;
        }
 
        /* Disable NIC interrupt */
@@ -712,7 +723,7 @@ static int dmfe_start_xmit(struct sk_buff *skb, struct DEVICE *dev)
        /* free this SKB */
        dev_kfree_skb(skb);
 
-       return 0;
+       return NETDEV_TX_OK;
 }
 
 
@@ -859,15 +870,15 @@ static void dmfe_free_tx_pkt(struct DEVICE *dev, struct dmfe_board_info * db)
 
                /* A packet sent completed */
                db->tx_packet_cnt--;
-               db->stats.tx_packets++;
+               dev->stats.tx_packets++;
 
                /* Transmit statistic counter */
                if ( tdes0 != 0x7fffffff ) {
                        /* printk(DRV_NAME ": tdes0=%x\n", tdes0); */
-                       db->stats.collisions += (tdes0 >> 3) & 0xf;
-                       db->stats.tx_bytes += le32_to_cpu(txptr->tdes1) & 0x7ff;
+                       dev->stats.collisions += (tdes0 >> 3) & 0xf;
+                       dev->stats.tx_bytes += le32_to_cpu(txptr->tdes1) & 0x7ff;
                        if (tdes0 & TDES0_ERR_MASK) {
-                               db->stats.tx_errors++;
+                               dev->stats.tx_errors++;
 
                                if (tdes0 & 0x0002) {   /* UnderRun */
                                        db->tx_fifo_underrun++;
@@ -961,13 +972,13 @@ static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db)
                        if (rdes0 & 0x8000) {
                                /* This is a error packet */
                                //printk(DRV_NAME ": rdes0: %lx\n", rdes0);
-                               db->stats.rx_errors++;
+                               dev->stats.rx_errors++;
                                if (rdes0 & 1)
-                                       db->stats.rx_fifo_errors++;
+                                       dev->stats.rx_fifo_errors++;
                                if (rdes0 & 2)
-                                       db->stats.rx_crc_errors++;
+                                       dev->stats.rx_crc_errors++;
                                if (rdes0 & 0x80)
-                                       db->stats.rx_length_errors++;
+                                       dev->stats.rx_length_errors++;
                        }
 
                        if ( !(rdes0 & 0x8000) ||
@@ -1000,9 +1011,8 @@ static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db)
 
                                        skb->protocol = eth_type_trans(skb, dev);
                                        netif_rx(skb);
-                                       dev->last_rx = jiffies;
-                                       db->stats.rx_packets++;
-                                       db->stats.rx_bytes += rxlen;
+                                       dev->stats.rx_packets++;
+                                       dev->stats.rx_bytes += rxlen;
                                }
                        } else {
                                /* Reuse SKB buffer when the packet is error */
@@ -1017,20 +1027,6 @@ static void dmfe_rx_packet(struct DEVICE *dev, struct dmfe_board_info * db)
        db->rx_ready_ptr = rxptr;
 }
 
-
-/*
- *     Get statistics from driver.
- */
-
-static struct net_device_stats * dmfe_get_stats(struct DEVICE *dev)
-{
-       struct dmfe_board_info *db = netdev_priv(dev);
-
-       DMFE_DBUG(0, "dmfe_get_stats", 0);
-       return &db->stats;
-}
-
-
 /*
  * Set DM910X multicast address
  */
@@ -1154,7 +1150,7 @@ static void dmfe_timer(unsigned long data)
 
        /* Operating Mode Check */
        if ( (db->dm910x_chk_mode & 0x1) &&
-               (db->stats.rx_packets > MAX_CHECK_PACKET) )
+               (dev->stats.rx_packets > MAX_CHECK_PACKET) )
                db->dm910x_chk_mode = 0x4;
 
        /* Dynamic reset DM910X : system error or transmit time-out */
@@ -1909,7 +1905,7 @@ static void dmfe_parse_srom(struct dmfe_board_info * db)
        if ( ( (int) srom[18] & 0xff) == SROM_V41_CODE) {
                /* SROM V4.01 */
                /* Get NIC support media mode */
-               db->NIC_capability = le16_to_cpup((__le16 *)srom + 34/2);
+               db->NIC_capability = le16_to_cpup((__le16 *) (srom + 34));
                db->PHY_reg4 = 0;
                for (tmp_reg = 1; tmp_reg < 0x10; tmp_reg <<= 1) {
                        switch( db->NIC_capability & tmp_reg ) {
@@ -1921,8 +1917,8 @@ static void dmfe_parse_srom(struct dmfe_board_info * db)
                }
 
                /* Media Mode Force or not check */
-               dmfe_mode = le32_to_cpup((__le32 *)srom + 34/4) &
-                               le32_to_cpup((__le32 *)srom + 36/4);
+               dmfe_mode = (le32_to_cpup((__le32 *) (srom + 34)) &
+                            le32_to_cpup((__le32 *) (srom + 36)));
                switch(dmfe_mode) {
                case 0x4: dmfe_media_mode = DMFE_100MHF; break; /* 100MHF */
                case 0x2: dmfe_media_mode = DMFE_10MFD; break;  /* 10MFD */
@@ -2118,8 +2114,8 @@ static int dmfe_suspend(struct pci_dev *pci_dev, pm_message_t state)
        pci_enable_wake(pci_dev, PCI_D3cold, 1);
 
        /* Power down device*/
-       pci_set_power_state(pci_dev, pci_choose_state (pci_dev,state));
        pci_save_state(pci_dev);
+       pci_set_power_state(pci_dev, pci_choose_state (pci_dev, state));
 
        return 0;
 }
@@ -2129,8 +2125,8 @@ static int dmfe_resume(struct pci_dev *pci_dev)
        struct net_device *dev = pci_get_drvdata(pci_dev);
        u32 tmp;
 
-       pci_restore_state(pci_dev);
        pci_set_power_state(pci_dev, PCI_D0);
+       pci_restore_state(pci_dev);
 
        /* Re-initilize DM910X board */
        dmfe_init_dm910x(dev);