mmc: sdhci: Issue sdhci RTPM put() after tuning
[linux-2.6.git] / crypto / pcrypt.c
index c9662e2..b2c99dc 100644 (file)
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/notifier.h>
+#include <linux/kobject.h>
+#include <linux/cpu.h>
 #include <crypto/pcrypt.h>
 
-struct pcrypt_instance {
+struct padata_pcrypt {
        struct padata_instance *pinst;
        struct workqueue_struct *wq;
 
@@ -53,9 +55,9 @@ 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 {
        struct crypto_spawn spawn;
@@ -68,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;
@@ -80,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);
@@ -275,11 +280,11 @@ static int pcrypt_aead_init_tfm(struct crypto_tfm *tfm)
 
        ictx->tfm_count++;
 
-       cpu_index = ictx->tfm_count % cpumask_weight(cpu_active_mask);
+       cpu_index = ictx->tfm_count % cpumask_weight(cpu_online_mask);
 
-       ctx->cb_cpu = cpumask_first(cpu_active_mask);
+       ctx->cb_cpu = cpumask_first(cpu_online_mask);
        for (cpu = 0; cpu < cpu_index; cpu++)
-               ctx->cb_cpu = cpumask_next(ctx->cb_cpu, cpu_active_mask);
+               ctx->cb_cpu = cpumask_next(ctx->cb_cpu, cpu_online_mask);
 
        cipher = crypto_spawn_aead(crypto_instance_ctx(inst));
 
@@ -403,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;
@@ -420,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();
 
@@ -429,17 +435,32 @@ static int pcrypt_cpumask_change_notify(struct notifier_block *self,
        return 0;
 }
 
-static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt,
-                                 const char *name)
+static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
+{
+       int ret;
+
+       pinst->kobj.kset = pcrypt_kset;
+       ret = kobject_add(&pinst->kobj, NULL, name);
+       if (!ret)
+               kobject_uevent(&pinst->kobj, KOBJ_ADD);
+
+       return ret;
+}
+
+static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
+                             const char *name)
 {
        int ret = -ENOMEM;
        struct pcrypt_cpumask *mask;
 
-       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;
 
@@ -451,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_online_mask);
        rcu_assign_pointer(pcrypt->cb_cpumask, mask);
 
        pcrypt->nblock.notifier_call = pcrypt_cpumask_change_notify;
@@ -459,7 +480,16 @@ static int __pcrypt_init_instance(struct pcrypt_instance *pcrypt,
        if (ret)
                goto err_free_cpumask;
 
+       ret = pcrypt_sysfs_add(pcrypt->pinst, name);
+       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:
        free_cpumask_var(mask->mask);
        kfree(mask);
@@ -468,10 +498,12 @@ 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)
 {
        free_cpumask_var(pcrypt->cb_cpumask->mask);
        kfree(pcrypt->cb_cpumask);
@@ -491,13 +523,17 @@ static struct crypto_template pcrypt_tmpl = {
 
 static int __init pcrypt_init(void)
 {
-       int err;
+       int err = -ENOMEM;
 
-       err = __pcrypt_init_instance(&pencrypt, "pencrypt");
-       if (err)
+       pcrypt_kset = kset_create_and_add("pcrypt", NULL, kernel_kobj);
+       if (!pcrypt_kset)
                goto err;
 
-       err = __pcrypt_init_instance(&pdecrypt, "pdecrypt");
+       err = pcrypt_init_padata(&pencrypt, "pencrypt");
+       if (err)
+               goto err_unreg_kset;
+
+       err = pcrypt_init_padata(&pdecrypt, "pdecrypt");
        if (err)
                goto err_deinit_pencrypt;
 
@@ -507,16 +543,19 @@ 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:
        return 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);
 }