]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/misc/mic/host/mic_virtio.h
184f3c84805b09149c7fd6ca93246050cbd35090
[karo-tx-linux.git] / drivers / misc / mic / host / mic_virtio.h
1 /*
2  * Intel MIC Platform Software Stack (MPSS)
3  *
4  * Copyright(c) 2013 Intel Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License, version 2, as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * General Public License for more details.
14  *
15  * The full GNU General Public License is included in this distribution in
16  * the file called "COPYING".
17  *
18  * Intel MIC Host driver.
19  *
20  */
21 #ifndef MIC_VIRTIO_H
22 #define MIC_VIRTIO_H
23
24 #include <linux/virtio_config.h>
25 #include <linux/mic_ioctl.h>
26
27 /*
28  * Note on endianness.
29  * 1. Host can be both BE or LE
30  * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
31  *    rings and ioreadXX/iowriteXX to access used ring.
32  * 3. Device page exposed by host to guest contains LE values. Guest
33  *    accesses these using ioreadXX/iowriteXX etc. This way in general we
34  *    obey the virtio spec according to which guest works with native
35  *    endianness and host is aware of guest endianness and does all
36  *    required endianness conversion.
37  * 4. Data provided from user space to guest (in ADD_DEVICE and
38  *    CONFIG_CHANGE ioctl's) is not interpreted by the driver and should be
39  *    in guest endianness.
40  */
41
42 /**
43  * struct mic_vringh - Virtio ring host information.
44  *
45  * @vring: The MIC vring used for setting up user space mappings.
46  * @vrh: The host VRINGH used for accessing the card vrings.
47  * @riov: The VRINGH read kernel IOV.
48  * @wiov: The VRINGH write kernel IOV.
49  * @head: The VRINGH head index address passed to vringh_getdesc_kern(..).
50  * @vr_mutex: Mutex for synchronizing access to the VRING.
51  * @mvdev: Back pointer to MIC virtio device for vringh_notify(..).
52  */
53 struct mic_vringh {
54         struct mic_vring vring;
55         struct vringh vrh;
56         struct vringh_kiov riov;
57         struct vringh_kiov wiov;
58         u16 head;
59         struct mutex vr_mutex;
60         struct mic_vdev *mvdev;
61 };
62
63 /**
64  * struct mic_vdev - Host information for a card Virtio device.
65  *
66  * @virtio_id - Virtio device id.
67  * @waitq - Waitqueue to allow ring3 apps to poll.
68  * @mdev - Back pointer to host MIC device.
69  * @poll_wake - Used for waking up threads blocked in poll.
70  * @out_bytes - Debug stats for number of bytes copied from host to card.
71  * @in_bytes - Debug stats for number of bytes copied from card to host.
72  * @mvr - Store per VRING data structures.
73  * @virtio_bh_work - Work struct used to schedule virtio bottom half handling.
74  * @dd - Virtio device descriptor.
75  * @dc - Virtio device control fields.
76  * @list - List of Virtio devices.
77  * @virtio_db - The doorbell used by the card to interrupt the host.
78  * @virtio_cookie - The cookie returned while requesting interrupts.
79  */
80 struct mic_vdev {
81         int virtio_id;
82         wait_queue_head_t waitq;
83         struct mic_device *mdev;
84         int poll_wake;
85         unsigned long out_bytes;
86         unsigned long in_bytes;
87         struct mic_vringh mvr[MIC_MAX_VRINGS];
88         struct work_struct virtio_bh_work;
89         struct mic_device_desc *dd;
90         struct mic_device_ctrl *dc;
91         struct list_head list;
92         int virtio_db;
93         struct mic_irq *virtio_cookie;
94 };
95
96 void mic_virtio_uninit(struct mic_device *mdev);
97 int mic_virtio_add_device(struct mic_vdev *mvdev,
98                         void __user *argp);
99 void mic_virtio_del_device(struct mic_vdev *mvdev);
100 int mic_virtio_config_change(struct mic_vdev *mvdev,
101                         void __user *argp);
102 int mic_virtio_copy_desc(struct mic_vdev *mvdev,
103         struct mic_copy_desc *request);
104 void mic_virtio_reset_devices(struct mic_device *mdev);
105 void mic_bh_handler(struct work_struct *work);
106
107 /* Helper API to obtain the MIC PCIe device */
108 static inline struct device *mic_dev(struct mic_vdev *mvdev)
109 {
110         return mvdev->mdev->sdev->parent;
111 }
112
113 /* Helper API to check if a virtio device is initialized */
114 static inline int mic_vdev_inited(struct mic_vdev *mvdev)
115 {
116         /* Device has not been created yet */
117         if (!mvdev->dd || !mvdev->dd->type) {
118                 dev_err(mic_dev(mvdev), "%s %d err %d\n",
119                         __func__, __LINE__, -EINVAL);
120                 return -EINVAL;
121         }
122
123         /* Device has been removed/deleted */
124         if (mvdev->dd->type == -1) {
125                 dev_err(mic_dev(mvdev), "%s %d err %d\n",
126                         __func__, __LINE__, -ENODEV);
127                 return -ENODEV;
128         }
129
130         return 0;
131 }
132
133 /* Helper API to check if a virtio device is running */
134 static inline bool mic_vdevup(struct mic_vdev *mvdev)
135 {
136         return !!mvdev->dd->status;
137 }
138 #endif