USB: musb: Fix CPPI IRQs not being signaled
[linux-2.6.git] / drivers / dma / ioat / dma.c
index 70262c0..c524d36 100644 (file)
@@ -251,18 +251,19 @@ static dma_cookie_t ioat1_tx_submit(struct dma_async_tx_descriptor *tx)
        dev_dbg(to_dev(&ioat->base), "%s: cookie: %d\n", __func__, cookie);
 
        /* write address into NextDescriptor field of last desc in chain */
-       first = to_ioat_desc(tx->tx_list.next);
+       first = to_ioat_desc(desc->tx_list.next);
        chain_tail = to_ioat_desc(ioat->used_desc.prev);
        /* make descriptor updates globally visible before chaining */
        wmb();
        chain_tail->hw->next = first->txd.phys;
-       list_splice_tail_init(&tx->tx_list, &ioat->used_desc);
+       list_splice_tail_init(&desc->tx_list, &ioat->used_desc);
        dump_desc_dbg(ioat, chain_tail);
        dump_desc_dbg(ioat, first);
 
        if (!test_and_set_bit(IOAT_COMPLETION_PENDING, &chan->state))
                mod_timer(&chan->timer, jiffies + COMPLETION_TIMEOUT);
 
+       ioat->active += desc->hw->tx_cnt;
        ioat->pending += desc->hw->tx_cnt;
        if (ioat->pending >= ioat_pending_level)
                __ioat1_dma_memcpy_issue_pending(ioat);
@@ -297,6 +298,7 @@ ioat_dma_alloc_descriptor(struct ioat_dma_chan *ioat, gfp_t flags)
 
        memset(desc, 0, sizeof(*desc));
 
+       INIT_LIST_HEAD(&desc_sw->tx_list);
        dma_async_tx_descriptor_init(&desc_sw->txd, &ioat->base.common);
        desc_sw->txd.tx_submit = ioat1_tx_submit;
        desc_sw->hw = desc;
@@ -521,7 +523,7 @@ ioat1_dma_prep_memcpy(struct dma_chan *c, dma_addr_t dma_dest,
 
        desc->txd.flags = flags;
        desc->len = total_len;
-       list_splice(&chain, &desc->txd.tx_list);
+       list_splice(&chain, &desc->tx_list);
        hw->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
        hw->ctl_f.compl_write = 1;
        hw->tx_cnt = tx_cnt;
@@ -611,6 +613,7 @@ static void __cleanup(struct ioat_dma_chan *ioat, unsigned long phys_complete)
                        chan->completed_cookie = tx->cookie;
                        tx->cookie = 0;
                        ioat_dma_unmap(chan, tx->flags, desc->len, desc->hw);
+                       ioat->active -= desc->hw->tx_cnt;
                        if (tx->callback) {
                                tx->callback(tx->callback_param);
                                tx->callback = NULL;
@@ -797,7 +800,7 @@ static void __devinit ioat_dma_test_callback(void *dma_async_param)
  * ioat_dma_self_test - Perform a IOAT transaction to verify the HW works.
  * @device: device to be tested
  */
-static int __devinit ioat_dma_self_test(struct ioatdma_device *device)
+int __devinit ioat_dma_self_test(struct ioatdma_device *device)
 {
        int i;
        u8 *src;
@@ -1028,13 +1031,8 @@ int __devinit ioat_probe(struct ioatdma_device *device)
        dma_cap_set(DMA_MEMCPY, dma->cap_mask);
        dma->dev = &pdev->dev;
 
-       dev_err(dev, "Intel(R) I/OAT DMA Engine found,"
-               " %d channels, device version 0x%02x, driver version %s\n",
-               dma->chancnt, device->version, IOAT_DMA_VERSION);
-
        if (!dma->chancnt) {
-               dev_err(dev, "Intel(R) I/OAT DMA Engine problem found: "
-                       "zero channels detected\n");
+               dev_err(dev, "zero channels detected\n");
                goto err_setup_interrupts;
        }
 
@@ -1042,7 +1040,7 @@ int __devinit ioat_probe(struct ioatdma_device *device)
        if (err)
                goto err_setup_interrupts;
 
-       err = ioat_dma_self_test(device);
+       err = device->self_test(device);
        if (err)
                goto err_self_test;
 
@@ -1085,6 +1083,113 @@ static void ioat1_intr_quirk(struct ioatdma_device *device)
        pci_write_config_dword(pdev, IOAT_PCI_DMACTRL_OFFSET, dmactrl);
 }
 
+static ssize_t ring_size_show(struct dma_chan *c, char *page)
+{
+       struct ioat_dma_chan *ioat = to_ioat_chan(c);
+
+       return sprintf(page, "%d\n", ioat->desccount);
+}
+static struct ioat_sysfs_entry ring_size_attr = __ATTR_RO(ring_size);
+
+static ssize_t ring_active_show(struct dma_chan *c, char *page)
+{
+       struct ioat_dma_chan *ioat = to_ioat_chan(c);
+
+       return sprintf(page, "%d\n", ioat->active);
+}
+static struct ioat_sysfs_entry ring_active_attr = __ATTR_RO(ring_active);
+
+static ssize_t cap_show(struct dma_chan *c, char *page)
+{
+       struct dma_device *dma = c->device;
+
+       return sprintf(page, "copy%s%s%s%s%s%s\n",
+                      dma_has_cap(DMA_PQ, dma->cap_mask) ? " pq" : "",
+                      dma_has_cap(DMA_PQ_VAL, dma->cap_mask) ? " pq_val" : "",
+                      dma_has_cap(DMA_XOR, dma->cap_mask) ? " xor" : "",
+                      dma_has_cap(DMA_XOR_VAL, dma->cap_mask) ? " xor_val" : "",
+                      dma_has_cap(DMA_MEMSET, dma->cap_mask)  ? " fill" : "",
+                      dma_has_cap(DMA_INTERRUPT, dma->cap_mask) ? " intr" : "");
+
+}
+struct ioat_sysfs_entry ioat_cap_attr = __ATTR_RO(cap);
+
+static ssize_t version_show(struct dma_chan *c, char *page)
+{
+       struct dma_device *dma = c->device;
+       struct ioatdma_device *device = to_ioatdma_device(dma);
+
+       return sprintf(page, "%d.%d\n",
+                      device->version >> 4, device->version & 0xf);
+}
+struct ioat_sysfs_entry ioat_version_attr = __ATTR_RO(version);
+
+static struct attribute *ioat1_attrs[] = {
+       &ring_size_attr.attr,
+       &ring_active_attr.attr,
+       &ioat_cap_attr.attr,
+       &ioat_version_attr.attr,
+       NULL,
+};
+
+static ssize_t
+ioat_attr_show(struct kobject *kobj, struct attribute *attr, char *page)
+{
+       struct ioat_sysfs_entry *entry;
+       struct ioat_chan_common *chan;
+
+       entry = container_of(attr, struct ioat_sysfs_entry, attr);
+       chan = container_of(kobj, struct ioat_chan_common, kobj);
+
+       if (!entry->show)
+               return -EIO;
+       return entry->show(&chan->common, page);
+}
+
+struct sysfs_ops ioat_sysfs_ops = {
+       .show   = ioat_attr_show,
+};
+
+static struct kobj_type ioat1_ktype = {
+       .sysfs_ops = &ioat_sysfs_ops,
+       .default_attrs = ioat1_attrs,
+};
+
+void ioat_kobject_add(struct ioatdma_device *device, struct kobj_type *type)
+{
+       struct dma_device *dma = &device->common;
+       struct dma_chan *c;
+
+       list_for_each_entry(c, &dma->channels, device_node) {
+               struct ioat_chan_common *chan = to_chan_common(c);
+               struct kobject *parent = &c->dev->device.kobj;
+               int err;
+
+               err = kobject_init_and_add(&chan->kobj, type, parent, "quickdata");
+               if (err) {
+                       dev_warn(to_dev(chan),
+                                "sysfs init error (%d), continuing...\n", err);
+                       kobject_put(&chan->kobj);
+                       set_bit(IOAT_KOBJ_INIT_FAIL, &chan->state);
+               }
+       }
+}
+
+void ioat_kobject_del(struct ioatdma_device *device)
+{
+       struct dma_device *dma = &device->common;
+       struct dma_chan *c;
+
+       list_for_each_entry(c, &dma->channels, device_node) {
+               struct ioat_chan_common *chan = to_chan_common(c);
+
+               if (!test_bit(IOAT_KOBJ_INIT_FAIL, &chan->state)) {
+                       kobject_del(&chan->kobj);
+                       kobject_put(&chan->kobj);
+               }
+       }
+}
+
 int __devinit ioat1_dma_probe(struct ioatdma_device *device, int dca)
 {
        struct pci_dev *pdev = device->pdev;
@@ -1093,6 +1198,7 @@ int __devinit ioat1_dma_probe(struct ioatdma_device *device, int dca)
 
        device->intr_quirk = ioat1_intr_quirk;
        device->enumerate_channels = ioat1_enumerate_channels;
+       device->self_test = ioat_dma_self_test;
        dma = &device->common;
        dma->device_prep_dma_memcpy = ioat1_dma_prep_memcpy;
        dma->device_issue_pending = ioat1_dma_memcpy_issue_pending;
@@ -1107,6 +1213,8 @@ int __devinit ioat1_dma_probe(struct ioatdma_device *device, int dca)
        err = ioat_register(device);
        if (err)
                return err;
+       ioat_kobject_add(device, &ioat1_ktype);
+
        if (dca)
                device->dca = ioat_dca_init(pdev, device->reg_base);
 
@@ -1119,6 +1227,8 @@ void __devexit ioat_dma_remove(struct ioatdma_device *device)
 
        ioat_disable_interrupts(device);
 
+       ioat_kobject_del(device);
+
        dma_async_device_unregister(dma);
 
        pci_pool_destroy(device->dma_pool);