Skip to content

Commit af4a722

Browse files
Harald FreudenbergerMartin Schwidefsky
authored andcommitted
s390/zcrypt: Support up to 256 crypto adapters.
There was an artificial restriction on the card/adapter id to only 6 bits but all the AP commands do support adapter ids with 8 bit. This patch removes this restriction to 64 adapters and now up to 256 adapter can get addressed. Some of the ioctl calls work on the max number of cards possible (which was 64). These ioctls are now deprecated but still supported. All the defines, structs and ioctl interface declarations have been kept for compabibility. There are now new ioctls (and defines for these) with an additional '2' appended which provide the extended versions with 256 cards supported. Signed-off-by: Harald Freudenberger <freude@linux.vnet.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 71cbbff commit af4a722

File tree

6 files changed

+237
-120
lines changed

6 files changed

+237
-120
lines changed

arch/s390/include/asm/ap.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
*/
2121
typedef unsigned int ap_qid_t;
2222

23-
#define AP_MKQID(_card, _queue) (((_card) & 63) << 8 | ((_queue) & 255))
24-
#define AP_QID_CARD(_qid) (((_qid) >> 8) & 63)
25-
#define AP_QID_QUEUE(_qid) ((_qid) & 255)
23+
#define AP_MKQID(_card, _queue) (((_card) & 0xff) << 8 | ((_queue) & 0xff))
24+
#define AP_QID_CARD(_qid) (((_qid) >> 8) & 0xff)
25+
#define AP_QID_QUEUE(_qid) ((_qid) & 0xff)
2626

2727
/**
2828
* struct ap_queue_status - Holds the AP queue status.

arch/s390/include/uapi/asm/zcrypt.h

Lines changed: 78 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ struct ep11_urb {
203203
} __attribute__((packed));
204204

205205
/**
206-
* struct zcrypt_device_status
206+
* struct zcrypt_device_status_ext
207207
* @hwtype: raw hardware type
208-
* @qid: 6 bit device index, 8 bit domain
208+
* @qid: 8 bit device index, 8 bit domain
209209
* @functions: AP device function bit field 'abcdef'
210210
* a, b, c = reserved
211211
* d = CCA coprocessor
@@ -214,28 +214,23 @@ struct ep11_urb {
214214
* @online online status
215215
* @reserved reserved
216216
*/
217-
struct zcrypt_device_status {
217+
struct zcrypt_device_status_ext {
218218
unsigned int hwtype:8;
219-
unsigned int qid:14;
219+
unsigned int qid:16;
220220
unsigned int online:1;
221221
unsigned int functions:6;
222-
unsigned int reserved:3;
222+
unsigned int reserved:1;
223223
};
224224

225-
#define MAX_ZDEV_CARDIDS 64
226-
#define MAX_ZDEV_DOMAINS 256
225+
#define MAX_ZDEV_CARDIDS_EXT 256
226+
#define MAX_ZDEV_DOMAINS_EXT 256
227227

228-
/**
229-
* Maximum number of zcrypt devices
230-
*/
231-
#define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS)
228+
/* Maximum number of zcrypt devices */
229+
#define MAX_ZDEV_ENTRIES_EXT (MAX_ZDEV_CARDIDS_EXT * MAX_ZDEV_DOMAINS_EXT)
232230

233-
/**
234-
* zcrypt_device_matrix
235-
* Device matrix of all zcrypt devices
236-
*/
237-
struct zcrypt_device_matrix {
238-
struct zcrypt_device_status device[MAX_ZDEV_ENTRIES];
231+
/* Device matrix of all zcrypt devices */
232+
struct zcrypt_device_matrix_ext {
233+
struct zcrypt_device_status_ext device[MAX_ZDEV_ENTRIES_EXT];
239234
};
240235

241236
#define AUTOSELECT ((unsigned int)0xFFFFFFFF)
@@ -270,39 +265,35 @@ struct zcrypt_device_matrix {
270265
* ZSENDEP11CPRB
271266
* Send an arbitrary EP11 CPRB to an EP11 coprocessor crypto card.
272267
*
273-
* Z90STAT_STATUS_MASK
274-
* Return an 64 element array of unsigned chars for the status of
275-
* all devices.
268+
* ZCRYPT_DEVICE_STATUS
269+
* The given struct zcrypt_device_matrix_ext is updated with
270+
* status information for each currently known apqn.
271+
*
272+
* ZCRYPT_STATUS_MASK
273+
* Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
274+
* status of all devices.
276275
* 0x01: PCICA
277276
* 0x02: PCICC
278277
* 0x03: PCIXCC_MCL2
279278
* 0x04: PCIXCC_MCL3
280279
* 0x05: CEX2C
281280
* 0x06: CEX2A
282-
* 0x0d: device is disabled via the proc filesystem
283-
*
284-
* Z90STAT_QDEPTH_MASK
285-
* Return an 64 element array of unsigned chars for the queue
286-
* depth of all devices.
287-
*
288-
* Z90STAT_PERDEV_REQCNT
289-
* Return an 64 element array of unsigned integers for the number
290-
* of successfully completed requests per device since the device
291-
* was detected and made available.
292-
*
293-
* Z90STAT_REQUESTQ_COUNT
294-
* Return an integer count of the number of entries waiting to be
295-
* sent to a device.
281+
* 0x07: CEX3C
282+
* 0x08: CEX3A
283+
* 0x0a: CEX4
284+
* 0x0b: CEX5
285+
* 0x0c: CEX6
286+
* 0x0d: device is disabled
296287
*
297-
* Z90STAT_PENDINGQ_COUNT
298-
* Return an integer count of the number of entries sent to all
299-
* devices awaiting the reply.
288+
* ZCRYPT_QDEPTH_MASK
289+
* Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned chars for the
290+
* queue depth of all devices.
300291
*
301-
* Z90STAT_TOTALOPEN_COUNT
302-
* Return an integer count of the number of open file handles.
292+
* ZCRYPT_PERDEV_REQCNT
293+
* Return an MAX_ZDEV_CARDIDS_EXT element array of unsigned integers for
294+
* the number of successfully completed requests per device since the
295+
* device was detected and made available.
303296
*
304-
* Z90STAT_DOMAIN_INDEX
305-
* Return the integer value of the Cryptographic Domain.
306297
*/
307298

308299
/**
@@ -312,15 +303,56 @@ struct zcrypt_device_matrix {
312303
#define ICARSACRT _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x06, 0)
313304
#define ZSECSENDCPRB _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x81, 0)
314305
#define ZSENDEP11CPRB _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x04, 0)
315-
#define ZDEVICESTATUS _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x4f, 0)
316306

317-
/* Status ioctl calls */
307+
#define ZCRYPT_DEVICE_STATUS _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x5f, 0)
308+
#define ZCRYPT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x58, char[MAX_ZDEV_CARDIDS_EXT])
309+
#define ZCRYPT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x59, char[MAX_ZDEV_CARDIDS_EXT])
310+
#define ZCRYPT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x5a, int[MAX_ZDEV_CARDIDS_EXT])
311+
312+
/*
313+
* Only deprecated defines, structs and ioctls below this line.
314+
*/
315+
316+
/* Deprecated: use MAX_ZDEV_CARDIDS_EXT */
317+
#define MAX_ZDEV_CARDIDS 64
318+
/* Deprecated: use MAX_ZDEV_DOMAINS_EXT */
319+
#define MAX_ZDEV_DOMAINS 256
320+
321+
/* Deprecated: use MAX_ZDEV_ENTRIES_EXT */
322+
#define MAX_ZDEV_ENTRIES (MAX_ZDEV_CARDIDS * MAX_ZDEV_DOMAINS)
323+
324+
/* Deprecated: use struct zcrypt_device_status_ext */
325+
struct zcrypt_device_status {
326+
unsigned int hwtype:8;
327+
unsigned int qid:14;
328+
unsigned int online:1;
329+
unsigned int functions:6;
330+
unsigned int reserved:3;
331+
};
332+
333+
/* Deprecated: use struct zcrypt_device_matrix_ext */
334+
struct zcrypt_device_matrix {
335+
struct zcrypt_device_status device[MAX_ZDEV_ENTRIES];
336+
};
337+
338+
/* Deprecated: use ZCRYPT_DEVICE_STATUS */
339+
#define ZDEVICESTATUS _IOC(_IOC_READ|_IOC_WRITE, ZCRYPT_IOCTL_MAGIC, 0x4f, 0)
340+
/* Deprecated: use ZCRYPT_STATUS_MASK */
341+
#define Z90STAT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x48, char[64])
342+
/* Deprecated: use ZCRYPT_QDEPTH_MASK */
343+
#define Z90STAT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x49, char[64])
344+
/* Deprecated: use ZCRYPT_PERDEV_REQCNT */
345+
#define Z90STAT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4a, int[64])
346+
347+
/* Deprecated: use sysfs to query these values */
318348
#define Z90STAT_REQUESTQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x44, int)
319349
#define Z90STAT_PENDINGQ_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x45, int)
320350
#define Z90STAT_TOTALOPEN_COUNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x46, int)
321351
#define Z90STAT_DOMAIN_INDEX _IOR(ZCRYPT_IOCTL_MAGIC, 0x47, int)
322-
#define Z90STAT_STATUS_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x48, char[64])
323-
#define Z90STAT_QDEPTH_MASK _IOR(ZCRYPT_IOCTL_MAGIC, 0x49, char[64])
324-
#define Z90STAT_PERDEV_REQCNT _IOR(ZCRYPT_IOCTL_MAGIC, 0x4a, int[64])
352+
353+
/*
354+
* The ioctl number ranges 0x40 - 0x42 and 0x4b - 0x4e had been used in the
355+
* past, don't assign new ioctls for these.
356+
*/
325357

326358
#endif /* __ASM_S390_ZCRYPT_H */

drivers/s390/crypto/ap_bus.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <linux/types.h>
1818
#include <asm/ap.h>
1919

20-
#define AP_DEVICES 64 /* Number of AP devices. */
20+
#define AP_DEVICES 256 /* Number of AP devices. */
2121
#define AP_DOMAINS 256 /* Number of AP domains. */
2222
#define AP_RESET_TIMEOUT (HZ*0.7) /* Time in ticks for reset timeouts. */
2323
#define AP_CONFIG_TIME 30 /* Time in seconds between AP bus rescans. */

drivers/s390/crypto/pkey_api.c

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ int pkey_findcard(const struct pkey_seckey *seckey,
889889
u16 *pcardnr, u16 *pdomain, int verify)
890890
{
891891
struct secaeskeytoken *t = (struct secaeskeytoken *) seckey;
892-
struct zcrypt_device_matrix *device_matrix;
892+
struct zcrypt_device_status_ext *device_status;
893893
u16 card, dom;
894894
u64 mkvp[2];
895895
int i, rc, oi = -1;
@@ -899,18 +899,19 @@ int pkey_findcard(const struct pkey_seckey *seckey,
899899
return -EINVAL;
900900

901901
/* fetch status of all crypto cards */
902-
device_matrix = kmalloc(sizeof(struct zcrypt_device_matrix),
902+
device_status = kmalloc(MAX_ZDEV_ENTRIES_EXT
903+
* sizeof(struct zcrypt_device_status_ext),
903904
GFP_KERNEL);
904-
if (!device_matrix)
905+
if (!device_status)
905906
return -ENOMEM;
906-
zcrypt_device_status_mask(device_matrix);
907+
zcrypt_device_status_mask_ext(device_status);
907908

908909
/* walk through all crypto cards */
909-
for (i = 0; i < MAX_ZDEV_ENTRIES; i++) {
910-
card = AP_QID_CARD(device_matrix->device[i].qid);
911-
dom = AP_QID_QUEUE(device_matrix->device[i].qid);
912-
if (device_matrix->device[i].online &&
913-
device_matrix->device[i].functions & 0x04) {
910+
for (i = 0; i < MAX_ZDEV_ENTRIES_EXT; i++) {
911+
card = AP_QID_CARD(device_status[i].qid);
912+
dom = AP_QID_QUEUE(device_status[i].qid);
913+
if (device_status[i].online &&
914+
device_status[i].functions & 0x04) {
914915
/* an enabled CCA Coprocessor card */
915916
/* try cached mkvp */
916917
if (mkvp_cache_fetch(card, dom, mkvp) == 0 &&
@@ -930,14 +931,14 @@ int pkey_findcard(const struct pkey_seckey *seckey,
930931
mkvp_cache_scrub(card, dom);
931932
}
932933
}
933-
if (i >= MAX_ZDEV_ENTRIES) {
934+
if (i >= MAX_ZDEV_ENTRIES_EXT) {
934935
/* nothing found, so this time without cache */
935-
for (i = 0; i < MAX_ZDEV_ENTRIES; i++) {
936-
if (!(device_matrix->device[i].online &&
937-
device_matrix->device[i].functions & 0x04))
936+
for (i = 0; i < MAX_ZDEV_ENTRIES_EXT; i++) {
937+
if (!(device_status[i].online &&
938+
device_status[i].functions & 0x04))
938939
continue;
939-
card = AP_QID_CARD(device_matrix->device[i].qid);
940-
dom = AP_QID_QUEUE(device_matrix->device[i].qid);
940+
card = AP_QID_CARD(device_status[i].qid);
941+
dom = AP_QID_QUEUE(device_status[i].qid);
941942
/* fresh fetch mkvp from adapter */
942943
if (fetch_mkvp(card, dom, mkvp) == 0) {
943944
mkvp_cache_update(card, dom, mkvp);
@@ -947,13 +948,13 @@ int pkey_findcard(const struct pkey_seckey *seckey,
947948
oi = i;
948949
}
949950
}
950-
if (i >= MAX_ZDEV_ENTRIES && oi >= 0) {
951+
if (i >= MAX_ZDEV_ENTRIES_EXT && oi >= 0) {
951952
/* old mkvp matched, use this card then */
952-
card = AP_QID_CARD(device_matrix->device[oi].qid);
953-
dom = AP_QID_QUEUE(device_matrix->device[oi].qid);
953+
card = AP_QID_CARD(device_status[oi].qid);
954+
dom = AP_QID_QUEUE(device_status[oi].qid);
954955
}
955956
}
956-
if (i < MAX_ZDEV_ENTRIES || oi >= 0) {
957+
if (i < MAX_ZDEV_ENTRIES_EXT || oi >= 0) {
957958
if (pcardnr)
958959
*pcardnr = card;
959960
if (pdomain)
@@ -962,7 +963,7 @@ int pkey_findcard(const struct pkey_seckey *seckey,
962963
} else
963964
rc = -ENODEV;
964965

965-
kfree(device_matrix);
966+
kfree(device_status);
966967
return rc;
967968
}
968969
EXPORT_SYMBOL(pkey_findcard);

0 commit comments

Comments
 (0)