[PATCH] libertas: skb dereferenced after netif_rx
[safe/jmp/linux-2.6] / drivers / net / mv643xx_eth.c
index 30b0d5b..1799eee 100644 (file)
@@ -51,8 +51,8 @@
 #include "mv643xx_eth.h"
 
 /* Static function declarations */
-static void eth_port_uc_addr_get(struct net_device *dev,
-                                               unsigned char *MacAddr);
+static void eth_port_uc_addr_get(unsigned int port_num, unsigned char *p_addr);
+static void eth_port_uc_addr_set(unsigned int port_num, unsigned char *p_addr);
 static void eth_port_set_multicast_list(struct net_device *);
 static void mv643xx_eth_port_enable_tx(unsigned int port_num,
                                                unsigned int queues);
@@ -74,7 +74,7 @@ static int ethernet_phy_detect(unsigned int eth_port_num);
 static int mv643xx_mdio_read(struct net_device *dev, int phy_id, int location);
 static void mv643xx_mdio_write(struct net_device *dev, int phy_id, int location, int val);
 static int mv643xx_eth_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
-static struct ethtool_ops mv643xx_ethtool_ops;
+static const struct ethtool_ops mv643xx_ethtool_ops;
 
 static char mv643xx_driver_name[] = "mv643xx_eth";
 static char mv643xx_driver_version[] = "1.0";
@@ -132,32 +132,28 @@ static int mv643xx_eth_change_mtu(struct net_device *dev, int new_mtu)
 }
 
 /*
- * mv643xx_eth_rx_task
+ * mv643xx_eth_rx_refill_descs
  *
  * Fills / refills RX queue on a certain gigabit ethernet port
  *
  * Input :     pointer to ethernet interface network device structure
  * Output :    N/A
  */
-static void mv643xx_eth_rx_task(void *data)
+static void mv643xx_eth_rx_refill_descs(struct net_device *dev)
 {
-       struct net_device *dev = (struct net_device *)data;
        struct mv643xx_private *mp = netdev_priv(dev);
        struct pkt_info pkt_info;
        struct sk_buff *skb;
        int unaligned;
 
-       if (test_and_set_bit(0, &mp->rx_task_busy))
-               panic("%s: Error in test_set_bit / clear_bit", dev->name);
-
-       while (mp->rx_desc_count < (mp->rx_ring_size - 5)) {
-               skb = dev_alloc_skb(ETH_RX_SKB_SIZE + ETH_DMA_ALIGN);
+       while (mp->rx_desc_count < mp->rx_ring_size) {
+               skb = dev_alloc_skb(ETH_RX_SKB_SIZE + dma_get_cache_alignment());
                if (!skb)
                        break;
                mp->rx_desc_count++;
-               unaligned = (u32)skb->data & (ETH_DMA_ALIGN - 1);
+               unaligned = (u32)skb->data & (dma_get_cache_alignment() - 1);
                if (unaligned)
-                       skb_reserve(skb, ETH_DMA_ALIGN - unaligned);
+                       skb_reserve(skb, dma_get_cache_alignment() - unaligned);
                pkt_info.cmd_sts = ETH_RX_ENABLE_INTERRUPT;
                pkt_info.byte_cnt = ETH_RX_SKB_SIZE;
                pkt_info.buf_ptr = dma_map_single(NULL, skb->data,
@@ -170,29 +166,19 @@ static void mv643xx_eth_rx_task(void *data)
                }
                skb_reserve(skb, ETH_HW_IP_ALIGN);
        }
-       clear_bit(0, &mp->rx_task_busy);
        /*
         * If RX ring is empty of SKB, set a timer to try allocating
-        * again in a later time .
+        * again at a later time.
         */
-       if ((mp->rx_desc_count == 0) && (mp->rx_timer_flag == 0)) {
+       if (mp->rx_desc_count == 0) {
                printk(KERN_INFO "%s: Rx ring is empty\n", dev->name);
-               /* After 100mSec */
-               mp->timeout.expires = jiffies + (HZ / 10);
+               mp->timeout.expires = jiffies + (HZ / 10);      /* 100 mSec */
                add_timer(&mp->timeout);
-               mp->rx_timer_flag = 1;
-       }
-#ifdef MV643XX_RX_QUEUE_FILL_ON_TASK
-       else {
-               /* Return interrupts */
-               mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(mp->port_num),
-                                                       INT_UNMASK_ALL);
        }
-#endif
 }
 
 /*
- * mv643xx_eth_rx_task_timer_wrapper
+ * mv643xx_eth_rx_refill_descs_timer_wrapper
  *
  * Timer routine to wake up RX queue filling task. This function is
  * used only in case the RX queue is empty, and all alloc_skb has
@@ -201,13 +187,9 @@ static void mv643xx_eth_rx_task(void *data)
  * Input :     pointer to ethernet interface network device structure
  * Output :    N/A
  */
-static void mv643xx_eth_rx_task_timer_wrapper(unsigned long data)
+static inline void mv643xx_eth_rx_refill_descs_timer_wrapper(unsigned long data)
 {
-       struct net_device *dev = (struct net_device *)data;
-       struct mv643xx_private *mp = netdev_priv(dev);
-
-       mp->rx_timer_flag = 0;
-       mv643xx_eth_rx_task((void *)data);
+       mv643xx_eth_rx_refill_descs((struct net_device *)data);
 }
 
 /*
@@ -295,14 +277,22 @@ static void mv643xx_eth_tx_timeout(struct net_device *dev)
  *
  * Actual routine to reset the adapter when a timeout on Tx has occurred
  */
-static void mv643xx_eth_tx_timeout_task(struct net_device *dev)
+static void mv643xx_eth_tx_timeout_task(struct work_struct *ugly)
 {
-       struct mv643xx_private *mp = netdev_priv(dev);
+       struct mv643xx_private *mp = container_of(ugly, struct mv643xx_private,
+                                                 tx_timeout_task);
+       struct net_device *dev = mp->mii.dev; /* yuck */
+
+       if (!netif_running(dev))
+               return;
+
+       netif_stop_queue(dev);
 
-       netif_device_detach(dev);
        eth_port_reset(mp->port_num);
        eth_port_start(dev);
-       netif_device_attach(dev);
+
+       if (mp->tx_ring_size - mp->tx_desc_count >= MAX_DESCS_PER_SKB)
+               netif_wake_queue(dev);
 }
 
 /**
@@ -324,6 +314,13 @@ int mv643xx_eth_free_tx_descs(struct net_device *dev, int force)
 
        while (mp->tx_desc_count > 0) {
                spin_lock_irqsave(&mp->lock, flags);
+
+               /* tx_desc_count might have changed before acquiring the lock */
+               if (mp->tx_desc_count <= 0) {
+                       spin_unlock_irqrestore(&mp->lock, flags);
+                       return released;
+               }
+
                tx_index = mp->tx_used_desc_q;
                desc = &mp->p_tx_desc_area[tx_index];
                cmd_sts = desc->cmd_sts;
@@ -342,13 +339,13 @@ int mv643xx_eth_free_tx_descs(struct net_device *dev, int force)
                if (skb)
                        mp->tx_skb[tx_index] = NULL;
 
-               spin_unlock_irqrestore(&mp->lock, flags);
-
                if (cmd_sts & ETH_ERROR_SUMMARY) {
                        printk("%s: Error in TX\n", dev->name);
                        mp->stats.tx_errors++;
                }
 
+               spin_unlock_irqrestore(&mp->lock, flags);
+
                if (cmd_sts & ETH_TX_FIRST_DESC)
                        dma_unmap_single(NULL, addr, count, DMA_TO_DEVICE);
                else
@@ -397,6 +394,8 @@ static int mv643xx_eth_receive_queue(struct net_device *dev, int budget)
        struct pkt_info pkt_info;
 
        while (budget-- > 0 && eth_port_receive(mp, &pkt_info) == ETH_OK) {
+               dma_unmap_single(NULL, pkt_info.buf_ptr, ETH_RX_SKB_SIZE,
+                                                       DMA_FROM_DEVICE);
                mp->rx_desc_count--;
                received_packets++;
 
@@ -435,7 +434,6 @@ static int mv643xx_eth_receive_queue(struct net_device *dev, int budget)
                         * received packet
                         */
                        skb_put(skb, pkt_info.byte_cnt - 4);
-                       skb->dev = dev;
 
                        if (pkt_info.cmd_sts & ETH_LAYER_4_CHECKSUM_OK) {
                                skb->ip_summed = CHECKSUM_UNNECESSARY;
@@ -451,6 +449,7 @@ static int mv643xx_eth_receive_queue(struct net_device *dev, int budget)
                }
                dev->last_rx = jiffies;
        }
+       mv643xx_eth_rx_refill_descs(dev);       /* Fill RX ring with skb's */
 
        return received_packets;
 }
@@ -516,8 +515,7 @@ static void mv643xx_eth_update_pscr(struct net_device *dev,
  * Output :    N/A
  */
 
-static irqreturn_t mv643xx_eth_int_handler(int irq, void *dev_id,
-                                               struct pt_regs *regs)
+static irqreturn_t mv643xx_eth_int_handler(int irq, void *dev_id)
 {
        struct net_device *dev = (struct net_device *)dev_id;
        struct mv643xx_private *mp = netdev_priv(dev);
@@ -531,18 +529,6 @@ static irqreturn_t mv643xx_eth_int_handler(int irq, void *dev_id,
                eth_int_cause_ext = mv_read(
                        MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num)) &
                                                ETH_INT_UNMASK_ALL_EXT;
-#ifdef MV643XX_RX_QUEUE_FILL_ON_TASK
-               /* Mask all interrupts on ethernet port */
-               mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num),
-                                                       INT_MASK_ALL);
-               /* wait for previous write to take effect */
-               mv_read(MV643XX_ETH_INTERRUPT_MASK_REG(port_num));
-
-               queue_task(&mp->rx_task, &tq_immediate);
-               mark_bh(IMMEDIATE_BH);
-#else
-               mp->rx_task.func(dev);
-#endif
                mv_write(MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num),
                                                        ~eth_int_cause_ext);
        }
@@ -581,9 +567,9 @@ static irqreturn_t mv643xx_eth_int_handler(int irq, void *dev_id,
 #else
        if (eth_int_cause & ETH_INT_CAUSE_RX)
                mv643xx_eth_receive_queue(dev, INT_MAX);
+#endif
        if (eth_int_cause_ext & ETH_INT_CAUSE_TX)
                mv643xx_eth_free_completed_tx_descs(dev);
-#endif
 
        /*
         * If no real interrupt occured, exit.
@@ -800,8 +786,14 @@ static int mv643xx_eth_open(struct net_device *dev)
        unsigned int size;
        int err;
 
+       /* Clear any pending ethernet port interrupts */
+       mv_write(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num), 0);
+       mv_write(MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num), 0);
+       /* wait for previous write to complete */
+       mv_read (MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num));
+
        err = request_irq(dev->irq, mv643xx_eth_int_handler,
-                       SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
+                       IRQF_SHARED | IRQF_SAMPLE_RANDOM, dev->name, dev);
        if (err) {
                printk(KERN_ERR "Can not assign IRQ number to MV643XX_eth%d\n",
                                                                port_num);
@@ -810,15 +802,10 @@ static int mv643xx_eth_open(struct net_device *dev)
 
        eth_port_init(mp);
 
-       INIT_WORK(&mp->rx_task, (void (*)(void *))mv643xx_eth_rx_task, dev);
-
        memset(&mp->timeout, 0, sizeof(struct timer_list));
-       mp->timeout.function = mv643xx_eth_rx_task_timer_wrapper;
+       mp->timeout.function = mv643xx_eth_rx_refill_descs_timer_wrapper;
        mp->timeout.data = (unsigned long)dev;
 
-       mp->rx_task_busy = 0;
-       mp->rx_timer_flag = 0;
-
        /* Allocate RX and TX skb rings */
        mp->rx_skb = kmalloc(sizeof(*mp->rx_skb) * mp->rx_ring_size,
                                                                GFP_KERNEL);
@@ -891,11 +878,7 @@ static int mv643xx_eth_open(struct net_device *dev)
 
        ether_init_rx_desc_ring(mp);
 
-       mv643xx_eth_rx_task(dev);       /* Fill RX ring with skb's */
-
-       /* Clear any pending ethernet port interrupts */
-       mv_write(MV643XX_ETH_INTERRUPT_CAUSE_REG(port_num), 0);
-       mv_write(MV643XX_ETH_INTERRUPT_CAUSE_EXTEND_REG(port_num), 0);
+       mv643xx_eth_rx_refill_descs(dev);       /* Fill RX ring with skb's */
 
        eth_port_start(dev);
 
@@ -1043,7 +1026,6 @@ static int mv643xx_poll(struct net_device *dev, int *budget)
                if (orig_budget > dev->quota)
                        orig_budget = dev->quota;
                work_done = mv643xx_eth_receive_queue(dev, orig_budget);
-               mp->rx_task.func(dev);
                *budget -= work_done;
                dev->quota -= work_done;
                if (work_done >= orig_budget)
@@ -1126,7 +1108,7 @@ static void eth_tx_fill_frag_descs(struct mv643xx_private *mp,
                                         ETH_TX_ENABLE_INTERRUPT;
                        mp->tx_skb[tx_index] = skb;
                } else
-                       mp->tx_skb[tx_index] = 0;
+                       mp->tx_skb[tx_index] = NULL;
 
                desc = &mp->p_tx_desc_area[tx_index];
                desc->l4i_chk = 0;
@@ -1162,7 +1144,7 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
                eth_tx_fill_frag_descs(mp, skb);
 
                length = skb_headlen(skb);
-               mp->tx_skb[tx_index] = 0;
+               mp->tx_skb[tx_index] = NULL;
        } else {
                cmd_sts |= ETH_ZERO_PADDING |
                           ETH_TX_LAST_DESC |
@@ -1174,20 +1156,20 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
        desc->byte_cnt = length;
        desc->buf_ptr = dma_map_single(NULL, skb->data, length, DMA_TO_DEVICE);
 
-       if (skb->ip_summed == CHECKSUM_HW) {
+       if (skb->ip_summed == CHECKSUM_PARTIAL) {
                BUG_ON(skb->protocol != ETH_P_IP);
 
                cmd_sts |= ETH_GEN_TCP_UDP_CHECKSUM |
                           ETH_GEN_IP_V_4_CHECKSUM  |
-                          skb->nh.iph->ihl << ETH_TX_IHL_SHIFT;
+                          ip_hdr(skb)->ihl << ETH_TX_IHL_SHIFT;
 
-               switch (skb->nh.iph->protocol) {
+               switch (ip_hdr(skb)->protocol) {
                case IPPROTO_UDP:
                        cmd_sts |= ETH_UDP_FRAME;
-                       desc->l4i_chk = skb->h.uh->check;
+                       desc->l4i_chk = udp_hdr(skb)->check;
                        break;
                case IPPROTO_TCP:
-                       desc->l4i_chk = skb->h.th->check;
+                       desc->l4i_chk = tcp_hdr(skb)->check;
                        break;
                default:
                        BUG();
@@ -1221,10 +1203,15 @@ static int mv643xx_eth_start_xmit(struct sk_buff *skb, struct net_device *dev)
 
        BUG_ON(netif_queue_stopped(dev));
        BUG_ON(skb == NULL);
-       BUG_ON(mp->tx_ring_size - mp->tx_desc_count < MAX_DESCS_PER_SKB);
+
+       if (mp->tx_ring_size - mp->tx_desc_count < MAX_DESCS_PER_SKB) {
+               printk(KERN_ERR "%s: transmit with queue full\n", dev->name);
+               netif_stop_queue(dev);
+               return 1;
+       }
 
        if (has_tiny_unaligned_frags(skb)) {
-               if ((skb_linearize(skb, GFP_ATOMIC) != 0)) {
+               if (__skb_linearize(skb)) {
                        stats->tx_dropped++;
                        printk(KERN_DEBUG "%s: failed to linearize tiny "
                                        "unaligned fragment\n", dev->name);
@@ -1274,7 +1261,7 @@ static void mv643xx_netpoll(struct net_device *netdev)
        /* wait for previous write to complete */
        mv_read(MV643XX_ETH_INTERRUPT_MASK_REG(port_num));
 
-       mv643xx_eth_int_handler(netdev->irq, netdev, NULL);
+       mv643xx_eth_int_handler(netdev->irq, netdev);
 
        mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num), ETH_INT_UNMASK_ALL);
 }
@@ -1323,7 +1310,7 @@ static void mv643xx_init_ethtool_cmd(struct net_device *dev, int phy_address,
 static int mv643xx_eth_probe(struct platform_device *pdev)
 {
        struct mv643xx_eth_platform_data *pd;
-       int port_num = pdev->id;
+       int port_num;
        struct mv643xx_private *mp;
        struct net_device *dev;
        u8 *p;
@@ -1333,6 +1320,12 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
        int duplex = DUPLEX_HALF;
        int speed = 0;                  /* default to auto-negotiation */
 
+       pd = pdev->dev.platform_data;
+       if (pd == NULL) {
+               printk(KERN_ERR "No mv643xx_eth_platform_data\n");
+               return -ENODEV;
+       }
+
        dev = alloc_etherdev(sizeof(struct mv643xx_private));
        if (!dev)
                return -ENOMEM;
@@ -1345,8 +1338,6 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
        BUG_ON(!res);
        dev->irq = res->start;
 
-       mp->port_num = port_num;
-
        dev->open = mv643xx_eth_open;
        dev->stop = mv643xx_eth_stop;
        dev->hard_start_xmit = mv643xx_eth_start_xmit;
@@ -1383,44 +1374,42 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
 #endif
 
        /* Configure the timeout task */
-       INIT_WORK(&mp->tx_timeout_task,
-                       (void (*)(void *))mv643xx_eth_tx_timeout_task, dev);
+       INIT_WORK(&mp->tx_timeout_task, mv643xx_eth_tx_timeout_task);
 
        spin_lock_init(&mp->lock);
 
+       port_num = mp->port_num = pd->port_number;
+
        /* set default config values */
-       eth_port_uc_addr_get(dev, dev->dev_addr);
+       eth_port_uc_addr_get(port_num, dev->dev_addr);
        mp->rx_ring_size = MV643XX_ETH_PORT_DEFAULT_RECEIVE_QUEUE_SIZE;
        mp->tx_ring_size = MV643XX_ETH_PORT_DEFAULT_TRANSMIT_QUEUE_SIZE;
 
-       pd = pdev->dev.platform_data;
-       if (pd) {
-               if (pd->mac_addr)
-                       memcpy(dev->dev_addr, pd->mac_addr, 6);
+       if (is_valid_ether_addr(pd->mac_addr))
+               memcpy(dev->dev_addr, pd->mac_addr, 6);
 
-               if (pd->phy_addr || pd->force_phy_addr)
-                       ethernet_phy_set(port_num, pd->phy_addr);
+       if (pd->phy_addr || pd->force_phy_addr)
+               ethernet_phy_set(port_num, pd->phy_addr);
 
-               if (pd->rx_queue_size)
-                       mp->rx_ring_size = pd->rx_queue_size;
+       if (pd->rx_queue_size)
+               mp->rx_ring_size = pd->rx_queue_size;
 
-               if (pd->tx_queue_size)
-                       mp->tx_ring_size = pd->tx_queue_size;
+       if (pd->tx_queue_size)
+               mp->tx_ring_size = pd->tx_queue_size;
 
-               if (pd->tx_sram_size) {
-                       mp->tx_sram_size = pd->tx_sram_size;
-                       mp->tx_sram_addr = pd->tx_sram_addr;
-               }
-
-               if (pd->rx_sram_size) {
-                       mp->rx_sram_size = pd->rx_sram_size;
-                       mp->rx_sram_addr = pd->rx_sram_addr;
-               }
+       if (pd->tx_sram_size) {
+               mp->tx_sram_size = pd->tx_sram_size;
+               mp->tx_sram_addr = pd->tx_sram_addr;
+       }
 
-               duplex = pd->duplex;
-               speed = pd->speed;
+       if (pd->rx_sram_size) {
+               mp->rx_sram_size = pd->rx_sram_size;
+               mp->rx_sram_addr = pd->rx_sram_addr;
        }
 
+       duplex = pd->duplex;
+       speed = pd->speed;
+
        /* Hook up MII support for ethtool */
        mp->mii.dev = dev;
        mp->mii.mdio_read = mv643xx_mdio_read;
@@ -1443,6 +1432,8 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
        mv643xx_eth_update_pscr(dev, &cmd);
        mv643xx_set_settings(dev, &cmd);
 
+       SET_MODULE_OWNER(dev);
+       SET_NETDEV_DEV(dev, &pdev->dev);
        err = register_netdev(dev);
        if (err)
                goto out;
@@ -1522,9 +1513,23 @@ static int mv643xx_eth_shared_remove(struct platform_device *pdev)
        return 0;
 }
 
+static void mv643xx_eth_shutdown(struct platform_device *pdev)
+{
+       struct net_device *dev = platform_get_drvdata(pdev);
+       struct mv643xx_private *mp = netdev_priv(dev);
+       unsigned int port_num = mp->port_num;
+
+       /* Mask all interrupts on ethernet port */
+       mv_write(MV643XX_ETH_INTERRUPT_MASK_REG(port_num), 0);
+       mv_read (MV643XX_ETH_INTERRUPT_MASK_REG(port_num));
+
+       eth_port_reset(port_num);
+}
+
 static struct platform_driver mv643xx_eth_driver = {
        .probe = mv643xx_eth_probe,
        .remove = mv643xx_eth_remove,
+       .shutdown = mv643xx_eth_shutdown,
        .driver = {
                .name = MV643XX_ETH_NAME,
        },
@@ -1834,26 +1839,9 @@ static void eth_port_start(struct net_device *dev)
 }
 
 /*
- * eth_port_uc_addr_set - This function Set the port Unicast address.
- *
- * DESCRIPTION:
- *             This function Set the port Ethernet MAC address.
- *
- * INPUT:
- *     unsigned int    eth_port_num    Port number.
- *     char *          p_addr          Address to be set
- *
- * OUTPUT:
- *     Set MAC address low and high registers. also calls
- *     eth_port_set_filter_table_entry() to set the unicast
- *     table with the proper information.
- *
- * RETURN:
- *     N/A.
- *
+ * eth_port_uc_addr_set - Write a MAC address into the port's hw registers
  */
-static void eth_port_uc_addr_set(unsigned int eth_port_num,
-                                                       unsigned char *p_addr)
+static void eth_port_uc_addr_set(unsigned int port_num, unsigned char *p_addr)
 {
        unsigned int mac_h;
        unsigned int mac_l;
@@ -1863,40 +1851,24 @@ static void eth_port_uc_addr_set(unsigned int eth_port_num,
        mac_h = (p_addr[0] << 24) | (p_addr[1] << 16) | (p_addr[2] << 8) |
                                                        (p_addr[3] << 0);
 
-       mv_write(MV643XX_ETH_MAC_ADDR_LOW(eth_port_num), mac_l);
-       mv_write(MV643XX_ETH_MAC_ADDR_HIGH(eth_port_num), mac_h);
+       mv_write(MV643XX_ETH_MAC_ADDR_LOW(port_num), mac_l);
+       mv_write(MV643XX_ETH_MAC_ADDR_HIGH(port_num), mac_h);
 
-       /* Accept frames of this address */
-       table = MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE(eth_port_num);
+       /* Accept frames with this address */
+       table = MV643XX_ETH_DA_FILTER_UNICAST_TABLE_BASE(port_num);
        eth_port_set_filter_table_entry(table, p_addr[5] & 0x0f);
 }
 
 /*
- * eth_port_uc_addr_get - This function retrieves the port Unicast address
- * (MAC address) from the ethernet hw registers.
- *
- * DESCRIPTION:
- *             This function retrieves the port Ethernet MAC address.
- *
- * INPUT:
- *     unsigned int    eth_port_num    Port number.
- *     char            *MacAddr        pointer where the MAC address is stored
- *
- * OUTPUT:
- *     Copy the MAC address to the location pointed to by MacAddr
- *
- * RETURN:
- *     N/A.
- *
+ * eth_port_uc_addr_get - Read the MAC address from the port's hw registers
  */
-static void eth_port_uc_addr_get(struct net_device *dev, unsigned char *p_addr)
+static void eth_port_uc_addr_get(unsigned int port_num, unsigned char *p_addr)
 {
-       struct mv643xx_private *mp = netdev_priv(dev);
        unsigned int mac_h;
        unsigned int mac_l;
 
-       mac_h = mv_read(MV643XX_ETH_MAC_ADDR_HIGH(mp->port_num));
-       mac_l = mv_read(MV643XX_ETH_MAC_ADDR_LOW(mp->port_num));
+       mac_h = mv_read(MV643XX_ETH_MAC_ADDR_HIGH(port_num));
+       mac_l = mv_read(MV643XX_ETH_MAC_ADDR_LOW(port_num));
 
        p_addr[0] = (mac_h >> 24) & 0xff;
        p_addr[1] = (mac_h >> 16) & 0xff;
@@ -2176,7 +2148,7 @@ static void eth_update_mib_counters(struct mv643xx_private *mp)
        for (offset = ETH_MIB_BAD_OCTETS_RECEIVED;
                        offset <= ETH_MIB_FRAMES_1024_TO_MAX_OCTETS;
                        offset += 4)
-               *(u32 *)((char *)p + offset) = read_mib(mp, offset);
+               *(u32 *)((char *)p + offset) += read_mib(mp, offset);
 
        p->good_octets_sent += read_mib(mp, ETH_MIB_GOOD_OCTETS_SENT_LOW);
        p->good_octets_sent +=
@@ -2185,7 +2157,7 @@ static void eth_update_mib_counters(struct mv643xx_private *mp)
        for (offset = ETH_MIB_GOOD_FRAMES_SENT;
                        offset <= ETH_MIB_LATE_COLLISION;
                        offset += 4)
-               *(u32 *)((char *)p + offset) = read_mib(mp, offset);
+               *(u32 *)((char *)p + offset) += read_mib(mp, offset);
 }
 
 /*
@@ -2743,7 +2715,7 @@ static void mv643xx_get_ethtool_stats(struct net_device *netdev,
        eth_update_mib_counters(mp);
 
        for (i = 0; i < MV643XX_STATS_LEN; i++) {
-               char *p = (char *)mp+mv643xx_gstrings_stats[i].stat_offset;     
+               char *p = (char *)mp+mv643xx_gstrings_stats[i].stat_offset;
                data[i] = (mv643xx_gstrings_stats[i].sizeof_stat ==
                        sizeof(uint64_t)) ? *(uint64_t *)p : *(uint32_t *)p;
        }
@@ -2786,14 +2758,13 @@ static int mv643xx_eth_do_ioctl(struct net_device *dev, struct ifreq *ifr, int c
        return generic_mii_ioctl(&mp->mii, if_mii(ifr), cmd, NULL);
 }
 
-static struct ethtool_ops mv643xx_ethtool_ops = {
+static const struct ethtool_ops mv643xx_ethtool_ops = {
        .get_settings           = mv643xx_get_settings,
        .set_settings           = mv643xx_set_settings,
        .get_drvinfo            = mv643xx_get_drvinfo,
        .get_link               = mv643xx_eth_get_link,
        .get_sg                 = ethtool_op_get_sg,
        .set_sg                 = ethtool_op_set_sg,
-       .get_strings            = mv643xx_get_strings,
        .get_stats_count        = mv643xx_get_stats_count,
        .get_ethtool_stats      = mv643xx_get_ethtool_stats,
        .get_strings            = mv643xx_get_strings,