Merge branch 'linus' into perf/urgent
[pandora-kernel.git] / drivers / firewire / ohci.c
index 2abdb32..7f03540 100644 (file)
@@ -25,7 +25,6 @@
 #include <linux/dma-mapping.h>
 #include <linux/firewire.h>
 #include <linux/firewire-constants.h>
-#include <linux/gfp.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
+#include <linux/mutex.h>
 #include <linux/pci.h>
 #include <linux/pci_ids.h>
+#include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/string.h>
+#include <linux/time.h>
 
 #include <asm/byteorder.h>
 #include <asm/page.h>
@@ -172,9 +174,9 @@ struct fw_ohci {
        int request_generation; /* for timestamping incoming requests */
        unsigned quirks;
        unsigned int pri_req_max;
-       unsigned int features;
        u32 bus_time;
        bool is_root;
+       bool csr_state_setclear_abdicate;
 
        /*
         * Spinlock for accessing fw_ohci data.  Never call out of
@@ -182,16 +184,20 @@ struct fw_ohci {
         */
        spinlock_t lock;
 
+       struct mutex phy_reg_mutex;
+
        struct ar_context ar_request_ctx;
        struct ar_context ar_response_ctx;
        struct context at_request_ctx;
        struct context at_response_ctx;
 
-       u32 it_context_mask;
+       u32 it_context_mask;     /* unoccupied IT contexts */
        struct iso_context *it_context_list;
-       u64 ir_context_channels;
-       u32 ir_context_mask;
+       u64 ir_context_channels; /* unoccupied channels */
+       u32 ir_context_mask;     /* unoccupied IR contexts */
        struct iso_context *ir_context_list;
+       u64 mc_channels; /* channels in use by the multichannel IR context */
+       bool mc_allocated;
 
        __be32    *config_rom;
        dma_addr_t config_rom_bus;
@@ -517,13 +523,10 @@ static int write_phy_reg(const struct fw_ohci *ohci, int addr, u32 val)
        return -EBUSY;
 }
 
-static int ohci_update_phy_reg(struct fw_card *card, int addr,
-                              int clear_bits, int set_bits)
+static int update_phy_reg(struct fw_ohci *ohci, int addr,
+                         int clear_bits, int set_bits)
 {
-       struct fw_ohci *ohci = fw_ohci(card);
-       int ret;
-
-       ret = read_phy_reg(ohci, addr);
+       int ret = read_phy_reg(ohci, addr);
        if (ret < 0)
                return ret;
 
@@ -541,13 +544,38 @@ static int read_paged_phy_reg(struct fw_ohci *ohci, int page, int addr)
 {
        int ret;
 
-       ret = ohci_update_phy_reg(&ohci->card, 7, PHY_PAGE_SELECT, page << 5);
+       ret = update_phy_reg(ohci, 7, PHY_PAGE_SELECT, page << 5);
        if (ret < 0)
                return ret;
 
        return read_phy_reg(ohci, addr);
 }
 
+static int ohci_read_phy_reg(struct fw_card *card, int addr)
+{
+       struct fw_ohci *ohci = fw_ohci(card);
+       int ret;
+
+       mutex_lock(&ohci->phy_reg_mutex);
+       ret = read_phy_reg(ohci, addr);
+       mutex_unlock(&ohci->phy_reg_mutex);
+
+       return ret;
+}
+
+static int ohci_update_phy_reg(struct fw_card *card, int addr,
+                              int clear_bits, int set_bits)
+{
+       struct fw_ohci *ohci = fw_ohci(card);
+       int ret;
+
+       mutex_lock(&ohci->phy_reg_mutex);
+       ret = update_phy_reg(ohci, addr, clear_bits, set_bits);
+       mutex_unlock(&ohci->phy_reg_mutex);
+
+       return ret;
+}
+
 static int ar_context_add_page(struct ar_context *ctx)
 {
        struct device *dev = ctx->ohci->card.device;
@@ -570,6 +598,7 @@ static int ar_context_add_page(struct ar_context *ctx)
        ab->descriptor.res_count      = cpu_to_le16(PAGE_SIZE - offset);
        ab->descriptor.branch_address = 0;
 
+       wmb(); /* finish init of new descriptors before branch_address update */
        ctx->last_buffer->descriptor.branch_address = cpu_to_le32(ab_bus | 1);
        ctx->last_buffer->next = ab;
        ctx->last_buffer = ab;
@@ -957,6 +986,8 @@ static void context_append(struct context *ctx,
        d_bus = desc->buffer_bus + (d - desc->buffer) * sizeof(*d);
 
        desc->used += (z + extra) * sizeof(*d);
+
+       wmb(); /* finish init of new descriptors before branch_address update */
        ctx->prev->branch_address = cpu_to_le32(d_bus | z);
        ctx->prev = find_branch_descriptor(d, z);
 
@@ -1043,6 +1074,9 @@ static int at_context_queue_packet(struct context *ctx,
                header[1] = cpu_to_le32(packet->header[0]);
                header[2] = cpu_to_le32(packet->header[1]);
                d[0].req_count = cpu_to_le16(12);
+
+               if (is_ping_packet(packet->header))
+                       d[0].control |= cpu_to_le16(DESCRIPTOR_PING);
                break;
 
        case 4:
@@ -1223,7 +1257,7 @@ static void handle_local_lock(struct fw_ohci *ohci,
                              struct fw_packet *packet, u32 csr)
 {
        struct fw_packet response;
-       int tcode, length, ext_tcode, sel;
+       int tcode, length, ext_tcode, sel, try;
        __be32 *payload, lock_old;
        u32 lock_arg, lock_data;
 
@@ -1250,21 +1284,26 @@ static void handle_local_lock(struct fw_ohci *ohci,
        reg_write(ohci, OHCI1394_CSRCompareData, lock_arg);
        reg_write(ohci, OHCI1394_CSRControl, sel);
 
-       if (reg_read(ohci, OHCI1394_CSRControl) & 0x80000000)
-               lock_old = cpu_to_be32(reg_read(ohci, OHCI1394_CSRData));
-       else
-               fw_notify("swap not done yet\n");
+       for (try = 0; try < 20; try++)
+               if (reg_read(ohci, OHCI1394_CSRControl) & 0x80000000) {
+                       lock_old = cpu_to_be32(reg_read(ohci,
+                                                       OHCI1394_CSRData));
+                       fw_fill_response(&response, packet->header,
+                                        RCODE_COMPLETE,
+                                        &lock_old, sizeof(lock_old));
+                       goto out;
+               }
+
+       fw_error("swap not done (CSR lock timeout)\n");
+       fw_fill_response(&response, packet->header, RCODE_BUSY, NULL, 0);
 
-       fw_fill_response(&response, packet->header,
-                        RCODE_COMPLETE, &lock_old, sizeof(lock_old));
  out:
        fw_core_handle_response(&ohci->card, &response);
 }
 
 static void handle_local_request(struct context *ctx, struct fw_packet *packet)
 {
-       u64 offset;
-       u32 csr;
+       u64 offset, csr;
 
        if (ctx == &ctx->ohci->at_request_ctx) {
                packet->ack = ACK_PENDING;
@@ -1490,7 +1529,7 @@ static void bus_reset_tasklet(unsigned long data)
         * was set up before this reset, the old one is now no longer
         * in use and we can free it. Update the config rom pointers
         * to point to the current config rom and clear the
-        * next_config_rom pointer so a new udpate can take place.
+        * next_config_rom pointer so a new update can take place.
         */
 
        if (ohci->next_config_rom != NULL) {
@@ -1530,7 +1569,9 @@ static void bus_reset_tasklet(unsigned long data)
                    self_id_count, ohci->self_id_buffer);
 
        fw_core_handle_bus_reset(&ohci->card, ohci->node_id, generation,
-                                self_id_count, ohci->self_id_buffer);
+                                self_id_count, ohci->self_id_buffer,
+                                ohci->csr_state_setclear_abdicate);
+       ohci->csr_state_setclear_abdicate = false;
 }
 
 static irqreturn_t irq_handler(int irq, void *data)
@@ -1674,7 +1715,7 @@ static int configure_1394a_enhancements(struct fw_ohci *ohci)
                clear = PHY_ENABLE_ACCEL | PHY_ENABLE_MULTI;
                set = 0;
        }
-       ret = ohci_update_phy_reg(&ohci->card, 5, clear, set);
+       ret = update_phy_reg(ohci, 5, clear, set);
        if (ret < 0)
                return ret;
 
@@ -1732,10 +1773,9 @@ static int ohci_enable(struct fw_card *card,
                  OHCI1394_HCControl_noByteSwapData);
 
        reg_write(ohci, OHCI1394_SelfIDBuffer, ohci->self_id_bus);
-       reg_write(ohci, OHCI1394_LinkControlClear,
-                 OHCI1394_LinkControl_rcvPhyPkt);
        reg_write(ohci, OHCI1394_LinkControlSet,
                  OHCI1394_LinkControl_rcvSelfID |
+                 OHCI1394_LinkControl_rcvPhyPkt |
                  OHCI1394_LinkControl_cycleTimerEnable |
                  OHCI1394_LinkControl_cycleMaster);
 
@@ -1753,15 +1793,14 @@ static int ohci_enable(struct fw_card *card,
        if (version >= OHCI_VERSION_1_1) {
                reg_write(ohci, OHCI1394_InitialChannelsAvailableHi,
                          0xfffffffe);
-               ohci->features |= FEATURE_CHANNEL_31_ALLOCATED;
+               card->broadcast_channel_auto_allocated = true;
        }
 
        /* Get implemented bits of the priority arbitration request counter. */
        reg_write(ohci, OHCI1394_FairnessControl, 0x3f);
        ohci->pri_req_max = reg_read(ohci, OHCI1394_FairnessControl) & 0x3f;
        reg_write(ohci, OHCI1394_FairnessControl, 0);
-       if (ohci->pri_req_max != 0)
-               ohci->features |= FEATURE_PRIORITY_BUDGET;
+       card->priority_budget_implemented = ohci->pri_req_max != 0;
 
        ar_context_run(&ohci->ar_request_ctx);
        ar_context_run(&ohci->ar_response_ctx);
@@ -1855,12 +1894,8 @@ static int ohci_enable(struct fw_card *card,
                  OHCI1394_HCControl_BIBimageValid);
        flush_writes(ohci);
 
-       /*
-        * We are ready to go, initiate bus reset to finish the
-        * initialization.
-        */
-
-       fw_core_initiate_bus_reset(&ohci->card, 1);
+       /* We are ready to go, reset bus to finish initialization. */
+       fw_schedule_bus_reset(&ohci->card, false, true);
 
        return 0;
 }
@@ -1935,7 +1970,7 @@ static int ohci_set_config_rom(struct fw_card *card,
         * takes effect.
         */
        if (ret == 0)
-               fw_core_initiate_bus_reset(&ohci->card, 1);
+               fw_schedule_bus_reset(&ohci->card, true, true);
        else
                dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE,
                                  next_config_rom, next_config_rom_bus);
@@ -2025,7 +2060,7 @@ static int ohci_enable_phys_dma(struct fw_card *card,
 #endif /* CONFIG_FIREWIRE_OHCI_REMOTE_DMA */
 }
 
-static u32 ohci_read_csr_reg(struct fw_card *card, int csr_offset)
+static u32 ohci_read_csr(struct fw_card *card, int csr_offset)
 {
        struct fw_ohci *ohci = fw_ohci(card);
        unsigned long flags;
@@ -2034,13 +2069,16 @@ static u32 ohci_read_csr_reg(struct fw_card *card, int csr_offset)
        switch (csr_offset) {
        case CSR_STATE_CLEAR:
        case CSR_STATE_SET:
-               /* the controller driver handles only the cmstr bit */
                if (ohci->is_root &&
                    (reg_read(ohci, OHCI1394_LinkControlSet) &
                     OHCI1394_LinkControl_cycleMaster))
-                       return CSR_STATE_BIT_CMSTR;
+                       value = CSR_STATE_BIT_CMSTR;
                else
-                       return 0;
+                       value = 0;
+               if (ohci->csr_state_setclear_abdicate)
+                       value |= CSR_STATE_BIT_ABDICATE;
+
+               return value;
 
        case CSR_NODE_IDS:
                return reg_read(ohci, OHCI1394_NodeID) << 16;
@@ -2073,19 +2111,20 @@ static u32 ohci_read_csr_reg(struct fw_card *card, int csr_offset)
        }
 }
 
-static void ohci_write_csr_reg(struct fw_card *card, int csr_offset, u32 value)
+static void ohci_write_csr(struct fw_card *card, int csr_offset, u32 value)
 {
        struct fw_ohci *ohci = fw_ohci(card);
        unsigned long flags;
 
        switch (csr_offset) {
        case CSR_STATE_CLEAR:
-               /* the controller driver handles only the cmstr bit */
                if ((value & CSR_STATE_BIT_CMSTR) && ohci->is_root) {
                        reg_write(ohci, OHCI1394_LinkControlClear,
                                  OHCI1394_LinkControl_cycleMaster);
                        flush_writes(ohci);
                }
+               if (value & CSR_STATE_BIT_ABDICATE)
+                       ohci->csr_state_setclear_abdicate = false;
                break;
 
        case CSR_STATE_SET:
@@ -2094,6 +2133,8 @@ static void ohci_write_csr_reg(struct fw_card *card, int csr_offset, u32 value)
                                  OHCI1394_LinkControl_cycleMaster);
                        flush_writes(ohci);
                }
+               if (value & CSR_STATE_BIT_ABDICATE)
+                       ohci->csr_state_setclear_abdicate = true;
                break;
 
        case CSR_NODE_IDS:
@@ -2132,13 +2173,6 @@ static void ohci_write_csr_reg(struct fw_card *card, int csr_offset, u32 value)
        }
 }
 
-static unsigned int ohci_get_features(struct fw_card *card)
-{
-       struct fw_ohci *ohci = fw_ohci(card);
-
-       return ohci->features;
-}
-
 static void copy_iso_headers(struct iso_context *ctx, void *p)
 {
        int i = ctx->header_length;
@@ -2171,10 +2205,9 @@ static int handle_ir_packet_per_buffer(struct context *context,
        __le32 *ir_header;
        void *p;
 
-       for (pd = d; pd <= last; pd++) {
+       for (pd = d; pd <= last; pd++)
                if (pd->transfer_status)
                        break;
-       }
        if (pd > last)
                /* Descriptor(s) not done yet, stop iteration */
                return 0;
@@ -2184,16 +2217,38 @@ static int handle_ir_packet_per_buffer(struct context *context,
 
        if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) {
                ir_header = (__le32 *) p;
-               ctx->base.callback(&ctx->base,
-                                  le32_to_cpu(ir_header[0]) & 0xffff,
-                                  ctx->header_length, ctx->header,
-                                  ctx->base.callback_data);
+               ctx->base.callback.sc(&ctx->base,
+                                     le32_to_cpu(ir_header[0]) & 0xffff,
+                                     ctx->header_length, ctx->header,
+                                     ctx->base.callback_data);
                ctx->header_length = 0;
        }
 
        return 1;
 }
 
+/* d == last because each descriptor block is only a single descriptor. */
+static int handle_ir_buffer_fill(struct context *context,
+                                struct descriptor *d,
+                                struct descriptor *last)
+{
+       struct iso_context *ctx =
+               container_of(context, struct iso_context, context);
+
+       if (!last->transfer_status)
+               /* Descriptor(s) not done yet, stop iteration */
+               return 0;
+
+       if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS)
+               ctx->base.callback.mc(&ctx->base,
+                                     le32_to_cpu(last->data_address) +
+                                     le16_to_cpu(last->req_count) -
+                                     le16_to_cpu(last->res_count),
+                                     ctx->base.callback_data);
+
+       return 1;
+}
+
 static int handle_it_packet(struct context *context,
                            struct descriptor *d,
                            struct descriptor *last)
@@ -2219,71 +2274,118 @@ static int handle_it_packet(struct context *context,
                ctx->header_length += 4;
        }
        if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) {
-               ctx->base.callback(&ctx->base, le16_to_cpu(last->res_count),
-                                  ctx->header_length, ctx->header,
-                                  ctx->base.callback_data);
+               ctx->base.callback.sc(&ctx->base, le16_to_cpu(last->res_count),
+                                     ctx->header_length, ctx->header,
+                                     ctx->base.callback_data);
                ctx->header_length = 0;
        }
        return 1;
 }
 
+static void set_multichannel_mask(struct fw_ohci *ohci, u64 channels)
+{
+       u32 hi = channels >> 32, lo = channels;
+
+       reg_write(ohci, OHCI1394_IRMultiChanMaskHiClear, ~hi);
+       reg_write(ohci, OHCI1394_IRMultiChanMaskLoClear, ~lo);
+       reg_write(ohci, OHCI1394_IRMultiChanMaskHiSet, hi);
+       reg_write(ohci, OHCI1394_IRMultiChanMaskLoSet, lo);
+       mmiowb();
+       ohci->mc_channels = channels;
+}
+
 static struct fw_iso_context *ohci_allocate_iso_context(struct fw_card *card,
                                int type, int channel, size_t header_size)
 {
        struct fw_ohci *ohci = fw_ohci(card);
-       struct iso_context *ctx, *list;
-       descriptor_callback_t callback;
-       u64 *channels, dont_care = ~0ULL;
-       u32 *mask, regs;
+       struct iso_context *uninitialized_var(ctx);
+       descriptor_callback_t uninitialized_var(callback);
+       u64 *uninitialized_var(channels);
+       u32 *uninitialized_var(mask), uninitialized_var(regs);
        unsigned long flags;
-       int index, ret = -ENOMEM;
+       int index, ret = -EBUSY;
+
+       spin_lock_irqsave(&ohci->lock, flags);
 
-       if (type == FW_ISO_CONTEXT_TRANSMIT) {
-               channels = &dont_care;
-               mask = &ohci->it_context_mask;
-               list = ohci->it_context_list;
+       switch (type) {
+       case FW_ISO_CONTEXT_TRANSMIT:
+               mask     = &ohci->it_context_mask;
                callback = handle_it_packet;
-       } else {
+               index    = ffs(*mask) - 1;
+               if (index >= 0) {
+                       *mask &= ~(1 << index);
+                       regs = OHCI1394_IsoXmitContextBase(index);
+                       ctx  = &ohci->it_context_list[index];
+               }
+               break;
+
+       case FW_ISO_CONTEXT_RECEIVE:
                channels = &ohci->ir_context_channels;
-               mask = &ohci->ir_context_mask;
-               list = ohci->ir_context_list;
+               mask     = &ohci->ir_context_mask;
                callback = handle_ir_packet_per_buffer;
-       }
+               index    = *channels & 1ULL << channel ? ffs(*mask) - 1 : -1;
+               if (index >= 0) {
+                       *channels &= ~(1ULL << channel);
+                       *mask     &= ~(1 << index);
+                       regs = OHCI1394_IsoRcvContextBase(index);
+                       ctx  = &ohci->ir_context_list[index];
+               }
+               break;
 
-       spin_lock_irqsave(&ohci->lock, flags);
-       index = *channels & 1ULL << channel ? ffs(*mask) - 1 : -1;
-       if (index >= 0) {
-               *channels &= ~(1ULL << channel);
-               *mask &= ~(1 << index);
+       case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
+               mask     = &ohci->ir_context_mask;
+               callback = handle_ir_buffer_fill;
+               index    = !ohci->mc_allocated ? ffs(*mask) - 1 : -1;
+               if (index >= 0) {
+                       ohci->mc_allocated = true;
+                       *mask &= ~(1 << index);
+                       regs = OHCI1394_IsoRcvContextBase(index);
+                       ctx  = &ohci->ir_context_list[index];
+               }
+               break;
+
+       default:
+               index = -1;
+               ret = -ENOSYS;
        }
+
        spin_unlock_irqrestore(&ohci->lock, flags);
 
        if (index < 0)
-               return ERR_PTR(-EBUSY);
-
-       if (type == FW_ISO_CONTEXT_TRANSMIT)
-               regs = OHCI1394_IsoXmitContextBase(index);
-       else
-               regs = OHCI1394_IsoRcvContextBase(index);
+               return ERR_PTR(ret);
 
-       ctx = &list[index];
        memset(ctx, 0, sizeof(*ctx));
        ctx->header_length = 0;
        ctx->header = (void *) __get_free_page(GFP_KERNEL);
-       if (ctx->header == NULL)
+       if (ctx->header == NULL) {
+               ret = -ENOMEM;
                goto out;
-
+       }
        ret = context_init(&ctx->context, ohci, regs, callback);
        if (ret < 0)
                goto out_with_header;
 
+       if (type == FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL)
+               set_multichannel_mask(ohci, 0);
+
        return &ctx->base;
 
  out_with_header:
        free_page((unsigned long)ctx->header);
  out:
        spin_lock_irqsave(&ohci->lock, flags);
+
+       switch (type) {
+       case FW_ISO_CONTEXT_RECEIVE:
+               *channels |= 1ULL << channel;
+               break;
+
+       case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
+               ohci->mc_allocated = false;
+               break;
+       }
        *mask |= 1 << index;
+
        spin_unlock_irqrestore(&ohci->lock, flags);
 
        return ERR_PTR(ret);
@@ -2294,10 +2396,11 @@ static int ohci_start_iso(struct fw_iso_context *base,
 {
        struct iso_context *ctx = container_of(base, struct iso_context, base);
        struct fw_ohci *ohci = ctx->context.ohci;
-       u32 control, match;
+       u32 control = IR_CONTEXT_ISOCH_HEADER, match;
        int index;
 
-       if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) {
+       switch (ctx->base.type) {
+       case FW_ISO_CONTEXT_TRANSMIT:
                index = ctx - ohci->it_context_list;
                match = 0;
                if (cycle >= 0)
@@ -2307,9 +2410,13 @@ static int ohci_start_iso(struct fw_iso_context *base,
                reg_write(ohci, OHCI1394_IsoXmitIntEventClear, 1 << index);
                reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, 1 << index);
                context_run(&ctx->context, match);
-       } else {
+               break;
+
+       case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
+               control |= IR_CONTEXT_BUFFER_FILL|IR_CONTEXT_MULTI_CHANNEL_MODE;
+               /* fall through */
+       case FW_ISO_CONTEXT_RECEIVE:
                index = ctx - ohci->ir_context_list;
-               control = IR_CONTEXT_ISOCH_HEADER;
                match = (tags << 28) | (sync << 8) | ctx->base.channel;
                if (cycle >= 0) {
                        match |= (cycle & 0x07fff) << 12;
@@ -2320,6 +2427,7 @@ static int ohci_start_iso(struct fw_iso_context *base,
                reg_write(ohci, OHCI1394_IsoRecvIntMaskSet, 1 << index);
                reg_write(ohci, CONTEXT_MATCH(ctx->context.regs), match);
                context_run(&ctx->context, control);
+               break;
        }
 
        return 0;
@@ -2331,12 +2439,17 @@ static int ohci_stop_iso(struct fw_iso_context *base)
        struct iso_context *ctx = container_of(base, struct iso_context, base);
        int index;
 
-       if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) {
+       switch (ctx->base.type) {
+       case FW_ISO_CONTEXT_TRANSMIT:
                index = ctx - ohci->it_context_list;
                reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, 1 << index);
-       } else {
+               break;
+
+       case FW_ISO_CONTEXT_RECEIVE:
+       case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
                index = ctx - ohci->ir_context_list;
                reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, 1 << index);
+               break;
        }
        flush_writes(ohci);
        context_stop(&ctx->context);
@@ -2357,24 +2470,65 @@ static void ohci_free_iso_context(struct fw_iso_context *base)
 
        spin_lock_irqsave(&ohci->lock, flags);
 
-       if (ctx->base.type == FW_ISO_CONTEXT_TRANSMIT) {
+       switch (base->type) {
+       case FW_ISO_CONTEXT_TRANSMIT:
                index = ctx - ohci->it_context_list;
                ohci->it_context_mask |= 1 << index;
-       } else {
+               break;
+
+       case FW_ISO_CONTEXT_RECEIVE:
                index = ctx - ohci->ir_context_list;
                ohci->ir_context_mask |= 1 << index;
                ohci->ir_context_channels |= 1ULL << base->channel;
+               break;
+
+       case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
+               index = ctx - ohci->ir_context_list;
+               ohci->ir_context_mask |= 1 << index;
+               ohci->ir_context_channels |= ohci->mc_channels;
+               ohci->mc_channels = 0;
+               ohci->mc_allocated = false;
+               break;
        }
 
        spin_unlock_irqrestore(&ohci->lock, flags);
 }
 
-static int ohci_queue_iso_transmit(struct fw_iso_context *base,
-                                  struct fw_iso_packet *packet,
-                                  struct fw_iso_buffer *buffer,
-                                  unsigned long payload)
+static int ohci_set_iso_channels(struct fw_iso_context *base, u64 *channels)
+{
+       struct fw_ohci *ohci = fw_ohci(base->card);
+       unsigned long flags;
+       int ret;
+
+       switch (base->type) {
+       case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
+
+               spin_lock_irqsave(&ohci->lock, flags);
+
+               /* Don't allow multichannel to grab other contexts' channels. */
+               if (~ohci->ir_context_channels & ~ohci->mc_channels & *channels) {
+                       *channels = ohci->ir_context_channels;
+                       ret = -EBUSY;
+               } else {
+                       set_multichannel_mask(ohci, *channels);
+                       ret = 0;
+               }
+
+               spin_unlock_irqrestore(&ohci->lock, flags);
+
+               break;
+       default:
+               ret = -EINVAL;
+       }
+
+       return ret;
+}
+
+static int queue_iso_transmit(struct iso_context *ctx,
+                             struct fw_iso_packet *packet,
+                             struct fw_iso_buffer *buffer,
+                             unsigned long payload)
 {
-       struct iso_context *ctx = container_of(base, struct iso_context, base);
        struct descriptor *d, *last, *pd;
        struct fw_iso_packet *p;
        __le32 *header;
@@ -2470,14 +2624,12 @@ static int ohci_queue_iso_transmit(struct fw_iso_context *base,
        return 0;
 }
 
-static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base,
-                                       struct fw_iso_packet *packet,
-                                       struct fw_iso_buffer *buffer,
-                                       unsigned long payload)
+static int queue_iso_packet_per_buffer(struct iso_context *ctx,
+                                      struct fw_iso_packet *packet,
+                                      struct fw_iso_buffer *buffer,
+                                      unsigned long payload)
 {
-       struct iso_context *ctx = container_of(base, struct iso_context, base);
        struct descriptor *d, *pd;
-       struct fw_iso_packet *p = packet;
        dma_addr_t d_bus, page_bus;
        u32 z, header_z, rest;
        int i, j, length;
@@ -2487,14 +2639,14 @@ static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base,
         * The OHCI controller puts the isochronous header and trailer in the
         * buffer, so we need at least 8 bytes.
         */
-       packet_count = p->header_length / ctx->base.header_size;
+       packet_count = packet->header_length / ctx->base.header_size;
        header_size  = max(ctx->base.header_size, (size_t)8);
 
        /* Get header size in number of descriptors. */
        header_z = DIV_ROUND_UP(header_size, sizeof(*d));
        page     = payload >> PAGE_SHIFT;
        offset   = payload & ~PAGE_MASK;
-       payload_per_buffer = p->payload_length / packet_count;
+       payload_per_buffer = packet->payload_length / packet_count;
 
        for (i = 0; i < packet_count; i++) {
                /* d points to the header descriptor */
@@ -2506,7 +2658,7 @@ static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base,
 
                d->control      = cpu_to_le16(DESCRIPTOR_STATUS |
                                              DESCRIPTOR_INPUT_MORE);
-               if (p->skip && i == 0)
+               if (packet->skip && i == 0)
                        d->control |= cpu_to_le16(DESCRIPTOR_WAIT);
                d->req_count    = cpu_to_le16(header_size);
                d->res_count    = d->req_count;
@@ -2539,7 +2691,7 @@ static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base,
                pd->control = cpu_to_le16(DESCRIPTOR_STATUS |
                                          DESCRIPTOR_INPUT_LAST |
                                          DESCRIPTOR_BRANCH_ALWAYS);
-               if (p->interrupt && i == packet_count - 1)
+               if (packet->interrupt && i == packet_count - 1)
                        pd->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS);
 
                context_append(&ctx->context, d, z, header_z);
@@ -2548,6 +2700,58 @@ static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base,
        return 0;
 }
 
+static int queue_iso_buffer_fill(struct iso_context *ctx,
+                                struct fw_iso_packet *packet,
+                                struct fw_iso_buffer *buffer,
+                                unsigned long payload)
+{
+       struct descriptor *d;
+       dma_addr_t d_bus, page_bus;
+       int page, offset, rest, z, i, length;
+
+       page   = payload >> PAGE_SHIFT;
+       offset = payload & ~PAGE_MASK;
+       rest   = packet->payload_length;
+
+       /* We need one descriptor for each page in the buffer. */
+       z = DIV_ROUND_UP(offset + rest, PAGE_SIZE);
+
+       if (WARN_ON(offset & 3 || rest & 3 || page + z > buffer->page_count))
+               return -EFAULT;
+
+       for (i = 0; i < z; i++) {
+               d = context_get_descriptors(&ctx->context, 1, &d_bus);
+               if (d == NULL)
+                       return -ENOMEM;
+
+               d->control = cpu_to_le16(DESCRIPTOR_INPUT_MORE |
+                                        DESCRIPTOR_BRANCH_ALWAYS);
+               if (packet->skip && i == 0)
+                       d->control |= cpu_to_le16(DESCRIPTOR_WAIT);
+               if (packet->interrupt && i == z - 1)
+                       d->control |= cpu_to_le16(DESCRIPTOR_IRQ_ALWAYS);
+
+               if (offset + rest < PAGE_SIZE)
+                       length = rest;
+               else
+                       length = PAGE_SIZE - offset;
+               d->req_count = cpu_to_le16(length);
+               d->res_count = d->req_count;
+               d->transfer_status = 0;
+
+               page_bus = page_private(buffer->pages[page]);
+               d->data_address = cpu_to_le32(page_bus + offset);
+
+               rest -= length;
+               offset = 0;
+               page++;
+
+               context_append(&ctx->context, d, 1, 0);
+       }
+
+       return 0;
+}
+
 static int ohci_queue_iso(struct fw_iso_context *base,
                          struct fw_iso_packet *packet,
                          struct fw_iso_buffer *buffer,
@@ -2555,14 +2759,20 @@ static int ohci_queue_iso(struct fw_iso_context *base,
 {
        struct iso_context *ctx = container_of(base, struct iso_context, base);
        unsigned long flags;
-       int ret;
+       int ret = -ENOSYS;
 
        spin_lock_irqsave(&ctx->context.ohci->lock, flags);
-       if (base->type == FW_ISO_CONTEXT_TRANSMIT)
-               ret = ohci_queue_iso_transmit(base, packet, buffer, payload);
-       else
-               ret = ohci_queue_iso_receive_packet_per_buffer(base, packet,
-                                                       buffer, payload);
+       switch (base->type) {
+       case FW_ISO_CONTEXT_TRANSMIT:
+               ret = queue_iso_transmit(ctx, packet, buffer, payload);
+               break;
+       case FW_ISO_CONTEXT_RECEIVE:
+               ret = queue_iso_packet_per_buffer(ctx, packet, buffer, payload);
+               break;
+       case FW_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
+               ret = queue_iso_buffer_fill(ctx, packet, buffer, payload);
+               break;
+       }
        spin_unlock_irqrestore(&ctx->context.ohci->lock, flags);
 
        return ret;
@@ -2570,18 +2780,19 @@ static int ohci_queue_iso(struct fw_iso_context *base,
 
 static const struct fw_card_driver ohci_driver = {
        .enable                 = ohci_enable,
+       .read_phy_reg           = ohci_read_phy_reg,
        .update_phy_reg         = ohci_update_phy_reg,
        .set_config_rom         = ohci_set_config_rom,
        .send_request           = ohci_send_request,
        .send_response          = ohci_send_response,
        .cancel_packet          = ohci_cancel_packet,
        .enable_phys_dma        = ohci_enable_phys_dma,
-       .read_csr_reg           = ohci_read_csr_reg,
-       .write_csr_reg          = ohci_write_csr_reg,
-       .get_features           = ohci_get_features,
+       .read_csr               = ohci_read_csr,
+       .write_csr              = ohci_write_csr,
 
        .allocate_iso_context   = ohci_allocate_iso_context,
        .free_iso_context       = ohci_free_iso_context,
+       .set_iso_channels       = ohci_set_iso_channels,
        .queue_iso              = ohci_queue_iso,
        .start_iso              = ohci_start_iso,
        .stop_iso               = ohci_stop_iso,
@@ -2646,6 +2857,7 @@ static int __devinit pci_probe(struct pci_dev *dev,
        pci_set_drvdata(dev, ohci);
 
        spin_lock_init(&ohci->lock);
+       mutex_init(&ohci->phy_reg_mutex);
 
        tasklet_init(&ohci->bus_reset_tasklet,
                     bus_reset_tasklet, (unsigned long)ohci);