arm: tegra: dc: corrct order to enable/disable dc irq
[linux-2.6.git] / drivers / firewire / core-iso.c
index 28076c8..57c3973 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/firewire-constants.h>
 #include <linux/kernel.h>
 #include <linux/mm.h>
+#include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/vmalloc.h>
 
@@ -71,7 +72,7 @@ int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
        for (j = 0; j < i; j++) {
                address = page_private(buffer->pages[j]);
                dma_unmap_page(card->device, address,
-                              PAGE_SIZE, DMA_TO_DEVICE);
+                              PAGE_SIZE, direction);
                __free_page(buffer->pages[j]);
        }
        kfree(buffer->pages);
@@ -80,6 +81,7 @@ int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
 
        return -ENOMEM;
 }
+EXPORT_SYMBOL(fw_iso_buffer_init);
 
 int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma)
 {
@@ -107,13 +109,31 @@ void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer,
        for (i = 0; i < buffer->page_count; i++) {
                address = page_private(buffer->pages[i]);
                dma_unmap_page(card->device, address,
-                              PAGE_SIZE, DMA_TO_DEVICE);
+                              PAGE_SIZE, buffer->direction);
                __free_page(buffer->pages[i]);
        }
 
        kfree(buffer->pages);
        buffer->pages = NULL;
 }
+EXPORT_SYMBOL(fw_iso_buffer_destroy);
+
+/* Convert DMA address to offset into virtually contiguous buffer. */
+size_t fw_iso_buffer_lookup(struct fw_iso_buffer *buffer, dma_addr_t completed)
+{
+       int i;
+       dma_addr_t address;
+       ssize_t offset;
+
+       for (i = 0; i < buffer->page_count; i++) {
+               address = page_private(buffer->pages[i]);
+               offset = (ssize_t)completed - (ssize_t)address;
+               if (offset > 0 && offset <= PAGE_SIZE)
+                       return (i << PAGE_SHIFT) + offset;
+       }
+
+       return 0;
+}
 
 struct fw_iso_context *fw_iso_context_create(struct fw_card *card,
                int type, int channel, int speed, size_t header_size,
@@ -131,39 +151,51 @@ struct fw_iso_context *fw_iso_context_create(struct fw_card *card,
        ctx->channel = channel;
        ctx->speed = speed;
        ctx->header_size = header_size;
-       ctx->callback = callback;
+       ctx->callback.sc = callback;
        ctx->callback_data = callback_data;
 
        return ctx;
 }
+EXPORT_SYMBOL(fw_iso_context_create);
 
 void fw_iso_context_destroy(struct fw_iso_context *ctx)
 {
-       struct fw_card *card = ctx->card;
-
-       card->driver->free_iso_context(ctx);
+       ctx->card->driver->free_iso_context(ctx);
 }
+EXPORT_SYMBOL(fw_iso_context_destroy);
 
 int fw_iso_context_start(struct fw_iso_context *ctx,
                         int cycle, int sync, int tags)
 {
        return ctx->card->driver->start_iso(ctx, cycle, sync, tags);
 }
+EXPORT_SYMBOL(fw_iso_context_start);
+
+int fw_iso_context_set_channels(struct fw_iso_context *ctx, u64 *channels)
+{
+       return ctx->card->driver->set_iso_channels(ctx, channels);
+}
 
 int fw_iso_context_queue(struct fw_iso_context *ctx,
                         struct fw_iso_packet *packet,
                         struct fw_iso_buffer *buffer,
                         unsigned long payload)
 {
-       struct fw_card *card = ctx->card;
+       return ctx->card->driver->queue_iso(ctx, packet, buffer, payload);
+}
+EXPORT_SYMBOL(fw_iso_context_queue);
 
-       return card->driver->queue_iso(ctx, packet, buffer, payload);
+void fw_iso_context_queue_flush(struct fw_iso_context *ctx)
+{
+       ctx->card->driver->flush_queue_iso(ctx);
 }
+EXPORT_SYMBOL(fw_iso_context_queue_flush);
 
 int fw_iso_context_stop(struct fw_iso_context *ctx)
 {
        return ctx->card->driver->stop_iso(ctx);
 }
+EXPORT_SYMBOL(fw_iso_context_stop);
 
 /*
  * Isochronous bus resource management (channels, bandwidth), client side
@@ -172,8 +204,8 @@ int fw_iso_context_stop(struct fw_iso_context *ctx)
 static int manage_bandwidth(struct fw_card *card, int irm_id, int generation,
                            int bandwidth, bool allocate)
 {
-       __be32 data[2];
        int try, new, old = allocate ? BANDWIDTH_AVAILABLE_INITIAL : 0;
+       __be32 data[2];
 
        /*
         * On a 1394a IRM with low contention, try < 1 is enough.
@@ -183,14 +215,14 @@ static int manage_bandwidth(struct fw_card *card, int irm_id, int generation,
        for (try = 0; try < 5; try++) {
                new = allocate ? old - bandwidth : old + bandwidth;
                if (new < 0 || new > BANDWIDTH_AVAILABLE_INITIAL)
-                       break;
+                       return -EBUSY;
 
                data[0] = cpu_to_be32(old);
                data[1] = cpu_to_be32(new);
                switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP,
                                irm_id, generation, SCODE_100,
                                CSR_REGISTER_BASE + CSR_BANDWIDTH_AVAILABLE,
-                               data, sizeof(data))) {
+                               data, 8)) {
                case RCODE_GENERATION:
                        /* A generation change frees all bandwidth. */
                        return allocate ? -EAGAIN : bandwidth;
@@ -208,48 +240,55 @@ static int manage_bandwidth(struct fw_card *card, int irm_id, int generation,
 }
 
 static int manage_channel(struct fw_card *card, int irm_id, int generation,
-                         u32 channels_mask, u64 offset, bool allocate)
+               u32 channels_mask, u64 offset, bool allocate)
 {
-       __be32 data[2], c, all, old;
-       int i, retry = 5;
+       __be32 bit, all, old;
+       __be32 data[2];
+       int channel, ret = -EIO, retry = 5;
 
        old = all = allocate ? cpu_to_be32(~0) : 0;
 
-       for (i = 0; i < 32; i++) {
-               if (!(channels_mask & 1 << i))
+       for (channel = 0; channel < 32; channel++) {
+               if (!(channels_mask & 1 << channel))
                        continue;
 
-               c = cpu_to_be32(1 << (31 - i));
-               if ((old & c) != (all & c))
+               ret = -EBUSY;
+
+               bit = cpu_to_be32(1 << (31 - channel));
+               if ((old & bit) != (all & bit))
                        continue;
 
                data[0] = old;
-               data[1] = old ^ c;
+               data[1] = old ^ bit;
                switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP,
                                           irm_id, generation, SCODE_100,
-                                          offset, data, sizeof(data))) {
+                                          offset, data, 8)) {
                case RCODE_GENERATION:
                        /* A generation change frees all channels. */
-                       return allocate ? -EAGAIN : i;
+                       return allocate ? -EAGAIN : channel;
 
                case RCODE_COMPLETE:
                        if (data[0] == old)
-                               return i;
+                               return channel;
 
                        old = data[0];
 
                        /* Is the IRM 1394a-2000 compliant? */
-                       if ((data[0] & c) == (data[1] & c))
+                       if ((data[0] & bit) == (data[1] & bit))
                                continue;
 
                        /* 1394-1995 IRM, fall through to retry. */
                default:
-                       if (retry--)
-                               i--;
+                       if (retry) {
+                               retry--;
+                               channel--;
+                       } else {
+                               ret = -EIO;
+                       }
                }
        }
 
-       return -EIO;
+       return ret;
 }
 
 static void deallocate_channel(struct fw_card *card, int irm_id,
@@ -266,7 +305,7 @@ static void deallocate_channel(struct fw_card *card, int irm_id,
 }
 
 /**
- * fw_iso_resource_manage - Allocate or deallocate a channel and/or bandwidth
+ * fw_iso_resource_manage() - Allocate or deallocate a channel and/or bandwidth
  *
  * In parameters: card, generation, channels_mask, bandwidth, allocate
  * Out parameters: channel, bandwidth
@@ -303,10 +342,12 @@ void fw_iso_resource_manage(struct fw_card *card, int generation,
 
        if (channels_hi)
                c = manage_channel(card, irm_id, generation, channels_hi,
-                   CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI, allocate);
+                               CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI,
+                               allocate);
        if (channels_lo && c < 0) {
                c = manage_channel(card, irm_id, generation, channels_lo,
-                   CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO, allocate);
+                               CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO,
+                               allocate);
                if (c >= 0)
                        c += 32;
        }
@@ -322,8 +363,10 @@ void fw_iso_resource_manage(struct fw_card *card, int generation,
        if (ret < 0)
                *bandwidth = 0;
 
-       if (allocate && ret < 0 && c >= 0) {
-               deallocate_channel(card, irm_id, generation, c);
+       if (allocate && ret < 0) {
+               if (c >= 0)
+                       deallocate_channel(card, irm_id, generation, c);
                *channel = ret;
        }
 }
+EXPORT_SYMBOL(fw_iso_resource_manage);