ramips: raeth: add a temporary pktlen variable
[openwrt.git] / target / linux / ramips / files / drivers / net / ramips.c
index 1f3c35a..338d200 100644 (file)
@@ -33,6 +33,9 @@
 
 #ifdef CONFIG_RALINK_RT305X
 #include "ramips_esw.c"
+#else
+static inline int rt305x_esw_init(void) { return 0; }
+static inline void rt305x_esw_exit(void) { }
 #endif
 
 #define phys_to_bus(a)  (a & 0x1FFFFFFF)
@@ -169,12 +172,13 @@ ramips_alloc_dma(struct raeth_priv *re)
 
        memset(re->rx, 0, sizeof(struct ramips_rx_dma) * NUM_RX_DESC);
        for (i = 0; i < NUM_RX_DESC; i++) {
-               struct sk_buff *new_skb = dev_alloc_skb(MAX_RX_LENGTH + 2);
+               struct sk_buff *new_skb = dev_alloc_skb(MAX_RX_LENGTH +
+                                                       NET_IP_ALIGN);
 
                if (!new_skb)
                        goto err_cleanup;
 
-               skb_reserve(new_skb, 2);
+               skb_reserve(new_skb, NET_IP_ALIGN);
                re->rx[i].rxd1 = dma_map_single(NULL,
                                                new_skb->data,
                                                MAX_RX_LENGTH,
@@ -211,7 +215,6 @@ ramips_eth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
        unsigned long tx;
        unsigned int tx_next;
        unsigned int mapped_addr;
-       unsigned long flags;
 
        if (priv->plat->min_pkt_len) {
                if (skb->len < priv->plat->min_pkt_len) {
@@ -229,7 +232,7 @@ ramips_eth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
        mapped_addr = (unsigned int) dma_map_single(NULL, skb->data, skb->len,
                                                    DMA_TO_DEVICE);
        dma_sync_single_for_device(NULL, mapped_addr, skb->len, DMA_TO_DEVICE);
-       spin_lock_irqsave(&priv->page_lock, flags);
+       spin_lock(&priv->page_lock);
        tx = ramips_fe_rr(RAMIPS_TX_CTX_IDX0);
        tx_next = (tx + 1) % NUM_TX_DESC;
 
@@ -246,11 +249,11 @@ ramips_eth_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
        priv->tx_skb[tx] = skb;
        wmb();
        ramips_fe_wr(tx_next, RAMIPS_TX_CTX_IDX0);
-       spin_unlock_irqrestore(&priv->page_lock, flags);
+       spin_unlock(&priv->page_lock);
        return NETDEV_TX_OK;
 
  out:
-       spin_unlock_irqrestore(&priv->page_lock, flags);
+       spin_unlock(&priv->page_lock);
        dev->stats.tx_dropped++;
        kfree_skb(skb);
        return NETDEV_TX_OK;
@@ -266,30 +269,35 @@ ramips_eth_rx_hw(unsigned long ptr)
 
        while (max_rx) {
                struct sk_buff *rx_skb, *new_skb;
+               int pktlen;
 
                rx = (ramips_fe_rr(RAMIPS_RX_CALC_IDX0) + 1) % NUM_RX_DESC;
                if (!(priv->rx[rx].rxd2 & RX_DMA_DONE))
                        break;
                max_rx--;
 
-               new_skb = netdev_alloc_skb(dev, MAX_RX_LENGTH + 2);
+               rx_skb = priv->rx_skb[rx];
+               pktlen = RX_DMA_PLEN0(priv->rx[rx].rxd2);
+
+               new_skb = netdev_alloc_skb(dev, MAX_RX_LENGTH + NET_IP_ALIGN);
                /* Reuse the buffer on allocation failures */
                if (new_skb) {
-                       rx_skb = priv->rx_skb[rx];
-                       skb_put(rx_skb, RX_DMA_PLEN0(priv->rx[rx].rxd2));
+                       skb_put(rx_skb, pktlen);
                        rx_skb->dev = dev;
                        rx_skb->protocol = eth_type_trans(rx_skb, dev);
                        rx_skb->ip_summed = CHECKSUM_NONE;
                        dev->stats.rx_packets++;
-                       dev->stats.rx_bytes += rx_skb->len;
+                       dev->stats.rx_bytes += pktlen;
                        netif_rx(rx_skb);
 
                        priv->rx_skb[rx] = new_skb;
-                       skb_reserve(new_skb, 2);
+                       skb_reserve(new_skb, NET_IP_ALIGN);
                        priv->rx[rx].rxd1 = dma_map_single(NULL,
                                                           new_skb->data,
                                                           MAX_RX_LENGTH,
                                                           DMA_FROM_DEVICE);
+               } else {
+                       dev->stats.rx_dropped++;
                }
 
                priv->rx[rx].rxd2 &= ~RX_DMA_DONE;
@@ -309,6 +317,7 @@ ramips_eth_tx_housekeeping(unsigned long ptr)
        struct net_device *dev = (struct net_device*)ptr;
        struct raeth_priv *priv = netdev_priv(dev);
 
+       spin_lock(&priv->page_lock);
        while ((priv->tx[priv->skb_free_idx].txd2 & TX_DMA_DONE) &&
               (priv->tx_skb[priv->skb_free_idx])) {
                dev_kfree_skb_irq(priv->tx_skb[priv->skb_free_idx]);
@@ -317,6 +326,7 @@ ramips_eth_tx_housekeeping(unsigned long ptr)
                if (priv->skb_free_idx >= NUM_TX_DESC)
                        priv->skb_free_idx = 0;
        }
+       spin_unlock(&priv->page_lock);
 
        ramips_fe_int_enable(RAMIPS_TX_DLY_INT);
 }
@@ -342,8 +352,10 @@ ramips_eth_irq(int irq, void *dev)
                tasklet_schedule(&priv->rx_tasklet);
        }
 
-       if (fe_int & RAMIPS_TX_DLY_INT)
-               ramips_eth_tx_housekeeping((unsigned long)dev);
+       if (fe_int & RAMIPS_TX_DLY_INT) {
+               ramips_fe_int_disable(RAMIPS_TX_DLY_INT);
+               tasklet_schedule(&priv->tx_housekeeping_tasklet);
+       }
 
        return IRQ_HANDLED;
 }
@@ -506,9 +518,6 @@ ramips_eth_plat_probe(struct platform_device *plat)
                goto err_free_dev;
        }
 
-#ifdef CONFIG_RALINK_RT305X
-       rt305x_esw_init();
-#endif
        printk(KERN_DEBUG "ramips_eth: loaded\n");
        return 0;
 
@@ -540,10 +549,23 @@ static struct platform_driver ramips_eth_driver = {
 static int __init
 ramips_eth_init(void)
 {
-       int ret = platform_driver_register(&ramips_eth_driver);
+       int ret;
+
+       ret = rt305x_esw_init();
        if (ret)
+               return ret;
+
+       ret = platform_driver_register(&ramips_eth_driver);
+       if (ret) {
                printk(KERN_ERR
                       "ramips_eth: Error registering platfom driver!\n");
+               goto esw_cleanup;
+       }
+
+       return 0;
+
+esw_cleanup:
+       rt305x_esw_exit();
        return ret;
 }
 
@@ -551,6 +573,7 @@ static void __exit
 ramips_eth_cleanup(void)
 {
        platform_driver_unregister(&ramips_eth_driver);
+       rt305x_esw_exit();
 }
 
 module_init(ramips_eth_init);
This page took 0.024393 seconds and 4 git commands to generate.