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 */
30 #define CEX4A_MAX_MESSAGE_SIZE MSGTYPE50_CRB3_MAX_MSG_SIZE
31 #define CEX4C_MAX_MESSAGE_SIZE MSGTYPE06_MAX_MSG_SIZE
33 /* Waiting time for requests to be processed.
34 * Currently there are some types of request which are not deterministic.
35 * But the maximum time limit managed by the stomper code is set to 60sec.
36 * Hence we have to wait at least that time period.
38 #define CEX4_CLEANUP_TIME (61*HZ)
40 static struct ap_device_id zcrypt_cex4_ids
[] = {
41 { AP_DEVICE(AP_DEVICE_TYPE_CEX4
) },
42 { /* end of list */ },
45 MODULE_DEVICE_TABLE(ap
, zcrypt_cex4_ids
);
46 MODULE_AUTHOR("IBM Corporation");
47 MODULE_DESCRIPTION("CEX4 Cryptographic Card device driver, " \
48 "Copyright IBM Corp. 2012");
49 MODULE_LICENSE("GPL");
51 static int zcrypt_cex4_probe(struct ap_device
*ap_dev
);
52 static void zcrypt_cex4_remove(struct ap_device
*ap_dev
);
54 static struct ap_driver zcrypt_cex4_driver
= {
55 .probe
= zcrypt_cex4_probe
,
56 .remove
= zcrypt_cex4_remove
,
57 .ids
= zcrypt_cex4_ids
,
58 .request_timeout
= CEX4_CLEANUP_TIME
,
62 * Probe function for CEX4 cards. It always accepts the AP device
63 * since the bus_match already checked the hardware type.
64 * @ap_dev: pointer to the AP device.
66 static int zcrypt_cex4_probe(struct ap_device
*ap_dev
)
68 struct zcrypt_device
*zdev
= NULL
;
71 switch (ap_dev
->device_type
) {
72 case AP_DEVICE_TYPE_CEX4
:
73 if (ap_test_bit(&ap_dev
->functions
, AP_FUNC_ACCEL
)) {
74 zdev
= zcrypt_device_alloc(CEX4A_MAX_MESSAGE_SIZE
);
77 zdev
->type_string
= "CEX4A";
78 zdev
->user_space_type
= ZCRYPT_CEX3A
;
79 zdev
->min_mod_size
= CEX4A_MIN_MOD_SIZE
;
80 if (ap_test_bit(&ap_dev
->functions
, AP_FUNC_MEX4K
) &&
81 ap_test_bit(&ap_dev
->functions
, AP_FUNC_CRT4K
)) {
83 CEX4A_MAX_MOD_SIZE_4K
;
84 zdev
->max_exp_bit_length
=
85 CEX4A_MAX_MOD_SIZE_4K
;
88 CEX4A_MAX_MOD_SIZE_2K
;
89 zdev
->max_exp_bit_length
=
90 CEX4A_MAX_MOD_SIZE_2K
;
93 zdev
->speed_rating
= CEX4A_SPEED_RATING
;
94 zdev
->ops
= zcrypt_msgtype_request(MSGTYPE50_NAME
,
95 MSGTYPE50_VARIANT_DEFAULT
);
96 } else if (ap_test_bit(&ap_dev
->functions
, AP_FUNC_COPRO
)) {
97 zdev
= zcrypt_device_alloc(CEX4C_MAX_MESSAGE_SIZE
);
100 zdev
->type_string
= "CEX4C";
101 zdev
->user_space_type
= ZCRYPT_CEX3C
;
102 zdev
->min_mod_size
= CEX4C_MIN_MOD_SIZE
;
103 zdev
->max_mod_size
= CEX4C_MAX_MOD_SIZE
;
104 zdev
->max_exp_bit_length
= CEX4C_MAX_MOD_SIZE
;
106 zdev
->speed_rating
= CEX4C_SPEED_RATING
;
107 zdev
->ops
= zcrypt_msgtype_request(MSGTYPE06_NAME
,
108 MSGTYPE06_VARIANT_DEFAULT
);
109 } else if (ap_test_bit(&ap_dev
->functions
, AP_FUNC_EP11
)) {
110 zdev
= zcrypt_device_alloc(CEX4C_MAX_MESSAGE_SIZE
);
113 zdev
->type_string
= "CEX4P";
114 zdev
->user_space_type
= ZCRYPT_CEX4
;
115 zdev
->min_mod_size
= CEX4C_MIN_MOD_SIZE
;
116 zdev
->max_mod_size
= CEX4C_MAX_MOD_SIZE
;
117 zdev
->max_exp_bit_length
= CEX4C_MAX_MOD_SIZE
;
119 zdev
->speed_rating
= CEX4C_SPEED_RATING
;
120 zdev
->ops
= zcrypt_msgtype_request(MSGTYPE06_NAME
,
121 MSGTYPE06_VARIANT_EP11
);
127 zdev
->ap_dev
= ap_dev
;
129 ap_dev
->reply
= &zdev
->reply
;
130 ap_dev
->private = zdev
;
131 rc
= zcrypt_device_register(zdev
);
133 zcrypt_msgtype_release(zdev
->ops
);
134 ap_dev
->private = NULL
;
135 zcrypt_device_free(zdev
);
141 * This is called to remove the extended CEX4 driver information
142 * if an AP device is removed.
144 static void zcrypt_cex4_remove(struct ap_device
*ap_dev
)
146 struct zcrypt_device
*zdev
= ap_dev
->private;
147 struct zcrypt_ops
*zops
;
151 zcrypt_device_unregister(zdev
);
152 zcrypt_msgtype_release(zops
);
156 int __init
zcrypt_cex4_init(void)
158 return ap_driver_register(&zcrypt_cex4_driver
, THIS_MODULE
, "cex4");
161 void __exit
zcrypt_cex4_exit(void)
163 ap_driver_unregister(&zcrypt_cex4_driver
);
166 module_init(zcrypt_cex4_init
);
167 module_exit(zcrypt_cex4_exit
);