Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
zcrypt_cex2a.c
Go to the documentation of this file.
1 /*
2  * zcrypt 2.1.0
3  *
4  * Copyright IBM Corp. 2001, 2012
5  * Author(s): Robert Burroughs
6  * Eric Rossman ([email protected])
7  *
8  * Hotplug & misc device support: Jochen Roehrig ([email protected])
9  * Major cleanup & driver split: Martin Schwidefsky <[email protected]>
10  * Ralph Wuerthner <[email protected]>
11  * MSGTYPE restruct: Holger Dengler <[email protected]>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26  */
27 
28 #include <linux/module.h>
29 #include <linux/slab.h>
30 #include <linux/init.h>
31 #include <linux/err.h>
32 #include <linux/atomic.h>
33 #include <asm/uaccess.h>
34 
35 #include "ap_bus.h"
36 #include "zcrypt_api.h"
37 #include "zcrypt_error.h"
38 #include "zcrypt_cex2a.h"
39 #include "zcrypt_msgtype50.h"
40 
41 #define CEX2A_MIN_MOD_SIZE 1 /* 8 bits */
42 #define CEX2A_MAX_MOD_SIZE 256 /* 2048 bits */
43 #define CEX3A_MIN_MOD_SIZE CEX2A_MIN_MOD_SIZE
44 #define CEX3A_MAX_MOD_SIZE 512 /* 4096 bits */
45 
46 #define CEX2A_SPEED_RATING 970
47 #define CEX3A_SPEED_RATING 900 /* Fixme: Needs finetuning */
48 
49 #define CEX2A_MAX_MESSAGE_SIZE 0x390 /* sizeof(struct type50_crb2_msg) */
50 #define CEX2A_MAX_RESPONSE_SIZE 0x110 /* max outputdatalength + type80_hdr */
51 
52 #define CEX3A_MAX_RESPONSE_SIZE 0x210 /* 512 bit modulus
53  * (max outputdatalength) +
54  * type80_hdr*/
55 #define CEX3A_MAX_MESSAGE_SIZE sizeof(struct type50_crb3_msg)
56 
57 #define CEX2A_CLEANUP_TIME (15*HZ)
58 #define CEX3A_CLEANUP_TIME CEX2A_CLEANUP_TIME
59 
60 static struct ap_device_id zcrypt_cex2a_ids[] = {
63  { /* end of list */ },
64 };
65 
66 MODULE_DEVICE_TABLE(ap, zcrypt_cex2a_ids);
67 MODULE_AUTHOR("IBM Corporation");
68 MODULE_DESCRIPTION("CEX2A Cryptographic Coprocessor device driver, " \
69  "Copyright IBM Corp. 2001, 2012");
70 MODULE_LICENSE("GPL");
71 
72 static int zcrypt_cex2a_probe(struct ap_device *ap_dev);
73 static void zcrypt_cex2a_remove(struct ap_device *ap_dev);
74 
75 static struct ap_driver zcrypt_cex2a_driver = {
76  .probe = zcrypt_cex2a_probe,
77  .remove = zcrypt_cex2a_remove,
78  .ids = zcrypt_cex2a_ids,
79  .request_timeout = CEX2A_CLEANUP_TIME,
80 };
81 
87 static int zcrypt_cex2a_probe(struct ap_device *ap_dev)
88 {
89  struct zcrypt_device *zdev = NULL;
90  int rc = 0;
91 
92  switch (ap_dev->device_type) {
95  if (!zdev)
96  return -ENOMEM;
98  zdev->type_string = "CEX2A";
101  zdev->short_crt = 1;
104  break;
107  if (!zdev)
108  return -ENOMEM;
110  zdev->type_string = "CEX3A";
114  if (ap_test_bit(&ap_dev->functions, AP_FUNC_MEX4K) &&
115  ap_test_bit(&ap_dev->functions, AP_FUNC_CRT4K)) {
118  }
119  zdev->short_crt = 1;
121  break;
122  }
123  if (!zdev)
124  return -ENODEV;
127  zdev->ap_dev = ap_dev;
128  zdev->online = 1;
129  ap_dev->reply = &zdev->reply;
130  ap_dev->private = zdev;
131  rc = zcrypt_device_register(zdev);
132  if (rc) {
133  ap_dev->private = NULL;
135  zcrypt_device_free(zdev);
136  }
137  return rc;
138 }
139 
144 static void zcrypt_cex2a_remove(struct ap_device *ap_dev)
145 {
146  struct zcrypt_device *zdev = ap_dev->private;
147  struct zcrypt_ops *zops = zdev->ops;
148 
151 }
152 
153 int __init zcrypt_cex2a_init(void)
154 {
155  return ap_driver_register(&zcrypt_cex2a_driver, THIS_MODULE, "cex2a");
156 }
157 
158 void __exit zcrypt_cex2a_exit(void)
159 {
160  ap_driver_unregister(&zcrypt_cex2a_driver);
161 }
162