include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / atm / firestream.c
index 7f7ec28..6e600af 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/pci.h>
+#include <linux/poison.h>
 #include <linux/errno.h>
 #include <linux/atm.h>
 #include <linux/atmdev.h>
@@ -45,6 +46,7 @@
 #include <linux/init.h>
 #include <linux/capability.h>
 #include <linux/bitops.h>
+#include <linux/slab.h>
 #include <asm/byteorder.h>
 #include <asm/system.h>
 #include <asm/string.h>
@@ -170,8 +172,8 @@ static char *res_strings[] = {
        "packet purged", 
        "packet ageing timeout", 
        "channel ageing timeout", 
-       "calculated lenght error", 
-       "programmed lenght limit error", 
+       "calculated length error", 
+       "programmed length limit error", 
        "aal5 crc32 error", 
        "oam transp or transpc crc10 error", 
        "reserved 25", 
@@ -330,8 +332,8 @@ module_param(fs_keystream, int, 0);
 #define FS_DEBUG_QSIZE   0x00001000
 
 
-#define func_enter() fs_dprintk (FS_DEBUG_FLOW, "fs: enter %s\n", __FUNCTION__)
-#define func_exit()  fs_dprintk (FS_DEBUG_FLOW, "fs: exit  %s\n", __FUNCTION__)
+#define func_enter() fs_dprintk(FS_DEBUG_FLOW, "fs: enter %s\n", __func__)
+#define func_exit()  fs_dprintk(FS_DEBUG_FLOW, "fs: exit  %s\n", __func__)
 
 
 static struct fs_dev *fs_boards = NULL;
@@ -511,7 +513,7 @@ static unsigned int make_rate (unsigned int rate, int r,
                }
                case ROUND_UP: {
                        /* check all bits that we are discarding */
-                       if (man & (-1>>9)) {
+                       if (man & (~0U>>9)) {
                                man = (man>>(32-9)) + 1;
                                if (man == (1<<9)) {
                                        /* no need to check for round up outside of range */
@@ -754,7 +756,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
                        fs_kfree_skb (skb);
 
                        fs_dprintk (FS_DEBUG_ALLOC, "Free trans-d: %p\n", td); 
-                       memset (td, 0x12, sizeof (struct FS_BPENTRY));
+                       memset (td, ATM_POISON_FREE, sizeof(struct FS_BPENTRY));
                        kfree (td);
                        break;
                default:
@@ -951,7 +953,7 @@ static int fs_open(struct atm_vcc *atm_vcc)
                   it most likely that the chip will notice it. It also prevents us
                   from having to wait for completion. On the other hand, we may
                   need to wait for completion anyway, to see if it completed
-                  succesfully. */
+                  successfully. */
 
                switch (atm_vcc->qos.aal) {
                case ATM_AAL2:
@@ -977,6 +979,7 @@ static int fs_open(struct atm_vcc *atm_vcc)
                /* Docs are vague about this atm_hdr field. By the way, the FS
                 * chip makes odd errors if lower bits are set.... -- REW */
                tc->atm_hdr =  (vpi << 20) | (vci << 4); 
+               tmc0 = 0;
                {
                        int pcr = atm_pcr_goal (txtp);
 
@@ -1001,6 +1004,10 @@ static int fs_open(struct atm_vcc *atm_vcc)
                                        r = ROUND_UP;
                                }
                                error = make_rate (pcr, r, &tmc0, NULL);
+                               if (error) {
+                                       kfree(tc);
+                                       return error;
+                               }
                        }
                        fs_dprintk (FS_DEBUG_OPEN, "pcr = %d.\n", pcr);
                }
@@ -1238,7 +1245,7 @@ static int fs_getsockopt(struct atm_vcc *vcc,int level,int optname,
 
 
 static int fs_setsockopt(struct atm_vcc *vcc,int level,int optname,
-                        void __user *optval,int optlen)
+                        void __user *optval,unsigned int optlen)
 {
        func_enter ();
        func_exit ();
@@ -1290,7 +1297,7 @@ static const struct atmdev_ops ops = {
 
 static void __devinit undocumented_pci_fix (struct pci_dev *pdev)
 {
-       int tint;
+       u32 tint;
 
        /* The Windows driver says: */
        /* Switch off FireStream Retry Limit Threshold 
@@ -1470,6 +1477,7 @@ static void top_off_fp (struct fs_dev *dev, struct freepool *fp,
        struct FS_BPENTRY *qe, *ne;
        struct sk_buff *skb;
        int n = 0;
+       u32 qe_tmp;
 
        fs_dprintk (FS_DEBUG_QUEUE, "Topping off queue at %x (%d-%d/%d)\n", 
                    fp->offset, read_fs (dev, FP_CNT (fp->offset)), fp->n, 
@@ -1497,10 +1505,16 @@ static void top_off_fp (struct fs_dev *dev, struct freepool *fp,
                ne->skb = skb;
                ne->fp = fp;
 
-               qe = (struct FS_BPENTRY *) (read_fs (dev, FP_EA(fp->offset)));
-               fs_dprintk (FS_DEBUG_QUEUE, "link at %p\n", qe);
-               if (qe) {
-                       qe = bus_to_virt ((long) qe);
+               /*
+                * FIXME: following code encodes and decodes
+                * machine pointers (could be 64-bit) into a
+                * 32-bit register.
+                */
+
+               qe_tmp = read_fs (dev, FP_EA(fp->offset));
+               fs_dprintk (FS_DEBUG_QUEUE, "link at %x\n", qe_tmp);
+               if (qe_tmp) {
+                       qe = bus_to_virt ((long) qe_tmp);
                        qe->next = virt_to_bus(ne);
                        qe->flags &= ~FP_FLAGS_EPI;
                } else
@@ -1545,7 +1559,7 @@ static void __devexit free_freepool (struct fs_dev *dev, struct freepool *fp)
 
 
 
-static irqreturn_t fs_irq (int irq, void *dev_id,  struct pt_regs * pt_regs
+static irqreturn_t fs_irq (int irq, void *dev_id) 
 {
        int i;
        u32 status;
@@ -1584,7 +1598,7 @@ static irqreturn_t fs_irq (int irq, void *dev_id,  struct pt_regs * pt_regs)
 
        /* print the bits in the ISR register. */
        if (fs_debug & FS_DEBUG_IRQ) {
-               /* The FS_DEBUG things are unneccesary here. But this way it is
+               /* The FS_DEBUG things are unnecessary here. But this way it is
                   clear for grep that these are debug prints. */
                fs_dprintk (FS_DEBUG_IRQ,  "IRQ status:");
                for (i=0;i<27;i++) 
@@ -1642,7 +1656,7 @@ static void fs_poll (unsigned long data)
 {
        struct fs_dev *dev = (struct fs_dev *) data;
   
-       fs_irq (0, dev, NULL);
+       fs_irq (0, dev);
        dev->timer.expires = jiffies + FS_POLL_FREQ;
        add_timer (&dev->timer);
 }
@@ -1657,9 +1671,10 @@ static int __devinit fs_init (struct fs_dev *dev)
        func_enter ();
        pci_dev = dev->pci_dev;
 
-       printk (KERN_INFO "found a FireStream %d card, base %08lx, irq%d.\n", 
+       printk (KERN_INFO "found a FireStream %d card, base %16llx, irq%d.\n",
                IS_FS50(dev)?50:155,
-               pci_resource_start(pci_dev, 0), dev->pci_dev->irq);
+               (unsigned long long)pci_resource_start(pci_dev, 0),
+               dev->pci_dev->irq);
 
        if (fs_debug & FS_DEBUG_INIT)
                my_hd ((unsigned char *) dev, sizeof (*dev));
@@ -1676,17 +1691,17 @@ static int __devinit fs_init (struct fs_dev *dev)
                  | (0 * SARMODE0_SHADEN) /* We don't use shadow registers. */
                  | (1 * SARMODE0_INTMODE_READCLEAR)
                  | (1 * SARMODE0_CWRE)
-                 | IS_FS50(dev)?SARMODE0_PRPWT_FS50_5: 
-                                SARMODE0_PRPWT_FS155_3
+                 | (IS_FS50(dev) ? SARMODE0_PRPWT_FS50_5:
+                         SARMODE0_PRPWT_FS155_3)
                  | (1 * SARMODE0_CALSUP_1)
-                 | IS_FS50 (dev)?(0
+                 | (IS_FS50(dev) ? (0
                                   | SARMODE0_RXVCS_32
                                   | SARMODE0_ABRVCS_32 
                                   | SARMODE0_TXVCS_32):
                                  (0
                                   | SARMODE0_RXVCS_1k
                                   | SARMODE0_ABRVCS_1k 
-                                  | SARMODE0_TXVCS_1k));
+                                  | SARMODE0_TXVCS_1k)));
 
        /* 10ms * 100 is 1 second. That should be enough, as AN3:9 says it takes
           1ms. */
@@ -1697,7 +1712,7 @@ static int __devinit fs_init (struct fs_dev *dev)
                /* This bit is documented as "RESERVED" */
                if (isr & ISR_INIT_ERR) {
                        printk (KERN_ERR "Error initializing the FS... \n");
-                       return 1;
+                       goto unmap;
                }
                if (isr & ISR_INIT) {
                        fs_dprintk (FS_DEBUG_INIT, "Ha! Initialized OK!\n");
@@ -1710,7 +1725,7 @@ static int __devinit fs_init (struct fs_dev *dev)
 
        if (!to) {
                printk (KERN_ERR "timeout initializing the FS... \n");
-               return 1;
+               goto unmap;
        }
 
        /* XXX fix for fs155 */
@@ -1782,7 +1797,7 @@ static int __devinit fs_init (struct fs_dev *dev)
                write_fs (dev, RAM, (1 << (28 - FS155_VPI_BITS - FS155_VCI_BITS)) - 1);
                dev->nchannels = FS155_NR_CHANNELS;
        }
-       dev->atm_vccs = kmalloc (dev->nchannels * sizeof (struct atm_vcc *), 
+       dev->atm_vccs = kcalloc (dev->nchannels, sizeof (struct atm_vcc *),
                                 GFP_KERNEL);
        fs_dprintk (FS_DEBUG_ALLOC, "Alloc atmvccs: %p(%Zd)\n",
                    dev->atm_vccs, dev->nchannels * sizeof (struct atm_vcc *));
@@ -1790,21 +1805,18 @@ static int __devinit fs_init (struct fs_dev *dev)
        if (!dev->atm_vccs) {
                printk (KERN_WARNING "Couldn't allocate memory for VCC buffers. Woops!\n");
                /* XXX Clean up..... */
-               return 1;
+               goto unmap;
        }
-       memset (dev->atm_vccs, 0, dev->nchannels * sizeof (struct atm_vcc *));
 
-       dev->tx_inuse = kmalloc (dev->nchannels / 8 /* bits/byte */ , GFP_KERNEL);
+       dev->tx_inuse = kzalloc (dev->nchannels / 8 /* bits/byte */ , GFP_KERNEL);
        fs_dprintk (FS_DEBUG_ALLOC, "Alloc tx_inuse: %p(%d)\n", 
                    dev->atm_vccs, dev->nchannels / 8);
 
        if (!dev->tx_inuse) {
                printk (KERN_WARNING "Couldn't allocate memory for tx_inuse bits!\n");
                /* XXX Clean up..... */
-               return 1;
+               goto unmap;
        }
-       memset (dev->tx_inuse, 0, dev->nchannels / 8);
-
        /* -- RAS1 : FS155 and 50 differ. Default (0) should be OK for both */
        /* -- RAS2 : FS50 only: Default is OK. */
 
@@ -1827,10 +1839,10 @@ static int __devinit fs_init (struct fs_dev *dev)
                init_q (dev, &dev->rx_rq[i], RXB_RQ(i), RXRQ_NENTRIES, 1);
 
        dev->irq = pci_dev->irq;
-       if (request_irq (dev->irq, fs_irq, SA_SHIRQ, "firestream", dev)) {
+       if (request_irq (dev->irq, fs_irq, IRQF_SHARED, "firestream", dev)) {
                printk (KERN_WARNING "couldn't get irq %d for firestream.\n", pci_dev->irq);
                /* XXX undo all previous stuff... */
-               return 1;
+               goto unmap;
        }
        fs_dprintk (FS_DEBUG_INIT, "Grabbed irq %d for dev at %p.\n", dev->irq, dev);
   
@@ -1880,6 +1892,9 @@ static int __devinit fs_init (struct fs_dev *dev)
   
        func_exit ();
        return 0;
+unmap:
+       iounmap(dev->base);
+       return 1;
 }
 
 static int __devinit firestream_init_one (struct pci_dev *pci_dev,
@@ -1891,14 +1906,11 @@ static int __devinit firestream_init_one (struct pci_dev *pci_dev,
        if (pci_enable_device(pci_dev)) 
                goto err_out;
 
-       fs_dev = kmalloc (sizeof (struct fs_dev), GFP_KERNEL);
+       fs_dev = kzalloc (sizeof (struct fs_dev), GFP_KERNEL);
        fs_dprintk (FS_DEBUG_ALLOC, "Alloc fs-dev: %p(%Zd)\n",
                    fs_dev, sizeof (struct fs_dev));
        if (!fs_dev)
                goto err_out;
-
-       memset (fs_dev, 0, sizeof (struct fs_dev));
-  
        atm_dev = atm_dev_register("fs", &ops, -1, NULL);
        if (!atm_dev)
                goto err_out_free_fs_dev;
@@ -2005,6 +2017,7 @@ static void __devexit firestream_remove_one (struct pci_dev *pdev)
                for (i=0;i < FS_NR_RX_QUEUES;i++)
                        free_queue (dev, &dev->rx_rq[i]);
 
+               iounmap(dev->base);
                fs_dprintk (FS_DEBUG_ALLOC, "Free fs-dev: %p\n", dev);
                nxtdev = dev->next;
                kfree (dev);