Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / net / irda / ali-ircc.c
index ad4ab63..2e7882e 100644 (file)
 #include <linux/init.h>
 #include <linux/rtnetlink.h>
 #include <linux/serial_reg.h>
+#include <linux/dma-mapping.h>
 
 #include <asm/io.h>
 #include <asm/dma.h>
 #include <asm/byteorder.h>
 
 #include <linux/pm.h>
+#include <linux/pm_legacy.h>
 
 #include <net/irda/wrapper.h>
 #include <net/irda/irda.h>
@@ -259,7 +261,8 @@ static int ali_ircc_open(int i, chipio_t *info)
                
        dev = alloc_irdadev(sizeof(*self));
        if (dev == NULL) {
-               ERROR("%s(), can't allocate memory for control block!\n", __FUNCTION__);
+               IRDA_ERROR("%s(), can't allocate memory for control block!\n",
+                          __FUNCTION__);
                return -ENOMEM;
        }
 
@@ -282,7 +285,7 @@ static int ali_ircc_open(int i, chipio_t *info)
        
        /* Reserve the ioports that we need */
        if (!request_region(self->io.fir_base, self->io.fir_ext, driver_name)) {
-               WARNING("%s(), can't get iobase of 0x%03x\n", __FUNCTION__,
+               IRDA_WARNING("%s(), can't get iobase of 0x%03x\n", __FUNCTION__,
                        self->io.fir_base);
                err = -ENODEV;
                goto err_out1;
@@ -304,16 +307,18 @@ static int ali_ircc_open(int i, chipio_t *info)
        self->tx_buff.truesize = 14384;
 
        /* Allocate memory if needed */
-       self->rx_buff.head = (__u8 *) kmalloc(self->rx_buff.truesize,
-                                             GFP_KERNEL |GFP_DMA); 
+       self->rx_buff.head =
+               dma_alloc_coherent(NULL, self->rx_buff.truesize,
+                                  &self->rx_buff_dma, GFP_KERNEL);
        if (self->rx_buff.head == NULL) {
                err = -ENOMEM;
                goto err_out2;
        }
        memset(self->rx_buff.head, 0, self->rx_buff.truesize);
        
-       self->tx_buff.head = (__u8 *) kmalloc(self->tx_buff.truesize, 
-                                             GFP_KERNEL|GFP_DMA); 
+       self->tx_buff.head =
+               dma_alloc_coherent(NULL, self->tx_buff.truesize,
+                                  &self->tx_buff_dma, GFP_KERNEL);
        if (self->tx_buff.head == NULL) {
                err = -ENOMEM;
                goto err_out3;
@@ -342,14 +347,14 @@ static int ali_ircc_open(int i, chipio_t *info)
 
        err = register_netdev(dev);
        if (err) {
-               ERROR("%s(), register_netdev() failed!\n", __FUNCTION__);
+               IRDA_ERROR("%s(), register_netdev() failed!\n", __FUNCTION__);
                goto err_out4;
        }
-       MESSAGE("IrDA: Registered device %s\n", dev->name);
+       IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
 
        /* Check dongle id */
        dongle_id = ali_ircc_read_dongle_id(i, info);
-       MESSAGE("%s(), %s, Found dongle: %s\n", __FUNCTION__, driver_name, dongle_types[dongle_id]);
+       IRDA_MESSAGE("%s(), %s, Found dongle: %s\n", __FUNCTION__, driver_name, dongle_types[dongle_id]);
                
        self->io.dongle_id = dongle_id;
        
@@ -362,9 +367,11 @@ static int ali_ircc_open(int i, chipio_t *info)
        return 0;
 
  err_out4:
-       kfree(self->tx_buff.head);
+       dma_free_coherent(NULL, self->tx_buff.truesize,
+                         self->tx_buff.head, self->tx_buff_dma);
  err_out3:
-       kfree(self->rx_buff.head);
+       dma_free_coherent(NULL, self->rx_buff.truesize,
+                         self->rx_buff.head, self->rx_buff_dma);
  err_out2:
        release_region(self->io.fir_base, self->io.fir_ext);
  err_out1:
@@ -386,7 +393,7 @@ static int __exit ali_ircc_close(struct ali_ircc_cb *self)
 
        IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
 
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
         iobase = self->io.fir_base;
 
@@ -398,10 +405,12 @@ static int __exit ali_ircc_close(struct ali_ircc_cb *self)
        release_region(self->io.fir_base, self->io.fir_ext);
 
        if (self->tx_buff.head)
-               kfree(self->tx_buff.head);
+               dma_free_coherent(NULL, self->tx_buff.truesize,
+                                 self->tx_buff.head, self->tx_buff_dma);
        
        if (self->rx_buff.head)
-               kfree(self->rx_buff.head);
+               dma_free_coherent(NULL, self->rx_buff.truesize,
+                                 self->rx_buff.head, self->rx_buff_dma);
 
        dev_self[self->index] = NULL;
        free_netdev(self->netdev);
@@ -482,7 +491,7 @@ static int ali_ircc_probe_53(ali_chip_t *chip, chipio_t *info)
        info->dma = reg & 0x07;
        
        if(info->dma == 0x04)
-               WARNING("%s(), No DMA channel assigned !\n", __FUNCTION__);
+               IRDA_WARNING("%s(), No DMA channel assigned !\n", __FUNCTION__);
        else
                IRDA_DEBUG(2, "%s(), probing dma=%d\n", __FUNCTION__, info->dma);
        
@@ -539,11 +548,11 @@ static int ali_ircc_setup(chipio_t *info)
        /* Should be 0x00 in the M1535/M1535D */
        if(version != 0x00)
        {
-               ERROR("%s, Wrong chip version %02x\n", driver_name, version);
+               IRDA_ERROR("%s, Wrong chip version %02x\n", driver_name, version);
                return -1;
        }
        
-       // MESSAGE("%s, Found chip at base=0x%03x\n", driver_name, info->cfg_base);
+       // IRDA_MESSAGE("%s, Found chip at base=0x%03x\n", driver_name, info->cfg_base);
        
        /* Set FIR FIFO Threshold Register */
        switch_bank(iobase, BANK1);
@@ -574,7 +583,7 @@ static int ali_ircc_setup(chipio_t *info)
        /* Switch to SIR space */
        FIR2SIR(iobase);
        
-       MESSAGE("%s, driver loaded (Benjamin Kong)\n", driver_name);
+       IRDA_MESSAGE("%s, driver loaded (Benjamin Kong)\n", driver_name);
        
        /* Enable receive interrupts */ 
        // outb(UART_IER_RDI, iobase+UART_IER); //benjamin 2000/11/23 01:25PM
@@ -638,7 +647,7 @@ static irqreturn_t ali_ircc_interrupt(int irq, void *dev_id,
        IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
                
        if (!dev) {
-               WARNING("%s: irq %d for unknown device.\n", driver_name, irq);
+               IRDA_WARNING("%s: irq %d for unknown device.\n", driver_name, irq);
                return IRQ_NONE;
        }       
        
@@ -844,7 +853,7 @@ static void ali_ircc_sir_receive(struct ali_ircc_cb *self)
        int iobase;
        
        IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__);
-       ASSERT(self != NULL, return;);
+       IRDA_ASSERT(self != NULL, return;);
 
        iobase = self->io.sir_base;
 
@@ -878,7 +887,7 @@ static void ali_ircc_sir_write_wakeup(struct ali_ircc_cb *self)
        int actual = 0;
        int iobase;     
 
-       ASSERT(self != NULL, return;);
+       IRDA_ASSERT(self != NULL, return;);
 
        IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
        
@@ -987,7 +996,7 @@ static void ali_ircc_fir_change_speed(struct ali_ircc_cb *priv, __u32 baud)
 
        IRDA_DEBUG(1, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
                
-       ASSERT(self != NULL, return;);
+       IRDA_ASSERT(self != NULL, return;);
 
        dev = self->netdev;
        iobase = self->io.fir_base;
@@ -1028,7 +1037,7 @@ static void ali_ircc_sir_change_speed(struct ali_ircc_cb *priv, __u32 speed)
        
        IRDA_DEBUG(1, "%s(), Setting speed to: %d\n", __FUNCTION__ , speed);
 
-       ASSERT(self != NULL, return;);
+       IRDA_ASSERT(self != NULL, return;);
 
        iobase = self->io.sir_base;
        
@@ -1308,19 +1317,19 @@ static int ali_ircc_net_open(struct net_device *dev)
                
        IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
        
-       ASSERT(dev != NULL, return -1;);
+       IRDA_ASSERT(dev != NULL, return -1;);
        
        self = (struct ali_ircc_cb *) dev->priv;
        
-       ASSERT(self != NULL, return 0;);
+       IRDA_ASSERT(self != NULL, return 0;);
        
        iobase = self->io.fir_base;
        
        /* Request IRQ and install Interrupt Handler */
        if (request_irq(self->io.irq, ali_ircc_interrupt, 0, dev->name, dev)) 
        {
-               WARNING("%s, unable to allocate irq=%d\n", driver_name, 
-                       self->io.irq);
+               IRDA_WARNING("%s, unable to allocate irq=%d\n", driver_name,
+                            self->io.irq);
                return -EAGAIN;
        }
        
@@ -1329,8 +1338,8 @@ static int ali_ircc_net_open(struct net_device *dev)
         * failure.
         */
        if (request_dma(self->io.dma, dev->name)) {
-               WARNING("%s, unable to allocate dma=%d\n", driver_name, 
-                       self->io.dma);
+               IRDA_WARNING("%s, unable to allocate dma=%d\n", driver_name,
+                            self->io.dma);
                free_irq(self->io.irq, self);
                return -EAGAIN;
        }
@@ -1369,10 +1378,10 @@ static int ali_ircc_net_close(struct net_device *dev)
                        
        IRDA_DEBUG(4, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
                
-       ASSERT(dev != NULL, return -1;);
+       IRDA_ASSERT(dev != NULL, return -1;);
 
        self = (struct ali_ircc_cb *) dev->priv;
-       ASSERT(self != NULL, return 0;);
+       IRDA_ASSERT(self != NULL, return 0;);
 
        /* Stop device */
        netif_stop_queue(dev);
@@ -1572,7 +1581,8 @@ static void ali_ircc_dma_xmit(struct ali_ircc_cb *self)
        self->io.direction = IO_XMIT;
        
        irda_setup_dma(self->io.dma, 
-                      self->tx_fifo.queue[self->tx_fifo.ptr].start, 
+                      ((u8 *)self->tx_fifo.queue[self->tx_fifo.ptr].start -
+                       self->tx_buff.head) + self->tx_buff_dma,
                       self->tx_fifo.queue[self->tx_fifo.ptr].len, 
                       DMA_TX_MODE);
                
@@ -1635,7 +1645,7 @@ static int  ali_ircc_dma_xmit_complete(struct ali_ircc_cb *self)
        if((inb(iobase+FIR_LSR) & LSR_FRAME_ABORT) == LSR_FRAME_ABORT)
        
        {
-               ERROR("%s(), ********* LSR_FRAME_ABORT *********\n", __FUNCTION__);     
+               IRDA_ERROR("%s(), ********* LSR_FRAME_ABORT *********\n", __FUNCTION__);        
                self->stats.tx_errors++;
                self->stats.tx_fifo_errors++;           
        }
@@ -1724,8 +1734,8 @@ static int ali_ircc_dma_receive(struct ali_ircc_cb *self)
        self->st_fifo.len = self->st_fifo.pending_bytes = 0;
        self->st_fifo.tail = self->st_fifo.head = 0;
                
-       irda_setup_dma(self->io.dma, self->rx_buff.data, 
-                      self->rx_buff.truesize, DMA_RX_MODE);    
+       irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
+                      DMA_RX_MODE);
         
        /* Set Receive Mode,Brick Wall */
        //switch_bank(iobase, BANK0);
@@ -1882,8 +1892,9 @@ static int  ali_ircc_dma_receive_complete(struct ali_ircc_cb *self)
                        skb = dev_alloc_skb(len+1);
                        if (skb == NULL)  
                        {
-                               WARNING("%s(), memory squeeze, "
-                                       "dropping frame.\n", __FUNCTION__);
+                               IRDA_WARNING("%s(), memory squeeze, "
+                                            "dropping frame.\n",
+                                            __FUNCTION__);
                                self->stats.rx_dropped++;
 
                                return FALSE;
@@ -1932,10 +1943,10 @@ static int ali_ircc_sir_hard_xmit(struct sk_buff *skb, struct net_device *dev)
        
        IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
        
-       ASSERT(dev != NULL, return 0;);
+       IRDA_ASSERT(dev != NULL, return 0;);
        
        self = (struct ali_ircc_cb *) dev->priv;
-       ASSERT(self != NULL, return 0;);
+       IRDA_ASSERT(self != NULL, return 0;);
 
        iobase = self->io.sir_base;
 
@@ -2000,11 +2011,11 @@ static int ali_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
        
        IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
        
-       ASSERT(dev != NULL, return -1;);
+       IRDA_ASSERT(dev != NULL, return -1;);
 
        self = dev->priv;
 
-       ASSERT(self != NULL, return -1;);
+       IRDA_ASSERT(self != NULL, return -1;);
 
        IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__ , dev->name, cmd);
        
@@ -2057,7 +2068,7 @@ static int ali_ircc_is_receiving(struct ali_ircc_cb *self)
        
        IRDA_DEBUG(2, "%s(), ---------------- Start -----------------\n", __FUNCTION__ );
        
-       ASSERT(self != NULL, return FALSE;);
+       IRDA_ASSERT(self != NULL, return FALSE;);
 
        spin_lock_irqsave(&self->lock, flags);
 
@@ -2101,7 +2112,7 @@ static void ali_ircc_suspend(struct ali_ircc_cb *self)
 {
        IRDA_DEBUG(2, "%s(), ---------------- Start ----------------\n", __FUNCTION__ );
        
-       MESSAGE("%s, Suspending\n", driver_name);
+       IRDA_MESSAGE("%s, Suspending\n", driver_name);
 
        if (self->io.suspended)
                return;
@@ -2122,7 +2133,7 @@ static void ali_ircc_wakeup(struct ali_ircc_cb *self)
        
        ali_ircc_net_open(self->netdev);
        
-       MESSAGE("%s, Waking up\n", driver_name);
+       IRDA_MESSAGE("%s, Waking up\n", driver_name);
 
        self->io.suspended = 0;
        
@@ -2256,11 +2267,11 @@ MODULE_DESCRIPTION("ALi FIR Controller Driver");
 MODULE_LICENSE("GPL");
 
 
-MODULE_PARM(io,  "1-4i");
+module_param_array(io, int, NULL, 0);
 MODULE_PARM_DESC(io, "Base I/O addresses");
-MODULE_PARM(irq, "1-4i");
+module_param_array(irq, int, NULL, 0);
 MODULE_PARM_DESC(irq, "IRQ lines");
-MODULE_PARM(dma, "1-4i");
+module_param_array(dma, int, NULL, 0);
 MODULE_PARM_DESC(dma, "DMA channels");
 
 module_init(ali_ircc_init);