xref: /linux/drivers/s390/crypto/vfio_ap_private.h (revision 1e753732bda6dcf888ea0b90b2a91ac1c1a0bae9)
11fde5734STony Krowiak /* SPDX-License-Identifier: GPL-2.0 */
21fde5734STony Krowiak /*
31fde5734STony Krowiak  * Private data and functions for adjunct processor VFIO matrix driver.
41fde5734STony Krowiak  *
51fde5734STony Krowiak  * Author(s): Tony Krowiak <akrowiak@linux.ibm.com>
665f06713STony Krowiak  *	      Halil Pasic <pasic@linux.ibm.com>
7ec89b55eSPierre Morel  *	      Pierre Morel <pmorel@linux.ibm.com>
81fde5734STony Krowiak  *
91fde5734STony Krowiak  * Copyright IBM Corp. 2018
101fde5734STony Krowiak  */
111fde5734STony Krowiak 
121fde5734STony Krowiak #ifndef _VFIO_AP_PRIVATE_H_
131fde5734STony Krowiak #define _VFIO_AP_PRIVATE_H_
141fde5734STony Krowiak 
151fde5734STony Krowiak #include <linux/types.h>
161fde5734STony Krowiak #include <linux/device.h>
171fde5734STony Krowiak #include <linux/mdev.h>
181fde5734STony Krowiak #include <linux/delay.h>
191fde5734STony Krowiak #include <linux/mutex.h>
20e5282de9SPierre Morel #include <linux/kvm_host.h>
211fde5734STony Krowiak 
221fde5734STony Krowiak #include "ap_bus.h"
231fde5734STony Krowiak 
241fde5734STony Krowiak #define VFIO_AP_MODULE_NAME "vfio_ap"
251fde5734STony Krowiak #define VFIO_AP_DRV_NAME "vfio_ap"
261fde5734STony Krowiak 
271fde5734STony Krowiak /**
281fde5734STony Krowiak  * ap_matrix_dev - the AP matrix device structure
291fde5734STony Krowiak  * @device:	generic device structure associated with the AP matrix device
3065f06713STony Krowiak  * @available_instances: number of mediated matrix devices that can be created
3165f06713STony Krowiak  * @info:	the struct containing the output from the PQAP(QCI) instruction
3265f06713STony Krowiak  * mdev_list:	the list of mediated matrix devices created
3365f06713STony Krowiak  * lock:	mutex for locking the AP matrix device. This lock will be
3465f06713STony Krowiak  *		taken every time we fiddle with state managed by the vfio_ap
3565f06713STony Krowiak  *		driver, be it using @mdev_list or writing the state of a
3665f06713STony Krowiak  *		single ap_matrix_mdev device. It's quite coarse but we don't
3765f06713STony Krowiak  *		expect much contention.
381fde5734STony Krowiak  */
391fde5734STony Krowiak struct ap_matrix_dev {
401fde5734STony Krowiak 	struct device device;
4165f06713STony Krowiak 	atomic_t available_instances;
4265f06713STony Krowiak 	struct ap_config_info info;
4365f06713STony Krowiak 	struct list_head mdev_list;
4465f06713STony Krowiak 	struct mutex lock;
4536360658SPierre Morel 	struct ap_driver  *vfio_ap_drv;
461fde5734STony Krowiak };
471fde5734STony Krowiak 
481fde5734STony Krowiak extern struct ap_matrix_dev *matrix_dev;
491fde5734STony Krowiak 
5065f06713STony Krowiak /**
5165f06713STony Krowiak  * The AP matrix is comprised of three bit masks identifying the adapters,
5265f06713STony Krowiak  * queues (domains) and control domains that belong to an AP matrix. The bits i
5365f06713STony Krowiak  * each mask, from least significant to most significant bit, correspond to IDs
5465f06713STony Krowiak  * 0 to 255. When a bit is set, the corresponding ID belongs to the matrix.
5565f06713STony Krowiak  *
5665f06713STony Krowiak  * @apm_max: max adapter number in @apm
5765f06713STony Krowiak  * @apm identifies the AP adapters in the matrix
5865f06713STony Krowiak  * @aqm_max: max domain number in @aqm
5965f06713STony Krowiak  * @aqm identifies the AP queues (domains) in the matrix
6065f06713STony Krowiak  * @adm_max: max domain number in @adm
6165f06713STony Krowiak  * @adm identifies the AP control domains in the matrix
6265f06713STony Krowiak  */
6365f06713STony Krowiak struct ap_matrix {
6465f06713STony Krowiak 	unsigned long apm_max;
6565f06713STony Krowiak 	DECLARE_BITMAP(apm, 256);
6665f06713STony Krowiak 	unsigned long aqm_max;
6765f06713STony Krowiak 	DECLARE_BITMAP(aqm, 256);
6865f06713STony Krowiak 	unsigned long adm_max;
6965f06713STony Krowiak 	DECLARE_BITMAP(adm, 256);
7065f06713STony Krowiak };
7165f06713STony Krowiak 
7265f06713STony Krowiak /**
7365f06713STony Krowiak  * struct ap_matrix_mdev - the mediated matrix device structure
7465f06713STony Krowiak  * @list:	allows the ap_matrix_mdev struct to be added to a list
7565f06713STony Krowiak  * @matrix:	the adapters, usage domains and control domains assigned to the
7665f06713STony Krowiak  *		mediated matrix device.
77258287c9STony Krowiak  * @group_notifier: notifier block used for specifying callback function for
78258287c9STony Krowiak  *		    handling the VFIO_GROUP_NOTIFY_SET_KVM event
79258287c9STony Krowiak  * @kvm:	the struct holding guest's state
8065f06713STony Krowiak  */
8165f06713STony Krowiak struct ap_matrix_mdev {
8265f06713STony Krowiak 	struct list_head node;
8365f06713STony Krowiak 	struct ap_matrix matrix;
84258287c9STony Krowiak 	struct notifier_block group_notifier;
8562e358ceSPierre Morel 	struct notifier_block iommu_notifier;
860cc00c8dSTony Krowiak 	bool kvm_busy;
870cc00c8dSTony Krowiak 	wait_queue_head_t wait_for_kvm;
88258287c9STony Krowiak 	struct kvm *kvm;
89*1e753732STony Krowiak 	crypto_hook pqap_hook;
9062e358ceSPierre Morel 	struct mdev_device *mdev;
9165f06713STony Krowiak };
9265f06713STony Krowiak 
93ec89b55eSPierre Morel struct vfio_ap_queue {
94ec89b55eSPierre Morel 	struct ap_matrix_mdev *matrix_mdev;
95ec89b55eSPierre Morel 	unsigned long saved_pfn;
96ec89b55eSPierre Morel 	int	apqn;
97ec89b55eSPierre Morel #define VFIO_AP_ISC_INVALID 0xff
98ec89b55eSPierre Morel 	unsigned char saved_isc;
99ec89b55eSPierre Morel };
1006c12a638STony Krowiak 
1016c12a638STony Krowiak int vfio_ap_mdev_register(void);
1026c12a638STony Krowiak void vfio_ap_mdev_unregister(void);
1036c12a638STony Krowiak int vfio_ap_mdev_reset_queue(struct vfio_ap_queue *q,
1046c12a638STony Krowiak 			     unsigned int retry);
1056c12a638STony Krowiak 
1061fde5734STony Krowiak #endif /* _VFIO_AP_PRIVATE_H_ */
107