md/raid5: use conf->raid_disks in preference to mddev->raid_disk
[safe/jmp/linux-2.6] / drivers / net / via-velocity.c
index 86b256c..754a4b1 100644 (file)
@@ -12,7 +12,7 @@
  *     Scatter gather
  *     More testing
  *
- * The changes are (c) Copyright 2004, Red Hat Inc. <alan@redhat.com>
+ * The changes are (c) Copyright 2004, Red Hat Inc. <alan@lxorguk.ukuu.org.uk>
  * Additional fixes and clean up: Francois Romieu
  *
  * This source has not been verified for use in safety critical systems.
@@ -377,7 +377,7 @@ static void velocity_print_info(struct velocity_info *vptr);
 static int velocity_open(struct net_device *dev);
 static int velocity_change_mtu(struct net_device *dev, int mtu);
 static int velocity_xmit(struct sk_buff *skb, struct net_device *dev);
-static int velocity_intr(int irq, void *dev_instance);
+static irqreturn_t velocity_intr(int irq, void *dev_instance);
 static void velocity_set_multi(struct net_device *dev);
 static struct net_device_stats *velocity_get_stats(struct net_device *dev);
 static int velocity_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
@@ -521,7 +521,7 @@ static void __devexit velocity_remove1(struct pci_dev *pdev)
  *     we don't duplicate code for each option.
  */
 
-static void __devinit velocity_set_int_opt(int *opt, int val, int min, int max, int def, char *name, char *devname)
+static void __devinit velocity_set_int_opt(int *opt, int val, int min, int max, int def, char *name, const char *devname)
 {
        if (val == -1)
                *opt = def;
@@ -550,7 +550,7 @@ static void __devinit velocity_set_int_opt(int *opt, int val, int min, int max,
  *     we don't duplicate code for each option.
  */
 
-static void __devinit velocity_set_bool_opt(u32 * opt, int val, int def, u32 flag, char *name, char *devname)
+static void __devinit velocity_set_bool_opt(u32 * opt, int val, int def, u32 flag, char *name, const char *devname)
 {
        (*opt) &= (~flag);
        if (val == -1)
@@ -576,7 +576,7 @@ static void __devinit velocity_set_bool_opt(u32 * opt, int val, int def, u32 fla
  *     for the current device
  */
 
-static void __devinit velocity_get_options(struct velocity_opt *opts, int index, char *devname)
+static void __devinit velocity_get_options(struct velocity_opt *opts, int index, const char *devname)
 {
 
        velocity_set_int_opt(&opts->rx_thresh, rx_thresh[index], RX_THRESH_MIN, RX_THRESH_MAX, RX_THRESH_DEF, "rx_thresh", devname);
@@ -662,6 +662,10 @@ static void velocity_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid
         spin_unlock_irq(&vptr->lock);
 }
 
+static void velocity_init_rx_ring_indexes(struct velocity_info *vptr)
+{
+       vptr->rx.dirty = vptr->rx.filled = vptr->rx.curr = 0;
+}
 
 /**
  *     velocity_rx_reset       -       handle a receive reset
@@ -677,16 +681,16 @@ static void velocity_rx_reset(struct velocity_info *vptr)
        struct mac_regs __iomem * regs = vptr->mac_regs;
        int i;
 
-       vptr->rd_dirty = vptr->rd_filled = vptr->rd_curr = 0;
+       velocity_init_rx_ring_indexes(vptr);
 
        /*
         *      Init state, all RD entries belong to the NIC
         */
        for (i = 0; i < vptr->options.numrx; ++i)
-               vptr->rd_ring[i].rdesc0.len |= OWNED_BY_NIC;
+               vptr->rx.ring[i].rdesc0.len |= OWNED_BY_NIC;
 
        writew(vptr->options.numrx, &regs->RBRDU);
-       writel(vptr->rd_pool_dma, &regs->RDBaseLo);
+       writel(vptr->rx.pool_dma, &regs->RDBaseLo);
        writew(0, &regs->RDIdx);
        writew(vptr->options.numrx - 1, &regs->RDCSize);
 }
@@ -779,15 +783,15 @@ static void velocity_init_registers(struct velocity_info *vptr,
 
                vptr->int_mask = INT_MASK_DEF;
 
-               writel(vptr->rd_pool_dma, &regs->RDBaseLo);
+               writel(vptr->rx.pool_dma, &regs->RDBaseLo);
                writew(vptr->options.numrx - 1, &regs->RDCSize);
                mac_rx_queue_run(regs);
                mac_rx_queue_wake(regs);
 
                writew(vptr->options.numtx - 1, &regs->TDCSize);
 
-               for (i = 0; i < vptr->num_txq; i++) {
-                       writel(vptr->td_pool_dma[i], &regs->TDBaseLo[i]);
+               for (i = 0; i < vptr->tx.numq; i++) {
+                       writel(vptr->tx.pool_dma[i], &regs->TDBaseLo[i]);
                        mac_tx_queue_run(regs, i);
                }
 
@@ -845,6 +849,21 @@ static int velocity_soft_reset(struct velocity_info *vptr)
        return 0;
 }
 
+static const struct net_device_ops velocity_netdev_ops = {
+       .ndo_open               = velocity_open,
+       .ndo_stop               = velocity_close,
+       .ndo_start_xmit         = velocity_xmit,
+       .ndo_get_stats          = velocity_get_stats,
+       .ndo_validate_addr      = eth_validate_addr,
+       .ndo_set_mac_address    = eth_mac_addr,
+       .ndo_set_multicast_list = velocity_set_multi,
+       .ndo_change_mtu         = velocity_change_mtu,
+       .ndo_do_ioctl           = velocity_ioctl,
+       .ndo_vlan_rx_add_vid    = velocity_vlan_rx_add_vid,
+       .ndo_vlan_rx_kill_vid   = velocity_vlan_rx_kill_vid,
+       .ndo_vlan_rx_register   = velocity_vlan_rx_register,
+};
+
 /**
  *     velocity_found1         -       set up discovered velocity card
  *     @pdev: PCI device
@@ -859,6 +878,7 @@ static int __devinit velocity_found1(struct pci_dev *pdev, const struct pci_devi
        static int first = 1;
        struct net_device *dev;
        int i;
+       const char *drv_string;
        const struct velocity_info_tbl *info = &chip_info_table[ent->driver_data];
        struct velocity_info *vptr;
        struct mac_regs __iomem * regs;
@@ -931,7 +951,9 @@ static int __devinit velocity_found1(struct pci_dev *pdev, const struct pci_devi
                dev->dev_addr[i] = readb(&regs->PAR[i]);
 
 
-       velocity_get_options(&vptr->options, velocity_nics, dev->name);
+       drv_string = dev_driver_string(&pdev->dev);
+
+       velocity_get_options(&vptr->options, velocity_nics, drv_string);
 
        /*
         *      Mask out the options cannot be set to the chip
@@ -951,18 +973,8 @@ static int __devinit velocity_found1(struct pci_dev *pdev, const struct pci_devi
        vptr->phy_id = MII_GET_PHY_ID(vptr->mac_regs);
 
        dev->irq = pdev->irq;
-       dev->open = velocity_open;
-       dev->hard_start_xmit = velocity_xmit;
-       dev->stop = velocity_close;
-       dev->get_stats = velocity_get_stats;
-       dev->set_multicast_list = velocity_set_multi;
-       dev->do_ioctl = velocity_ioctl;
+       dev->netdev_ops = &velocity_netdev_ops;
        dev->ethtool_ops = &velocity_ethtool_ops;
-       dev->change_mtu = velocity_change_mtu;
-
-       dev->vlan_rx_add_vid = velocity_vlan_rx_add_vid;
-       dev->vlan_rx_kill_vid = velocity_vlan_rx_kill_vid;
-       dev->vlan_rx_register = velocity_vlan_rx_register;
 
 #ifdef  VELOCITY_ZERO_COPY_SUPPORT
        dev->features |= NETIF_F_SG;
@@ -1047,7 +1059,7 @@ static void __devinit velocity_init_info(struct pci_dev *pdev,
 
        vptr->pdev = pdev;
        vptr->chip_id = info->chip_id;
-       vptr->num_txq = info->txqueue;
+       vptr->tx.numq = info->txqueue;
        vptr->multicast_limit = MCAM_SIZE;
        spin_lock_init(&vptr->lock);
        INIT_LIST_HEAD(&vptr->list);
@@ -1093,14 +1105,14 @@ static int __devinit velocity_get_pci_info(struct velocity_info *vptr, struct pc
 }
 
 /**
- *     velocity_init_rings     -       set up DMA rings
+ *     velocity_init_dma_rings -       set up DMA rings
  *     @vptr: Velocity to set up
  *
  *     Allocate PCI mapped DMA rings for the receive and transmit layer
  *     to use.
  */
 
-static int velocity_init_rings(struct velocity_info *vptr)
+static int velocity_init_dma_rings(struct velocity_info *vptr)
 {
        struct velocity_opt *opt = &vptr->options;
        const unsigned int rx_ring_size = opt->numrx * sizeof(struct rx_desc);
@@ -1116,7 +1128,7 @@ static int velocity_init_rings(struct velocity_info *vptr)
         * pci_alloc_consistent() fulfills the requirement for 64 bytes
         * alignment
         */
-       pool = pci_alloc_consistent(pdev, tx_ring_size * vptr->num_txq +
+       pool = pci_alloc_consistent(pdev, tx_ring_size * vptr->tx.numq +
                                    rx_ring_size, &pool_dma);
        if (!pool) {
                dev_err(&pdev->dev, "%s : DMA memory allocation failed.\n",
@@ -1124,15 +1136,15 @@ static int velocity_init_rings(struct velocity_info *vptr)
                return -ENOMEM;
        }
 
-       vptr->rd_ring = pool;
-       vptr->rd_pool_dma = pool_dma;
+       vptr->rx.ring = pool;
+       vptr->rx.pool_dma = pool_dma;
 
        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;
+       for (i = 0; i < vptr->tx.numq; i++) {
+               vptr->tx.rings[i] = pool;
+               vptr->tx.pool_dma[i] = pool_dma;
                pool += tx_ring_size;
                pool_dma += tx_ring_size;
        }
@@ -1141,21 +1153,21 @@ static int velocity_init_rings(struct velocity_info *vptr)
 }
 
 /**
- *     velocity_free_rings     -       free PCI ring pointers
+ *     velocity_free_dma_rings -       free PCI ring pointers
  *     @vptr: Velocity to free from
  *
  *     Clean up the PCI ring buffers allocated to this velocity.
  */
 
-static void velocity_free_rings(struct velocity_info *vptr)
+static void velocity_free_dma_rings(struct velocity_info *vptr)
 {
        const int size = vptr->options.numrx * sizeof(struct rx_desc) +
-               vptr->options.numtx * sizeof(struct tx_desc) * vptr->num_txq;
+               vptr->options.numtx * sizeof(struct tx_desc) * vptr->tx.numq;
 
-       pci_free_consistent(vptr->pdev, size, vptr->rd_ring, vptr->rd_pool_dma);
+       pci_free_consistent(vptr->pdev, size, vptr->rx.ring, vptr->rx.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;
@@ -1164,49 +1176,52 @@ static inline void velocity_give_many_rx_descs(struct velocity_info *vptr)
         * RD number must be equal to 4X per hardware spec
         * (programming guide rev 1.20, p.13)
         */
-       if (vptr->rd_filled < 4)
+       if (vptr->rx.filled < 4)
                return;
 
        wmb();
 
-       unusable = vptr->rd_filled & 0x0003;
-       dirty = vptr->rd_dirty - unusable;
-       for (avail = vptr->rd_filled & 0xfffc; avail; avail--) {
+       unusable = vptr->rx.filled & 0x0003;
+       dirty = vptr->rx.dirty - unusable;
+       for (avail = vptr->rx.filled & 0xfffc; avail; avail--) {
                dirty = (dirty > 0) ? dirty - 1 : vptr->options.numrx - 1;
-               vptr->rd_ring[dirty].rdesc0.len |= OWNED_BY_NIC;
+               vptr->rx.ring[dirty].rdesc0.len |= OWNED_BY_NIC;
        }
 
-       writew(vptr->rd_filled & 0xfffc, &regs->RBRDU);
-       vptr->rd_filled = unusable;
+       writew(vptr->rx.filled & 0xfffc, &regs->RBRDU);
+       vptr->rx.filled = unusable;
 }
 
 static int velocity_rx_refill(struct velocity_info *vptr)
 {
-       int dirty = vptr->rd_dirty, done = 0, ret = 0;
+       int dirty = vptr->rx.dirty, done = 0;
 
        do {
-               struct rx_desc *rd = vptr->rd_ring + dirty;
+               struct rx_desc *rd = vptr->rx.ring + dirty;
 
                /* Fine for an all zero Rx desc at init time as well */
                if (rd->rdesc0.len & OWNED_BY_NIC)
                        break;
 
-               if (!vptr->rd_info[dirty].skb) {
-                       ret = velocity_alloc_rx_buf(vptr, dirty);
-                       if (ret < 0)
+               if (!vptr->rx.info[dirty].skb) {
+                       if (velocity_alloc_rx_buf(vptr, dirty) < 0)
                                break;
                }
                done++;
                dirty = (dirty < vptr->options.numrx - 1) ? dirty + 1 : 0;
-       } while (dirty != vptr->rd_curr);
+       } while (dirty != vptr->rx.curr);
 
        if (done) {
-               vptr->rd_dirty = dirty;
-               vptr->rd_filled += done;
-               velocity_give_many_rx_descs(vptr);
+               vptr->rx.dirty = dirty;
+               vptr->rx.filled += done;
        }
 
-       return ret;
+       return done;
+}
+
+static void velocity_set_rxbufsize(struct velocity_info *vptr, int mtu)
+{
+       vptr->rx.buf_sz = (mtu <= ETH_DATA_LEN) ? PKT_BUF_SZ : mtu + 32;
 }
 
 /**
@@ -1219,25 +1234,24 @@ 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;
-
-       vptr->rx_buf_sz = (mtu <= ETH_DATA_LEN) ? PKT_BUF_SZ : mtu + 32;
+       int ret = -ENOMEM;
 
-       vptr->rd_info = kcalloc(vptr->options.numrx,
+       vptr->rx.info = kcalloc(vptr->options.numrx,
                                sizeof(struct velocity_rd_info), GFP_KERNEL);
-       if (!vptr->rd_info)
-               return -ENOMEM;
+       if (!vptr->rx.info)
+               goto out;
 
-       vptr->rd_filled = vptr->rd_dirty = vptr->rd_curr = 0;
+       velocity_init_rx_ring_indexes(vptr);
 
-       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;
 }
 
@@ -1253,27 +1267,27 @@ static void velocity_free_rd_ring(struct velocity_info *vptr)
 {
        int i;
 
-       if (vptr->rd_info == NULL)
+       if (vptr->rx.info == NULL)
                return;
 
        for (i = 0; i < vptr->options.numrx; i++) {
-               struct velocity_rd_info *rd_info = &(vptr->rd_info[i]);
-               struct rx_desc *rd = vptr->rd_ring + i;
+               struct velocity_rd_info *rd_info = &(vptr->rx.info[i]);
+               struct rx_desc *rd = vptr->rx.ring + i;
 
                memset(rd, 0, sizeof(*rd));
 
                if (!rd_info->skb)
                        continue;
-               pci_unmap_single(vptr->pdev, rd_info->skb_dma, vptr->rx_buf_sz,
+               pci_unmap_single(vptr->pdev, rd_info->skb_dma, vptr->rx.buf_sz,
                                 PCI_DMA_FROMDEVICE);
-               rd_info->skb_dma = (dma_addr_t) NULL;
+               rd_info->skb_dma = 0;
 
                dev_kfree_skb(rd_info->skb);
                rd_info->skb = NULL;
        }
 
-       kfree(vptr->rd_info);
-       vptr->rd_info = NULL;
+       kfree(vptr->rx.info);
+       vptr->rx.info = NULL;
 }
 
 /**
@@ -1288,22 +1302,22 @@ static void velocity_free_rd_ring(struct velocity_info *vptr)
 static int velocity_init_td_ring(struct velocity_info *vptr)
 {
        dma_addr_t curr;
-       unsigned int j;
+       int j;
 
        /* Init the TD ring entries */
-       for (j = 0; j < vptr->num_txq; j++) {
-               curr = vptr->td_pool_dma[j];
+       for (j = 0; j < vptr->tx.numq; j++) {
+               curr = vptr->tx.pool_dma[j];
 
-               vptr->td_infos[j] = kcalloc(vptr->options.numtx,
+               vptr->tx.infos[j] = kcalloc(vptr->options.numtx,
                                            sizeof(struct velocity_td_info),
                                            GFP_KERNEL);
-               if (!vptr->td_infos[j]) {
+               if (!vptr->tx.infos[j]) {
                        while(--j >= 0)
-                               kfree(vptr->td_infos[j]);
+                               kfree(vptr->tx.infos[j]);
                        return -ENOMEM;
                }
 
-               vptr->td_tail[j] = vptr->td_curr[j] = vptr->td_used[j] = 0;
+               vptr->tx.tail[j] = vptr->tx.curr[j] = vptr->tx.used[j] = 0;
        }
        return 0;
 }
@@ -1315,7 +1329,7 @@ static int velocity_init_td_ring(struct velocity_info *vptr)
 static void velocity_free_td_ring_entry(struct velocity_info *vptr,
                                                         int q, int n)
 {
-       struct velocity_td_info * td_info = &(vptr->td_infos[q][n]);
+       struct velocity_td_info * td_info = &(vptr->tx.infos[q][n]);
        int i;
 
        if (td_info == NULL)
@@ -1327,7 +1341,7 @@ static void velocity_free_td_ring_entry(struct velocity_info *vptr,
                        if (td_info->skb_dma[i]) {
                                pci_unmap_single(vptr->pdev, td_info->skb_dma[i],
                                        td_info->skb->len, PCI_DMA_TODEVICE);
-                               td_info->skb_dma[i] = (dma_addr_t) NULL;
+                               td_info->skb_dma[i] = 0;
                        }
                }
                dev_kfree_skb(td_info->skb);
@@ -1347,15 +1361,15 @@ static void velocity_free_td_ring(struct velocity_info *vptr)
 {
        int i, j;
 
-       for (j = 0; j < vptr->num_txq; j++) {
-               if (vptr->td_infos[j] == NULL)
+       for (j = 0; j < vptr->tx.numq; j++) {
+               if (vptr->tx.infos[j] == NULL)
                        continue;
                for (i = 0; i < vptr->options.numtx; i++) {
                        velocity_free_td_ring_entry(vptr, j, i);
 
                }
-               kfree(vptr->td_infos[j]);
-               vptr->td_infos[j] = NULL;
+               kfree(vptr->tx.infos[j]);
+               vptr->tx.infos[j] = NULL;
        }
 }
 
@@ -1372,13 +1386,13 @@ static void velocity_free_td_ring(struct velocity_info *vptr)
 static int velocity_rx_srv(struct velocity_info *vptr, int status)
 {
        struct net_device_stats *stats = &vptr->stats;
-       int rd_curr = vptr->rd_curr;
+       int rd_curr = vptr->rx.curr;
        int works = 0;
 
        do {
-               struct rx_desc *rd = vptr->rd_ring + rd_curr;
+               struct rx_desc *rd = vptr->rx.ring + rd_curr;
 
-               if (!vptr->rd_info[rd_curr].skb)
+               if (!vptr->rx.info[rd_curr].skb)
                        break;
 
                if (rd->rdesc0.len & OWNED_BY_NIC)
@@ -1403,19 +1417,15 @@ static int velocity_rx_srv(struct velocity_info *vptr, int status)
 
                rd->size |= RX_INTEN;
 
-               vptr->dev->last_rx = jiffies;
-
                rd_curr++;
                if (rd_curr >= vptr->options.numrx)
                        rd_curr = 0;
        } while (++works <= 15);
 
-       vptr->rd_curr = rd_curr;
+       vptr->rx.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;
@@ -1510,8 +1520,8 @@ static int velocity_receive_frame(struct velocity_info *vptr, int idx)
 {
        void (*pci_action)(struct pci_dev *, dma_addr_t, size_t, int);
        struct net_device_stats *stats = &vptr->stats;
-       struct velocity_rd_info *rd_info = &(vptr->rd_info[idx]);
-       struct rx_desc *rd = &(vptr->rd_ring[idx]);
+       struct velocity_rd_info *rd_info = &(vptr->rx.info[idx]);
+       struct rx_desc *rd = &(vptr->rx.ring[idx]);
        int pkt_len = le16_to_cpu(rd->rdesc0.len) & 0x3fff;
        struct sk_buff *skb;
 
@@ -1527,7 +1537,7 @@ static int velocity_receive_frame(struct velocity_info *vptr, int idx)
        skb = rd_info->skb;
 
        pci_dma_sync_single_for_cpu(vptr->pdev, rd_info->skb_dma,
-                                   vptr->rx_buf_sz, PCI_DMA_FROMDEVICE);
+                                   vptr->rx.buf_sz, PCI_DMA_FROMDEVICE);
 
        /*
         *      Drop frame not meeting IEEE 802.3
@@ -1550,7 +1560,7 @@ static int velocity_receive_frame(struct velocity_info *vptr, int idx)
                rd_info->skb = NULL;
        }
 
-       pci_action(vptr->pdev, rd_info->skb_dma, vptr->rx_buf_sz,
+       pci_action(vptr->pdev, rd_info->skb_dma, vptr->rx.buf_sz,
                   PCI_DMA_FROMDEVICE);
 
        skb_put(skb, pkt_len - 4);
@@ -1580,10 +1590,10 @@ static int velocity_receive_frame(struct velocity_info *vptr, int idx)
 
 static int velocity_alloc_rx_buf(struct velocity_info *vptr, int idx)
 {
-       struct rx_desc *rd = &(vptr->rd_ring[idx]);
-       struct velocity_rd_info *rd_info = &(vptr->rd_info[idx]);
+       struct rx_desc *rd = &(vptr->rx.ring[idx]);
+       struct velocity_rd_info *rd_info = &(vptr->rx.info[idx]);
 
-       rd_info->skb = netdev_alloc_skb(vptr->dev, vptr->rx_buf_sz + 64);
+       rd_info->skb = dev_alloc_skb(vptr->rx.buf_sz + 64);
        if (rd_info->skb == NULL)
                return -ENOMEM;
 
@@ -1592,14 +1602,15 @@ static int velocity_alloc_rx_buf(struct velocity_info *vptr, int idx)
         *      64byte alignment.
         */
        skb_reserve(rd_info->skb, (unsigned long) rd_info->skb->data & 63);
-       rd_info->skb_dma = pci_map_single(vptr->pdev, rd_info->skb->data, vptr->rx_buf_sz, PCI_DMA_FROMDEVICE);
+       rd_info->skb_dma = pci_map_single(vptr->pdev, rd_info->skb->data,
+                                       vptr->rx.buf_sz, PCI_DMA_FROMDEVICE);
 
        /*
         *      Fill in the descriptor to match
-        */
+        */
 
        *((u32 *) & (rd->rdesc0)) = 0;
-       rd->size = cpu_to_le16(vptr->rx_buf_sz) | RX_INTEN;
+       rd->size = cpu_to_le16(vptr->rx.buf_sz) | RX_INTEN;
        rd->pa_low = cpu_to_le32(rd_info->skb_dma);
        rd->pa_high = 0;
        return 0;
@@ -1625,15 +1636,15 @@ static int velocity_tx_srv(struct velocity_info *vptr, u32 status)
        struct velocity_td_info *tdinfo;
        struct net_device_stats *stats = &vptr->stats;
 
-       for (qnum = 0; qnum < vptr->num_txq; qnum++) {
-               for (idx = vptr->td_tail[qnum]; vptr->td_used[qnum] > 0;
+       for (qnum = 0; qnum < vptr->tx.numq; qnum++) {
+               for (idx = vptr->tx.tail[qnum]; vptr->tx.used[qnum] > 0;
                        idx = (idx + 1) % vptr->options.numtx) {
 
                        /*
                         *      Get Tx Descriptor
                         */
-                       td = &(vptr->td_rings[qnum][idx]);
-                       tdinfo = &(vptr->td_infos[qnum][idx]);
+                       td = &(vptr->tx.rings[qnum][idx]);
+                       tdinfo = &(vptr->tx.infos[qnum][idx]);
 
                        if (td->tdesc0.len & OWNED_BY_NIC)
                                break;
@@ -1657,9 +1668,9 @@ static int velocity_tx_srv(struct velocity_info *vptr, u32 status)
                                stats->tx_bytes += tdinfo->skb->len;
                        }
                        velocity_free_tx_buf(vptr, tdinfo);
-                       vptr->td_used[qnum]--;
+                       vptr->tx.used[qnum]--;
                }
-               vptr->td_tail[qnum] = idx;
+               vptr->tx.tail[qnum] = idx;
 
                if (AVAIL_TD(vptr, qnum) < 1) {
                        full = 1;
@@ -1827,17 +1838,19 @@ static void velocity_free_tx_buf(struct velocity_info *vptr, struct velocity_td_
 {
        struct sk_buff *skb = tdinfo->skb;
        int i;
+       int pktlen;
 
        /*
         *      Don't unmap the pre-allocated tx_bufs
         */
        if (tdinfo->skb_dma) {
 
+               pktlen = (skb->len > ETH_ZLEN ? : ETH_ZLEN);
                for (i = 0; i < tdinfo->nskb_dma; i++) {
 #ifdef VELOCITY_ZERO_COPY_SUPPORT
                        pci_unmap_single(vptr->pdev, tdinfo->skb_dma[i], le16_to_cpu(td->tdesc1.len), PCI_DMA_TODEVICE);
 #else
-                       pci_unmap_single(vptr->pdev, tdinfo->skb_dma[i], skb->len, PCI_DMA_TODEVICE);
+                       pci_unmap_single(vptr->pdev, tdinfo->skb_dma[i], pktlen, PCI_DMA_TODEVICE);
 #endif
                        tdinfo->skb_dma[i] = 0;
                }
@@ -1846,6 +1859,40 @@ static void velocity_free_tx_buf(struct velocity_info *vptr, struct velocity_td_
        tdinfo->skb = NULL;
 }
 
+static int velocity_init_rings(struct velocity_info *vptr, int mtu)
+{
+       int ret;
+
+       velocity_set_rxbufsize(vptr, mtu);
+
+       ret = velocity_init_dma_rings(vptr);
+       if (ret < 0)
+               goto out;
+
+       ret = velocity_init_rd_ring(vptr);
+       if (ret < 0)
+               goto err_free_dma_rings_0;
+
+       ret = velocity_init_td_ring(vptr);
+       if (ret < 0)
+               goto err_free_rd_ring_1;
+out:
+       return ret;
+
+err_free_rd_ring_1:
+       velocity_free_rd_ring(vptr);
+err_free_dma_rings_0:
+       velocity_free_dma_rings(vptr);
+       goto out;
+}
+
+static void velocity_free_rings(struct velocity_info *vptr)
+{
+       velocity_free_td_ring(vptr);
+       velocity_free_rd_ring(vptr);
+       velocity_free_dma_rings(vptr);
+}
+
 /**
  *     velocity_open           -       interface activation callback
  *     @dev: network layer device to open
@@ -1862,21 +1909,15 @@ static int velocity_open(struct net_device *dev)
        struct velocity_info *vptr = netdev_priv(dev);
        int ret;
 
-       ret = velocity_init_rings(vptr);
+       ret = velocity_init_rings(vptr, dev->mtu);
        if (ret < 0)
                goto out;
 
-       ret = velocity_init_rd_ring(vptr);
-       if (ret < 0)
-               goto err_free_desc_rings;
-
-       ret = velocity_init_td_ring(vptr);
-       if (ret < 0)
-               goto err_free_rd_ring;
-
        /* 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,
@@ -1884,7 +1925,8 @@ static int velocity_open(struct net_device *dev)
        if (ret < 0) {
                /* Power down the chip */
                pci_set_power_state(vptr->pdev, PCI_D3hot);
-               goto err_free_td_ring;
+               velocity_free_rings(vptr);
+               goto out;
        }
 
        mac_enable_int(vptr->mac_regs);
@@ -1892,14 +1934,6 @@ static int velocity_open(struct net_device *dev)
        vptr->flags |= VELOCITY_FLAGS_OPENED;
 out:
        return ret;
-
-err_free_td_ring:
-       velocity_free_td_ring(vptr);
-err_free_rd_ring:
-       velocity_free_rd_ring(vptr);
-err_free_desc_rings:
-       velocity_free_rings(vptr);
-       goto out;
 }
 
 /**
@@ -1915,48 +1949,72 @@ err_free_desc_rings:
 static int velocity_change_mtu(struct net_device *dev, int new_mtu)
 {
        struct velocity_info *vptr = netdev_priv(dev);
-       unsigned long flags;
-       int oldmtu = dev->mtu;
        int ret = 0;
 
        if ((new_mtu < VELOCITY_MIN_MTU) || new_mtu > (VELOCITY_MAX_MTU)) {
                VELOCITY_PRT(MSG_LEVEL_ERR, KERN_NOTICE "%s: Invalid MTU.\n",
                                vptr->dev->name);
-               return -EINVAL;
+               ret = -EINVAL;
+               goto out_0;
        }
 
        if (!netif_running(dev)) {
                dev->mtu = new_mtu;
-               return 0;
+               goto out_0;
        }
 
-       if (new_mtu != oldmtu) {
+       if (dev->mtu != new_mtu) {
+               struct velocity_info *tmp_vptr;
+               unsigned long flags;
+               struct rx_info rx;
+               struct tx_info tx;
+
+               tmp_vptr = kzalloc(sizeof(*tmp_vptr), GFP_KERNEL);
+               if (!tmp_vptr) {
+                       ret = -ENOMEM;
+                       goto out_0;
+               }
+
+               tmp_vptr->dev = dev;
+               tmp_vptr->pdev = vptr->pdev;
+               tmp_vptr->options = vptr->options;
+               tmp_vptr->tx.numq = vptr->tx.numq;
+
+               ret = velocity_init_rings(tmp_vptr, new_mtu);
+               if (ret < 0)
+                       goto out_free_tmp_vptr_1;
+
                spin_lock_irqsave(&vptr->lock, flags);
 
                netif_stop_queue(dev);
                velocity_shutdown(vptr);
 
-               velocity_free_td_ring(vptr);
-               velocity_free_rd_ring(vptr);
+               rx = vptr->rx;
+               tx = vptr->tx;
 
-               dev->mtu = new_mtu;
+               vptr->rx = tmp_vptr->rx;
+               vptr->tx = tmp_vptr->tx;
 
-               ret = velocity_init_rd_ring(vptr);
-               if (ret < 0)
-                       goto out_unlock;
+               tmp_vptr->rx = rx;
+               tmp_vptr->tx = tx;
 
-               ret = velocity_init_td_ring(vptr);
-               if (ret < 0)
-                       goto out_unlock;
+               dev->mtu = new_mtu;
+
+               velocity_give_many_rx_descs(vptr);
 
                velocity_init_registers(vptr, VELOCITY_INIT_COLD);
 
                mac_enable_int(vptr->mac_regs);
                netif_start_queue(dev);
-out_unlock:
+
                spin_unlock_irqrestore(&vptr->lock, flags);
-       }
 
+               velocity_free_rings(tmp_vptr);
+
+out_free_tmp_vptr_1:
+               kfree(tmp_vptr);
+       }
+out_0:
        return ret;
 }
 
@@ -2002,9 +2060,6 @@ static int velocity_close(struct net_device *dev)
        /* Power down the chip */
        pci_set_power_state(vptr->pdev, PCI_D3hot);
 
-       /* Free the resources */
-       velocity_free_td_ring(vptr);
-       velocity_free_rd_ring(vptr);
        velocity_free_rings(vptr);
 
        vptr->flags &= (~VELOCITY_FLAGS_OPENED);
@@ -2027,17 +2082,14 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
        struct tx_desc *td_ptr;
        struct velocity_td_info *tdinfo;
        unsigned long flags;
-       int pktlen = skb->len;
+       int pktlen;
        __le16 len;
        int index;
 
 
-
-       if (skb->len < ETH_ZLEN) {
-               if (skb_padto(skb, ETH_ZLEN))
-                       goto out;
-               pktlen = ETH_ZLEN;
-       }
+       if (skb_padto(skb, ETH_ZLEN))
+               goto out;
+       pktlen = max_t(unsigned int, skb->len, ETH_ZLEN);
 
        len = cpu_to_le16(pktlen);
 
@@ -2050,9 +2102,9 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
 
        spin_lock_irqsave(&vptr->lock, flags);
 
-       index = vptr->td_curr[qnum];
-       td_ptr = &(vptr->td_rings[qnum][index]);
-       tdinfo = &(vptr->td_infos[qnum][index]);
+       index = vptr->tx.curr[qnum];
+       td_ptr = &(vptr->tx.rings[qnum][index]);
+       tdinfo = &(vptr->tx.infos[qnum][index]);
 
        td_ptr->tdesc1.TCR = TCR0_TIC;
        td_ptr->td_buf[0].size &= ~TD_QUEUE;
@@ -2065,9 +2117,9 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
                        skb_copy_from_linear_data(skb, tdinfo->buf, skb->len);
                        tdinfo->skb_dma[0] = tdinfo->buf_dma;
                        td_ptr->tdesc0.len = len;
-                       td_ptr->td_buf[0].pa_low = cpu_to_le32(tdinfo->skb_dma[0]);
-                       td_ptr->td_buf[0].pa_high = 0;
-                       td_ptr->td_buf[0].size = len;   /* queue is 0 anyway */
+                       td_ptr->tx.buf[0].pa_low = cpu_to_le32(tdinfo->skb_dma[0]);
+                       td_ptr->tx.buf[0].pa_high = 0;
+                       td_ptr->tx.buf[0].size = len;   /* queue is 0 anyway */
                        tdinfo->nskb_dma = 1;
                } else {
                        int i = 0;
@@ -2078,9 +2130,9 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
                        td_ptr->tdesc0.len = len;
 
                        /* FIXME: support 48bit DMA later */
-                       td_ptr->td_buf[i].pa_low = cpu_to_le32(tdinfo->skb_dma);
-                       td_ptr->td_buf[i].pa_high = 0;
-                       td_ptr->td_buf[i].size = cpu_to_le16(skb_headlen(skb));
+                       td_ptr->tx.buf[i].pa_low = cpu_to_le32(tdinfo->skb_dma);
+                       td_ptr->tx.buf[i].pa_high = 0;
+                       td_ptr->tx.buf[i].size = cpu_to_le16(skb_headlen(skb));
 
                        for (i = 0; i < nfrags; i++) {
                                skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
@@ -2088,9 +2140,9 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
 
                                tdinfo->skb_dma[i + 1] = pci_map_single(vptr->pdev, addr, frag->size, PCI_DMA_TODEVICE);
 
-                               td_ptr->td_buf[i + 1].pa_low = cpu_to_le32(tdinfo->skb_dma[i + 1]);
-                               td_ptr->td_buf[i + 1].pa_high = 0;
-                               td_ptr->td_buf[i + 1].size = cpu_to_le16(frag->size);
+                               td_ptr->tx.buf[i + 1].pa_low = cpu_to_le32(tdinfo->skb_dma[i + 1]);
+                               td_ptr->tx.buf[i + 1].pa_high = 0;
+                               td_ptr->tx.buf[i + 1].size = cpu_to_le16(frag->size);
                        }
                        tdinfo->nskb_dma = i - 1;
                }
@@ -2136,13 +2188,13 @@ static int velocity_xmit(struct sk_buff *skb, struct net_device *dev)
                if (prev < 0)
                        prev = vptr->options.numtx - 1;
                td_ptr->tdesc0.len |= OWNED_BY_NIC;
-               vptr->td_used[qnum]++;
-               vptr->td_curr[qnum] = (index + 1) % vptr->options.numtx;
+               vptr->tx.used[qnum]++;
+               vptr->tx.curr[qnum] = (index + 1) % vptr->options.numtx;
 
                if (AVAIL_TD(vptr, qnum) < 1)
                        netif_stop_queue(dev);
 
-               td_ptr = &(vptr->td_rings[qnum][prev]);
+               td_ptr = &(vptr->tx.rings[qnum][prev]);
                td_ptr->td_buf[0].size |= TD_QUEUE;
                mac_tx_queue_wake(vptr->mac_regs, qnum);
        }
@@ -2163,7 +2215,7 @@ out:
  *     efficiently as possible.
  */
 
-static int velocity_intr(int irq, void *dev_instance)
+static irqreturn_t velocity_intr(int irq, void *dev_instance)
 {
        struct net_device *dev = dev_instance;
        struct velocity_info *vptr = netdev_priv(dev);
@@ -2246,7 +2298,7 @@ static void velocity_set_multi(struct net_device *dev)
                }
 
                mac_set_cam_mask(regs, vptr->mCAMmask);
-               rx_mode = (RCR_AM | RCR_AB);
+               rx_mode = RCR_AM | RCR_AB | RCR_AP;
        }
        if (dev->mtu > 1500)
                rx_mode |= RCR_AL;
@@ -3399,8 +3451,8 @@ static int velocity_resume(struct pci_dev *pdev)
 
        velocity_tx_srv(vptr, 0);
 
-       for (i = 0; i < vptr->num_txq; i++) {
-               if (vptr->td_used[i]) {
+       for (i = 0; i < vptr->tx.numq; i++) {
+               if (vptr->tx.used[i]) {
                        mac_tx_queue_wake(vptr->mac_regs, i);
                }
        }