Merge tag 's390-5.20-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
[linux-2.6-microblaze.git] / drivers / s390 / crypto / vfio_ap_private.h
index d912487..d782cf4 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/mutex.h>
 #include <linux/kvm_host.h>
 #include <linux/vfio.h>
+#include <linux/hashtable.h>
 
 #include "ap_bus.h"
 
  * @available_instances: number of mediated matrix devices that can be created
  * @info:      the struct containing the output from the PQAP(QCI) instruction
  * @mdev_list: the list of mediated matrix devices created
- * @lock:      mutex for locking the AP matrix device. This lock will be
+ * @mdevs_lock: mutex for locking the AP matrix device. This lock will be
  *             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.
  * @vfio_ap_drv: the vfio_ap device driver
+ * @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.
  */
 struct ap_matrix_dev {
        struct device device;
        atomic_t available_instances;
        struct ap_config_info info;
        struct list_head mdev_list;
-       struct mutex lock;
+       struct mutex mdevs_lock; /* serializes access to each ap_matrix_mdev */
        struct ap_driver  *vfio_ap_drv;
+       struct mutex guests_lock; /* serializes access to each KVM guest */
 };
 
 extern struct ap_matrix_dev *matrix_dev;
@@ -74,6 +81,15 @@ struct ap_matrix {
        DECLARE_BITMAP(adm, 256);
 };
 
+/**
+ * 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);
+};
+
 /**
  * struct ap_matrix_mdev - Contains the data associated with a matrix mediated
  *                        device.
@@ -81,18 +97,29 @@ struct ap_matrix {
  * @node:      allows the ap_matrix_mdev struct to be added to a list
  * @matrix:    the adapters, usage domains and control domains assigned to the
  *             mediated matrix device.
+ * @shadow_apcb:    the shadow copy of the APCB field of the KVM guest's CRYCB
  * @kvm:       the struct holding guest's state
  * @pqap_hook: the function pointer to the interception handler for the
  *             PQAP(AQIC) instruction.
  * @mdev:      the mediated device
+ * @qtable:    table of queues (struct vfio_ap_queue) assigned to the mdev
+ * @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
  */
 struct ap_matrix_mdev {
        struct vfio_device vdev;
        struct list_head node;
        struct ap_matrix matrix;
+       struct ap_matrix shadow_apcb;
        struct kvm *kvm;
        crypto_hook pqap_hook;
        struct mdev_device *mdev;
+       struct ap_queue_table qtable;
+       DECLARE_BITMAP(apm_add, AP_DEVICES);
+       DECLARE_BITMAP(aqm_add, AP_DOMAINS);
+       DECLARE_BITMAP(adm_add, AP_DOMAINS);
 };
 
 /**
@@ -102,6 +129,8 @@ struct ap_matrix_mdev {
  * @saved_iova: the notification indicator byte (nib) address
  * @apqn: the APQN of the AP queue device
  * @saved_isc: the guest ISC registered with the GIB interface
+ * @mdev_qnode: allows the vfio_ap_queue struct to be added to a hashtable
+ * @reset_rc: the status response code from the last reset of the queue
  */
 struct vfio_ap_queue {
        struct ap_matrix_mdev *matrix_mdev;
@@ -109,11 +138,21 @@ struct vfio_ap_queue {
        int     apqn;
 #define VFIO_AP_ISC_INVALID 0xff
        unsigned char saved_isc;
+       struct hlist_node mdev_qnode;
+       unsigned int reset_rc;
 };
 
 int vfio_ap_mdev_register(void);
 void vfio_ap_mdev_unregister(void);
-int vfio_ap_mdev_reset_queue(struct vfio_ap_queue *q,
-                            unsigned int retry);
+
+int vfio_ap_mdev_probe_queue(struct ap_device *queue);
+void vfio_ap_mdev_remove_queue(struct ap_device *queue);
+
+int vfio_ap_mdev_resource_in_use(unsigned long *apm, unsigned long *aqm);
+
+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);
 
 #endif /* _VFIO_AP_PRIVATE_H_ */