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 #define CEX4_CLEANUP_TIME (15*HZ)
35 static struct ap_device_id zcrypt_cex4_ids
[] = {
36 { AP_DEVICE(AP_DEVICE_TYPE_CEX4
) },
37 { /* end of list */ },
40 MODULE_DEVICE_TABLE(ap
, zcrypt_cex4_ids
);
41 MODULE_AUTHOR("IBM Corporation");
42 MODULE_DESCRIPTION("CEX4 Cryptographic Card device driver, " \
43 "Copyright IBM Corp. 2012");
44 MODULE_LICENSE("GPL");
46 static int zcrypt_cex4_probe(struct ap_device
*ap_dev
);
47 static void zcrypt_cex4_remove(struct ap_device
*ap_dev
);
49 static struct ap_driver zcrypt_cex4_driver
= {
50 .probe
= zcrypt_cex4_probe
,
51 .remove
= zcrypt_cex4_remove
,
52 .ids
= zcrypt_cex4_ids
,
53 .request_timeout
= CEX4_CLEANUP_TIME
,
57 * Probe function for CEX4 cards. It always accepts the AP device
58 * since the bus_match already checked the hardware type.
59 * @ap_dev: pointer to the AP device.
61 static int zcrypt_cex4_probe(struct ap_device
*ap_dev
)
63 struct zcrypt_device
*zdev
= NULL
;
66 switch (ap_dev
->device_type
) {
67 case AP_DEVICE_TYPE_CEX4
:
68 if (ap_test_bit(&ap_dev
->functions
, AP_FUNC_ACCEL
)) {
69 zdev
= zcrypt_device_alloc(CEX4A_MAX_MESSAGE_SIZE
);
72 zdev
->type_string
= "CEX4A";
73 zdev
->user_space_type
= ZCRYPT_CEX3A
;
74 zdev
->min_mod_size
= CEX4A_MIN_MOD_SIZE
;
75 if (ap_test_bit(&ap_dev
->functions
, AP_FUNC_MEX4K
) &&
76 ap_test_bit(&ap_dev
->functions
, AP_FUNC_CRT4K
)) {
78 CEX4A_MAX_MOD_SIZE_4K
;
79 zdev
->max_exp_bit_length
=
80 CEX4A_MAX_MOD_SIZE_4K
;
83 CEX4A_MAX_MOD_SIZE_2K
;
84 zdev
->max_exp_bit_length
=
85 CEX4A_MAX_MOD_SIZE_2K
;
88 zdev
->speed_rating
= CEX4A_SPEED_RATING
;
89 zdev
->ops
= zcrypt_msgtype_request(MSGTYPE50_NAME
,
90 MSGTYPE50_VARIANT_DEFAULT
);
91 } else if (ap_test_bit(&ap_dev
->functions
, AP_FUNC_COPRO
)) {
92 zdev
= zcrypt_device_alloc(CEX4C_MAX_MESSAGE_SIZE
);
95 zdev
->type_string
= "CEX4C";
96 zdev
->user_space_type
= ZCRYPT_CEX3C
;
97 zdev
->min_mod_size
= CEX4C_MIN_MOD_SIZE
;
98 zdev
->max_mod_size
= CEX4C_MAX_MOD_SIZE
;
99 zdev
->max_exp_bit_length
= CEX4C_MAX_MOD_SIZE
;
101 zdev
->speed_rating
= CEX4C_SPEED_RATING
;
102 zdev
->ops
= zcrypt_msgtype_request(MSGTYPE06_NAME
,
103 MSGTYPE06_VARIANT_DEFAULT
);
109 zdev
->ap_dev
= ap_dev
;
111 ap_dev
->reply
= &zdev
->reply
;
112 ap_dev
->private = zdev
;
113 rc
= zcrypt_device_register(zdev
);
115 zcrypt_msgtype_release(zdev
->ops
);
116 ap_dev
->private = NULL
;
117 zcrypt_device_free(zdev
);
123 * This is called to remove the extended CEX4 driver information
124 * if an AP device is removed.
126 static void zcrypt_cex4_remove(struct ap_device
*ap_dev
)
128 struct zcrypt_device
*zdev
= ap_dev
->private;
129 struct zcrypt_ops
*zops
;
133 zcrypt_device_unregister(zdev
);
134 zcrypt_msgtype_release(zops
);
138 int __init
zcrypt_cex4_init(void)
140 return ap_driver_register(&zcrypt_cex4_driver
, THIS_MODULE
, "cex4");
143 void __exit
zcrypt_cex4_exit(void)
145 ap_driver_unregister(&zcrypt_cex4_driver
);
148 module_init(zcrypt_cex4_init
);
149 module_exit(zcrypt_cex4_exit
);