Linux 5.1.15
[linux/fpc-iii.git] / drivers / misc / mic / vop / vop_main.h
blobba47ec7a638647e7c765015fb6b7b0cd6dd816e9
1 /*
2 * Intel MIC Platform Software Stack (MPSS)
4 * Copyright(c) 2016 Intel Corporation.
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.
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.
15 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
18 * Intel Virtio Over PCIe (VOP) driver.
21 #ifndef _VOP_MAIN_H_
22 #define _VOP_MAIN_H_
24 #include <linux/vringh.h>
25 #include <linux/virtio_config.h>
26 #include <linux/virtio.h>
27 #include <linux/miscdevice.h>
29 #include <linux/mic_common.h>
30 #include "../common/mic_dev.h"
32 #include "../bus/vop_bus.h"
35 * Note on endianness.
36 * 1. Host can be both BE or LE
37 * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
38 * rings and ioreadXX/iowriteXX to access used ring.
39 * 3. Device page exposed by host to guest contains LE values. Guest
40 * accesses these using ioreadXX/iowriteXX etc. This way in general we
41 * obey the virtio spec according to which guest works with native
42 * endianness and host is aware of guest endianness and does all
43 * required endianness conversion.
44 * 4. Data provided from user space to guest (in ADD_DEVICE and
45 * CONFIG_CHANGE ioctl's) is not interpreted by the driver and should be
46 * in guest endianness.
50 * vop_info - Allocated per invocation of VOP probe
52 * @vpdev: VOP device
53 * @hotplug_work: Handle virtio device creation, deletion and configuration
54 * @cookie: Cookie received upon requesting a virtio configuration interrupt
55 * @h2c_config_db: The doorbell used by the peer to indicate a config change
56 * @vdev_list: List of "active" virtio devices injected in the peer node
57 * @vop_mutex: Synchronize access to the device page as well as serialize
58 * creation/deletion of virtio devices on the peer node
59 * @dp: Peer device page information
60 * @dbg: Debugfs entry
61 * @dma_ch: The DMA channel used by this transport for data transfers.
62 * @name: Name for this transport used in misc device creation.
63 * @miscdev: The misc device registered.
65 struct vop_info {
66 struct vop_device *vpdev;
67 struct work_struct hotplug_work;
68 struct mic_irq *cookie;
69 int h2c_config_db;
70 struct list_head vdev_list;
71 struct mutex vop_mutex;
72 void __iomem *dp;
73 struct dentry *dbg;
74 struct dma_chan *dma_ch;
75 char name[16];
76 struct miscdevice miscdev;
79 /**
80 * struct vop_vringh - Virtio ring host information.
82 * @vring: The VOP vring used for setting up user space mappings.
83 * @vrh: The host VRINGH used for accessing the card vrings.
84 * @riov: The VRINGH read kernel IOV.
85 * @wiov: The VRINGH write kernel IOV.
86 * @head: The VRINGH head index address passed to vringh_getdesc_kern(..).
87 * @vr_mutex: Mutex for synchronizing access to the VRING.
88 * @buf: Temporary kernel buffer used to copy in/out data
89 * from/to the card via DMA.
90 * @buf_da: dma address of buf.
91 * @vdev: Back pointer to VOP virtio device for vringh_notify(..).
93 struct vop_vringh {
94 struct mic_vring vring;
95 struct vringh vrh;
96 struct vringh_kiov riov;
97 struct vringh_kiov wiov;
98 u16 head;
99 struct mutex vr_mutex;
100 void *buf;
101 dma_addr_t buf_da;
102 struct vop_vdev *vdev;
106 * struct vop_vdev - Host information for a card Virtio device.
108 * @virtio_id - Virtio device id.
109 * @waitq - Waitqueue to allow ring3 apps to poll.
110 * @vpdev - pointer to VOP bus device.
111 * @poll_wake - Used for waking up threads blocked in poll.
112 * @out_bytes - Debug stats for number of bytes copied from host to card.
113 * @in_bytes - Debug stats for number of bytes copied from card to host.
114 * @out_bytes_dma - Debug stats for number of bytes copied from host to card
115 * using DMA.
116 * @in_bytes_dma - Debug stats for number of bytes copied from card to host
117 * using DMA.
118 * @tx_len_unaligned - Debug stats for number of bytes copied to the card where
119 * the transfer length did not have the required DMA alignment.
120 * @tx_dst_unaligned - Debug stats for number of bytes copied where the
121 * destination address on the card did not have the required DMA alignment.
122 * @vvr - Store per VRING data structures.
123 * @virtio_bh_work - Work struct used to schedule virtio bottom half handling.
124 * @dd - Virtio device descriptor.
125 * @dc - Virtio device control fields.
126 * @list - List of Virtio devices.
127 * @virtio_db - The doorbell used by the card to interrupt the host.
128 * @virtio_cookie - The cookie returned while requesting interrupts.
129 * @vi: Transport information.
130 * @vdev_mutex: Mutex synchronizing virtio device injection,
131 * removal and data transfers.
132 * @destroy: Track if a virtio device is being destroyed.
133 * @deleted: The virtio device has been deleted.
135 struct vop_vdev {
136 int virtio_id;
137 wait_queue_head_t waitq;
138 struct vop_device *vpdev;
139 int poll_wake;
140 unsigned long out_bytes;
141 unsigned long in_bytes;
142 unsigned long out_bytes_dma;
143 unsigned long in_bytes_dma;
144 unsigned long tx_len_unaligned;
145 unsigned long tx_dst_unaligned;
146 unsigned long rx_dst_unaligned;
147 struct vop_vringh vvr[MIC_MAX_VRINGS];
148 struct work_struct virtio_bh_work;
149 struct mic_device_desc *dd;
150 struct mic_device_ctrl *dc;
151 struct list_head list;
152 int virtio_db;
153 struct mic_irq *virtio_cookie;
154 struct vop_info *vi;
155 struct mutex vdev_mutex;
156 struct completion destroy;
157 bool deleted;
160 /* Helper API to check if a virtio device is running */
161 static inline bool vop_vdevup(struct vop_vdev *vdev)
163 return !!vdev->dd->status;
166 void vop_init_debugfs(struct vop_info *vi);
167 void vop_exit_debugfs(struct vop_info *vi);
168 int vop_host_init(struct vop_info *vi);
169 void vop_host_uninit(struct vop_info *vi);
170 #endif