2 * Copyright IBM Corp. 2012
3 * Author(s): Holger Dengler <hd@linux.vnet.ibm.com>
6 #include <linux/module.h>
7 #include <linux/slab.h>
8 #include <linux/init.h>
10 #include <linux/atomic.h>
11 #include <linux/uaccess.h>
14 #include "zcrypt_api.h"
15 #include "zcrypt_msgtype6.h"
16 #include "zcrypt_msgtype50.h"
17 #include "zcrypt_error.h"
18 #include "zcrypt_cex4.h"
20 #define CEX4A_MIN_MOD_SIZE 1 /* 8 bits */
21 #define CEX4A_MAX_MOD_SIZE_2K 256 /* 2048 bits */
22 #define CEX4A_MAX_MOD_SIZE_4K 512 /* 4096 bits */
24 #define CEX4C_MIN_MOD_SIZE 16 /* 256 bits */
25 #define CEX4C_MAX_MOD_SIZE 512 /* 4096 bits */
27 #define CEX4A_SPEED_RATING 900 /* TODO new card, new speed rating */
28 #define CEX4C_SPEED_RATING 6500 /* TODO new card, new speed rating */
29 #define CEX4P_SPEED_RATING 7000 /* TODO new card, new speed rating */
30 #define CEX5A_SPEED_RATING 450 /* TODO new card, new speed rating */
31 #define CEX5C_SPEED_RATING 3250 /* TODO new card, new speed rating */
32 #define CEX5P_SPEED_RATING 3500 /* TODO new card, new speed rating */
34 #define CEX4A_MAX_MESSAGE_SIZE MSGTYPE50_CRB3_MAX_MSG_SIZE
35 #define CEX4C_MAX_MESSAGE_SIZE MSGTYPE06_MAX_MSG_SIZE
37 /* Waiting time for requests to be processed.
38 * Currently there are some types of request which are not deterministic.
39 * But the maximum time limit managed by the stomper code is set to 60sec.
40 * Hence we have to wait at least that time period.
42 #define CEX4_CLEANUP_TIME (900*HZ)
44 static struct ap_device_id zcrypt_cex4_ids
[] = {
45 { AP_DEVICE(AP_DEVICE_TYPE_CEX4
) },
46 { AP_DEVICE(AP_DEVICE_TYPE_CEX5
) },
47 { /* end of list */ },
50 MODULE_DEVICE_TABLE(ap
, zcrypt_cex4_ids
);
51 MODULE_AUTHOR("IBM Corporation");
52 MODULE_DESCRIPTION("CEX4 Cryptographic Card device driver, " \
53 "Copyright IBM Corp. 2012");
54 MODULE_LICENSE("GPL");
56 static int zcrypt_cex4_probe(struct ap_device
*ap_dev
);
57 static void zcrypt_cex4_remove(struct ap_device
*ap_dev
);
59 static struct ap_driver zcrypt_cex4_driver
= {
60 .probe
= zcrypt_cex4_probe
,
61 .remove
= zcrypt_cex4_remove
,
62 .ids
= zcrypt_cex4_ids
,
63 .request_timeout
= CEX4_CLEANUP_TIME
,
67 * Probe function for CEX4 cards. It always accepts the AP device
68 * since the bus_match already checked the hardware type.
69 * @ap_dev: pointer to the AP device.
71 static int zcrypt_cex4_probe(struct ap_device
*ap_dev
)
73 struct zcrypt_device
*zdev
= NULL
;
76 switch (ap_dev
->device_type
) {
77 case AP_DEVICE_TYPE_CEX4
:
78 case AP_DEVICE_TYPE_CEX5
:
79 if (ap_test_bit(&ap_dev
->functions
, AP_FUNC_ACCEL
)) {
80 zdev
= zcrypt_device_alloc(CEX4A_MAX_MESSAGE_SIZE
);
83 if (ap_dev
->device_type
== AP_DEVICE_TYPE_CEX4
) {
84 zdev
->type_string
= "CEX4A";
85 zdev
->speed_rating
= CEX4A_SPEED_RATING
;
87 zdev
->type_string
= "CEX5A";
88 zdev
->speed_rating
= CEX5A_SPEED_RATING
;
90 zdev
->user_space_type
= ZCRYPT_CEX3A
;
91 zdev
->min_mod_size
= CEX4A_MIN_MOD_SIZE
;
92 if (ap_test_bit(&ap_dev
->functions
, AP_FUNC_MEX4K
) &&
93 ap_test_bit(&ap_dev
->functions
, AP_FUNC_CRT4K
)) {
95 CEX4A_MAX_MOD_SIZE_4K
;
96 zdev
->max_exp_bit_length
=
97 CEX4A_MAX_MOD_SIZE_4K
;
100 CEX4A_MAX_MOD_SIZE_2K
;
101 zdev
->max_exp_bit_length
=
102 CEX4A_MAX_MOD_SIZE_2K
;
105 zdev
->ops
= zcrypt_msgtype_request(MSGTYPE50_NAME
,
106 MSGTYPE50_VARIANT_DEFAULT
);
107 } else if (ap_test_bit(&ap_dev
->functions
, AP_FUNC_COPRO
)) {
108 zdev
= zcrypt_device_alloc(CEX4C_MAX_MESSAGE_SIZE
);
111 if (ap_dev
->device_type
== AP_DEVICE_TYPE_CEX4
) {
112 zdev
->type_string
= "CEX4C";
113 zdev
->speed_rating
= CEX4C_SPEED_RATING
;
115 zdev
->type_string
= "CEX5C";
116 zdev
->speed_rating
= CEX5C_SPEED_RATING
;
118 zdev
->user_space_type
= ZCRYPT_CEX3C
;
119 zdev
->min_mod_size
= CEX4C_MIN_MOD_SIZE
;
120 zdev
->max_mod_size
= CEX4C_MAX_MOD_SIZE
;
121 zdev
->max_exp_bit_length
= CEX4C_MAX_MOD_SIZE
;
123 zdev
->ops
= zcrypt_msgtype_request(MSGTYPE06_NAME
,
124 MSGTYPE06_VARIANT_DEFAULT
);
125 } else if (ap_test_bit(&ap_dev
->functions
, AP_FUNC_EP11
)) {
126 zdev
= zcrypt_device_alloc(CEX4C_MAX_MESSAGE_SIZE
);
129 if (ap_dev
->device_type
== AP_DEVICE_TYPE_CEX4
) {
130 zdev
->type_string
= "CEX4P";
131 zdev
->speed_rating
= CEX4P_SPEED_RATING
;
133 zdev
->type_string
= "CEX5P";
134 zdev
->speed_rating
= CEX5P_SPEED_RATING
;
136 zdev
->user_space_type
= ZCRYPT_CEX4
;
137 zdev
->min_mod_size
= CEX4C_MIN_MOD_SIZE
;
138 zdev
->max_mod_size
= CEX4C_MAX_MOD_SIZE
;
139 zdev
->max_exp_bit_length
= CEX4C_MAX_MOD_SIZE
;
141 zdev
->ops
= zcrypt_msgtype_request(MSGTYPE06_NAME
,
142 MSGTYPE06_VARIANT_EP11
);
148 zdev
->ap_dev
= ap_dev
;
150 ap_dev
->reply
= &zdev
->reply
;
151 ap_dev
->private = zdev
;
152 rc
= zcrypt_device_register(zdev
);
154 zcrypt_msgtype_release(zdev
->ops
);
155 ap_dev
->private = NULL
;
156 zcrypt_device_free(zdev
);
162 * This is called to remove the extended CEX4 driver information
163 * if an AP device is removed.
165 static void zcrypt_cex4_remove(struct ap_device
*ap_dev
)
167 struct zcrypt_device
*zdev
= ap_dev
->private;
168 struct zcrypt_ops
*zops
;
172 zcrypt_device_unregister(zdev
);
173 zcrypt_msgtype_release(zops
);
177 int __init
zcrypt_cex4_init(void)
179 return ap_driver_register(&zcrypt_cex4_driver
, THIS_MODULE
, "cex4");
182 void __exit
zcrypt_cex4_exit(void)
184 ap_driver_unregister(&zcrypt_cex4_driver
);
187 module_init(zcrypt_cex4_init
);
188 module_exit(zcrypt_cex4_exit
);