2018-09-25 19:16:19 -04:00
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Private data and functions for adjunct processor VFIO matrix driver .
*
* Author ( s ) : Tony Krowiak < akrowiak @ linux . ibm . com >
2018-09-25 19:16:20 -04:00
* Halil Pasic < pasic @ linux . ibm . com >
2019-05-21 17:34:36 +02:00
* Pierre Morel < pmorel @ linux . ibm . com >
2018-09-25 19:16:19 -04:00
*
* Copyright IBM Corp . 2018
*/
# ifndef _VFIO_AP_PRIVATE_H_
# define _VFIO_AP_PRIVATE_H_
# include <linux/types.h>
# include <linux/mdev.h>
# include <linux/delay.h>
2023-05-30 18:35:37 -04:00
# include <linux/eventfd.h>
2018-09-25 19:16:19 -04:00
# include <linux/mutex.h>
2019-05-21 17:34:34 +02:00
# include <linux/kvm_host.h>
2021-08-23 11:42:04 -03:00
# include <linux/vfio.h>
s390/vfio-ap: manage link between queue struct and matrix mdev
Let's create links between each queue device bound to the vfio_ap device
driver and the matrix mdev to which the queue's APQN is assigned. The idea
is to facilitate efficient retrieval of the objects representing the queue
devices and matrix mdevs as well as to verify that a queue assigned to
a matrix mdev is bound to the driver.
The links will be created as follows:
* When the queue device is probed, if its APQN is assigned to a matrix
mdev, the structures representing the queue device and the matrix mdev
will be linked.
* When an adapter or domain is assigned to a matrix mdev, for each new
APQN assigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be linked.
The links will be removed as follows:
* When the queue device is removed, if its APQN is assigned to a matrix
mdev, the link from the structure representing the matrix mdev to the
structure representing the queue will be removed. Since the storage
allocated for the vfio_ap_queue will be freed, there is no need to
remove the link to the matrix_mdev to which the queue's APQN is
assigned.
* When an adapter or domain is unassigned from a matrix mdev, for each
APQN unassigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be unlinked.
* When an mdev is removed, the link from any queues assigned to the mdev
to the mdev will be removed.
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
2021-02-01 11:18:09 -05:00
# include <linux/hashtable.h>
2018-09-25 19:16:19 -04:00
# include "ap_bus.h"
# define VFIO_AP_MODULE_NAME "vfio_ap"
# define VFIO_AP_DRV_NAME "vfio_ap"
/**
2021-10-19 12:57:32 -04:00
* struct ap_matrix_dev - Contains the data for the matrix device .
*
2018-09-25 19:16:19 -04:00
* @ device : generic device structure associated with the AP matrix device
2018-09-25 19:16:20 -04:00
* @ info : the struct containing the output from the PQAP ( QCI ) instruction
2021-10-19 12:57:32 -04:00
* @ mdev_list : the list of mediated matrix devices created
2022-03-16 12:23:12 -04:00
* @ mdevs_lock : mutex for locking the AP matrix device . This lock will be
2018-09-25 19:16:20 -04:00
* taken every time we fiddle with state managed by the vfio_ap
* driver , be it using @ mdev_list or writing the state of a
* single ap_matrix_mdev device . It ' s quite coarse but we don ' t
* expect much contention .
2021-10-19 12:57:32 -04:00
* @ vfio_ap_drv : the vfio_ap device driver
2021-09-23 22:21:58 -04:00
* @ guests_lock : mutex for controlling access to a guest that is using AP
* devices passed through by the vfio_ap device driver . This lock
* will be taken when the AP devices are plugged into or unplugged
* from a guest , and when an ap_matrix_mdev device is added to or
* removed from @ mdev_list or the list is iterated .
2018-09-25 19:16:19 -04:00
*/
struct ap_matrix_dev {
struct device device ;
2018-09-25 19:16:20 -04:00
struct ap_config_info info ;
struct list_head mdev_list ;
2022-03-16 12:23:12 -04:00
struct mutex mdevs_lock ; /* serializes access to each ap_matrix_mdev */
2019-02-12 16:53:45 +01:00
struct ap_driver * vfio_ap_drv ;
2021-09-23 22:21:58 -04:00
struct mutex guests_lock ; /* serializes access to each KVM guest */
2022-09-23 11:26:42 +02:00
struct mdev_parent parent ;
2022-09-23 11:26:43 +02:00
struct mdev_type mdev_type ;
2022-10-21 10:50:02 -04:00
struct mdev_type * mdev_types [ 1 ] ;
2018-09-25 19:16:19 -04:00
} ;
extern struct ap_matrix_dev * matrix_dev ;
2018-09-25 19:16:20 -04:00
/**
2021-10-19 12:57:32 -04:00
* struct ap_matrix - matrix of adapters , domains and control domains
2018-09-25 19:16:20 -04:00
*
* @ apm_max : max adapter number in @ apm
2021-10-19 12:57:32 -04:00
* @ apm : identifies the AP adapters in the matrix
2018-09-25 19:16:20 -04:00
* @ aqm_max : max domain number in @ aqm
2021-10-19 12:57:32 -04:00
* @ aqm : identifies the AP queues ( domains ) in the matrix
2018-09-25 19:16:20 -04:00
* @ adm_max : max domain number in @ adm
2021-10-19 12:57:32 -04:00
* @ adm : identifies the AP control domains in the matrix
*
* The AP matrix is comprised of three bit masks identifying the adapters ,
* queues ( domains ) and control domains that belong to an AP matrix . The bits in
* each mask , from left to right , correspond to IDs 0 to 255. When a bit is set
* the corresponding ID belongs to the matrix .
2018-09-25 19:16:20 -04:00
*/
struct ap_matrix {
unsigned long apm_max ;
DECLARE_BITMAP ( apm , 256 ) ;
unsigned long aqm_max ;
DECLARE_BITMAP ( aqm , 256 ) ;
unsigned long adm_max ;
DECLARE_BITMAP ( adm , 256 ) ;
} ;
s390/vfio-ap: manage link between queue struct and matrix mdev
Let's create links between each queue device bound to the vfio_ap device
driver and the matrix mdev to which the queue's APQN is assigned. The idea
is to facilitate efficient retrieval of the objects representing the queue
devices and matrix mdevs as well as to verify that a queue assigned to
a matrix mdev is bound to the driver.
The links will be created as follows:
* When the queue device is probed, if its APQN is assigned to a matrix
mdev, the structures representing the queue device and the matrix mdev
will be linked.
* When an adapter or domain is assigned to a matrix mdev, for each new
APQN assigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be linked.
The links will be removed as follows:
* When the queue device is removed, if its APQN is assigned to a matrix
mdev, the link from the structure representing the matrix mdev to the
structure representing the queue will be removed. Since the storage
allocated for the vfio_ap_queue will be freed, there is no need to
remove the link to the matrix_mdev to which the queue's APQN is
assigned.
* When an adapter or domain is unassigned from a matrix mdev, for each
APQN unassigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be unlinked.
* When an mdev is removed, the link from any queues assigned to the mdev
to the mdev will be removed.
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
2021-02-01 11:18:09 -05:00
/**
* struct ap_queue_table - a table of queue objects .
*
* @ queues : a hashtable of queues ( struct vfio_ap_queue ) .
*/
struct ap_queue_table {
DECLARE_HASHTABLE ( queues , 8 ) ;
} ;
2018-09-25 19:16:20 -04:00
/**
2021-10-19 12:57:32 -04:00
* struct ap_matrix_mdev - Contains the data associated with a matrix mediated
* device .
* @ vdev : the vfio device
* @ node : allows the ap_matrix_mdev struct to be added to a list
2018-09-25 19:16:20 -04:00
* @ matrix : the adapters , usage domains and control domains assigned to the
* mediated matrix device .
2019-12-11 15:35:54 -05:00
* @ shadow_apcb : the shadow copy of the APCB field of the KVM guest ' s CRYCB
2018-09-25 19:16:26 -04:00
* @ kvm : the struct holding guest ' s state
2021-10-19 12:57:32 -04:00
* @ pqap_hook : the function pointer to the interception handler for the
* PQAP ( AQIC ) instruction .
* @ mdev : the mediated device
s390/vfio-ap: manage link between queue struct and matrix mdev
Let's create links between each queue device bound to the vfio_ap device
driver and the matrix mdev to which the queue's APQN is assigned. The idea
is to facilitate efficient retrieval of the objects representing the queue
devices and matrix mdevs as well as to verify that a queue assigned to
a matrix mdev is bound to the driver.
The links will be created as follows:
* When the queue device is probed, if its APQN is assigned to a matrix
mdev, the structures representing the queue device and the matrix mdev
will be linked.
* When an adapter or domain is assigned to a matrix mdev, for each new
APQN assigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be linked.
The links will be removed as follows:
* When the queue device is removed, if its APQN is assigned to a matrix
mdev, the link from the structure representing the matrix mdev to the
structure representing the queue will be removed. Since the storage
allocated for the vfio_ap_queue will be freed, there is no need to
remove the link to the matrix_mdev to which the queue's APQN is
assigned.
* When an adapter or domain is unassigned from a matrix mdev, for each
APQN unassigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be unlinked.
* When an mdev is removed, the link from any queues assigned to the mdev
to the mdev will be removed.
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
2021-02-01 11:18:09 -05:00
* @ qtable : table of queues ( struct vfio_ap_queue ) assigned to the mdev
2023-05-30 18:35:37 -04:00
* @ req_trigger eventfd ctx for signaling userspace to return a device
2022-04-04 09:40:10 -04:00
* @ apm_add : bitmap of APIDs added to the host ' s AP configuration
* @ aqm_add : bitmap of APQIs added to the host ' s AP configuration
* @ adm_add : bitmap of control domain numbers added to the host ' s AP
* configuration
2018-09-25 19:16:20 -04:00
*/
struct ap_matrix_mdev {
2021-08-23 11:42:04 -03:00
struct vfio_device vdev ;
2018-09-25 19:16:20 -04:00
struct list_head node ;
struct ap_matrix matrix ;
2019-12-11 15:35:54 -05:00
struct ap_matrix shadow_apcb ;
2018-09-25 19:16:26 -04:00
struct kvm * kvm ;
2021-08-23 17:20:46 -04:00
crypto_hook pqap_hook ;
2019-05-21 17:34:35 +02:00
struct mdev_device * mdev ;
s390/vfio-ap: manage link between queue struct and matrix mdev
Let's create links between each queue device bound to the vfio_ap device
driver and the matrix mdev to which the queue's APQN is assigned. The idea
is to facilitate efficient retrieval of the objects representing the queue
devices and matrix mdevs as well as to verify that a queue assigned to
a matrix mdev is bound to the driver.
The links will be created as follows:
* When the queue device is probed, if its APQN is assigned to a matrix
mdev, the structures representing the queue device and the matrix mdev
will be linked.
* When an adapter or domain is assigned to a matrix mdev, for each new
APQN assigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be linked.
The links will be removed as follows:
* When the queue device is removed, if its APQN is assigned to a matrix
mdev, the link from the structure representing the matrix mdev to the
structure representing the queue will be removed. Since the storage
allocated for the vfio_ap_queue will be freed, there is no need to
remove the link to the matrix_mdev to which the queue's APQN is
assigned.
* When an adapter or domain is unassigned from a matrix mdev, for each
APQN unassigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be unlinked.
* When an mdev is removed, the link from any queues assigned to the mdev
to the mdev will be removed.
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
2021-02-01 11:18:09 -05:00
struct ap_queue_table qtable ;
2023-05-30 18:35:37 -04:00
struct eventfd_ctx * req_trigger ;
2022-04-04 09:40:10 -04:00
DECLARE_BITMAP ( apm_add , AP_DEVICES ) ;
DECLARE_BITMAP ( aqm_add , AP_DOMAINS ) ;
DECLARE_BITMAP ( adm_add , AP_DOMAINS ) ;
2018-09-25 19:16:20 -04:00
} ;
2021-10-19 12:57:32 -04:00
/**
* struct vfio_ap_queue - contains the data associated with a queue bound to the
* vfio_ap device driver
* @ matrix_mdev : the matrix mediated device
2022-07-22 19:02:52 -07:00
* @ saved_iova : the notification indicator byte ( nib ) address
2021-10-19 12:57:32 -04:00
* @ apqn : the APQN of the AP queue device
* @ saved_isc : the guest ISC registered with the GIB interface
s390/vfio-ap: manage link between queue struct and matrix mdev
Let's create links between each queue device bound to the vfio_ap device
driver and the matrix mdev to which the queue's APQN is assigned. The idea
is to facilitate efficient retrieval of the objects representing the queue
devices and matrix mdevs as well as to verify that a queue assigned to
a matrix mdev is bound to the driver.
The links will be created as follows:
* When the queue device is probed, if its APQN is assigned to a matrix
mdev, the structures representing the queue device and the matrix mdev
will be linked.
* When an adapter or domain is assigned to a matrix mdev, for each new
APQN assigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be linked.
The links will be removed as follows:
* When the queue device is removed, if its APQN is assigned to a matrix
mdev, the link from the structure representing the matrix mdev to the
structure representing the queue will be removed. Since the storage
allocated for the vfio_ap_queue will be freed, there is no need to
remove the link to the matrix_mdev to which the queue's APQN is
assigned.
* When an adapter or domain is unassigned from a matrix mdev, for each
APQN unassigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be unlinked.
* When an mdev is removed, the link from any queues assigned to the mdev
to the mdev will be removed.
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
2021-02-01 11:18:09 -05:00
* @ mdev_qnode : allows the vfio_ap_queue struct to be added to a hashtable
2023-08-15 14:43:27 -04:00
* @ reset_status : the status from the last reset of the queue
2023-08-15 14:43:28 -04:00
* @ reset_work : work to wait for queue reset to complete
2021-10-19 12:57:32 -04:00
*/
2019-05-21 17:34:36 +02:00
struct vfio_ap_queue {
struct ap_matrix_mdev * matrix_mdev ;
2022-07-22 19:02:52 -07:00
dma_addr_t saved_iova ;
2019-05-21 17:34:36 +02:00
int apqn ;
# define VFIO_AP_ISC_INVALID 0xff
unsigned char saved_isc ;
s390/vfio-ap: manage link between queue struct and matrix mdev
Let's create links between each queue device bound to the vfio_ap device
driver and the matrix mdev to which the queue's APQN is assigned. The idea
is to facilitate efficient retrieval of the objects representing the queue
devices and matrix mdevs as well as to verify that a queue assigned to
a matrix mdev is bound to the driver.
The links will be created as follows:
* When the queue device is probed, if its APQN is assigned to a matrix
mdev, the structures representing the queue device and the matrix mdev
will be linked.
* When an adapter or domain is assigned to a matrix mdev, for each new
APQN assigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be linked.
The links will be removed as follows:
* When the queue device is removed, if its APQN is assigned to a matrix
mdev, the link from the structure representing the matrix mdev to the
structure representing the queue will be removed. Since the storage
allocated for the vfio_ap_queue will be freed, there is no need to
remove the link to the matrix_mdev to which the queue's APQN is
assigned.
* When an adapter or domain is unassigned from a matrix mdev, for each
APQN unassigned that references a queue device bound to the vfio_ap
device driver, the structures representing the queue device and the
matrix mdev will be unlinked.
* When an mdev is removed, the link from any queues assigned to the mdev
to the mdev will be removed.
Signed-off-by: Tony Krowiak <akrowiak@linux.ibm.com>
Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
2021-02-01 11:18:09 -05:00
struct hlist_node mdev_qnode ;
2023-08-15 14:43:27 -04:00
struct ap_queue_status reset_status ;
2023-08-15 14:43:28 -04:00
struct work_struct reset_work ;
2019-05-21 17:34:36 +02:00
} ;
2020-12-22 20:15:53 -05:00
int vfio_ap_mdev_register ( void ) ;
void vfio_ap_mdev_unregister ( void ) ;
2020-10-14 15:34:49 -04:00
int vfio_ap_mdev_probe_queue ( struct ap_device * queue ) ;
void vfio_ap_mdev_remove_queue ( struct ap_device * queue ) ;
2020-12-22 20:15:53 -05:00
2021-09-30 11:43:38 -04:00
int vfio_ap_mdev_resource_in_use ( unsigned long * apm , unsigned long * aqm ) ;
2022-04-04 09:40:10 -04:00
void vfio_ap_on_cfg_changed ( struct ap_config_info * new_config_info ,
struct ap_config_info * old_config_info ) ;
void vfio_ap_on_scan_complete ( struct ap_config_info * new_config_info ,
struct ap_config_info * old_config_info ) ;
2020-12-22 20:15:53 -05:00
2018-09-25 19:16:19 -04:00
# endif /* _VFIO_AP_PRIVATE_H_ */