arm: tegra: cardhu: remove NVSD debug message
[linux-2.6.git] / crypto / pcrypt.c
index 7153a50..29a89da 100644 (file)
 #include <linux/slab.h>
 #include <linux/notifier.h>
 #include <linux/kobject.h>
+#include <linux/cpu.h>
 #include <crypto/pcrypt.h>
 
-struct pcrypt_instance {
-       const char *name;
+struct padata_pcrypt {
        struct padata_instance *pinst;
        struct workqueue_struct *wq;
 
@@ -55,8 +55,8 @@ struct pcrypt_instance {
        struct notifier_block nblock;
 };
 
-static struct pcrypt_instance pencrypt;
-static struct pcrypt_instance pdecrypt;
+static struct padata_pcrypt pencrypt;
+static struct padata_pcrypt pdecrypt;
 static struct kset           *pcrypt_kset;
 
 struct pcrypt_instance_ctx {
@@ -70,7 +70,7 @@ struct pcrypt_aead_ctx {
 };
 
 static int pcrypt_do_parallel(struct padata_priv *padata, unsigned int *cb_cpu,
-                             struct pcrypt_instance *pcrypt)
+                             struct padata_pcrypt *pcrypt)
 {
        unsigned int cpu_index, cpu, i;
        struct pcrypt_cpumask *cpumask;
@@ -82,6 +82,9 @@ static int pcrypt_do_parallel(struct padata_priv *padata, unsigned int *cb_cpu,
        if (cpumask_test_cpu(cpu, cpumask->mask))
                        goto out;
 
+       if (!cpumask_weight(cpumask->mask))
+                       goto out;
+
        cpu_index = cpu % cpumask_weight(cpumask->mask);
 
        cpu = cpumask_first(cpumask->mask);
@@ -405,13 +408,14 @@ static void pcrypt_free(struct crypto_instance *inst)
 static int pcrypt_cpumask_change_notify(struct notifier_block *self,
                                        unsigned long val, void *data)
 {
-       struct pcrypt_instance *pcrypt;
+       struct padata_pcrypt *pcrypt;
        struct pcrypt_cpumask *new_mask, *old_mask;
+       struct padata_cpumask *cpumask = (struct padata_cpumask *)data;
 
        if (!(val & PADATA_CPU_SERIAL))
                return 0;
 
-       pcrypt = container_of(self, struct pcrypt_instance, nblock);
+       pcrypt = container_of(self, struct padata_pcrypt, nblock);
        new_mask = kmalloc(sizeof(*new_mask), GFP_KERNEL);
        if (!new_mask)
                return -ENOMEM;
@@ -422,7 +426,7 @@ static int pcrypt_cpumask_change_notify(struct notifier_block *self,
 
        old_mask = pcrypt->cb_cpumask;
 
-       padata_get_cpumask(pcrypt->pinst, PADATA_CPU_SERIAL, new_mask->mask);
+       cpumask_copy(new_mask->mask, cpumask->cbcpu);
        rcu_assign_pointer(pcrypt->cb_cpumask, new_mask);
        synchronize_rcu_bh();
 
@@ -443,18 +447,20 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
        return ret;
 }
 
-static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt,
-                                 const char *name)
+static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
+                             const char *name)
 {
        int ret = -ENOMEM;
        struct pcrypt_cpumask *mask;
 
-       pcrypt->name = name;
-       pcrypt->wq = create_workqueue(name);
+       get_online_cpus();
+
+       pcrypt->wq = alloc_workqueue(name,
+                                    WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
        if (!pcrypt->wq)
                goto err;
 
-       pcrypt->pinst = padata_alloc(pcrypt->wq);
+       pcrypt->pinst = padata_alloc_possible(pcrypt->wq);
        if (!pcrypt->pinst)
                goto err_destroy_workqueue;
 
@@ -466,7 +472,7 @@ static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt,
                goto err_free_padata;
        }
 
-       padata_get_cpumask(pcrypt->pinst, PADATA_CPU_SERIAL, mask->mask);
+       cpumask_and(mask->mask, cpu_possible_mask, cpu_active_mask);
        rcu_assign_pointer(pcrypt->cb_cpumask, mask);
 
        pcrypt->nblock.notifier_call = pcrypt_cpumask_change_notify;
@@ -478,7 +484,10 @@ static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt,
        if (ret)
                goto err_unregister_notifier;
 
+       put_online_cpus();
+
        return ret;
+
 err_unregister_notifier:
        padata_unregister_cpumask_notifier(pcrypt->pinst, &pcrypt->nblock);
 err_free_cpumask:
@@ -489,12 +498,13 @@ err_free_padata:
 err_destroy_workqueue:
        destroy_workqueue(pcrypt->wq);
 err:
+       put_online_cpus();
+
        return ret;
 }
 
-static void __pcrypt_deinit_instance(struct pcrypt_instance *pcrypt)
+static void pcrypt_fini_padata(struct padata_pcrypt *pcrypt)
 {
-       kobject_put(&pcrypt->pinst->kobj);
        free_cpumask_var(pcrypt->cb_cpumask->mask);
        kfree(pcrypt->cb_cpumask);
 
@@ -519,11 +529,11 @@ static int __init pcrypt_init(void)
        if (!pcrypt_kset)
                goto err;
 
-       err = __pcrypt_init_instance(&pencrypt, "pencrypt");
+       err = pcrypt_init_padata(&pencrypt, "pencrypt");
        if (err)
                goto err_unreg_kset;
 
-       err = __pcrypt_init_instance(&pdecrypt, "pdecrypt");
+       err = pcrypt_init_padata(&pdecrypt, "pdecrypt");
        if (err)
                goto err_deinit_pencrypt;
 
@@ -533,7 +543,7 @@ static int __init pcrypt_init(void)
        return crypto_register_template(&pcrypt_tmpl);
 
 err_deinit_pencrypt:
-       __pcrypt_deinit_instance(&pencrypt);
+       pcrypt_fini_padata(&pencrypt);
 err_unreg_kset:
        kset_unregister(pcrypt_kset);
 err:
@@ -542,8 +552,8 @@ err:
 
 static void __exit pcrypt_exit(void)
 {
-       __pcrypt_deinit_instance(&pencrypt);
-       __pcrypt_deinit_instance(&pdecrypt);
+       pcrypt_fini_padata(&pencrypt);
+       pcrypt_fini_padata(&pdecrypt);
 
        kset_unregister(pcrypt_kset);
        crypto_unregister_template(&pcrypt_tmpl);