]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ieee1394/ohci1394.c
[PATCH] m68k: wd33c93: extra delay
[linux-2.6-omap-h63xx.git] / drivers / ieee1394 / ohci1394.c
index dcb5776e5c44076271cf676cafa83c378a57f318..3d278412e1ca07f46b9e69887864d1d076c91a26 100644 (file)
@@ -161,12 +161,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_DRIVER_NAME , ## args)
 #define PRINT(level, fmt, args...) \
 printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
 
-static char version[] __devinitdata =
-       "$Rev: 1313 $ Ben Collins <bcollins@debian.org>";
-
 /* Module Parameters */
 static int phys_dma = 1;
-module_param(phys_dma, int, 0644);
+module_param(phys_dma, int, 0444);
 MODULE_PARM_DESC(phys_dma, "Enable physical dma (default = 1).");
 
 static void dma_trm_tasklet(unsigned long data);
@@ -547,12 +544,20 @@ static void ohci_initialize(struct ti_ohci *ohci)
        /* Initialize IR Legacy DMA channel mask */
        ohci->ir_legacy_channels = 0;
 
-       /*
-        * Accept AT requests from all nodes. This probably
-        * will have to be controlled from the subsystem
-        * on a per node basis.
-        */
-       reg_write(ohci,OHCI1394_AsReqFilterHiSet, 0x80000000);
+       /* Accept AR requests from all nodes */
+       reg_write(ohci, OHCI1394_AsReqFilterHiSet, 0x80000000);
+
+       /* Set the address range of the physical response unit.
+        * Most controllers do not implement it as a writable register though.
+        * They will keep a hardwired offset of 0x00010000 and show 0x0 as
+        * register content.
+        * To actually enable physical responses is the job of our interrupt
+        * handler which programs the physical request filter. */
+       reg_write(ohci, OHCI1394_PhyUpperBound,
+                 OHCI1394_PHYS_UPPER_BOUND_PROGRAMMED >> 16);
+
+       DBGMSG("physUpperBoundOffset=%08x",
+              reg_read(ohci, OHCI1394_PhyUpperBound));
 
        /* Specify AT retries */
        reg_write(ohci, OHCI1394_ATRetries,
@@ -575,24 +580,23 @@ static void ohci_initialize(struct ti_ohci *ohci)
                  OHCI1394_reqTxComplete |
                  OHCI1394_isochRx |
                  OHCI1394_isochTx |
+                 OHCI1394_postedWriteErr |
+                 OHCI1394_cycleTooLong |
                  OHCI1394_cycleInconsistent);
 
        /* Enable link */
        reg_write(ohci, OHCI1394_HCControlSet, OHCI1394_HCControl_linkEnable);
 
        buf = reg_read(ohci, OHCI1394_Version);
-#ifndef __sparc__
        sprintf (irq_buf, "%d", ohci->dev->irq);
-#else
-       sprintf (irq_buf, "%s", __irq_itoa(ohci->dev->irq));
-#endif
        PRINT(KERN_INFO, "OHCI-1394 %d.%d (PCI): IRQ=[%s]  "
-             "MMIO=[%lx-%lx]  Max Packet=[%d]",
+             "MMIO=[%lx-%lx]  Max Packet=[%d]  IR/IT contexts=[%d/%d]",
              ((((buf) >> 16) & 0xf) + (((buf) >> 20) & 0xf) * 10),
              ((((buf) >> 4) & 0xf) + ((buf) & 0xf) * 10), irq_buf,
              pci_resource_start(ohci->dev, 0),
              pci_resource_start(ohci->dev, 0) + OHCI1394_REGISTER_SIZE - 1,
-             ohci->max_packet_size);
+             ohci->max_packet_size,
+             ohci->nb_iso_rcv_ctx, ohci->nb_iso_xmit_ctx);
 
        /* Check all of our ports to make sure that if anything is
         * connected, we enable that port. */
@@ -2376,7 +2380,19 @@ static irqreturn_t ohci_irq_handler(int irq, void *dev_id,
 
                event &= ~OHCI1394_unrecoverableError;
        }
-
+       if (event & OHCI1394_postedWriteErr) {
+               PRINT(KERN_ERR, "physical posted write error");
+               /* no recovery strategy yet, had to involve protocol drivers */
+       }
+       if (event & OHCI1394_cycleTooLong) {
+               if(printk_ratelimit())
+                       PRINT(KERN_WARNING, "isochronous cycle too long");
+               else
+                       DBGMSG("OHCI1394_cycleTooLong");
+               reg_write(ohci, OHCI1394_LinkControlSet,
+                         OHCI1394_LinkControl_CycleMaster);
+               event &= ~OHCI1394_cycleTooLong;
+       }
        if (event & OHCI1394_cycleInconsistent) {
                /* We subscribe to the cycleInconsistent event only to
                 * clear the corresponding event bit... otherwise,
@@ -2384,7 +2400,6 @@ static irqreturn_t ohci_irq_handler(int irq, void *dev_id,
                DBGMSG("OHCI1394_cycleInconsistent");
                event &= ~OHCI1394_cycleInconsistent;
        }
-
        if (event & OHCI1394_busReset) {
                /* The busReset event bit can't be cleared during the
                 * selfID phase, so we disable busReset interrupts, to
@@ -2428,7 +2443,6 @@ static irqreturn_t ohci_irq_handler(int irq, void *dev_id,
                }
                event &= ~OHCI1394_busReset;
        }
-
        if (event & OHCI1394_reqTxComplete) {
                struct dma_trm_ctx *d = &ohci->at_req_context;
                DBGMSG("Got reqTxComplete interrupt "
@@ -2516,26 +2530,20 @@ static irqreturn_t ohci_irq_handler(int irq, void *dev_id,
                        reg_write(ohci, OHCI1394_IntMaskSet, OHCI1394_busReset);
                        spin_unlock_irqrestore(&ohci->event_lock, flags);
 
-                       /* Accept Physical requests from all nodes. */
-                       reg_write(ohci,OHCI1394_AsReqFilterHiSet, 0xffffffff);
-                       reg_write(ohci,OHCI1394_AsReqFilterLoSet, 0xffffffff);
-
                        /* Turn on phys dma reception.
                         *
                         * TODO: Enable some sort of filtering management.
                         */
                        if (phys_dma) {
-                               reg_write(ohci,OHCI1394_PhyReqFilterHiSet, 0xffffffff);
-                               reg_write(ohci,OHCI1394_PhyReqFilterLoSet, 0xffffffff);
-                               reg_write(ohci,OHCI1394_PhyUpperBound, 0xffff0000);
-                       } else {
-                               reg_write(ohci,OHCI1394_PhyReqFilterHiSet, 0x00000000);
-                               reg_write(ohci,OHCI1394_PhyReqFilterLoSet, 0x00000000);
+                               reg_write(ohci, OHCI1394_PhyReqFilterHiSet,
+                                         0xffffffff);
+                               reg_write(ohci, OHCI1394_PhyReqFilterLoSet,
+                                         0xffffffff);
                        }
 
                        DBGMSG("PhyReqFilter=%08x%08x",
-                              reg_read(ohci,OHCI1394_PhyReqFilterHiSet),
-                              reg_read(ohci,OHCI1394_PhyReqFilterLoSet));
+                              reg_read(ohci, OHCI1394_PhyReqFilterHiSet),
+                              reg_read(ohci, OHCI1394_PhyReqFilterLoSet));
 
                        hpsb_selfid_complete(host, phyid, isroot);
                } else
@@ -2960,28 +2968,23 @@ alloc_dma_rcv_ctx(struct ti_ohci *ohci, struct dma_rcv_ctx *d,
        d->ctrlClear = 0;
        d->cmdPtr = 0;
 
-       d->buf_cpu = kmalloc(d->num_desc * sizeof(quadlet_t*), GFP_ATOMIC);
-       d->buf_bus = kmalloc(d->num_desc * sizeof(dma_addr_t), GFP_ATOMIC);
+       d->buf_cpu = kzalloc(d->num_desc * sizeof(*d->buf_cpu), GFP_ATOMIC);
+       d->buf_bus = kzalloc(d->num_desc * sizeof(*d->buf_bus), GFP_ATOMIC);
 
        if (d->buf_cpu == NULL || d->buf_bus == NULL) {
                PRINT(KERN_ERR, "Failed to allocate dma buffer");
                free_dma_rcv_ctx(d);
                return -ENOMEM;
        }
-       memset(d->buf_cpu, 0, d->num_desc * sizeof(quadlet_t*));
-       memset(d->buf_bus, 0, d->num_desc * sizeof(dma_addr_t));
 
-       d->prg_cpu = kmalloc(d->num_desc * sizeof(struct dma_cmd*),
-                               GFP_ATOMIC);
-       d->prg_bus = kmalloc(d->num_desc * sizeof(dma_addr_t), GFP_ATOMIC);
+       d->prg_cpu = kzalloc(d->num_desc * sizeof(*d->prg_cpu), GFP_ATOMIC);
+       d->prg_bus = kzalloc(d->num_desc * sizeof(*d->prg_bus), GFP_ATOMIC);
 
        if (d->prg_cpu == NULL || d->prg_bus == NULL) {
                PRINT(KERN_ERR, "Failed to allocate dma prg");
                free_dma_rcv_ctx(d);
                return -ENOMEM;
        }
-       memset(d->prg_cpu, 0, d->num_desc * sizeof(struct dma_cmd*));
-       memset(d->prg_bus, 0, d->num_desc * sizeof(dma_addr_t));
 
        d->spb = kmalloc(d->split_buf_size, GFP_ATOMIC);
 
@@ -3093,17 +3096,14 @@ alloc_dma_trm_ctx(struct ti_ohci *ohci, struct dma_trm_ctx *d,
        d->ctrlClear = 0;
        d->cmdPtr = 0;
 
-       d->prg_cpu = kmalloc(d->num_desc * sizeof(struct at_dma_prg*),
-                            GFP_KERNEL);
-       d->prg_bus = kmalloc(d->num_desc * sizeof(dma_addr_t), GFP_KERNEL);
+       d->prg_cpu = kzalloc(d->num_desc * sizeof(*d->prg_cpu), GFP_KERNEL);
+       d->prg_bus = kzalloc(d->num_desc * sizeof(*d->prg_bus), GFP_KERNEL);
 
        if (d->prg_cpu == NULL || d->prg_bus == NULL) {
                PRINT(KERN_ERR, "Failed to allocate at dma prg");
                free_dma_trm_ctx(d);
                return -ENOMEM;
        }
-       memset(d->prg_cpu, 0, d->num_desc * sizeof(struct at_dma_prg*));
-       memset(d->prg_bus, 0, d->num_desc * sizeof(dma_addr_t));
 
        len = sprintf(pool_name, "ohci1394_trm_prg");
        sprintf(pool_name+len, "%d", num_allocs);
@@ -3215,15 +3215,10 @@ do {                                            \
 static int __devinit ohci1394_pci_probe(struct pci_dev *dev,
                                        const struct pci_device_id *ent)
 {
-       static int version_printed = 0;
-
        struct hpsb_host *host;
        struct ti_ohci *ohci;   /* shortcut to currently handled device */
        unsigned long ohci_base;
 
-       if (version_printed++ == 0)
-               PRINT_G(KERN_INFO, "%s", version);
-
         if (pci_enable_device(dev))
                FAIL(-ENXIO, "Failed to enable OHCI hardware");
         pci_set_master(dev);
@@ -3274,8 +3269,8 @@ static int __devinit ohci1394_pci_probe(struct pci_dev *dev,
         * fail to report the right length.  Anyway, the ohci spec
         * clearly says it's 2kb, so this shouldn't be a problem. */
        ohci_base = pci_resource_start(dev, 0);
-       if (pci_resource_len(dev, 0) != OHCI1394_REGISTER_SIZE)
-               PRINT(KERN_WARNING, "Unexpected PCI resource length of %lx!",
+       if (pci_resource_len(dev, 0) < OHCI1394_REGISTER_SIZE)
+               PRINT(KERN_WARNING, "PCI resource length of %lx too small!",
                      pci_resource_len(dev, 0));
 
        /* Seems PCMCIA handles this internally. Not sure why. Seems
@@ -3367,13 +3362,8 @@ static int __devinit ohci1394_pci_probe(struct pci_dev *dev,
        /* Determine the number of available IR and IT contexts. */
        ohci->nb_iso_rcv_ctx =
                get_nb_iso_ctx(ohci, OHCI1394_IsoRecvIntMaskSet);
-       DBGMSG("%d iso receive contexts available",
-              ohci->nb_iso_rcv_ctx);
-
        ohci->nb_iso_xmit_ctx =
                get_nb_iso_ctx(ohci, OHCI1394_IsoXmitIntMaskSet);
-       DBGMSG("%d iso transmit contexts available",
-              ohci->nb_iso_xmit_ctx);
 
        /* Set the usage bits for non-existent contexts so they can't
         * be allocated */
@@ -3421,6 +3411,14 @@ static int __devinit ohci1394_pci_probe(struct pci_dev *dev,
        host->csr.max_rec = (reg_read(ohci, OHCI1394_BusOptions) >> 12) & 0xf;
        host->csr.lnk_spd = reg_read(ohci, OHCI1394_BusOptions) & 0x7;
 
+       if (phys_dma) {
+               host->low_addr_space =
+                       (u64) reg_read(ohci, OHCI1394_PhyUpperBound) << 16;
+               if (!host->low_addr_space)
+                       host->low_addr_space = OHCI1394_PHYS_UPPER_BOUND_FIXED;
+       }
+       host->middle_addr_space = OHCI1394_MIDDLE_ADDRESS_SPACE;
+
        /* Tell the highlevel this host is ready */
        if (hpsb_add_host(host))
                FAIL(-ENOMEM, "Failed to register host with highlevel");
@@ -3479,24 +3477,13 @@ static void ohci1394_pci_remove(struct pci_dev *pdev)
        case OHCI_INIT_HAVE_TXRX_BUFFERS__MAYBE:
                /* The ohci_soft_reset() stops all DMA contexts, so we
                 * dont need to do this.  */
-               /* Free AR dma */
                free_dma_rcv_ctx(&ohci->ar_req_context);
                free_dma_rcv_ctx(&ohci->ar_resp_context);
-
-               /* Free AT dma */
                free_dma_trm_ctx(&ohci->at_req_context);
                free_dma_trm_ctx(&ohci->at_resp_context);
-
-               /* Free IR dma */
                free_dma_rcv_ctx(&ohci->ir_legacy_context);
-
-               /* Free IT dma */
                free_dma_trm_ctx(&ohci->it_legacy_context);
 
-               /* Free IR legacy dma */
-               free_dma_rcv_ctx(&ohci->ir_legacy_context);
-
-
        case OHCI_INIT_HAVE_SELFID_BUFFER:
                pci_free_consistent(ohci->dev, OHCI1394_SI_DMA_BUF_SIZE,
                                    ohci->selfid_buf_cpu,
@@ -3546,7 +3533,7 @@ static void ohci1394_pci_remove(struct pci_dev *pdev)
 static int ohci1394_pci_resume (struct pci_dev *pdev)
 {
 #ifdef CONFIG_PPC_PMAC
-       if (_machine == _MACH_Pmac) {
+       if (machine_is(powermac)) {
                struct device_node *of_node;
 
                /* Re-enable 1394 */
@@ -3556,6 +3543,7 @@ static int ohci1394_pci_resume (struct pci_dev *pdev)
        }
 #endif /* CONFIG_PPC_PMAC */
 
+       pci_restore_state(pdev);
        pci_enable_device(pdev);
 
        return 0;
@@ -3565,7 +3553,7 @@ static int ohci1394_pci_resume (struct pci_dev *pdev)
 static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
 {
 #ifdef CONFIG_PPC_PMAC
-       if (_machine == _MACH_Pmac) {
+       if (machine_is(powermac)) {
                struct device_node *of_node;
 
                /* Disable 1394 */
@@ -3575,6 +3563,8 @@ static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state)
        }
 #endif
 
+       pci_save_state(pdev);
+
        return 0;
 }