Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Private data and functions for adjunct processor VFIO matrix driver.
0004  *
0005  * Author(s): Tony Krowiak <akrowiak@linux.ibm.com>
0006  *        Halil Pasic <pasic@linux.ibm.com>
0007  *        Pierre Morel <pmorel@linux.ibm.com>
0008  *
0009  * Copyright IBM Corp. 2018
0010  */
0011 
0012 #ifndef _VFIO_AP_PRIVATE_H_
0013 #define _VFIO_AP_PRIVATE_H_
0014 
0015 #include <linux/types.h>
0016 #include <linux/device.h>
0017 #include <linux/mdev.h>
0018 #include <linux/delay.h>
0019 #include <linux/mutex.h>
0020 #include <linux/kvm_host.h>
0021 #include <linux/vfio.h>
0022 #include <linux/hashtable.h>
0023 
0024 #include "ap_bus.h"
0025 
0026 #define VFIO_AP_MODULE_NAME "vfio_ap"
0027 #define VFIO_AP_DRV_NAME "vfio_ap"
0028 
0029 /**
0030  * struct ap_matrix_dev - Contains the data for the matrix device.
0031  *
0032  * @device: generic device structure associated with the AP matrix device
0033  * @available_instances: number of mediated matrix devices that can be created
0034  * @info:   the struct containing the output from the PQAP(QCI) instruction
0035  * @mdev_list:  the list of mediated matrix devices created
0036  * @mdevs_lock: mutex for locking the AP matrix device. This lock will be
0037  *      taken every time we fiddle with state managed by the vfio_ap
0038  *      driver, be it using @mdev_list or writing the state of a
0039  *      single ap_matrix_mdev device. It's quite coarse but we don't
0040  *      expect much contention.
0041  * @vfio_ap_drv: the vfio_ap device driver
0042  * @guests_lock: mutex for controlling access to a guest that is using AP
0043  *       devices passed through by the vfio_ap device driver. This lock
0044  *       will be taken when the AP devices are plugged into or unplugged
0045  *       from a guest, and when an ap_matrix_mdev device is added to or
0046  *       removed from @mdev_list or the list is iterated.
0047  */
0048 struct ap_matrix_dev {
0049     struct device device;
0050     atomic_t available_instances;
0051     struct ap_config_info info;
0052     struct list_head mdev_list;
0053     struct mutex mdevs_lock; /* serializes access to each ap_matrix_mdev */
0054     struct ap_driver  *vfio_ap_drv;
0055     struct mutex guests_lock; /* serializes access to each KVM guest */
0056 };
0057 
0058 extern struct ap_matrix_dev *matrix_dev;
0059 
0060 /**
0061  * struct ap_matrix - matrix of adapters, domains and control domains
0062  *
0063  * @apm_max: max adapter number in @apm
0064  * @apm: identifies the AP adapters in the matrix
0065  * @aqm_max: max domain number in @aqm
0066  * @aqm: identifies the AP queues (domains) in the matrix
0067  * @adm_max: max domain number in @adm
0068  * @adm: identifies the AP control domains in the matrix
0069  *
0070  * The AP matrix is comprised of three bit masks identifying the adapters,
0071  * queues (domains) and control domains that belong to an AP matrix. The bits in
0072  * each mask, from left to right, correspond to IDs 0 to 255. When a bit is set
0073  * the corresponding ID belongs to the matrix.
0074  */
0075 struct ap_matrix {
0076     unsigned long apm_max;
0077     DECLARE_BITMAP(apm, 256);
0078     unsigned long aqm_max;
0079     DECLARE_BITMAP(aqm, 256);
0080     unsigned long adm_max;
0081     DECLARE_BITMAP(adm, 256);
0082 };
0083 
0084 /**
0085  * struct ap_queue_table - a table of queue objects.
0086  *
0087  * @queues: a hashtable of queues (struct vfio_ap_queue).
0088  */
0089 struct ap_queue_table {
0090     DECLARE_HASHTABLE(queues, 8);
0091 };
0092 
0093 /**
0094  * struct ap_matrix_mdev - Contains the data associated with a matrix mediated
0095  *             device.
0096  * @vdev:   the vfio device
0097  * @node:   allows the ap_matrix_mdev struct to be added to a list
0098  * @matrix: the adapters, usage domains and control domains assigned to the
0099  *      mediated matrix device.
0100  * @shadow_apcb:    the shadow copy of the APCB field of the KVM guest's CRYCB
0101  * @kvm:    the struct holding guest's state
0102  * @pqap_hook:  the function pointer to the interception handler for the
0103  *      PQAP(AQIC) instruction.
0104  * @mdev:   the mediated device
0105  * @qtable: table of queues (struct vfio_ap_queue) assigned to the mdev
0106  * @apm_add:    bitmap of APIDs added to the host's AP configuration
0107  * @aqm_add:    bitmap of APQIs added to the host's AP configuration
0108  * @adm_add:    bitmap of control domain numbers added to the host's AP
0109  *      configuration
0110  */
0111 struct ap_matrix_mdev {
0112     struct vfio_device vdev;
0113     struct list_head node;
0114     struct ap_matrix matrix;
0115     struct ap_matrix shadow_apcb;
0116     struct kvm *kvm;
0117     crypto_hook pqap_hook;
0118     struct mdev_device *mdev;
0119     struct ap_queue_table qtable;
0120     DECLARE_BITMAP(apm_add, AP_DEVICES);
0121     DECLARE_BITMAP(aqm_add, AP_DOMAINS);
0122     DECLARE_BITMAP(adm_add, AP_DOMAINS);
0123 };
0124 
0125 /**
0126  * struct vfio_ap_queue - contains the data associated with a queue bound to the
0127  *            vfio_ap device driver
0128  * @matrix_mdev: the matrix mediated device
0129  * @saved_iova: the notification indicator byte (nib) address
0130  * @apqn: the APQN of the AP queue device
0131  * @saved_isc: the guest ISC registered with the GIB interface
0132  * @mdev_qnode: allows the vfio_ap_queue struct to be added to a hashtable
0133  * @reset_rc: the status response code from the last reset of the queue
0134  */
0135 struct vfio_ap_queue {
0136     struct ap_matrix_mdev *matrix_mdev;
0137     dma_addr_t saved_iova;
0138     int apqn;
0139 #define VFIO_AP_ISC_INVALID 0xff
0140     unsigned char saved_isc;
0141     struct hlist_node mdev_qnode;
0142     unsigned int reset_rc;
0143 };
0144 
0145 int vfio_ap_mdev_register(void);
0146 void vfio_ap_mdev_unregister(void);
0147 
0148 int vfio_ap_mdev_probe_queue(struct ap_device *queue);
0149 void vfio_ap_mdev_remove_queue(struct ap_device *queue);
0150 
0151 int vfio_ap_mdev_resource_in_use(unsigned long *apm, unsigned long *aqm);
0152 
0153 void vfio_ap_on_cfg_changed(struct ap_config_info *new_config_info,
0154                 struct ap_config_info *old_config_info);
0155 void vfio_ap_on_scan_complete(struct ap_config_info *new_config_info,
0156                   struct ap_config_info *old_config_info);
0157 
0158 #endif /* _VFIO_AP_PRIVATE_H_ */