ipwireless: Remove pt_regs from interrupt handler
[pandora-kernel.git] / drivers / char / pcmcia / ipwireless / hardware.c
index ba6340a..0ccbbc1 100644 (file)
@@ -227,15 +227,12 @@ struct MEMINFREG {
        unsigned short memreg_tx_new;   /* TX2 (new) Register (R/W) */
 };
 
-#define IODMADPR 0x00          /* DMA Data Port Register (R/W) */
-
 #define CARD_PRESENT_VALUE (0xBEEFCAFEUL)
 
 #define MEMTX_TX                       0x0001
 #define MEMRX_RX                       0x0001
 #define MEMRX_RX_DONE                  0x0001
 #define MEMRX_PCINTACKK                0x0001
-#define MEMRX_MEMSPURIOUSINT           0x0001
 
 #define NL_NUM_OF_PRIORITIES       3
 #define NL_NUM_OF_PROTOCOLS        3
@@ -245,7 +242,7 @@ struct ipw_hardware {
        unsigned int base_port;
        short hw_version;
        unsigned short ll_mtu;
-       spinlock_t spinlock;
+       spinlock_t lock;
 
        int initializing;
        int init_loops;
@@ -389,7 +386,7 @@ static void dump_data_bytes(const char *type, const unsigned char *data,
 static int do_send_fragment(struct ipw_hardware *hw, const unsigned char *data,
                            unsigned length)
 {
-       int i;
+       unsigned i;
        unsigned long flags;
 
        start_timing();
@@ -403,7 +400,7 @@ static int do_send_fragment(struct ipw_hardware *hw, const unsigned char *data,
        if (ipwireless_debug)
                dump_data_bytes("send", data, length);
 
-       spin_lock_irqsave(&hw->spinlock, flags);
+       spin_lock_irqsave(&hw->lock, flags);
 
        hw->tx_ready = 0;
 
@@ -414,7 +411,7 @@ static int do_send_fragment(struct ipw_hardware *hw, const unsigned char *data,
                        unsigned short d = data[i];
                        __le16 raw_data;
 
-                       if (likely(i + 1 < length))
+                       if (i + 1 < length)
                                d |= data[i + 1] << 8;
                        raw_data = cpu_to_le16(d);
                        outw(raw_data, hw->base_port + IODWR);
@@ -422,25 +419,25 @@ static int do_send_fragment(struct ipw_hardware *hw, const unsigned char *data,
 
                outw(DCR_TXDONE, hw->base_port + IODCR);
        } else if (hw->hw_version == HW_VERSION_2) {
-               outw((unsigned short) length, hw->base_port + IODMADPR);
+               outw((unsigned short) length, hw->base_port);
 
                for (i = 0; i < length; i += 2) {
                        unsigned short d = data[i];
                        __le16 raw_data;
 
-                       if ((i + 1 < length))
+                       if (i + 1 < length)
                                d |= data[i + 1] << 8;
                        raw_data = cpu_to_le16(d);
-                       outw(raw_data, hw->base_port + IODMADPR);
+                       outw(raw_data, hw->base_port);
                }
                while ((i & 3) != 2) {
-                       outw((unsigned short) 0xDEAD, hw->base_port + IODMADPR);
+                       outw((unsigned short) 0xDEAD, hw->base_port);
                        i += 2;
                }
                writew(MEMRX_RX, &hw->memory_info_regs->memreg_rx);
        }
 
-       spin_unlock_irqrestore(&hw->spinlock, flags);
+       spin_unlock_irqrestore(&hw->lock, flags);
 
        end_write_timing(length);
 
@@ -493,10 +490,10 @@ static int do_send_packet(struct ipw_hardware *hw, struct ipw_tx_packet *packet)
                 */
                unsigned long flags;
 
-               spin_lock_irqsave(&hw->spinlock, flags);
+               spin_lock_irqsave(&hw->lock, flags);
                list_add(&packet->queue, &hw->tx_queue[0]);
                hw->tx_queued++;
-               spin_unlock_irqrestore(&hw->spinlock, flags);
+               spin_unlock_irqrestore(&hw->lock, flags);
        } else {
                if (packet->packet_callback)
                        packet->packet_callback(packet->callback_data,
@@ -511,7 +508,7 @@ static void ipw_setup_hardware(struct ipw_hardware *hw)
 {
        unsigned long flags;
 
-       spin_lock_irqsave(&hw->spinlock, flags);
+       spin_lock_irqsave(&hw->lock, flags);
        if (hw->hw_version == HW_VERSION_1) {
                /* Reset RX FIFO */
                outw(DCR_RXRESET, hw->base_port + IODCR);
@@ -530,7 +527,7 @@ static void ipw_setup_hardware(struct ipw_hardware *hw)
                csr |= 1;
                writew(csr, &hw->memregs_CCR->reg_config_and_status);
        }
-       spin_unlock_irqrestore(&hw->spinlock, flags);
+       spin_unlock_irqrestore(&hw->lock, flags);
 }
 
 /*
@@ -549,28 +546,22 @@ static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
        if (!packet) {
                unsigned long flags;
 
-               /*
-                * If this is the first fragment, then we will need to fetch a
-                * packet to put it in.
-                */
-               spin_lock_irqsave(&hw->spinlock, flags);
-               /* If we have one in our pool, then pull it out. */
+               spin_lock_irqsave(&hw->lock, flags);
                if (!list_empty(&hw->rx_pool)) {
                        packet = list_first_entry(&hw->rx_pool,
                                        struct ipw_rx_packet, queue);
                        list_del(&packet->queue);
                        hw->rx_pool_size--;
-                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       spin_unlock_irqrestore(&hw->lock, flags);
                } else {
-                       /* Otherwise allocate a new one. */
                        static int min_capacity = 256;
                        int new_capacity;
 
-                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       spin_unlock_irqrestore(&hw->lock, flags);
                        new_capacity =
-                           minimum_free_space > min_capacity
-                           ? minimum_free_space
-                           : min_capacity;
+                               (minimum_free_space > min_capacity
+                                ? minimum_free_space
+                                : min_capacity);
                        packet = kmalloc(sizeof(struct ipw_rx_packet)
                                        + new_capacity, GFP_ATOMIC);
                        if (!packet)
@@ -580,18 +571,16 @@ static struct ipw_rx_packet *pool_allocate(struct ipw_hardware *hw,
                packet->length = 0;
        }
 
-       /*
-        * If this packet does not have sufficient capacity for the data we
-        * want to add, then make it bigger.
-        */
        if (packet->length + minimum_free_space > packet->capacity) {
                struct ipw_rx_packet *old_packet = packet;
 
                packet = kmalloc(sizeof(struct ipw_rx_packet) +
                                old_packet->length + minimum_free_space,
                                GFP_ATOMIC);
-               if (!packet)
+               if (!packet) {
+                       kfree(old_packet);
                        return NULL;
+               }
                memcpy(packet, old_packet,
                                sizeof(struct ipw_rx_packet)
                                        + old_packet->length);
@@ -656,9 +645,9 @@ static void queue_received_packet(struct ipw_hardware *hw,
                        packet = *assem;
                        *assem = NULL;
                        /* Count queued DATA bytes only */
-                       spin_lock_irqsave(&hw->spinlock, flags);
+                       spin_lock_irqsave(&hw->lock, flags);
                        hw->rx_bytes_queued += packet->length;
-                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       spin_unlock_irqrestore(&hw->lock, flags);
                }
        } else {
                /* If it's a CTRL packet, don't assemble, just queue it. */
@@ -680,13 +669,13 @@ static void queue_received_packet(struct ipw_hardware *hw,
         * network layer.
         */
        if (packet) {
-               spin_lock_irqsave(&hw->spinlock, flags);
+               spin_lock_irqsave(&hw->lock, flags);
                list_add_tail(&packet->queue, &hw->rx_queue);
                /* Block reception of incoming packets if queue is full. */
                hw->blocking_rx =
-                       hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE;
+                       (hw->rx_bytes_queued >= IPWIRELESS_RX_QUEUE_SIZE);
 
-               spin_unlock_irqrestore(&hw->spinlock, flags);
+               spin_unlock_irqrestore(&hw->lock, flags);
                schedule_work(&hw->work_rx);
        }
 }
@@ -700,7 +689,7 @@ static void ipw_receive_data_work(struct work_struct *work_rx)
            container_of(work_rx, struct ipw_hardware, work_rx);
        unsigned long flags;
 
-       spin_lock_irqsave(&hw->spinlock, flags);
+       spin_lock_irqsave(&hw->lock, flags);
        while (!list_empty(&hw->rx_queue)) {
                struct ipw_rx_packet *packet =
                        list_first_entry(&hw->rx_queue,
@@ -718,7 +707,7 @@ static void ipw_receive_data_work(struct work_struct *work_rx)
                if (packet->protocol == TL_PROTOCOLID_COM_DATA) {
                        if (hw->network != NULL) {
                                /* If the network hasn't been disconnected. */
-                               spin_unlock_irqrestore(&hw->spinlock, flags);
+                               spin_unlock_irqrestore(&hw->lock, flags);
                                /*
                                 * This must run unlocked due to tty processing
                                 * and mutex locking
@@ -729,7 +718,7 @@ static void ipw_receive_data_work(struct work_struct *work_rx)
                                                (unsigned char *)packet
                                                + sizeof(struct ipw_rx_packet),
                                                packet->length);
-                               spin_lock_irqsave(&hw->spinlock, flags);
+                               spin_lock_irqsave(&hw->lock, flags);
                        }
                        /* Count queued DATA bytes only */
                        hw->rx_bytes_queued -= packet->length;
@@ -753,7 +742,7 @@ static void ipw_receive_data_work(struct work_struct *work_rx)
                if (hw->shutting_down)
                        break;
        }
-       spin_unlock_irqrestore(&hw->spinlock, flags);
+       spin_unlock_irqrestore(&hw->lock, flags);
 }
 
 static void handle_received_CTRL_packet(struct ipw_hardware *hw,
@@ -848,7 +837,7 @@ static void acknowledge_data_read(struct ipw_hardware *hw)
 static void do_receive_packet(struct ipw_hardware *hw)
 {
        unsigned len;
-       unsigned int i;
+       unsigned i;
        unsigned char pkt[LL_MTU_MAX];
 
        start_timing();
@@ -871,7 +860,7 @@ static void do_receive_packet(struct ipw_hardware *hw)
                        pkt[i + 1] = (unsigned char) (data >> 8);
                }
        } else {
-               len = inw(hw->base_port + IODMADPR);
+               len = inw(hw->base_port);
                if (len > hw->ll_mtu) {
                        printk(KERN_INFO IPWIRELESS_PCCARD_NAME
                               ": received a packet of %u bytes - "
@@ -882,7 +871,7 @@ static void do_receive_packet(struct ipw_hardware *hw)
                }
 
                for (i = 0; i < len; i += 2) {
-                       __le16 raw_data = inw(hw->base_port + IODMADPR);
+                       __le16 raw_data = inw(hw->base_port);
                        unsigned short data = le16_to_cpu(raw_data);
 
                        pkt[i] = (unsigned char) data;
@@ -890,7 +879,7 @@ static void do_receive_packet(struct ipw_hardware *hw)
                }
 
                while ((i & 3) != 2) {
-                       inw(hw->base_port + IODMADPR);
+                       inw(hw->base_port);
                        i += 2;
                }
        }
@@ -914,8 +903,7 @@ static int get_current_packet_priority(struct ipw_hardware *hw)
         * until setup is complete.
         */
        return (hw->to_setup || hw->initializing
-                       ? PRIO_SETUP + 1 :
-                       NL_NUM_OF_PRIORITIES);
+                       ? PRIO_SETUP + 1 : NL_NUM_OF_PRIORITIES);
 }
 
 /*
@@ -926,17 +914,17 @@ static int get_packets_from_hw(struct ipw_hardware *hw)
        int received = 0;
        unsigned long flags;
 
-       spin_lock_irqsave(&hw->spinlock, flags);
+       spin_lock_irqsave(&hw->lock, flags);
        while (hw->rx_ready && !hw->blocking_rx) {
                received = 1;
                hw->rx_ready--;
-               spin_unlock_irqrestore(&hw->spinlock, flags);
+               spin_unlock_irqrestore(&hw->lock, flags);
 
                do_receive_packet(hw);
 
-               spin_lock_irqsave(&hw->spinlock, flags);
+               spin_lock_irqsave(&hw->lock, flags);
        }
-       spin_unlock_irqrestore(&hw->spinlock, flags);
+       spin_unlock_irqrestore(&hw->lock, flags);
 
        return received;
 }
@@ -952,7 +940,7 @@ static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
        int more_to_send = 0;
        unsigned long flags;
 
-       spin_lock_irqsave(&hw->spinlock, flags);
+       spin_lock_irqsave(&hw->lock, flags);
        if (hw->tx_queued && hw->tx_ready) {
                int priority;
                struct ipw_tx_packet *packet = NULL;
@@ -973,17 +961,17 @@ static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
                }
                if (!packet) {
                        hw->tx_queued = 0;
-                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       spin_unlock_irqrestore(&hw->lock, flags);
                        return 0;
                }
 
-               spin_unlock_irqrestore(&hw->spinlock, flags);
+               spin_unlock_irqrestore(&hw->lock, flags);
 
                /* Send */
                do_send_packet(hw, packet);
 
                /* Check if more to send */
-               spin_lock_irqsave(&hw->spinlock, flags);
+               spin_lock_irqsave(&hw->lock, flags);
                for (priority = 0; priority < priority_limit; priority++)
                        if (!list_empty(&hw->tx_queue[priority])) {
                                more_to_send = 1;
@@ -993,7 +981,7 @@ static int send_pending_packet(struct ipw_hardware *hw, int priority_limit)
                if (!more_to_send)
                        hw->tx_queued = 0;
        }
-       spin_unlock_irqrestore(&hw->spinlock, flags);
+       spin_unlock_irqrestore(&hw->lock, flags);
 
        return more_to_send;
 }
@@ -1006,9 +994,9 @@ static void ipwireless_do_tasklet(unsigned long hw_)
        struct ipw_hardware *hw = (struct ipw_hardware *) hw_;
        unsigned long flags;
 
-       spin_lock_irqsave(&hw->spinlock, flags);
+       spin_lock_irqsave(&hw->lock, flags);
        if (hw->shutting_down) {
-               spin_unlock_irqrestore(&hw->spinlock, flags);
+               spin_unlock_irqrestore(&hw->lock, flags);
                return;
        }
 
@@ -1017,7 +1005,7 @@ static void ipwireless_do_tasklet(unsigned long hw_)
                 * Initial setup data sent to hardware
                 */
                hw->to_setup = 2;
-               spin_unlock_irqrestore(&hw->spinlock, flags);
+               spin_unlock_irqrestore(&hw->lock, flags);
 
                ipw_setup_hardware(hw);
                ipw_send_setup_packet(hw);
@@ -1028,7 +1016,7 @@ static void ipwireless_do_tasklet(unsigned long hw_)
                int priority_limit = get_current_packet_priority(hw);
                int again;
 
-               spin_unlock_irqrestore(&hw->spinlock, flags);
+               spin_unlock_irqrestore(&hw->lock, flags);
 
                do {
                        again = send_pending_packet(hw, priority_limit);
@@ -1066,16 +1054,16 @@ static irqreturn_t ipwireless_handle_v1_interrupt(int irq,
                /* Transmit complete. */
                if (irqn & IR_TXINTR) {
                        ack |= IR_TXINTR;
-                       spin_lock_irqsave(&hw->spinlock, flags);
+                       spin_lock_irqsave(&hw->lock, flags);
                        hw->tx_ready = 1;
-                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       spin_unlock_irqrestore(&hw->lock, flags);
                }
                /* Received data */
                if (irqn & IR_RXINTR) {
                        ack |= IR_RXINTR;
-                       spin_lock_irqsave(&hw->spinlock, flags);
+                       spin_lock_irqsave(&hw->lock, flags);
                        hw->rx_ready++;
-                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       spin_unlock_irqrestore(&hw->lock, flags);
                }
                if (ack != 0) {
                        outw(ack, hw->base_port + IOIR);
@@ -1126,9 +1114,8 @@ static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
                        } else {
                                return IRQ_NONE;
                        }
-               } else {
+               } else
                        return IRQ_NONE;
-               }
        }
 
        /*
@@ -1147,9 +1134,9 @@ static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
                if (hw->serial_number_detected) {
                        if (memtx_serial != hw->last_memtx_serial) {
                                hw->last_memtx_serial = memtx_serial;
-                               spin_lock_irqsave(&hw->spinlock, flags);
+                               spin_lock_irqsave(&hw->lock, flags);
                                hw->rx_ready++;
-                               spin_unlock_irqrestore(&hw->spinlock, flags);
+                               spin_unlock_irqrestore(&hw->lock, flags);
                                rx = 1;
                        } else
                                /* Ignore 'Timer Recovery' duplicates. */
@@ -1164,18 +1151,18 @@ static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
                                printk(KERN_DEBUG IPWIRELESS_PCCARD_NAME
                                        ": memreg_tx serial num detected\n");
 
-                               spin_lock_irqsave(&hw->spinlock, flags);
+                               spin_lock_irqsave(&hw->lock, flags);
                                hw->rx_ready++;
-                               spin_unlock_irqrestore(&hw->spinlock, flags);
+                               spin_unlock_irqrestore(&hw->lock, flags);
                        }
                        rx = 1;
                }
        }
        if (memrxdone & MEMRX_RX_DONE) {
                writew(0, &hw->memory_info_regs->memreg_rx_done);
-               spin_lock_irqsave(&hw->spinlock, flags);
+               spin_lock_irqsave(&hw->lock, flags);
                hw->tx_ready = 1;
-               spin_unlock_irqrestore(&hw->spinlock, flags);
+               spin_unlock_irqrestore(&hw->lock, flags);
                tx = 1;
        }
        if (tx)
@@ -1209,7 +1196,7 @@ static irqreturn_t ipwireless_handle_v2_v3_interrupt(int irq,
        return IRQ_HANDLED;
 }
 
-irqreturn_t ipwireless_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+irqreturn_t ipwireless_interrupt(int irq, void *dev_id)
 {
        struct ipw_hardware *hw = dev_id;
 
@@ -1224,9 +1211,9 @@ static void flush_packets_to_hw(struct ipw_hardware *hw)
        int priority_limit;
        unsigned long flags;
 
-       spin_lock_irqsave(&hw->spinlock, flags);
+       spin_lock_irqsave(&hw->lock, flags);
        priority_limit = get_current_packet_priority(hw);
-       spin_unlock_irqrestore(&hw->spinlock, flags);
+       spin_unlock_irqrestore(&hw->lock, flags);
 
        while (send_pending_packet(hw, priority_limit));
 }
@@ -1236,10 +1223,10 @@ static void send_packet(struct ipw_hardware *hw, int priority,
 {
        unsigned long flags;
 
-       spin_lock_irqsave(&hw->spinlock, flags);
+       spin_lock_irqsave(&hw->lock, flags);
        list_add_tail(&packet->queue, &hw->tx_queue[priority]);
        hw->tx_queued++;
-       spin_unlock_irqrestore(&hw->spinlock, flags);
+       spin_unlock_irqrestore(&hw->lock, flags);
 
        flush_packets_to_hw(hw);
 }
@@ -1295,15 +1282,14 @@ int ipwireless_send_packet(struct ipw_hardware *hw, unsigned int channel_idx,
 {
        struct ipw_tx_packet *packet;
 
-       packet = alloc_data_packet(length,
-                              (unsigned char) (channel_idx + 1),
-                              TL_PROTOCOLID_COM_DATA);
+       packet = alloc_data_packet(length, (channel_idx + 1),
+                       TL_PROTOCOLID_COM_DATA);
        if (!packet)
                return -ENOMEM;
        packet->packet_callback = callback;
        packet->callback_data = callback_data;
-       memcpy((unsigned char *) packet +
-                       sizeof(struct ipw_tx_packet), data, length);
+       memcpy((unsigned char *) packet + sizeof(struct ipw_tx_packet), data,
+                       length);
 
        send_packet(hw, PRIO_DATA, packet);
        return 0;
@@ -1319,12 +1305,11 @@ static int set_control_line(struct ipw_hardware *hw, int prio,
                protocolid = TL_PROTOCOLID_SETUP;
 
        packet = alloc_ctrl_packet(sizeof(struct ipw_control_packet),
-                       (unsigned char) (channel_idx + 1),
-                       protocolid, line);
+                       (channel_idx + 1), protocolid, line);
        if (!packet)
                return -ENOMEM;
        packet->header.length = sizeof(struct ipw_control_packet_body);
-       packet->body.value = (unsigned char) (state == 0 ? 0 : 1);
+       packet->body.value = (state == 0 ? 0 : 1);
        send_packet(hw, prio, &packet->header);
        return 0;
 }
@@ -1627,7 +1612,7 @@ struct ipw_hardware *ipwireless_hardware_create(void)
 
        INIT_LIST_HEAD(&hw->rx_queue);
        INIT_LIST_HEAD(&hw->rx_pool);
-       spin_lock_init(&hw->spinlock);
+       spin_lock_init(&hw->lock);
        tasklet_init(&hw->tasklet, ipwireless_do_tasklet, (unsigned long) hw);
        INIT_WORK(&hw->work_rx, ipw_receive_data_work);
        setup_timer(&hw->setup_timer, ipwireless_setup_timer,
@@ -1649,8 +1634,8 @@ void ipwireless_init_hardware_v1(struct ipw_hardware *hw,
                enable_irq(hw->irq);
        }
        hw->base_port = base_port;
-       hw->hw_version = is_v2_card ? HW_VERSION_2 : HW_VERSION_1;
-       hw->ll_mtu = hw->hw_version == HW_VERSION_1 ? LL_MTU_V1 : LL_MTU_V2;
+       hw->hw_version = (is_v2_card ? HW_VERSION_2 : HW_VERSION_1);
+       hw->ll_mtu = (hw->hw_version == HW_VERSION_1 ? LL_MTU_V1 : LL_MTU_V2);
        hw->memregs_CCR = (struct MEMCCR __iomem *)
                        ((unsigned short __iomem *) attr_memory + 0x200);
        hw->memory_info_regs = (struct MEMINFREG __iomem *) common_memory;
@@ -1693,10 +1678,10 @@ static void ipwireless_setup_timer(unsigned long data)
                if (is_card_present(hw)) {
                        unsigned long flags;
 
-                       spin_lock_irqsave(&hw->spinlock, flags);
+                       spin_lock_irqsave(&hw->lock, flags);
                        hw->to_setup = 1;
                        hw->tx_ready = 1;
-                       spin_unlock_irqrestore(&hw->spinlock, flags);
+                       spin_unlock_irqrestore(&hw->lock, flags);
                        tasklet_schedule(&hw->tasklet);
                }