xref: /linux/drivers/s390/crypto/vfio_ap_private.h (revision eb0feefd4c025b2697464d141f7ff178095f34df)
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>
21*eb0feefdSJason Gunthorpe #include <linux/vfio.h>
221fde5734STony Krowiak 
231fde5734STony Krowiak #include "ap_bus.h"
241fde5734STony Krowiak 
251fde5734STony Krowiak #define VFIO_AP_MODULE_NAME "vfio_ap"
261fde5734STony Krowiak #define VFIO_AP_DRV_NAME "vfio_ap"
271fde5734STony Krowiak 
281fde5734STony Krowiak /**
291fde5734STony Krowiak  * ap_matrix_dev - the AP matrix device structure
301fde5734STony Krowiak  * @device:	generic device structure associated with the AP matrix device
3165f06713STony Krowiak  * @available_instances: number of mediated matrix devices that can be created
3265f06713STony Krowiak  * @info:	the struct containing the output from the PQAP(QCI) instruction
3365f06713STony Krowiak  * mdev_list:	the list of mediated matrix devices created
3465f06713STony Krowiak  * lock:	mutex for locking the AP matrix device. This lock will be
3565f06713STony Krowiak  *		taken every time we fiddle with state managed by the vfio_ap
3665f06713STony Krowiak  *		driver, be it using @mdev_list or writing the state of a
3765f06713STony Krowiak  *		single ap_matrix_mdev device. It's quite coarse but we don't
3865f06713STony Krowiak  *		expect much contention.
391fde5734STony Krowiak  */
401fde5734STony Krowiak struct ap_matrix_dev {
411fde5734STony Krowiak 	struct device device;
4265f06713STony Krowiak 	atomic_t available_instances;
4365f06713STony Krowiak 	struct ap_config_info info;
4465f06713STony Krowiak 	struct list_head mdev_list;
4565f06713STony Krowiak 	struct mutex lock;
4636360658SPierre Morel 	struct ap_driver  *vfio_ap_drv;
471fde5734STony Krowiak };
481fde5734STony Krowiak 
491fde5734STony Krowiak extern struct ap_matrix_dev *matrix_dev;
501fde5734STony Krowiak 
5165f06713STony Krowiak /**
5265f06713STony Krowiak  * The AP matrix is comprised of three bit masks identifying the adapters,
5365f06713STony Krowiak  * queues (domains) and control domains that belong to an AP matrix. The bits i
5465f06713STony Krowiak  * each mask, from least significant to most significant bit, correspond to IDs
5565f06713STony Krowiak  * 0 to 255. When a bit is set, the corresponding ID belongs to the matrix.
5665f06713STony Krowiak  *
5765f06713STony Krowiak  * @apm_max: max adapter number in @apm
5865f06713STony Krowiak  * @apm identifies the AP adapters in the matrix
5965f06713STony Krowiak  * @aqm_max: max domain number in @aqm
6065f06713STony Krowiak  * @aqm identifies the AP queues (domains) in the matrix
6165f06713STony Krowiak  * @adm_max: max domain number in @adm
6265f06713STony Krowiak  * @adm identifies the AP control domains in the matrix
6365f06713STony Krowiak  */
6465f06713STony Krowiak struct ap_matrix {
6565f06713STony Krowiak 	unsigned long apm_max;
6665f06713STony Krowiak 	DECLARE_BITMAP(apm, 256);
6765f06713STony Krowiak 	unsigned long aqm_max;
6865f06713STony Krowiak 	DECLARE_BITMAP(aqm, 256);
6965f06713STony Krowiak 	unsigned long adm_max;
7065f06713STony Krowiak 	DECLARE_BITMAP(adm, 256);
7165f06713STony Krowiak };
7265f06713STony Krowiak 
7365f06713STony Krowiak /**
7465f06713STony Krowiak  * struct ap_matrix_mdev - the mediated matrix device structure
7565f06713STony Krowiak  * @list:	allows the ap_matrix_mdev struct to be added to a list
7665f06713STony Krowiak  * @matrix:	the adapters, usage domains and control domains assigned to the
7765f06713STony Krowiak  *		mediated matrix device.
78258287c9STony Krowiak  * @group_notifier: notifier block used for specifying callback function for
79258287c9STony Krowiak  *		    handling the VFIO_GROUP_NOTIFY_SET_KVM event
80258287c9STony Krowiak  * @kvm:	the struct holding guest's state
8165f06713STony Krowiak  */
8265f06713STony Krowiak struct ap_matrix_mdev {
83*eb0feefdSJason Gunthorpe 	struct vfio_device vdev;
8465f06713STony Krowiak 	struct list_head node;
8565f06713STony Krowiak 	struct ap_matrix matrix;
86258287c9STony Krowiak 	struct notifier_block group_notifier;
8762e358ceSPierre Morel 	struct notifier_block iommu_notifier;
88258287c9STony Krowiak 	struct kvm *kvm;
891e753732STony 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