Skip to content

Commit a303e88

Browse files
hfreudeheicarst
authored andcommitted
s390/zcrypt: provide cex4 cca sysfs attributes for cex3
This patch introduces the sysfs attributes serialnr and mkvps for cex2c and cex3c cards. These sysfs attributes are available for cex4c and higher since commit 7c4e91c ("s390/zcrypt: new sysfs attributes serialnr and mkvps")' and this patch now provides the same for the older cex2 and cex3 cards. Signed-off-by: Harald Freudenberger <[email protected]> Signed-off-by: Heiko Carstens <[email protected]>
1 parent dc4b6de commit a303e88

File tree

2 files changed

+132
-8
lines changed

2 files changed

+132
-8
lines changed

drivers/s390/crypto/zcrypt_cex2c.c

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "zcrypt_msgtype6.h"
2626
#include "zcrypt_cex2c.h"
2727
#include "zcrypt_cca_key.h"
28+
#include "zcrypt_ccamisc.h"
2829

2930
#define CEX2C_MIN_MOD_SIZE 16 /* 128 bits */
3031
#define CEX2C_MAX_MOD_SIZE 256 /* 2048 bits */
@@ -58,6 +59,91 @@ static struct ap_device_id zcrypt_cex2c_queue_ids[] = {
5859

5960
MODULE_DEVICE_TABLE(ap, zcrypt_cex2c_queue_ids);
6061

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+
61147
/**
62148
* Large random number detection function. Its sends a message to a CEX2C/CEX3C
63149
* 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)
178264
if (rc) {
179265
ac->private = NULL;
180266
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+
}
181278
}
182279

183280
return rc;
@@ -189,8 +286,11 @@ static int zcrypt_cex2c_card_probe(struct ap_device *ap_dev)
189286
*/
190287
static void zcrypt_cex2c_card_remove(struct ap_device *ap_dev)
191288
{
289+
struct ap_card *ac = to_ap_card(&ap_dev->device);
192290
struct zcrypt_card *zc = to_ap_card(&ap_dev->device)->private;
193291

292+
if (ap_test_bit(&ac->functions, AP_FUNC_COPRO))
293+
sysfs_remove_group(&ap_dev->device.kobj, &cca_card_attr_grp);
194294
if (zc)
195295
zcrypt_card_unregister(zc);
196296
}
@@ -239,7 +339,19 @@ static int zcrypt_cex2c_queue_probe(struct ap_device *ap_dev)
239339
if (rc) {
240340
aq->private = NULL;
241341
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+
}
242353
}
354+
243355
return rc;
244356
}
245357

@@ -252,6 +364,8 @@ static void zcrypt_cex2c_queue_remove(struct ap_device *ap_dev)
252364
struct ap_queue *aq = to_ap_queue(&ap_dev->device);
253365
struct zcrypt_queue *zq = aq->private;
254366

367+
if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO))
368+
sysfs_remove_group(&ap_dev->device.kobj, &cca_queue_attr_grp);
255369
if (zq)
256370
zcrypt_queue_unregister(zq);
257371
}

drivers/s390/crypto/zcrypt_cex4.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -529,22 +529,27 @@ static int zcrypt_cex4_card_probe(struct ap_device *ap_dev)
529529
if (rc) {
530530
ac->private = NULL;
531531
zcrypt_card_free(zc);
532-
goto out;
532+
return rc;
533533
}
534534

535535
if (ap_test_bit(&ac->functions, AP_FUNC_COPRO)) {
536536
rc = sysfs_create_group(&ap_dev->device.kobj,
537537
&cca_card_attr_grp);
538-
if (rc)
538+
if (rc) {
539539
zcrypt_card_unregister(zc);
540+
ac->private = NULL;
541+
zcrypt_card_free(zc);
542+
}
540543
} else if (ap_test_bit(&ac->functions, AP_FUNC_EP11)) {
541544
rc = sysfs_create_group(&ap_dev->device.kobj,
542545
&ep11_card_attr_grp);
543-
if (rc)
546+
if (rc) {
544547
zcrypt_card_unregister(zc);
548+
ac->private = NULL;
549+
zcrypt_card_free(zc);
550+
}
545551
}
546552

547-
out:
548553
return rc;
549554
}
550555

@@ -617,22 +622,27 @@ static int zcrypt_cex4_queue_probe(struct ap_device *ap_dev)
617622
if (rc) {
618623
aq->private = NULL;
619624
zcrypt_queue_free(zq);
620-
goto out;
625+
return rc;
621626
}
622627

623628
if (ap_test_bit(&aq->card->functions, AP_FUNC_COPRO)) {
624629
rc = sysfs_create_group(&ap_dev->device.kobj,
625630
&cca_queue_attr_grp);
626-
if (rc)
631+
if (rc) {
627632
zcrypt_queue_unregister(zq);
633+
aq->private = NULL;
634+
zcrypt_queue_free(zq);
635+
}
628636
} else if (ap_test_bit(&aq->card->functions, AP_FUNC_EP11)) {
629637
rc = sysfs_create_group(&ap_dev->device.kobj,
630638
&ep11_queue_attr_grp);
631-
if (rc)
639+
if (rc) {
632640
zcrypt_queue_unregister(zq);
641+
aq->private = NULL;
642+
zcrypt_queue_free(zq);
643+
}
633644
}
634645

635-
out:
636646
return rc;
637647
}
638648

0 commit comments

Comments
 (0)