2018-08-17 10:36:01 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2006-09-20 13:58:27 +00:00
|
|
|
/*
|
2019-08-16 09:05:58 +00:00
|
|
|
* Copyright IBM Corp. 2001, 2019
|
2006-09-20 13:58:27 +00:00
|
|
|
* Author(s): Robert Burroughs
|
|
|
|
* Eric Rossman (edrossma@us.ibm.com)
|
|
|
|
* Cornelia Huck <cornelia.huck@de.ibm.com>
|
|
|
|
*
|
|
|
|
* Hotplug & misc device support: Jochen Roehrig (roehrig@de.ibm.com)
|
|
|
|
* Major cleanup & driver split: Martin Schwidefsky <schwidefsky@de.ibm.com>
|
|
|
|
* Ralph Wuerthner <rwuerthn@de.ibm.com>
|
2012-08-28 14:45:36 +00:00
|
|
|
* MSGTYPE restruct: Holger Dengler <hd@linux.vnet.ibm.com>
|
2006-09-20 13:58:27 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ZCRYPT_API_H_
|
|
|
|
#define _ZCRYPT_API_H_
|
|
|
|
|
2012-09-10 19:34:26 +00:00
|
|
|
#include <linux/atomic.h>
|
|
|
|
#include <asm/debug.h>
|
2006-09-20 13:58:27 +00:00
|
|
|
#include <asm/zcrypt.h>
|
2012-09-10 19:34:26 +00:00
|
|
|
#include "ap_bus.h"
|
2006-09-20 13:58:27 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-04 13:30:24 +00:00
|
|
|
* Supported device types
|
2006-09-20 13:58:27 +00:00
|
|
|
*/
|
|
|
|
#define ZCRYPT_CEX2C 5
|
|
|
|
#define ZCRYPT_CEX2A 6
|
2009-12-07 11:51:57 +00:00
|
|
|
#define ZCRYPT_CEX3C 7
|
|
|
|
#define ZCRYPT_CEX3A 8
|
2013-11-20 09:47:13 +00:00
|
|
|
#define ZCRYPT_CEX4 10
|
2015-01-23 13:56:25 +00:00
|
|
|
#define ZCRYPT_CEX5 11
|
2017-10-10 09:25:06 +00:00
|
|
|
#define ZCRYPT_CEX6 12
|
2019-08-16 09:05:58 +00:00
|
|
|
#define ZCRYPT_CEX7 13
|
2006-09-20 13:58:27 +00:00
|
|
|
|
2008-04-17 05:46:15 +00:00
|
|
|
/**
|
|
|
|
* Large random numbers are pulled in 4096 byte chunks from the crypto cards
|
2011-03-31 01:57:33 +00:00
|
|
|
* and stored in a page. Be careful when increasing this buffer due to size
|
2008-04-17 05:46:15 +00:00
|
|
|
* limitations for AP requests.
|
|
|
|
*/
|
|
|
|
#define ZCRYPT_RNG_BUFFER_SIZE 4096
|
|
|
|
|
2016-08-25 09:14:15 +00:00
|
|
|
/*
|
|
|
|
* Identifier for Crypto Request Performance Index
|
|
|
|
*/
|
|
|
|
enum crypto_ops {
|
2016-08-25 09:16:03 +00:00
|
|
|
MEX_1K,
|
2016-08-25 09:14:15 +00:00
|
|
|
MEX_2K,
|
|
|
|
MEX_4K,
|
|
|
|
CRT_1K,
|
|
|
|
CRT_2K,
|
|
|
|
CRT_4K,
|
|
|
|
HWRNG,
|
|
|
|
SECKEY,
|
|
|
|
NUM_OPS
|
|
|
|
};
|
|
|
|
|
2016-08-25 09:16:03 +00:00
|
|
|
struct zcrypt_queue;
|
2006-09-20 13:58:27 +00:00
|
|
|
|
2020-07-02 09:10:11 +00:00
|
|
|
/* struct to hold tracking information for a userspace request/response */
|
|
|
|
struct zcrypt_track {
|
|
|
|
int again_counter; /* retry attempts counter */
|
|
|
|
int last_qid; /* last qid used */
|
|
|
|
int last_rc; /* last return code */
|
2020-09-29 14:07:22 +00:00
|
|
|
#ifdef CONFIG_ZCRYPT_DEBUG
|
|
|
|
struct ap_fi fi; /* failure injection cmd */
|
|
|
|
#endif
|
2020-07-02 09:10:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* defines related to message tracking */
|
|
|
|
#define TRACK_AGAIN_MAX 10
|
|
|
|
#define TRACK_AGAIN_CARD_WEIGHT_PENALTY 1000
|
|
|
|
#define TRACK_AGAIN_QUEUE_WEIGHT_PENALTY 10000
|
|
|
|
|
2006-09-20 13:58:27 +00:00
|
|
|
struct zcrypt_ops {
|
2020-09-26 20:51:38 +00:00
|
|
|
long (*rsa_modexpo)(struct zcrypt_queue *, struct ica_rsa_modexpo *,
|
|
|
|
struct ap_message *);
|
2016-08-25 09:16:03 +00:00
|
|
|
long (*rsa_modexpo_crt)(struct zcrypt_queue *,
|
2020-09-26 20:51:38 +00:00
|
|
|
struct ica_rsa_modexpo_crt *,
|
|
|
|
struct ap_message *);
|
2020-09-15 15:01:58 +00:00
|
|
|
long (*send_cprb)(bool userspace, struct zcrypt_queue *, struct ica_xcRB *,
|
2016-08-25 09:14:15 +00:00
|
|
|
struct ap_message *);
|
2020-09-15 15:01:58 +00:00
|
|
|
long (*send_ep11_cprb)(bool userspace, struct zcrypt_queue *, struct ep11_urb *,
|
2016-08-25 09:14:15 +00:00
|
|
|
struct ap_message *);
|
2016-08-25 09:16:03 +00:00
|
|
|
long (*rng)(struct zcrypt_queue *, char *, struct ap_message *);
|
2012-08-28 14:45:36 +00:00
|
|
|
struct list_head list; /* zcrypt ops list. */
|
|
|
|
struct module *owner;
|
|
|
|
int variant;
|
s390/zcrypt: Fix initialisation when zcrypt is built-in
ap_bus and zcrypt_api assumed module information to always be present
and initialisation to be done in module loading order (symbol
dependencies). These assumptions don't hold if zcrypt is built-in;
THIS_MODULE will be NULL in this case and init call order is linker
order, i.e. Makefile order.
Fix initialisation order by ordering the object files in the Makefile
according to their dependencies, like the module loader would do.
Fix message type registration by using a dedicated "name" field rather
than piggy-backing on the module ("owner") information. There's no
change to the requirement that module name and msgtype name are
identical. The existing name macros are used.
We don't need any special code for dealing with the drivers being
built-in; the generic module support code already does the right
thing.
Test results:
1. CONFIG_MODULES=y, CONFIG_ZCRYPT=y
KVM: boots, no /sys/bus/ap (expected)
LPAR with CEX5: boots, /sys/bus/ap/devices/card*/type present
2. CONFIG_MODULES=y, CONFIG_ZCRYPT=m=:
KVM: boots, loading zcrypt_cex4 (and ap) fails (expected)
LPAR with CEX5: boots, loading =zcrypt_cex4= succeeds,
/sys/bus/ap/devices/card*/type present after explicit module
loading
3. CONFIG_MODULES unset, CONFIG_ZCRYPT=y:
KVM: boots, no /sys/bus/ap (expected)
LPAR with CEX5: boots, /sys/bus/ap/devices/card*/type present
No further testing (user-space functionality) was done.
Fixes: 3b6245fd303f ("s390/zcrypt: Separate msgtype implementation from card modules.")
Signed-off-by: Sascha Silbe <silbe@linux.vnet.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
2015-10-28 10:06:08 +00:00
|
|
|
char name[128];
|
2006-09-20 13:58:27 +00:00
|
|
|
};
|
|
|
|
|
2016-08-25 09:16:03 +00:00
|
|
|
struct zcrypt_card {
|
2006-09-20 13:58:27 +00:00
|
|
|
struct list_head list; /* Device list. */
|
2016-08-25 09:16:03 +00:00
|
|
|
struct list_head zqueues; /* List of zcrypt queues */
|
2006-09-20 13:58:27 +00:00
|
|
|
struct kref refcount; /* device refcounting */
|
2016-08-25 09:16:03 +00:00
|
|
|
struct ap_card *card; /* The "real" ap card device. */
|
2006-09-20 13:58:27 +00:00
|
|
|
int online; /* User online/offline */
|
|
|
|
|
|
|
|
int user_space_type; /* User space device id. */
|
|
|
|
char *type_string; /* User space device name. */
|
|
|
|
int min_mod_size; /* Min number of bits. */
|
|
|
|
int max_mod_size; /* Max number of bits. */
|
2016-08-25 09:16:03 +00:00
|
|
|
int max_exp_bit_length;
|
2020-07-02 09:10:11 +00:00
|
|
|
const int *speed_rating; /* Speed idx of crypto ops. */
|
2016-08-25 09:16:03 +00:00
|
|
|
atomic_t load; /* Utilization of the crypto device */
|
|
|
|
|
|
|
|
int request_count; /* # current requests. */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct zcrypt_queue {
|
|
|
|
struct list_head list; /* Device list. */
|
|
|
|
struct kref refcount; /* device refcounting */
|
|
|
|
struct zcrypt_card *zcard;
|
|
|
|
struct zcrypt_ops *ops; /* Crypto operations. */
|
|
|
|
struct ap_queue *queue; /* The "real" ap queue device. */
|
|
|
|
int online; /* User online/offline */
|
|
|
|
|
|
|
|
atomic_t load; /* Utilization of the crypto device */
|
2006-09-20 13:58:27 +00:00
|
|
|
|
|
|
|
int request_count; /* # current requests. */
|
|
|
|
|
|
|
|
struct ap_message reply; /* Per-device reply structure. */
|
|
|
|
};
|
|
|
|
|
2012-09-10 19:34:26 +00:00
|
|
|
/* transport layer rescanning */
|
|
|
|
extern atomic_t zcrypt_rescan_req;
|
|
|
|
|
2016-08-25 09:16:03 +00:00
|
|
|
extern spinlock_t zcrypt_list_lock;
|
|
|
|
extern struct list_head zcrypt_card_list;
|
|
|
|
|
|
|
|
#define for_each_zcrypt_card(_zc) \
|
|
|
|
list_for_each_entry(_zc, &zcrypt_card_list, list)
|
|
|
|
|
|
|
|
#define for_each_zcrypt_queue(_zq, _zc) \
|
|
|
|
list_for_each_entry(_zq, &(_zc)->zqueues, list)
|
|
|
|
|
|
|
|
struct zcrypt_card *zcrypt_card_alloc(void);
|
|
|
|
void zcrypt_card_free(struct zcrypt_card *);
|
|
|
|
void zcrypt_card_get(struct zcrypt_card *);
|
|
|
|
int zcrypt_card_put(struct zcrypt_card *);
|
|
|
|
int zcrypt_card_register(struct zcrypt_card *);
|
|
|
|
void zcrypt_card_unregister(struct zcrypt_card *);
|
|
|
|
|
|
|
|
struct zcrypt_queue *zcrypt_queue_alloc(size_t);
|
|
|
|
void zcrypt_queue_free(struct zcrypt_queue *);
|
|
|
|
void zcrypt_queue_get(struct zcrypt_queue *);
|
|
|
|
int zcrypt_queue_put(struct zcrypt_queue *);
|
|
|
|
int zcrypt_queue_register(struct zcrypt_queue *);
|
|
|
|
void zcrypt_queue_unregister(struct zcrypt_queue *);
|
2021-04-13 16:11:09 +00:00
|
|
|
bool zcrypt_queue_force_online(struct zcrypt_queue *zq, int online);
|
2016-08-25 09:16:03 +00:00
|
|
|
|
|
|
|
int zcrypt_rng_device_add(void);
|
|
|
|
void zcrypt_rng_device_remove(void);
|
|
|
|
|
2012-08-28 14:45:36 +00:00
|
|
|
void zcrypt_msgtype_register(struct zcrypt_ops *);
|
|
|
|
void zcrypt_msgtype_unregister(struct zcrypt_ops *);
|
2016-09-02 13:21:45 +00:00
|
|
|
struct zcrypt_ops *zcrypt_msgtype(unsigned char *, int);
|
2006-09-20 13:58:27 +00:00
|
|
|
int zcrypt_api_init(void);
|
|
|
|
void zcrypt_api_exit(void);
|
2016-11-02 13:32:32 +00:00
|
|
|
long zcrypt_send_cprb(struct ica_xcRB *xcRB);
|
2019-08-30 13:57:17 +00:00
|
|
|
long zcrypt_send_ep11_cprb(struct ep11_urb *urb);
|
2018-04-09 14:18:37 +00:00
|
|
|
void zcrypt_device_status_mask_ext(struct zcrypt_device_status_ext *devstatus);
|
2019-06-18 13:53:12 +00:00
|
|
|
int zcrypt_device_status_ext(int card, int queue,
|
|
|
|
struct zcrypt_device_status_ext *devstatus);
|
2006-09-20 13:58:27 +00:00
|
|
|
|
2020-09-01 10:48:14 +00:00
|
|
|
int zcrypt_wait_api_operational(void);
|
|
|
|
|
2020-09-15 15:01:58 +00:00
|
|
|
static inline unsigned long z_copy_from_user(bool userspace,
|
|
|
|
void *to,
|
|
|
|
const void __user *from,
|
|
|
|
unsigned long n)
|
|
|
|
{
|
|
|
|
if (likely(userspace))
|
|
|
|
return copy_from_user(to, from, n);
|
|
|
|
memcpy(to, (void __force *) from, n);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned long z_copy_to_user(bool userspace,
|
|
|
|
void __user *to,
|
|
|
|
const void *from,
|
|
|
|
unsigned long n)
|
|
|
|
{
|
|
|
|
if (likely(userspace))
|
|
|
|
return copy_to_user(to, from, n);
|
|
|
|
memcpy((void __force *) to, from, n);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-09-20 13:58:27 +00:00
|
|
|
#endif /* _ZCRYPT_API_H_ */
|