]> err.no Git - linux-2.6/blobdiff - drivers/net/via-velocity.c
via-velocity: move residual free rx descriptors count register update
[linux-2.6] / drivers / net / via-velocity.c
index fce2dfd0e9e6cc44e49d57b480878b8a8c3ceae2..086d69c1992024f488c8493a6141c4b43264845f 100644 (file)
@@ -1102,47 +1102,41 @@ static int __devinit velocity_get_pci_info(struct velocity_info *vptr, struct pc
 
 static int velocity_init_rings(struct velocity_info *vptr)
 {
-       int i;
-       unsigned int psize;
+       struct velocity_opt *opt = &vptr->options;
+       const unsigned int rx_ring_size = opt->numrx * sizeof(struct rx_desc);
+       const unsigned int tx_ring_size = opt->numtx * sizeof(struct tx_desc);
+       struct pci_dev *pdev = vptr->pdev;
        dma_addr_t pool_dma;
-       u8 *pool;
-
-       /*
-        *      Allocate all RD/TD rings a single pool
-        */
-
-       psize = vptr->options.numrx * sizeof(struct rx_desc) +
-               vptr->options.numtx * sizeof(struct tx_desc) * vptr->num_txq;
+       void *pool;
+       unsigned int i;
 
        /*
+        * Allocate all RD/TD rings a single pool.
+        *
         * pci_alloc_consistent() fulfills the requirement for 64 bytes
         * alignment
         */
-       pool = pci_alloc_consistent(vptr->pdev, psize, &pool_dma);
-
-       if (pool == NULL) {
-               printk(KERN_ERR "%s : DMA memory allocation failed.\n",
-                                       vptr->dev->name);
+       pool = pci_alloc_consistent(pdev, tx_ring_size * vptr->num_txq +
+                                   rx_ring_size, &pool_dma);
+       if (!pool) {
+               dev_err(&pdev->dev, "%s : DMA memory allocation failed.\n",
+                       vptr->dev->name);
                return -ENOMEM;
        }
 
-       memset(pool, 0, psize);
-
-       vptr->rd_ring = (struct rx_desc *) pool;
-
+       vptr->rd_ring = pool;
        vptr->rd_pool_dma = pool_dma;
 
-       i = vptr->options.numrx * sizeof(struct rx_desc);
-       pool += i;
-       pool_dma += i;
-       for (i = 0; i < vptr->num_txq; i++) {
-               int offset = vptr->options.numtx * sizeof(struct tx_desc);
+       pool += rx_ring_size;
+       pool_dma += rx_ring_size;
 
+       for (i = 0; i < vptr->num_txq; i++) {
+               vptr->td_rings[i] = pool;
                vptr->td_pool_dma[i] = pool_dma;
-               vptr->td_rings[i] = (struct tx_desc *) pool;
-               pool += offset;
-               pool_dma += offset;
+               pool += tx_ring_size;
+               pool_dma += tx_ring_size;
        }
+
        return 0;
 }
 
@@ -1161,7 +1155,7 @@ static void velocity_free_rings(struct velocity_info *vptr)
        pci_free_consistent(vptr->pdev, size, vptr->rd_ring, vptr->rd_pool_dma);
 }
 
-static inline void velocity_give_many_rx_descs(struct velocity_info *vptr)
+static void velocity_give_many_rx_descs(struct velocity_info *vptr)
 {
        struct mac_regs __iomem *regs = vptr->mac_regs;
        int avail, dirty, unusable;
@@ -1188,7 +1182,7 @@ static inline void velocity_give_many_rx_descs(struct velocity_info *vptr)
 
 static int velocity_rx_refill(struct velocity_info *vptr)
 {
-       int dirty = vptr->rd_dirty, done = 0, ret = 0;
+       int dirty = vptr->rd_dirty, done = 0;
 
        do {
                struct rx_desc *rd = vptr->rd_ring + dirty;
@@ -1198,8 +1192,7 @@ static int velocity_rx_refill(struct velocity_info *vptr)
                        break;
 
                if (!vptr->rd_info[dirty].skb) {
-                       ret = velocity_alloc_rx_buf(vptr, dirty);
-                       if (ret < 0)
+                       if (velocity_alloc_rx_buf(vptr, dirty) < 0)
                                break;
                }
                done++;
@@ -1209,10 +1202,9 @@ static int velocity_rx_refill(struct velocity_info *vptr)
        if (done) {
                vptr->rd_dirty = dirty;
                vptr->rd_filled += done;
-               velocity_give_many_rx_descs(vptr);
        }
 
-       return ret;
+       return done;
 }
 
 /**
@@ -1225,25 +1217,27 @@ static int velocity_rx_refill(struct velocity_info *vptr)
 
 static int velocity_init_rd_ring(struct velocity_info *vptr)
 {
-       int ret;
        int mtu = vptr->dev->mtu;
+       int ret = -ENOMEM;
 
        vptr->rx_buf_sz = (mtu <= ETH_DATA_LEN) ? PKT_BUF_SZ : mtu + 32;
 
        vptr->rd_info = kcalloc(vptr->options.numrx,
                                sizeof(struct velocity_rd_info), GFP_KERNEL);
        if (!vptr->rd_info)
-               return -ENOMEM;
+               goto out;
 
        vptr->rd_filled = vptr->rd_dirty = vptr->rd_curr = 0;
 
-       ret = velocity_rx_refill(vptr);
-       if (ret < 0) {
+       if (velocity_rx_refill(vptr) != vptr->options.numrx) {
                VELOCITY_PRT(MSG_LEVEL_ERR, KERN_ERR
                        "%s: failed to allocate RX buffer.\n", vptr->dev->name);
                velocity_free_rd_ring(vptr);
+               goto out;
        }
 
+       ret = 0;
+out:
        return ret;
 }
 
@@ -1418,10 +1412,8 @@ static int velocity_rx_srv(struct velocity_info *vptr, int status)
 
        vptr->rd_curr = rd_curr;
 
-       if (works > 0 && velocity_rx_refill(vptr) < 0) {
-               VELOCITY_PRT(MSG_LEVEL_ERR, KERN_ERR
-                       "%s: rx buf allocation failure\n", vptr->dev->name);
-       }
+       if ((works > 0) && (velocity_rx_refill(vptr) > 0))
+               velocity_give_many_rx_descs(vptr);
 
        VAR_USED(stats);
        return works;
@@ -1883,6 +1875,8 @@ static int velocity_open(struct net_device *dev)
        /* Ensure chip is running */
        pci_set_power_state(vptr->pdev, PCI_D0);
 
+       velocity_give_many_rx_descs(vptr);
+
        velocity_init_registers(vptr, VELOCITY_INIT_COLD);
 
        ret = request_irq(vptr->pdev->irq, &velocity_intr, IRQF_SHARED,