sh_eth: fix EESIPR values for SH77{34|63}
[linux/fpc-iii.git] / drivers / s390 / crypto / zcrypt_card.c
blob53436ea522305dfd27fa3e89d216d6b1d910ae9e
1 /*
2 * zcrypt 2.1.0
4 * Copyright IBM Corp. 2001, 2012
5 * Author(s): Robert Burroughs
6 * Eric Rossman (edrossma@us.ibm.com)
7 * Cornelia Huck <cornelia.huck@de.ibm.com>
9 * Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
10 * Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
11 * Ralph Wuerthner <rwuerthn@de.ibm.com>
12 * MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
17 * any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
28 #include <linux/miscdevice.h>
29 #include <linux/fs.h>
30 #include <linux/proc_fs.h>
31 #include <linux/seq_file.h>
32 #include <linux/compat.h>
33 #include <linux/slab.h>
34 #include <linux/atomic.h>
35 #include <linux/uaccess.h>
36 #include <linux/hw_random.h>
37 #include <linux/debugfs.h>
38 #include <asm/debug.h>
40 #include "zcrypt_debug.h"
41 #include "zcrypt_api.h"
43 #include "zcrypt_msgtype6.h"
44 #include "zcrypt_msgtype50.h"
47 * Device attributes common for all crypto card devices.
50 static ssize_t zcrypt_card_type_show(struct device *dev,
51 struct device_attribute *attr, char *buf)
53 struct zcrypt_card *zc = to_ap_card(dev)->private;
55 return snprintf(buf, PAGE_SIZE, "%s\n", zc->type_string);
58 static DEVICE_ATTR(type, 0444, zcrypt_card_type_show, NULL);
60 static ssize_t zcrypt_card_online_show(struct device *dev,
61 struct device_attribute *attr,
62 char *buf)
64 struct zcrypt_card *zc = to_ap_card(dev)->private;
66 return snprintf(buf, PAGE_SIZE, "%d\n", zc->online);
69 static ssize_t zcrypt_card_online_store(struct device *dev,
70 struct device_attribute *attr,
71 const char *buf, size_t count)
73 struct zcrypt_card *zc = to_ap_card(dev)->private;
74 struct zcrypt_queue *zq;
75 int online, id;
77 if (sscanf(buf, "%d\n", &online) != 1 || online < 0 || online > 1)
78 return -EINVAL;
80 zc->online = online;
81 id = zc->card->id;
83 ZCRYPT_DBF(DBF_INFO, "card=%02x online=%d\n", id, online);
85 spin_lock(&zcrypt_list_lock);
86 list_for_each_entry(zq, &zc->zqueues, list)
87 zcrypt_queue_force_online(zq, online);
88 spin_unlock(&zcrypt_list_lock);
89 return count;
92 static DEVICE_ATTR(online, 0644, zcrypt_card_online_show,
93 zcrypt_card_online_store);
95 static struct attribute *zcrypt_card_attrs[] = {
96 &dev_attr_type.attr,
97 &dev_attr_online.attr,
98 NULL,
101 static struct attribute_group zcrypt_card_attr_group = {
102 .attrs = zcrypt_card_attrs,
105 struct zcrypt_card *zcrypt_card_alloc(void)
107 struct zcrypt_card *zc;
109 zc = kzalloc(sizeof(struct zcrypt_card), GFP_KERNEL);
110 if (!zc)
111 return NULL;
112 INIT_LIST_HEAD(&zc->list);
113 INIT_LIST_HEAD(&zc->zqueues);
114 kref_init(&zc->refcount);
115 return zc;
117 EXPORT_SYMBOL(zcrypt_card_alloc);
119 void zcrypt_card_free(struct zcrypt_card *zc)
121 kfree(zc);
123 EXPORT_SYMBOL(zcrypt_card_free);
125 static void zcrypt_card_release(struct kref *kref)
127 struct zcrypt_card *zdev =
128 container_of(kref, struct zcrypt_card, refcount);
129 zcrypt_card_free(zdev);
132 void zcrypt_card_get(struct zcrypt_card *zc)
134 kref_get(&zc->refcount);
136 EXPORT_SYMBOL(zcrypt_card_get);
138 int zcrypt_card_put(struct zcrypt_card *zc)
140 return kref_put(&zc->refcount, zcrypt_card_release);
142 EXPORT_SYMBOL(zcrypt_card_put);
145 * zcrypt_card_register() - Register a crypto card device.
146 * @zc: Pointer to a crypto card device
148 * Register a crypto card device. Returns 0 if successful.
150 int zcrypt_card_register(struct zcrypt_card *zc)
152 int rc;
154 rc = sysfs_create_group(&zc->card->ap_dev.device.kobj,
155 &zcrypt_card_attr_group);
156 if (rc)
157 return rc;
159 spin_lock(&zcrypt_list_lock);
160 list_add_tail(&zc->list, &zcrypt_card_list);
161 spin_unlock(&zcrypt_list_lock);
163 zc->online = 1;
165 ZCRYPT_DBF(DBF_INFO, "card=%02x register online=1\n", zc->card->id);
167 return rc;
169 EXPORT_SYMBOL(zcrypt_card_register);
172 * zcrypt_card_unregister(): Unregister a crypto card device.
173 * @zc: Pointer to crypto card device
175 * Unregister a crypto card device.
177 void zcrypt_card_unregister(struct zcrypt_card *zc)
179 ZCRYPT_DBF(DBF_INFO, "card=%02x unregister\n", zc->card->id);
181 spin_lock(&zcrypt_list_lock);
182 list_del_init(&zc->list);
183 spin_unlock(&zcrypt_list_lock);
184 sysfs_remove_group(&zc->card->ap_dev.device.kobj,
185 &zcrypt_card_attr_group);
187 EXPORT_SYMBOL(zcrypt_card_unregister);