include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / drivers / atm / iphase.c
index f20b0b2..ee9ddeb 100644 (file)
 #include <linux/uio.h>  
 #include <linux/init.h>  
 #include <linux/wait.h>
+#include <linux/slab.h>
 #include <asm/system.h>  
 #include <asm/io.h>  
 #include <asm/atomic.h>  
 #include <asm/uaccess.h>  
 #include <asm/string.h>  
 #include <asm/byteorder.h>  
-#include <linux/vmalloc.h>  
+#include <linux/vmalloc.h>
+#include <linux/jiffies.h>
 #include "iphase.h"              
 #include "suni.h"                
-#define swap(x) (((x & 0xff) << 8) | ((x & 0xff00) >> 8))  
-struct suni_priv {
-        struct k_sonet_stats sonet_stats; /* link diagnostics */
-        unsigned char loop_mode;        /* loopback mode */
-        struct atm_dev *dev;            /* device back-pointer */
-        struct suni_priv *next;         /* next SUNI */
-}; 
+#define swap_byte_order(x) (((x & 0xff) << 8) | ((x & 0xff00) >> 8))
+
 #define PRIV(dev) ((struct suni_priv *) dev->phy_data)
 
 static unsigned char ia_phy_get(struct atm_dev *dev, unsigned long addr);
@@ -93,10 +90,6 @@ module_param(IADebugFlag, uint, 0644);
 
 MODULE_LICENSE("GPL");
 
-#if BITS_PER_LONG != 32
-#  error FIXME: this driver only works on 32-bit platforms
-#endif
-
 /**************************** IA_LIB **********************************/
 
 static void ia_init_rtn_q (IARTN_Q *que) 
@@ -164,8 +157,8 @@ static void ia_hack_tcq(IADEV *dev) {
         }
         iavcc_r->vc_desc_cnt--;
         dev->desc_tbl[desc1 -1].timestamp = 0;
-        IF_EVENT(printk("ia_hack: return_q skb = 0x%x desc = %d\n", 
-                                   (u32)dev->desc_tbl[desc1 -1].txskb, desc1);)
+        IF_EVENT(printk("ia_hack: return_q skb = 0x%p desc = %d\n",
+                                   dev->desc_tbl[desc1 -1].txskb, desc1);)
         if (iavcc_r->pcr < dev->rate_limit) {
            IA_SKB_STATE (dev->desc_tbl[desc1-1].txskb) |= IA_TX_DONE;
            if (ia_enque_rtn_q(&dev->tx_return_q, dev->desc_tbl[desc1 -1]) < 0)
@@ -189,7 +182,7 @@ static u16 get_desc (IADEV *dev, struct ia_vcc *iavcc) {
   int ltimeout;
 
   ia_hack_tcq (dev);
-  if(((jiffies - timer)>50)||((dev->ffL.tcq_rd==dev->host_tcq_wr))){      
+  if((time_after(jiffies,timer+50)) || ((dev->ffL.tcq_rd==dev->host_tcq_wr))) {
      timer = jiffies; 
      i=0;
      while (i < dev->num_tx_desc) {
@@ -305,7 +298,7 @@ static void clear_lockup (struct atm_vcc *vcc, IADEV *dev) {
 **  |  R | NZ |  5-bit exponent  |        9-bit mantissa         |
 **  +----+----+------------------+-------------------------------+
 ** 
-**    R = reserverd (written as 0)
+**    R = reserved (written as 0)
 **    NZ = 0 if 0 cells/sec; 1 otherwise
 **
 **    if NZ = 1, rate = 1.mmmmmmmmm x 2^(eeeee) cells/sec
@@ -535,8 +528,8 @@ static int ia_cbr_setup (IADEV *dev, struct atm_vcc *vcc) {
       inc = 0;
       testSlot = idealSlot;
       TstSchedTbl = (u16*)(SchedTbl+testSlot);  //set index and read in value
-      IF_CBR(printk("CBR Testslot 0x%x AT Location 0x%x, NumToAssign=%d\n",
-                                testSlot, (u32)TstSchedTbl,toBeAssigned);) 
+      IF_CBR(printk("CBR Testslot 0x%x AT Location 0x%p, NumToAssign=%d\n",
+                                testSlot, TstSchedTbl,toBeAssigned);)
       memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC));
       while (cbrVC)  // If another VC at this location, we have to keep looking
       {
@@ -544,8 +537,8 @@ static int ia_cbr_setup (IADEV *dev, struct atm_vcc *vcc) {
           testSlot = idealSlot - inc;
           if (testSlot < 0) { // Wrap if necessary
              testSlot += dev->CbrTotEntries;
-             IF_CBR(printk("Testslot Wrap. STable Start=0x%x,Testslot=%d\n",
-                                                       (u32)SchedTbl,testSlot);)
+             IF_CBR(printk("Testslot Wrap. STable Start=0x%p,Testslot=%d\n",
+                                                       SchedTbl,testSlot);)
           }
           TstSchedTbl = (u16 *)(SchedTbl + testSlot);  // set table index
           memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC)); 
@@ -560,12 +553,12 @@ static int ia_cbr_setup (IADEV *dev, struct atm_vcc *vcc) {
           } 
           // set table index and read in value
           TstSchedTbl = (u16*)(SchedTbl + testSlot);
-          IF_CBR(printk("Reading CBR Tbl from 0x%x, CbrVal=0x%x Iteration %d\n",
-                          (u32)TstSchedTbl,cbrVC,inc);) 
+          IF_CBR(printk("Reading CBR Tbl from 0x%p, CbrVal=0x%x Iteration %d\n",
+                          TstSchedTbl,cbrVC,inc);)
           memcpy((caddr_t)&cbrVC,(caddr_t)TstSchedTbl,sizeof(cbrVC));
        } /* while */
        // Move this VCI number into this location of the CBR Sched table.
-       memcpy((caddr_t)TstSchedTbl, (caddr_t)&vcIndex,sizeof(TstSchedTbl));
+       memcpy((caddr_t)TstSchedTbl, (caddr_t)&vcIndex, sizeof(*TstSchedTbl));
        dev->CbrRemEntries--;
        toBeAssigned--;
    } /* while */ 
@@ -958,6 +951,7 @@ static void ia_suni_pm7345_init (IADEV *iadev)
 
 /***************************** IA_LIB END *****************************/
     
+#ifdef CONFIG_ATM_IA_DEBUG
 static int tcnter = 0;
 static void xdump( u_char*  cp, int  length, char*  prefix )
 {
@@ -984,14 +978,13 @@ static void xdump( u_char*  cp, int  length, char*  prefix )
             else
                 pBuf += sprintf( pBuf, "." );
                 }
-        sprintf( pBuf, "\n" );
-        // SPrint(prntBuf);
-        printk(prntBuf);
+        printk("%s\n", prntBuf);
         count += col;
         pBuf = prntBuf;
     }
 
 }  /* close xdump(... */
+#endif /* CONFIG_ATM_IA_DEBUG */
 
   
 static struct atm_dev *ia_boards = NULL;  
@@ -1140,7 +1133,7 @@ static int rx_pkt(struct atm_dev *dev)
                     IF_ERR(printk(" cause: packet time out\n");)
                 }
                 else {
-                    IF_ERR(printk(" cause: buffer over flow\n");)
+                    IF_ERR(printk(" cause: buffer overflow\n");)
                 }
                goto out_free_desc;
        }  
@@ -1223,7 +1216,7 @@ static void rx_intr(struct atm_dev *dev)
         iadev->rx_tmp_jif = jiffies; 
         iadev->rxing = 0;
      } 
-     else if (((jiffies - iadev->rx_tmp_jif) > 50) && 
+     else if ((time_after(jiffies, iadev->rx_tmp_jif + 50)) &&
                ((iadev->rx_pkt_cnt - iadev->rx_tmp_cnt) == 0)) {
         for (i = 1; i <= iadev->num_rx_desc; i++)
                free_desc(dev, i);
@@ -1312,7 +1305,7 @@ static void rx_dle_intr(struct atm_dev *dev)
           // get real pkt length  pwang_test
           trailer = (struct cpcs_trailer*)((u_char *)skb->data +
                                  skb->len - sizeof(*trailer));
-          length =  swap(trailer->length);
+         length = swap_byte_order(trailer->length);
           if ((length > iadev->rx_buf_sz) || (length > 
                               (skb->len - sizeof(struct cpcs_trailer))))
           {
@@ -1408,7 +1401,6 @@ static int rx_init(struct atm_dev *dev)
        struct abr_vc_table  *abr_vc_table; 
        u16 *vc_table;  
        u16 *reass_table;  
-        u16 *ptr16;
        int i,j, vcsize_sel;  
        u_short freeq_st_adr;  
        u_short *freeq_start;  
@@ -1423,21 +1415,22 @@ static int rx_init(struct atm_dev *dev)
                printk(KERN_ERR DEV_LABEL "can't allocate DLEs\n");
                goto err_out;
        }
-       iadev->rx_dle_q.start = (struct dle*)dle_addr;  
+       iadev->rx_dle_q.start = (struct dle *)dle_addr;
        iadev->rx_dle_q.read = iadev->rx_dle_q.start;  
        iadev->rx_dle_q.write = iadev->rx_dle_q.start;  
-       iadev->rx_dle_q.end = (struct dle*)((u32)dle_addr+sizeof(struct dle)*DLE_ENTRIES);  
+       iadev->rx_dle_q.end = (struct dle*)((unsigned long)dle_addr+sizeof(struct dle)*DLE_ENTRIES);
        /* the end of the dle q points to the entry after the last  
        DLE that can be used. */  
   
        /* write the upper 20 bits of the start address to rx list address register */  
+       /* We know this is 32bit bus addressed so the following is safe */
        writel(iadev->rx_dle_dma & 0xfffff000,
               iadev->dma + IPHASE5575_RX_LIST_ADDR);  
-       IF_INIT(printk("Tx Dle list addr: 0x%08x value: 0x%0x\n", 
-                      (u32)(iadev->dma+IPHASE5575_TX_LIST_ADDR), 
+       IF_INIT(printk("Tx Dle list addr: 0x%p value: 0x%0x\n",
+                      iadev->dma+IPHASE5575_TX_LIST_ADDR,
                       *(u32*)(iadev->dma+IPHASE5575_TX_LIST_ADDR));  
-       printk("Rx Dle list addr: 0x%08x value: 0x%0x\n", 
-                      (u32)(iadev->dma+IPHASE5575_RX_LIST_ADDR), 
+       printk("Rx Dle list addr: 0x%p value: 0x%0x\n",
+                      iadev->dma+IPHASE5575_RX_LIST_ADDR,
                       *(u32*)(iadev->dma+IPHASE5575_RX_LIST_ADDR));)  
   
        writew(0xffff, iadev->reass_reg+REASS_MASK_REG);  
@@ -1476,7 +1469,7 @@ static int rx_init(struct atm_dev *dev)
                buf_desc_ptr++;           
                rx_pkt_start += iadev->rx_buf_sz;  
        }  
-       IF_INIT(printk("Rx Buffer desc ptr: 0x%0x\n", (u32)(buf_desc_ptr));)  
+       IF_INIT(printk("Rx Buffer desc ptr: 0x%p\n", buf_desc_ptr);)
         i = FREE_BUF_DESC_Q*iadev->memSize; 
        writew(i >> 16,  iadev->reass_reg+REASS_QUEUE_BASE); 
         writew(i, iadev->reass_reg+FREEQ_ST_ADR);
@@ -1493,7 +1486,7 @@ static int rx_init(struct atm_dev *dev)
                *freeq_start = (u_short)i;  
                freeq_start++;  
        }  
-       IF_INIT(printk("freeq_start: 0x%0x\n", (u32)freeq_start);)  
+       IF_INIT(printk("freeq_start: 0x%p\n", freeq_start);)
         /* Packet Complete Queue */
         i = (PKT_COMP_Q * iadev->memSize) & 0xffff;
         writew(i, iadev->reass_reg+PCQ_ST_ADR);
@@ -1584,11 +1577,12 @@ static int rx_init(struct atm_dev *dev)
           Set Packet Aging Interval count register to overflow in about 4 us
        */  
         writew(0xF6F8, iadev->reass_reg+PKT_TM_CNT );
-        ptr16 = (u16*)j;
-        i = ((u32)ptr16 >> 6) & 0xff;
-       ptr16  += j - 1;
-       i |=(((u32)ptr16 << 2) & 0xff00);
+
+        i = (j >> 6) & 0xFF;
+        j += 2 * (j - 1);
+        i |= ((j << 2) & 0xFF00);
         writew(i, iadev->reass_reg+TMOUT_RANGE);
+
         /* initiate the desc_tble */
         for(i=0; i<iadev->num_tx_desc;i++)
             iadev->desc_tbl[i].timestamp = 0;
@@ -1601,14 +1595,14 @@ static int rx_init(struct atm_dev *dev)
   
        skb_queue_head_init(&iadev->rx_dma_q);  
        iadev->rx_free_desc_qhead = NULL;   
-       iadev->rx_open = kmalloc(4*iadev->num_vc,GFP_KERNEL);
-       if (!iadev->rx_open)  
-       {  
+
+       iadev->rx_open = kzalloc(4 * iadev->num_vc, GFP_KERNEL);
+       if (!iadev->rx_open) {
                printk(KERN_ERR DEV_LABEL "itf %d couldn't get free page\n",
                dev->number);  
                goto err_free_dle;
        }  
-       memset(iadev->rx_open, 0, 4*iadev->num_vc);  
+
         iadev->rxing = 1;
         iadev->rx_pkt_cnt = 0;
        /* Mode Register */  
@@ -1718,7 +1712,7 @@ static void tx_dle_intr(struct atm_dev *dev)
                IA_SKB_STATE(skb) |= IA_DLED;
                skb_queue_tail(&iavcc->txing_skb, skb);
             }
-            IF_EVENT(printk("tx_dle_intr: enque skb = 0x%x \n", (u32)skb);)
+            IF_EVENT(printk("tx_dle_intr: enque skb = 0x%p \n", skb);)
             if (++dle == iadev->tx_dle_q.end)
                  dle = iadev->tx_dle_q.start;
         }
@@ -1911,7 +1905,7 @@ static int tx_init(struct atm_dev *dev)
        iadev->tx_dle_q.start = (struct dle*)dle_addr;  
        iadev->tx_dle_q.read = iadev->tx_dle_q.start;  
        iadev->tx_dle_q.write = iadev->tx_dle_q.start;  
-       iadev->tx_dle_q.end = (struct dle*)((u32)dle_addr+sizeof(struct dle)*DLE_ENTRIES);  
+       iadev->tx_dle_q.end = (struct dle*)((unsigned long)dle_addr+sizeof(struct dle)*DLE_ENTRIES);
 
        /* write the upper 20 bits of the start address to tx list address register */  
        writel(iadev->tx_dle_dma & 0xfffff000,
@@ -2049,8 +2043,8 @@ static int tx_init(struct atm_dev *dev)
         writew(tmp16, iadev->seg_reg+CBR_TAB_END+1); // CBR_PTR;
         tmp16 = (CBR_SCHED_TABLE*iadev->memSize + iadev->num_vc*6 - 2) >> 1;
         writew(tmp16, iadev->seg_reg+CBR_TAB_END);
-        IF_INIT(printk("iadev->seg_reg = 0x%x CBR_PTR_BASE = 0x%x\n",
-               (u32)iadev->seg_reg, readw(iadev->seg_reg+CBR_PTR_BASE));)
+        IF_INIT(printk("iadev->seg_reg = 0x%p CBR_PTR_BASE = 0x%x\n",
+               iadev->seg_reg, readw(iadev->seg_reg+CBR_PTR_BASE));)
         IF_INIT(printk("CBR_TAB_BEG = 0x%x, CBR_TAB_END = 0x%x, CBR_PTR = 0x%x\n",
           readw(iadev->seg_reg+CBR_TAB_BEG), readw(iadev->seg_reg+CBR_TAB_END),
           readw(iadev->seg_reg+CBR_TAB_END+1));)
@@ -2195,7 +2189,7 @@ err_out:
        return -ENOMEM;
 }   
    
-static irqreturn_t ia_int(int irq, void *dev_id, struct pt_regs *regs)  
+static irqreturn_t ia_int(int irq, void *dev_id)  
 {  
    struct atm_dev *dev;  
    IADEV *iadev;  
@@ -2290,7 +2284,6 @@ static int __devinit ia_init(struct atm_dev *dev)
        unsigned long real_base;
        void __iomem *base;
        unsigned short command;  
-       unsigned char revision;  
        int error, i; 
          
        /* The device has been identified and registered. Now we read   
@@ -2305,16 +2298,14 @@ static int __devinit ia_init(struct atm_dev *dev)
        real_base = pci_resource_start (iadev->pci, 0);
        iadev->irq = iadev->pci->irq;
                  
-       if ((error = pci_read_config_word(iadev->pci, PCI_COMMAND,&command))   
-                   || (error = pci_read_config_byte(iadev->pci,   
-                               PCI_REVISION_ID,&revision)))   
-       {  
+       error = pci_read_config_word(iadev->pci, PCI_COMMAND, &command);
+       if (error) {
                printk(KERN_ERR DEV_LABEL "(itf %d): init error 0x%x\n",  
                                dev->number,error);  
                return -EINVAL;  
        }  
        IF_INIT(printk(DEV_LABEL "(itf %d): rev.%d,realbase=0x%lx,irq=%d\n",  
-                       dev->number, revision, real_base, iadev->irq);)  
+                       dev->number, iadev->pci->revision, real_base, iadev->irq);)
          
        /* find mapping size of board */  
          
@@ -2353,7 +2344,7 @@ static int __devinit ia_init(struct atm_dev *dev)
                return error;  
        }  
        IF_INIT(printk(DEV_LABEL " (itf %d): rev.%d,base=%p,irq=%d\n",  
-                       dev->number, revision, base, iadev->irq);)  
+                       dev->number, iadev->pci->revision, base, iadev->irq);)
          
        /* filling the iphase dev structure */  
        iadev->mem = iadev->pci_map_size /2;  
@@ -2562,17 +2553,11 @@ static int __devinit ia_start(struct atm_dev *dev)
                error = suni_init(dev);
                if (error)
                        goto err_free_rx;
-               /* 
-                * Enable interrupt on loss of signal
-                * SUNI_RSOP_CIE - 0x10
-                * SUNI_RSOP_CIE_LOSE - 0x04
-                */
-               ia_phy_put(dev, ia_phy_get(dev, 0x10) | 0x04, 0x10);
-#ifndef MODULE
-               error = dev->phy->start(dev);
-               if (error)
-                       goto err_free_rx;
-#endif
+               if (dev->phy->start) {
+                       error = dev->phy->start(dev);
+                       if (error)
+                               goto err_free_rx;
+               }
                /* Get iadev->carrier_detect status */
                IaFrontEndIntr(iadev);
        }
@@ -2878,7 +2863,7 @@ static int ia_getsockopt(struct atm_vcc *vcc, int level, int optname,
 }  
   
 static int ia_setsockopt(struct atm_vcc *vcc, int level, int optname,   
-       void __user *optval, int optlen)  
+       void __user *optval, unsigned int optlen)  
 {  
        IF_EVENT(printk(">ia_setsockopt\n");)  
        return -EINVAL;  
@@ -2913,7 +2898,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
                  dev_kfree_skb_any(skb);
           return 0;
         }
-        if ((u32)skb->data & 3) {
+        if ((unsigned long)skb->data & 3) {
            printk("Misaligned SKB\n");
            if (vcc->pop)
                  vcc->pop(vcc, skb);
@@ -2977,8 +2962,8 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
  
        /* Put the packet in a tx buffer */   
        trailer = iadev->tx_buf[desc-1].cpcs;
-        IF_TX(printk("Sent: skb = 0x%x skb->data: 0x%x len: %d, desc: %d\n",
-                  (u32)skb, (u32)skb->data, skb->len, desc);)
+        IF_TX(printk("Sent: skb = 0x%p skb->data: 0x%p len: %d, desc: %d\n",
+                  skb, skb->data, skb->len, desc);)
        trailer->control = 0; 
         /*big endian*/ 
        trailer->length = ((skb->len & 0xff) << 8) | ((skb->len & 0xff00) >> 8);
@@ -3009,7 +2994,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
                skb->len, PCI_DMA_TODEVICE);
        wr_ptr->local_pkt_addr = (buf_desc_ptr->buf_start_hi << 16) | 
                                                   buf_desc_ptr->buf_start_lo;  
-       /* wr_ptr->bytes = swap(total_len);     didn't seem to affect ?? */  
+       /* wr_ptr->bytes = swap_byte_order(total_len); didn't seem to affect?? */
        wr_ptr->bytes = skb->len;  
 
         /* hw bug - DLEs of 0x2d, 0x2e, 0x2f cause DMA lockup */
@@ -3174,12 +3159,12 @@ static int __devinit ia_init_one(struct pci_dev *pdev,
         unsigned long flags;
        int ret;
 
-       iadev = kmalloc(sizeof(*iadev), GFP_KERNEL); 
+       iadev = kzalloc(sizeof(*iadev), GFP_KERNEL);
        if (!iadev) {
                ret = -ENOMEM;
                goto err_out;
        }
-       memset(iadev, 0, sizeof(*iadev));
+
        iadev->pci = pdev;
 
        IF_INIT(printk("ia detected at bus:%d dev: %d function:%d\n",
@@ -3195,9 +3180,11 @@ static int __devinit ia_init_one(struct pci_dev *pdev,
        }
        dev->dev_data = iadev;
        IF_INIT(printk(DEV_LABEL "registered at (itf :%d)\n", dev->number);)
-       IF_INIT(printk("dev_id = 0x%x iadev->LineRate = %d \n", (u32)dev,
+       IF_INIT(printk("dev_id = 0x%p iadev->LineRate = %d \n", dev,
                iadev->LineRate);)
 
+       pci_set_drvdata(pdev, dev);
+
        ia_dev[iadev_count] = iadev;
        _ia_dev[iadev_count] = dev;
        iadev_count++;
@@ -3219,8 +3206,6 @@ static int __devinit ia_init_one(struct pci_dev *pdev,
        iadev->next_board = ia_boards;  
        ia_boards = dev;  
 
-       pci_set_drvdata(pdev, dev);
-
        return 0;
 
 err_out_deregister_dev:
@@ -3238,9 +3223,14 @@ static void __devexit ia_remove_one(struct pci_dev *pdev)
        struct atm_dev *dev = pci_get_drvdata(pdev);
        IADEV *iadev = INPH_IA_DEV(dev);
 
-       ia_phy_put(dev, ia_phy_get(dev,0x10) & ~(0x4), 0x10); 
+       /* Disable phy interrupts */
+       ia_phy_put(dev, ia_phy_get(dev, SUNI_RSOP_CIE) & ~(SUNI_RSOP_CIE_LOSE),
+                                  SUNI_RSOP_CIE);
        udelay(1);
 
+       if (dev->phy && dev->phy->stop)
+               dev->phy->stop(dev);
+
        /* De-register device */  
        free_irq(iadev->irq, dev);
        iadev_count--;