fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / atm / idt77252.c
index b929f43..f407861 100644 (file)
@@ -34,8 +34,8 @@ static char const rcsid[] =
 
 
 #include <linux/module.h>
-#include <linux/config.h>
 #include <linux/pci.h>
+#include <linux/poison.h>
 #include <linux/skbuff.h>
 #include <linux/kernel.h>
 #include <linux/vmalloc.h>
@@ -46,6 +46,7 @@ static char const rcsid[] =
 #include <linux/init.h>
 #include <linux/bitops.h>
 #include <linux/wait.h>
+#include <linux/jiffies.h>
 #include <asm/semaphore.h>
 #include <asm/io.h>
 #include <asm/uaccess.h>
@@ -134,7 +135,7 @@ static int idt77252_change_qos(struct atm_vcc *vcc, struct atm_qos *qos,
                               int flags);
 static int idt77252_proc_read(struct atm_dev *dev, loff_t * pos,
                              char *page);
-static void idt77252_softint(void *dev_id);
+static void idt77252_softint(struct work_struct *work);
 
 
 static struct atmdev_ops idt77252_ops =
@@ -641,11 +642,9 @@ alloc_scq(struct idt77252_dev *card, int class)
 {
        struct scq_info *scq;
 
-       scq = (struct scq_info *) kmalloc(sizeof(struct scq_info), GFP_KERNEL);
+       scq = kzalloc(sizeof(struct scq_info), GFP_KERNEL);
        if (!scq)
                return NULL;
-       memset(scq, 0, sizeof(struct scq_info));
-
        scq->base = pci_alloc_consistent(card->pcidev, SCQ_SIZE,
                                         &scq->paddr);
        if (scq->base == NULL) {
@@ -727,10 +726,11 @@ push_on_scq(struct idt77252_dev *card, struct vc_map *vc, struct sk_buff *skb)
        spin_lock_irqsave(&vc->lock, flags);
        if (vc->estimator) {
                struct atm_vcc *vcc = vc->tx_vcc;
+               struct sock *sk = sk_atm(vcc);
 
                vc->estimator->cells += (skb->len + 47) / 48;
-               if (atomic_read(&vcc->sk->sk_wmem_alloc) >
-                   (vcc->sk->sk_sndbuf >> 1)) {
+               if (atomic_read(&sk->sk_wmem_alloc) >
+                   (sk->sk_sndbuf >> 1)) {
                        u32 cps = vc->estimator->maxcps;
 
                        vc->estimator->cps = cps;
@@ -779,7 +779,7 @@ push_on_scq(struct idt77252_dev *card, struct vc_map *vc, struct sk_buff *skb)
        return 0;
 
 out:
-       if (jiffies - scq->trans_start > HZ) {
+       if (time_after(jiffies, scq->trans_start + HZ)) {
                printk("%s: Error pushing TBD for %d.%d\n",
                       card->name, vc->tx_vcc->vpi, vc->tx_vcc->vci);
 #ifdef CONFIG_ATM_IDT77252_DEBUG
@@ -1099,7 +1099,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
                               cell, ATM_CELL_PAYLOAD);
 
                        ATM_SKB(sb)->vcc = vcc;
-                       do_gettimeofday(&sb->stamp);
+                       __net_timestamp(sb);
                        vcc->push(vcc, sb);
                        atomic_inc(&vcc->stats->rx);
 
@@ -1177,7 +1177,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
 
                        skb_trim(skb, len);
                        ATM_SKB(skb)->vcc = vcc;
-                       do_gettimeofday(&skb->stamp);
+                       __net_timestamp(skb);
 
                        vcc->push(vcc, skb);
                        atomic_inc(&vcc->stats->rx);
@@ -1199,7 +1199,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
 
                skb_trim(skb, len);
                ATM_SKB(skb)->vcc = vcc;
-               do_gettimeofday(&skb->stamp);
+               __net_timestamp(skb);
 
                vcc->push(vcc, skb);
                atomic_inc(&vcc->stats->rx);
@@ -1266,8 +1266,9 @@ idt77252_rx_raw(struct idt77252_dev *card)
        head = IDT77252_PRV_PADDR(queue) + (queue->data - queue->head - 16);
        tail = readl(SAR_REG_RAWCT);
 
-       pci_dma_sync_single(card->pcidev, IDT77252_PRV_PADDR(queue),
-                           queue->end - queue->head - 16, PCI_DMA_FROMDEVICE);
+       pci_dma_sync_single_for_cpu(card->pcidev, IDT77252_PRV_PADDR(queue),
+                                   queue->end - queue->head - 16,
+                                   PCI_DMA_FROMDEVICE);
 
        while (head != tail) {
                unsigned int vpi, vci, pti;
@@ -1324,7 +1325,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
                        goto drop;
                }
 
-               if ((vcc->sk != NULL) && !atm_charge(vcc, sb->truesize)) {
+               if (!atm_charge(vcc, sb->truesize)) {
                        RXPRINTK("%s: atm_charge() dropped AAL0 packets.\n",
                                 card->name);
                        dev_kfree_skb(sb);
@@ -1337,7 +1338,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
                       ATM_CELL_PAYLOAD);
 
                ATM_SKB(sb)->vcc = vcc;
-               do_gettimeofday(&sb->stamp);
+               __net_timestamp(sb);
                vcc->push(vcc, sb);
                atomic_inc(&vcc->stats->rx);
 
@@ -1360,10 +1361,10 @@ drop:
                        if (next) {
                                card->raw_cell_head = next;
                                queue = card->raw_cell_head;
-                               pci_dma_sync_single(card->pcidev,
-                                                   IDT77252_PRV_PADDR(queue),
-                                                   queue->end - queue->data,
-                                                   PCI_DMA_FROMDEVICE);
+                               pci_dma_sync_single_for_cpu(card->pcidev,
+                                                           IDT77252_PRV_PADDR(queue),
+                                                           queue->end - queue->data,
+                                                           PCI_DMA_FROMDEVICE);
                        } else {
                                card->raw_cell_head = NULL;
                                printk("%s: raw cell queue overrun\n",
@@ -2028,7 +2029,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
                atomic_inc(&vcc->stats->tx_err);
                return -ENOMEM;
        }
-       atomic_add(skb->truesize, &vcc->sk->sk_wmem_alloc);
+       atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
 
        memcpy(skb_put(skb, 52), cell, 52);
 
@@ -2139,11 +2140,9 @@ idt77252_init_est(struct vc_map *vc, int pcr)
 {
        struct rate_estimator *est;
 
-       est = kmalloc(sizeof(struct rate_estimator), GFP_KERNEL);
+       est = kzalloc(sizeof(struct rate_estimator), GFP_KERNEL);
        if (!est)
                return NULL;
-       memset(est, 0, sizeof(*est));
-
        est->maxcps = pcr < 0 ? -pcr : pcr;
        est->cps = est->maxcps;
        est->avcps = est->cps << 5;
@@ -2448,14 +2447,12 @@ idt77252_open(struct atm_vcc *vcc)
 
        index = VPCI2VC(card, vpi, vci);
        if (!card->vcs[index]) {
-               card->vcs[index] = kmalloc(sizeof(struct vc_map), GFP_KERNEL);
+               card->vcs[index] = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
                if (!card->vcs[index]) {
                        printk("%s: can't alloc vc in open()\n", card->name);
                        up(&card->mutex);
                        return -ENOMEM;
                }
-               memset(card->vcs[index], 0, sizeof(struct vc_map));
-
                card->vcs[index]->card = card;
                card->vcs[index]->index = index;
 
@@ -2516,7 +2513,7 @@ idt77252_close(struct atm_vcc *vcc)
        struct vc_map *vc = vcc->dev_data;
        unsigned long flags;
        unsigned long addr;
-       int timeout;
+       unsigned long timeout;
 
        down(&card->mutex);
 
@@ -2566,9 +2563,9 @@ done:
                }
                spin_unlock_irqrestore(&vc->lock, flags);
 
-               timeout = 5 * HZ;
+               timeout = 5 * 1000;
                while (atomic_read(&vc->scq->used) > 0) {
-                       timeout = schedule_timeout(timeout);
+                       timeout = msleep_interruptible(timeout);
                        if (!timeout)
                                break;
                }
@@ -2777,7 +2774,7 @@ idt77252_collect_stat(struct idt77252_dev *card)
 }
 
 static irqreturn_t
-idt77252_interrupt(int irq, void *dev_id, struct pt_regs *ptregs)
+idt77252_interrupt(int irq, void *dev_id)
 {
        struct idt77252_dev *card = dev_id;
        u32 stat;
@@ -2869,9 +2866,10 @@ out:
 }
 
 static void
-idt77252_softint(void *dev_id)
+idt77252_softint(struct work_struct *work)
 {
-       struct idt77252_dev *card = dev_id;
+       struct idt77252_dev *card =
+               container_of(work, struct idt77252_dev, tqueue);
        u32 stat;
        int done;
 
@@ -2923,13 +2921,11 @@ open_card_oam(struct idt77252_dev *card)
                for (vci = 3; vci < 5; vci++) {
                        index = VPCI2VC(card, vpi, vci);
 
-                       vc = kmalloc(sizeof(struct vc_map), GFP_KERNEL);
+                       vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
                        if (!vc) {
                                printk("%s: can't alloc vc\n", card->name);
                                return -ENOMEM;
                        }
-                       memset(vc, 0, sizeof(struct vc_map));
-
                        vc->index = index;
                        card->vcs[index] = vc;
 
@@ -2992,12 +2988,11 @@ open_card_ubr0(struct idt77252_dev *card)
 {
        struct vc_map *vc;
 
-       vc = kmalloc(sizeof(struct vc_map), GFP_KERNEL);
+       vc = kzalloc(sizeof(struct vc_map), GFP_KERNEL);
        if (!vc) {
                printk("%s: can't alloc vc\n", card->name);
                return -ENOMEM;
        }
-       memset(vc, 0, sizeof(struct vc_map));
        card->vcs[0] = vc;
        vc->class = SCHED_UBR0;
 
@@ -3135,14 +3130,11 @@ deinit_card(struct idt77252_dev *card)
                }
        }
 
-       if (card->soft_tst)
-               vfree(card->soft_tst);
+       vfree(card->soft_tst);
 
-       if (card->scd2vc)
-               vfree(card->scd2vc);
+       vfree(card->scd2vc);
 
-       if (card->vcs)
-               vfree(card->vcs);
+       vfree(card->vcs);
 
        if (card->raw_cell_hnd) {
                pci_free_consistent(card->pcidev, 2 * sizeof(u32),
@@ -3164,11 +3156,11 @@ deinit_card(struct idt77252_dev *card)
 
        for (i = 0; i < 4; i++) {
                if (card->fbq[i])
-                       iounmap((void *) card->fbq[i]);
+                       iounmap(card->fbq[i]);
        }
 
        if (card->membase)
-               iounmap((void *) card->membase);
+               iounmap(card->membase);
 
        clear_bit(IDT77252_BIT_INIT, &card->flags);
        DIPRINTK("%s: Card deinitialized.\n", card->name);
@@ -3387,7 +3379,7 @@ init_card(struct atm_dev *dev)
                writel(SAR_STAT_TMROF, SAR_REG_STAT);
        }
        IPRINTK("%s: Request IRQ ... ", card->name);
-       if (request_irq(pcidev->irq, idt77252_interrupt, SA_INTERRUPT|SA_SHIRQ,
+       if (request_irq(pcidev->irq, idt77252_interrupt, IRQF_DISABLED|IRQF_SHARED,
                        card->name, card) != 0) {
                printk("%s: can't allocate IRQ.\n", card->name);
                deinit_card(card);
@@ -3658,7 +3650,7 @@ probe_sram(struct idt77252_dev *card)
        writel(SAR_CMD_WRITE_SRAM | (0 << 2), SAR_REG_CMD);
 
        for (addr = 0x4000; addr < 0x80000; addr += 0x4000) {
-               writel(0xdeadbeef, SAR_REG_DR0);
+               writel(ATM_POISON, SAR_REG_DR0);
                writel(SAR_CMD_WRITE_SRAM | (addr << 2), SAR_REG_CMD);
 
                writel(SAR_CMD_READ_SRAM | (0 << 2), SAR_REG_CMD);
@@ -3681,27 +3673,32 @@ idt77252_init_one(struct pci_dev *pcidev, const struct pci_device_id *id)
        struct idt77252_dev *card;
        struct atm_dev *dev;
        ushort revision = 0;
-       int i;
+       int i, err;
 
 
+       if ((err = pci_enable_device(pcidev))) {
+               printk("idt77252: can't enable PCI device at %s\n", pci_name(pcidev));
+               return err;
+       }
+
        if (pci_read_config_word(pcidev, PCI_REVISION_ID, &revision)) {
                printk("idt77252-%d: can't read PCI_REVISION_ID\n", index);
-               return -ENODEV;
+               err = -ENODEV;
+               goto err_out_disable_pdev;
        }
 
-       card = kmalloc(sizeof(struct idt77252_dev), GFP_KERNEL);
+       card = kzalloc(sizeof(struct idt77252_dev), GFP_KERNEL);
        if (!card) {
                printk("idt77252-%d: can't allocate private data\n", index);
-               return -ENOMEM;
+               err = -ENOMEM;
+               goto err_out_disable_pdev;
        }
-       memset(card, 0, sizeof(struct idt77252_dev));
-
        card->revision = revision;
        card->index = index;
        card->pcidev = pcidev;
        sprintf(card->name, "idt77252-%d", card->index);
 
-       INIT_WORK(&card->tqueue, idt77252_softint, (void *)card);
+       INIT_WORK(&card->tqueue, idt77252_softint);
 
        membase = pci_resource_start(pcidev, 1);
        srambase = pci_resource_start(pcidev, 2);
@@ -3715,26 +3712,24 @@ idt77252_init_one(struct pci_dev *pcidev, const struct pci_device_id *id)
        card->tst_timer.function = tst_timer;
 
        /* Do the I/O remapping... */
-       card->membase = (unsigned long) ioremap(membase, 1024);
+       card->membase = ioremap(membase, 1024);
        if (!card->membase) {
                printk("%s: can't ioremap() membase\n", card->name);
-               kfree(card);
-               return -EIO;
+               err = -EIO;
+               goto err_out_free_card;
        }
 
        if (idt77252_preset(card)) {
                printk("%s: preset failed\n", card->name);
-               iounmap((void *) card->membase);
-               kfree(card);
-               return -EIO;
+               err = -EIO;
+               goto err_out_iounmap;
        }
 
-       dev = atm_dev_register("idt77252", &idt77252_ops, -1, 0);
+       dev = atm_dev_register("idt77252", &idt77252_ops, -1, NULL);
        if (!dev) {
                printk("%s: can't register atm device\n", card->name);
-               iounmap((void *) card->membase);
-               kfree(card);
-               return -EIO;
+               err = -EIO;
+               goto err_out_iounmap;
        }
        dev->dev_data = card;
        card->atmdev = dev;
@@ -3743,22 +3738,19 @@ idt77252_init_one(struct pci_dev *pcidev, const struct pci_device_id *id)
        suni_init(dev);
        if (!dev->phy) {
                printk("%s: can't init SUNI\n", card->name);
-               deinit_card(card);
-               kfree(card);
-               return -EIO;
+               err = -EIO;
+               goto err_out_deinit_card;
        }
 #endif /* CONFIG_ATM_IDT77252_USE_SUNI */
 
        card->sramsize = probe_sram(card);
 
        for (i = 0; i < 4; i++) {
-               card->fbq[i] = (unsigned long)
-                           ioremap(srambase | 0x200000 | (i << 18), 4);
+               card->fbq[i] = ioremap(srambase | 0x200000 | (i << 18), 4);
                if (!card->fbq[i]) {
                        printk("%s: can't ioremap() FBQ%d\n", card->name, i);
-                       deinit_card(card);
-                       kfree(card);
-                       return -EIO;
+                       err = -EIO;
+                       goto err_out_deinit_card;
                }
        }
 
@@ -3769,9 +3761,8 @@ idt77252_init_one(struct pci_dev *pcidev, const struct pci_device_id *id)
 
        if (init_card(dev)) {
                printk("%s: init_card failed\n", card->name);
-               deinit_card(card);
-               kfree(card);
-               return -EIO;
+               err = -EIO;
+               goto err_out_deinit_card;
        }
 
        dev->ci_range.vpi_bits = card->vpibits;
@@ -3783,12 +3774,8 @@ idt77252_init_one(struct pci_dev *pcidev, const struct pci_device_id *id)
 
        if (idt77252_dev_open(card)) {
                printk("%s: dev_open failed\n", card->name);
-
-               if (dev->phy->stop)
-                       dev->phy->stop(dev);
-               deinit_card(card);
-               kfree(card);
-               return -EIO;
+               err = -EIO;
+               goto err_out_stop;
        }
 
        *last = card;
@@ -3796,6 +3783,23 @@ idt77252_init_one(struct pci_dev *pcidev, const struct pci_device_id *id)
        index++;
 
        return 0;
+
+err_out_stop:
+       if (dev->phy->stop)
+               dev->phy->stop(dev);
+
+err_out_deinit_card:
+       deinit_card(card);
+
+err_out_iounmap:
+       iounmap(card->membase);
+
+err_out_free_card:
+       kfree(card);
+
+err_out_disable_pdev:
+       pci_disable_device(pcidev);
+       return err;
 }
 
 static struct pci_device_id idt77252_pci_tbl[] =
@@ -3805,6 +3809,8 @@ static struct pci_device_id idt77252_pci_tbl[] =
        { 0, }
 };
 
+MODULE_DEVICE_TABLE(pci, idt77252_pci_tbl);
+
 static struct pci_driver idt77252_driver = {
        .name           = "idt77252",
        .id_table       = idt77252_pci_tbl,
@@ -3826,11 +3832,7 @@ static int __init idt77252_init(void)
                return -EIO;
        }
 
-       if (pci_register_driver(&idt77252_driver) > 0)
-               return 0;
-
-       pci_unregister_driver(&idt77252_driver);
-       return -ENODEV;
+       return pci_register_driver(&idt77252_driver);
 }
 
 static void __exit idt77252_exit(void)
@@ -3848,6 +3850,7 @@ static void __exit idt77252_exit(void)
                if (dev->phy->stop)
                        dev->phy->stop(dev);
                deinit_card(card);
+               pci_disable_device(card->pcidev);
                kfree(card);
        }
 
@@ -3859,10 +3862,10 @@ module_exit(idt77252_exit);
 
 MODULE_LICENSE("GPL");
 
-MODULE_PARM(vpibits, "i");
+module_param(vpibits, uint, 0);
 MODULE_PARM_DESC(vpibits, "number of VPI bits supported (0, 1, or 2)");
 #ifdef CONFIG_ATM_IDT77252_DEBUG
-MODULE_PARM(debug, "i");
+module_param(debug, ulong, 0644);
 MODULE_PARM_DESC(debug,   "debug bitmap, see drivers/atm/idt77252.h");
 #endif