25
25
#include "zcrypt_msgtype6.h"
26
26
#include "zcrypt_cex2c.h"
27
27
#include "zcrypt_cca_key.h"
28
+ #include "zcrypt_ccamisc.h"
28
29
29
30
#define CEX2C_MIN_MOD_SIZE 16 /* 128 bits */
30
31
#define CEX2C_MAX_MOD_SIZE 256 /* 2048 bits */
@@ -58,6 +59,91 @@ static struct ap_device_id zcrypt_cex2c_queue_ids[] = {
58
59
59
60
MODULE_DEVICE_TABLE (ap , zcrypt_cex2c_queue_ids );
60
61
62
+ /*
63
+ * CCA card additional device attributes
64
+ */
65
+ static ssize_t cca_serialnr_show (struct device * dev ,
66
+ struct device_attribute * attr ,
67
+ char * buf )
68
+ {
69
+ struct cca_info ci ;
70
+ struct ap_card * ac = to_ap_card (dev );
71
+ struct zcrypt_card * zc = ac -> private ;
72
+
73
+ memset (& ci , 0 , sizeof (ci ));
74
+
75
+ if (ap_domain_index >= 0 )
76
+ cca_get_info (ac -> id , ap_domain_index , & ci , zc -> online );
77
+
78
+ return scnprintf (buf , PAGE_SIZE , "%s\n" , ci .serial );
79
+ }
80
+
81
+ static struct device_attribute dev_attr_cca_serialnr =
82
+ __ATTR (serialnr , 0444 , cca_serialnr_show , NULL );
83
+
84
+ static struct attribute * cca_card_attrs [] = {
85
+ & dev_attr_cca_serialnr .attr ,
86
+ NULL ,
87
+ };
88
+
89
+ static const struct attribute_group cca_card_attr_grp = {
90
+ .attrs = cca_card_attrs ,
91
+ };
92
+
93
+ /*
94
+ * CCA queue additional device attributes
95
+ */
96
+ static ssize_t cca_mkvps_show (struct device * dev ,
97
+ struct device_attribute * attr ,
98
+ char * buf )
99
+ {
100
+ int n = 0 ;
101
+ struct cca_info ci ;
102
+ struct zcrypt_queue * zq = to_ap_queue (dev )-> private ;
103
+ static const char * const cao_state [] = { "invalid" , "valid" };
104
+ static const char * const new_state [] = { "empty" , "partial" , "full" };
105
+
106
+ memset (& ci , 0 , sizeof (ci ));
107
+
108
+ cca_get_info (AP_QID_CARD (zq -> queue -> qid ),
109
+ AP_QID_QUEUE (zq -> queue -> qid ),
110
+ & ci , zq -> online );
111
+
112
+ if (ci .new_mk_state >= '1' && ci .new_mk_state <= '3' )
113
+ n = scnprintf (buf , PAGE_SIZE , "AES NEW: %s 0x%016llx\n" ,
114
+ new_state [ci .new_mk_state - '1' ], ci .new_mkvp );
115
+ else
116
+ n = scnprintf (buf , PAGE_SIZE , "AES NEW: - -\n" );
117
+
118
+ if (ci .cur_mk_state >= '1' && ci .cur_mk_state <= '2' )
119
+ n += scnprintf (buf + n , PAGE_SIZE - n ,
120
+ "AES CUR: %s 0x%016llx\n" ,
121
+ cao_state [ci .cur_mk_state - '1' ], ci .cur_mkvp );
122
+ else
123
+ n += scnprintf (buf + n , PAGE_SIZE - n , "AES CUR: - -\n" );
124
+
125
+ if (ci .old_mk_state >= '1' && ci .old_mk_state <= '2' )
126
+ n += scnprintf (buf + n , PAGE_SIZE - n ,
127
+ "AES OLD: %s 0x%016llx\n" ,
128
+ cao_state [ci .old_mk_state - '1' ], ci .old_mkvp );
129
+ else
130
+ n += scnprintf (buf + n , PAGE_SIZE - n , "AES OLD: - -\n" );
131
+
132
+ return n ;
133
+ }
134
+
135
+ static struct device_attribute dev_attr_cca_mkvps =
136
+ __ATTR (mkvps , 0444 , cca_mkvps_show , NULL );
137
+
138
+ static struct attribute * cca_queue_attrs [] = {
139
+ & dev_attr_cca_mkvps .attr ,
140
+ NULL ,
141
+ };
142
+
143
+ static const struct attribute_group cca_queue_attr_grp = {
144
+ .attrs = cca_queue_attrs ,
145
+ };
146
+
61
147
/**
62
148
* Large random number detection function. Its sends a message to a CEX2C/CEX3C
63
149
* card to find out if large random numbers are supported.
@@ -178,6 +264,17 @@ static int zcrypt_cex2c_card_probe(struct ap_device *ap_dev)
178
264
if (rc ) {
179
265
ac -> private = NULL ;
180
266
zcrypt_card_free (zc );
267
+ return rc ;
268
+ }
269
+
270
+ if (ap_test_bit (& ac -> functions , AP_FUNC_COPRO )) {
271
+ rc = sysfs_create_group (& ap_dev -> device .kobj ,
272
+ & cca_card_attr_grp );
273
+ if (rc ) {
274
+ zcrypt_card_unregister (zc );
275
+ ac -> private = NULL ;
276
+ zcrypt_card_free (zc );
277
+ }
181
278
}
182
279
183
280
return rc ;
@@ -189,8 +286,11 @@ static int zcrypt_cex2c_card_probe(struct ap_device *ap_dev)
189
286
*/
190
287
static void zcrypt_cex2c_card_remove (struct ap_device * ap_dev )
191
288
{
289
+ struct ap_card * ac = to_ap_card (& ap_dev -> device );
192
290
struct zcrypt_card * zc = to_ap_card (& ap_dev -> device )-> private ;
193
291
292
+ if (ap_test_bit (& ac -> functions , AP_FUNC_COPRO ))
293
+ sysfs_remove_group (& ap_dev -> device .kobj , & cca_card_attr_grp );
194
294
if (zc )
195
295
zcrypt_card_unregister (zc );
196
296
}
@@ -239,7 +339,19 @@ static int zcrypt_cex2c_queue_probe(struct ap_device *ap_dev)
239
339
if (rc ) {
240
340
aq -> private = NULL ;
241
341
zcrypt_queue_free (zq );
342
+ return rc ;
343
+ }
344
+
345
+ if (ap_test_bit (& aq -> card -> functions , AP_FUNC_COPRO )) {
346
+ rc = sysfs_create_group (& ap_dev -> device .kobj ,
347
+ & cca_queue_attr_grp );
348
+ if (rc ) {
349
+ zcrypt_queue_unregister (zq );
350
+ aq -> private = NULL ;
351
+ zcrypt_queue_free (zq );
352
+ }
242
353
}
354
+
243
355
return rc ;
244
356
}
245
357
@@ -252,6 +364,8 @@ static void zcrypt_cex2c_queue_remove(struct ap_device *ap_dev)
252
364
struct ap_queue * aq = to_ap_queue (& ap_dev -> device );
253
365
struct zcrypt_queue * zq = aq -> private ;
254
366
367
+ if (ap_test_bit (& aq -> card -> functions , AP_FUNC_COPRO ))
368
+ sysfs_remove_group (& ap_dev -> device .kobj , & cca_queue_attr_grp );
255
369
if (zq )
256
370
zcrypt_queue_unregister (zq );
257
371
}
0 commit comments