]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/infiniband/hw/ehca/ehca_pd.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6
[linux-2.6-omap-h63xx.git] / drivers / infiniband / hw / ehca / ehca_pd.c
index d5345e5b3cd661a0de94104fb16bd4f1fca33c76..43bcf085fcf21808c11b6075cc6fd4d80e7f926d 100644 (file)
@@ -49,16 +49,21 @@ struct ib_pd *ehca_alloc_pd(struct ib_device *device,
                            struct ib_ucontext *context, struct ib_udata *udata)
 {
        struct ehca_pd *pd;
+       int i;
 
-       pd = kmem_cache_alloc(pd_cache, GFP_KERNEL);
+       pd = kmem_cache_zalloc(pd_cache, GFP_KERNEL);
        if (!pd) {
                ehca_err(device, "device=%p context=%p out of memory",
                         device, context);
                return ERR_PTR(-ENOMEM);
        }
 
-       memset(pd, 0, sizeof(struct ehca_pd));
        pd->ownpid = current->tgid;
+       for (i = 0; i < 2; i++) {
+               INIT_LIST_HEAD(&pd->free[i]);
+               INIT_LIST_HEAD(&pd->full[i]);
+       }
+       mutex_init(&pd->lock);
 
        /*
         * Kernel PD: when device = -1, 0
@@ -82,6 +87,8 @@ int ehca_dealloc_pd(struct ib_pd *pd)
 {
        u32 cur_pid = current->tgid;
        struct ehca_pd *my_pd = container_of(pd, struct ehca_pd, ib_pd);
+       int i, leftovers = 0;
+       struct ipz_small_queue_page *page, *tmp;
 
        if (my_pd->ib_pd.uobject && my_pd->ib_pd.uobject->context &&
            my_pd->ownpid != cur_pid) {
@@ -90,8 +97,20 @@ int ehca_dealloc_pd(struct ib_pd *pd)
                return -EINVAL;
        }
 
-       kmem_cache_free(pd_cache,
-                       container_of(pd, struct ehca_pd, ib_pd));
+       for (i = 0; i < 2; i++) {
+               list_splice(&my_pd->full[i], &my_pd->free[i]);
+               list_for_each_entry_safe(page, tmp, &my_pd->free[i], list) {
+                       leftovers = 1;
+                       free_page(page->page);
+                       kmem_cache_free(small_qp_cache, page);
+               }
+       }
+
+       if (leftovers)
+               ehca_warn(pd->device,
+                         "Some small queue pages were not freed");
+
+       kmem_cache_free(pd_cache, my_pd);
 
        return 0;
 }
@@ -101,7 +120,7 @@ int ehca_init_pd_cache(void)
        pd_cache = kmem_cache_create("ehca_cache_pd",
                                     sizeof(struct ehca_pd), 0,
                                     SLAB_HWCACHE_ALIGN,
-                                    NULL, NULL);
+                                    NULL);
        if (!pd_cache)
                return -ENOMEM;
        return 0;