Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/drzeus/mmc
[safe/jmp/linux-2.6] / drivers / net / mv643xx_eth.c
index bb96931..6bb5af3 100644 (file)
@@ -351,10 +351,8 @@ struct rx_queue {
        int rx_desc_area_size;
        struct sk_buff **rx_skb;
 
-#ifdef CONFIG_MV643XX_ETH_LRO
        struct net_lro_mgr lro_mgr;
        struct net_lro_desc lro_arr[8];
-#endif
 };
 
 struct tx_queue {
@@ -395,12 +393,12 @@ struct mv643xx_eth_private {
        struct work_struct tx_timeout_task;
 
        struct napi_struct napi;
+       u8 oom;
        u8 work_link;
        u8 work_tx;
        u8 work_tx_end;
        u8 work_rx;
        u8 work_rx_refill;
-       u8 work_rx_oom;
 
        int skb_size;
        struct sk_buff_head rx_recycle;
@@ -516,7 +514,6 @@ static void txq_maybe_wake(struct tx_queue *txq)
 
 
 /* rx napi ******************************************************************/
-#ifdef CONFIG_MV643XX_ETH_LRO
 static int
 mv643xx_get_skb_header(struct sk_buff *skb, void **iphdr, void **tcph,
                       u64 *hdr_flags, void *priv)
@@ -542,7 +539,6 @@ mv643xx_get_skb_header(struct sk_buff *skb, void **iphdr, void **tcph,
 
        return 0;
 }
-#endif
 
 static int rxq_process(struct rx_queue *rxq, int budget)
 {
@@ -573,7 +569,7 @@ static int rxq_process(struct rx_queue *rxq, int budget)
                if (rxq->rx_curr_desc == rxq->rx_ring_size)
                        rxq->rx_curr_desc = 0;
 
-               dma_unmap_single(NULL, rx_desc->buf_ptr,
+               dma_unmap_single(mp->dev->dev.parent, rx_desc->buf_ptr,
                                 rx_desc->buf_size, DMA_FROM_DEVICE);
                rxq->rx_desc_count--;
                rx++;
@@ -612,13 +608,11 @@ static int rxq_process(struct rx_queue *rxq, int budget)
                        skb->ip_summed = CHECKSUM_UNNECESSARY;
                skb->protocol = eth_type_trans(skb, mp->dev);
 
-#ifdef CONFIG_MV643XX_ETH_LRO
                if (skb->dev->features & NETIF_F_LRO &&
                    skb->ip_summed == CHECKSUM_UNNECESSARY) {
                        lro_receive_skb(&rxq->lro_mgr, skb, (void *)cmd_sts);
                        lro_flush_needed = 1;
                } else
-#endif
                        netif_receive_skb(skb);
 
                continue;
@@ -640,10 +634,8 @@ err:
                dev_kfree_skb(skb);
        }
 
-#ifdef CONFIG_MV643XX_ETH_LRO
        if (lro_flush_needed)
                lro_flush_all(&rxq->lro_mgr);
-#endif
 
        if (rx < budget)
                mp->work_rx &= ~(1 << rxq->index);
@@ -669,7 +661,7 @@ static int rxq_refill(struct rx_queue *rxq, int budget)
                                            dma_get_cache_alignment() - 1);
 
                if (skb == NULL) {
-                       mp->work_rx_oom |= 1 << rxq->index;
+                       mp->oom = 1;
                        goto oom;
                }
 
@@ -686,8 +678,9 @@ static int rxq_refill(struct rx_queue *rxq, int budget)
 
                rx_desc = rxq->rx_desc_area + rx;
 
-               rx_desc->buf_ptr = dma_map_single(NULL, skb->data,
-                                       mp->skb_size, DMA_FROM_DEVICE);
+               rx_desc->buf_ptr = dma_map_single(mp->dev->dev.parent,
+                                                 skb->data, mp->skb_size,
+                                                 DMA_FROM_DEVICE);
                rx_desc->buf_size = mp->skb_size;
                rxq->rx_skb[rx] = skb;
                wmb();
@@ -726,6 +719,7 @@ static inline unsigned int has_tiny_unaligned_frags(struct sk_buff *skb)
 
 static void txq_submit_frag_skb(struct tx_queue *txq, struct sk_buff *skb)
 {
+       struct mv643xx_eth_private *mp = txq_to_mp(txq);
        int nr_frags = skb_shinfo(skb)->nr_frags;
        int frag;
 
@@ -754,10 +748,10 @@ static void txq_submit_frag_skb(struct tx_queue *txq, struct sk_buff *skb)
 
                desc->l4i_chk = 0;
                desc->byte_cnt = this_frag->size;
-               desc->buf_ptr = dma_map_page(NULL, this_frag->page,
-                                               this_frag->page_offset,
-                                               this_frag->size,
-                                               DMA_TO_DEVICE);
+               desc->buf_ptr = dma_map_page(mp->dev->dev.parent,
+                                            this_frag->page,
+                                            this_frag->page_offset,
+                                            this_frag->size, DMA_TO_DEVICE);
        }
 }
 
@@ -834,7 +828,8 @@ no_csum:
 
        desc->l4i_chk = l4i_chk;
        desc->byte_cnt = length;
-       desc->buf_ptr = dma_map_single(NULL, skb->data, length, DMA_TO_DEVICE);
+       desc->buf_ptr = dma_map_single(mp->dev->dev.parent, skb->data,
+                                      length, DMA_TO_DEVICE);
 
        __skb_queue_tail(&txq->tx_skb, skb);
 
@@ -964,10 +959,10 @@ static int txq_reclaim(struct tx_queue *txq, int budget, int force)
                }
 
                if (cmd_sts & TX_FIRST_DESC) {
-                       dma_unmap_single(NULL, desc->buf_ptr,
+                       dma_unmap_single(mp->dev->dev.parent, desc->buf_ptr,
                                         desc->byte_cnt, DMA_TO_DEVICE);
                } else {
-                       dma_unmap_page(NULL, desc->buf_ptr,
+                       dma_unmap_page(mp->dev->dev.parent, desc->buf_ptr,
                                       desc->byte_cnt, DMA_TO_DEVICE);
                }
 
@@ -1231,7 +1226,6 @@ static void mv643xx_eth_grab_lro_stats(struct mv643xx_eth_private *mp)
        u32 lro_no_desc = 0;
        int i;
 
-#ifdef CONFIG_MV643XX_ETH_LRO
        for (i = 0; i < mp->rxq_count; i++) {
                struct rx_queue *rxq = mp->rxq + i;
 
@@ -1239,7 +1233,6 @@ static void mv643xx_eth_grab_lro_stats(struct mv643xx_eth_private *mp)
                lro_flushed += rxq->lro_mgr.stats.flushed;
                lro_no_desc += rxq->lro_mgr.stats.no_desc;
        }
-#endif
 
        mp->lro_counters.lro_aggregated = lro_aggregated;
        mp->lro_counters.lro_flushed = lro_flushed;
@@ -1263,9 +1256,8 @@ static void mib_counters_update(struct mv643xx_eth_private *mp)
 {
        struct mib_counters *p = &mp->mib_counters;
 
-       spin_lock(&mp->mib_counters_lock);
+       spin_lock_bh(&mp->mib_counters_lock);
        p->good_octets_received += mib_read(mp, 0x00);
-       p->good_octets_received += (u64)mib_read(mp, 0x04) << 32;
        p->bad_octets_received += mib_read(mp, 0x08);
        p->internal_mac_transmit_err += mib_read(mp, 0x0c);
        p->good_frames_received += mib_read(mp, 0x10);
@@ -1279,7 +1271,6 @@ static void mib_counters_update(struct mv643xx_eth_private *mp)
        p->frames_512_to_1023_octets += mib_read(mp, 0x30);
        p->frames_1024_to_max_octets += mib_read(mp, 0x34);
        p->good_octets_sent += mib_read(mp, 0x38);
-       p->good_octets_sent += (u64)mib_read(mp, 0x3c) << 32;
        p->good_frames_sent += mib_read(mp, 0x40);
        p->excessive_collision += mib_read(mp, 0x44);
        p->multicast_frames_sent += mib_read(mp, 0x48);
@@ -1296,7 +1287,7 @@ static void mib_counters_update(struct mv643xx_eth_private *mp)
        p->bad_crc_event += mib_read(mp, 0x74);
        p->collision += mib_read(mp, 0x78);
        p->late_collision += mib_read(mp, 0x7c);
-       spin_unlock(&mp->mib_counters_lock);
+       spin_unlock_bh(&mp->mib_counters_lock);
 
        mod_timer(&mp->mib_counters_timer, jiffies + 30 * HZ);
 }
@@ -1831,7 +1822,7 @@ oom:
                return;
        }
 
-       mc_spec = kmalloc(0x200, GFP_KERNEL);
+       mc_spec = kmalloc(0x200, GFP_ATOMIC);
        if (mc_spec == NULL)
                goto oom;
        mc_other = mc_spec + (0x100 >> 2);
@@ -1906,9 +1897,9 @@ static int rxq_init(struct mv643xx_eth_private *mp, int index)
                                                mp->rx_desc_sram_size);
                rxq->rx_desc_dma = mp->rx_desc_sram_addr;
        } else {
-               rxq->rx_desc_area = dma_alloc_coherent(NULL, size,
-                                                       &rxq->rx_desc_dma,
-                                                       GFP_KERNEL);
+               rxq->rx_desc_area = dma_alloc_coherent(mp->dev->dev.parent,
+                                                      size, &rxq->rx_desc_dma,
+                                                      GFP_KERNEL);
        }
 
        if (rxq->rx_desc_area == NULL) {
@@ -1939,7 +1930,6 @@ static int rxq_init(struct mv643xx_eth_private *mp, int index)
                                        nexti * sizeof(struct rx_desc);
        }
 
-#ifdef CONFIG_MV643XX_ETH_LRO
        rxq->lro_mgr.dev = mp->dev;
        memset(&rxq->lro_mgr.stats, 0, sizeof(rxq->lro_mgr.stats));
        rxq->lro_mgr.features = LRO_F_NAPI;
@@ -1952,7 +1942,6 @@ static int rxq_init(struct mv643xx_eth_private *mp, int index)
        rxq->lro_mgr.get_skb_header = mv643xx_get_skb_header;
 
        memset(&rxq->lro_arr, 0, sizeof(rxq->lro_arr));
-#endif
 
        return 0;
 
@@ -1961,7 +1950,7 @@ out_free:
        if (index == 0 && size <= mp->rx_desc_sram_size)
                iounmap(rxq->rx_desc_area);
        else
-               dma_free_coherent(NULL, size,
+               dma_free_coherent(mp->dev->dev.parent, size,
                                  rxq->rx_desc_area,
                                  rxq->rx_desc_dma);
 
@@ -1993,7 +1982,7 @@ static void rxq_deinit(struct rx_queue *rxq)
            rxq->rx_desc_area_size <= mp->rx_desc_sram_size)
                iounmap(rxq->rx_desc_area);
        else
-               dma_free_coherent(NULL, rxq->rx_desc_area_size,
+               dma_free_coherent(mp->dev->dev.parent, rxq->rx_desc_area_size,
                                  rxq->rx_desc_area, rxq->rx_desc_dma);
 
        kfree(rxq->rx_skb);
@@ -2021,9 +2010,9 @@ static int txq_init(struct mv643xx_eth_private *mp, int index)
                                                mp->tx_desc_sram_size);
                txq->tx_desc_dma = mp->tx_desc_sram_addr;
        } else {
-               txq->tx_desc_area = dma_alloc_coherent(NULL, size,
-                                                       &txq->tx_desc_dma,
-                                                       GFP_KERNEL);
+               txq->tx_desc_area = dma_alloc_coherent(mp->dev->dev.parent,
+                                                      size, &txq->tx_desc_dma,
+                                                      GFP_KERNEL);
        }
 
        if (txq->tx_desc_area == NULL) {
@@ -2067,7 +2056,7 @@ static void txq_deinit(struct tx_queue *txq)
            txq->tx_desc_area_size <= mp->tx_desc_sram_size)
                iounmap(txq->tx_desc_area);
        else
-               dma_free_coherent(NULL, txq->tx_desc_area_size,
+               dma_free_coherent(mp->dev->dev.parent, txq->tx_desc_area_size,
                                  txq->tx_desc_area, txq->tx_desc_dma);
 }
 
@@ -2179,8 +2168,10 @@ static int mv643xx_eth_poll(struct napi_struct *napi, int budget)
 
        mp = container_of(napi, struct mv643xx_eth_private, napi);
 
-       mp->work_rx_refill |= mp->work_rx_oom;
-       mp->work_rx_oom = 0;
+       if (unlikely(mp->oom)) {
+               mp->oom = 0;
+               del_timer(&mp->rx_oom);
+       }
 
        work_done = 0;
        while (work_done < budget) {
@@ -2194,8 +2185,10 @@ static int mv643xx_eth_poll(struct napi_struct *napi, int budget)
                        continue;
                }
 
-               queue_mask = mp->work_tx | mp->work_tx_end |
-                               mp->work_rx | mp->work_rx_refill;
+               queue_mask = mp->work_tx | mp->work_tx_end | mp->work_rx;
+               if (likely(!mp->oom))
+                       queue_mask |= mp->work_rx_refill;
+
                if (!queue_mask) {
                        if (mv643xx_eth_collect_events(mp))
                                continue;
@@ -2216,7 +2209,7 @@ static int mv643xx_eth_poll(struct napi_struct *napi, int budget)
                        txq_maybe_wake(mp->txq + queue);
                } else if (mp->work_rx & queue_mask) {
                        work_done += rxq_process(mp->rxq + queue, work_tbd);
-               } else if (mp->work_rx_refill & queue_mask) {
+               } else if (!mp->oom && (mp->work_rx_refill & queue_mask)) {
                        work_done += rxq_refill(mp->rxq + queue, work_tbd);
                } else {
                        BUG();
@@ -2224,7 +2217,7 @@ static int mv643xx_eth_poll(struct napi_struct *napi, int budget)
        }
 
        if (work_done < budget) {
-               if (mp->work_rx_oom)
+               if (mp->oom)
                        mod_timer(&mp->rx_oom, jiffies + (HZ / 10));
                napi_complete(napi);
                wrlp(mp, INT_MASK, INT_TX_END | INT_RX | INT_EXT);
@@ -2286,8 +2279,6 @@ static void port_start(struct mv643xx_eth_private *mp)
                pscr |= FORCE_LINK_PASS;
        wrlp(mp, PORT_SERIAL_CONTROL, pscr);
 
-       wrlp(mp, SDMA_CONFIG, PORT_SDMA_CONFIG_DEFAULT_VALUE);
-
        /*
         * Configure TX path and queues.
         */
@@ -2301,11 +2292,6 @@ static void port_start(struct mv643xx_eth_private *mp)
        }
 
        /*
-        * Add configured unicast address to address filter table.
-        */
-       mv643xx_eth_program_unicast_filter(mp->dev);
-
-       /*
         * Receive all unmatched unicast, TCP, UDP, BPDU and broadcast
         * frames to RX queue #0, and include the pseudo-header when
         * calculating receive checksums.
@@ -2318,6 +2304,11 @@ static void port_start(struct mv643xx_eth_private *mp)
        wrlp(mp, PORT_CONFIG_EXT, 0x00000000);
 
        /*
+        * Add configured unicast addresses to address filter table.
+        */
+       mv643xx_eth_program_unicast_filter(mp->dev);
+
+       /*
         * Enable the receive queues.
         */
        for (i = 0; i < mp->rxq_count; i++) {
@@ -2386,7 +2377,7 @@ static int mv643xx_eth_open(struct net_device *dev)
                rxq_refill(mp->rxq + i, INT_MAX);
        }
 
-       if (mp->work_rx_oom) {
+       if (mp->oom) {
                mp->rx_oom.expires = jiffies + (HZ / 10);
                add_timer(&mp->rx_oom);
        }
@@ -2400,13 +2391,8 @@ static int mv643xx_eth_open(struct net_device *dev)
                }
        }
 
-       netif_carrier_off(dev);
-
        port_start(mp);
 
-       set_rx_coal(mp, 0);
-       set_tx_coal(mp, 0);
-
        wrlp(mp, INT_MASK_EXT, INT_EXT_LINK_PHY | INT_EXT_TX);
        wrlp(mp, INT_MASK, INT_TX_END | INT_RX | INT_EXT);
 
@@ -2457,8 +2443,6 @@ static int mv643xx_eth_stop(struct net_device *dev)
        wrlp(mp, INT_MASK, 0x00000000);
        rdlp(mp, INT_MASK);
 
-       del_timer_sync(&mp->mib_counters_timer);
-
        napi_disable(&mp->napi);
 
        del_timer_sync(&mp->rx_oom);
@@ -2470,6 +2454,7 @@ static int mv643xx_eth_stop(struct net_device *dev)
        port_reset(mp);
        mv643xx_eth_get_stats(dev);
        mib_counters_update(mp);
+       del_timer_sync(&mp->mib_counters_timer);
 
        skb_queue_purge(&mp->rx_recycle);
 
@@ -2874,6 +2859,21 @@ static void init_pscr(struct mv643xx_eth_private *mp, int speed, int duplex)
        wrlp(mp, PORT_SERIAL_CONTROL, pscr);
 }
 
+static const struct net_device_ops mv643xx_eth_netdev_ops = {
+       .ndo_open               = mv643xx_eth_open,
+       .ndo_stop               = mv643xx_eth_stop,
+       .ndo_start_xmit         = mv643xx_eth_xmit,
+       .ndo_set_rx_mode        = mv643xx_eth_set_rx_mode,
+       .ndo_set_mac_address    = mv643xx_eth_set_mac_address,
+       .ndo_do_ioctl           = mv643xx_eth_ioctl,
+       .ndo_change_mtu         = mv643xx_eth_change_mtu,
+       .ndo_tx_timeout         = mv643xx_eth_tx_timeout,
+       .ndo_get_stats          = mv643xx_eth_get_stats,
+#ifdef CONFIG_NET_POLL_CONTROLLER
+       .ndo_poll_controller    = mv643xx_eth_netpoll,
+#endif
+};
+
 static int mv643xx_eth_probe(struct platform_device *pdev)
 {
        struct mv643xx_eth_platform_data *pd;
@@ -2945,18 +2945,8 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
        BUG_ON(!res);
        dev->irq = res->start;
 
-       dev->get_stats = mv643xx_eth_get_stats;
-       dev->hard_start_xmit = mv643xx_eth_xmit;
-       dev->open = mv643xx_eth_open;
-       dev->stop = mv643xx_eth_stop;
-       dev->set_rx_mode = mv643xx_eth_set_rx_mode;
-       dev->set_mac_address = mv643xx_eth_set_mac_address;
-       dev->do_ioctl = mv643xx_eth_ioctl;
-       dev->change_mtu = mv643xx_eth_change_mtu;
-       dev->tx_timeout = mv643xx_eth_tx_timeout;
-#ifdef CONFIG_NET_POLL_CONTROLLER
-       dev->poll_controller = mv643xx_eth_netpoll;
-#endif
+       dev->netdev_ops = &mv643xx_eth_netdev_ops;
+
        dev->watchdog_timeo = 2 * HZ;
        dev->base_addr = 0;
 
@@ -2968,6 +2958,13 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
        if (mp->shared->win_protect)
                wrl(mp, WINDOW_PROTECT(mp->port_num), mp->shared->win_protect);
 
+       netif_carrier_off(dev);
+
+       wrlp(mp, SDMA_CONFIG, PORT_SDMA_CONFIG_DEFAULT_VALUE);
+
+       set_rx_coal(mp, 250);
+       set_tx_coal(mp, 0);
+
        err = register_netdev(dev);
        if (err)
                goto out;