1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Intel MIC Platform Software Stack (MPSS)
5 * Copyright(c) 2016 Intel Corporation.
7 * Intel Virtio Over PCIe (VOP) driver.
12 #include <linux/vringh.h>
13 #include <linux/virtio_config.h>
14 #include <linux/virtio.h>
15 #include <linux/miscdevice.h>
17 #include <linux/mic_common.h>
18 #include "../common/mic_dev.h"
20 #include "../bus/vop_bus.h"
24 * 1. Host can be both BE or LE
25 * 2. Guest/card is LE. Host uses le_to_cpu to access desc/avail
26 * rings and ioreadXX/iowriteXX to access used ring.
27 * 3. Device page exposed by host to guest contains LE values. Guest
28 * accesses these using ioreadXX/iowriteXX etc. This way in general we
29 * obey the virtio spec according to which guest works with native
30 * endianness and host is aware of guest endianness and does all
31 * required endianness conversion.
32 * 4. Data provided from user space to guest (in ADD_DEVICE and
33 * CONFIG_CHANGE ioctl's) is not interpreted by the driver and should be
34 * in guest endianness.
38 * vop_info - Allocated per invocation of VOP probe
41 * @hotplug_work: Handle virtio device creation, deletion and configuration
42 * @cookie: Cookie received upon requesting a virtio configuration interrupt
43 * @h2c_config_db: The doorbell used by the peer to indicate a config change
44 * @vdev_list: List of "active" virtio devices injected in the peer node
45 * @vop_mutex: Synchronize access to the device page as well as serialize
46 * creation/deletion of virtio devices on the peer node
47 * @dp: Peer device page information
49 * @dma_ch: The DMA channel used by this transport for data transfers.
50 * @name: Name for this transport used in misc device creation.
51 * @miscdev: The misc device registered.
54 struct vop_device
*vpdev
;
55 struct work_struct hotplug_work
;
56 struct mic_irq
*cookie
;
58 struct list_head vdev_list
;
59 struct mutex vop_mutex
;
62 struct dma_chan
*dma_ch
;
64 struct miscdevice miscdev
;
68 * struct vop_vringh - Virtio ring host information.
70 * @vring: The VOP vring used for setting up user space mappings.
71 * @vrh: The host VRINGH used for accessing the card vrings.
72 * @riov: The VRINGH read kernel IOV.
73 * @wiov: The VRINGH write kernel IOV.
74 * @head: The VRINGH head index address passed to vringh_getdesc_kern(..).
75 * @vr_mutex: Mutex for synchronizing access to the VRING.
76 * @buf: Temporary kernel buffer used to copy in/out data
77 * from/to the card via DMA.
78 * @buf_da: dma address of buf.
79 * @vdev: Back pointer to VOP virtio device for vringh_notify(..).
82 struct mic_vring vring
;
84 struct vringh_kiov riov
;
85 struct vringh_kiov wiov
;
87 struct mutex vr_mutex
;
90 struct vop_vdev
*vdev
;
94 * struct vop_vdev - Host information for a card Virtio device.
96 * @virtio_id - Virtio device id.
97 * @waitq - Waitqueue to allow ring3 apps to poll.
98 * @vpdev - pointer to VOP bus device.
99 * @poll_wake - Used for waking up threads blocked in poll.
100 * @out_bytes - Debug stats for number of bytes copied from host to card.
101 * @in_bytes - Debug stats for number of bytes copied from card to host.
102 * @out_bytes_dma - Debug stats for number of bytes copied from host to card
104 * @in_bytes_dma - Debug stats for number of bytes copied from card to host
106 * @tx_len_unaligned - Debug stats for number of bytes copied to the card where
107 * the transfer length did not have the required DMA alignment.
108 * @tx_dst_unaligned - Debug stats for number of bytes copied where the
109 * destination address on the card did not have the required DMA alignment.
110 * @vvr - Store per VRING data structures.
111 * @virtio_bh_work - Work struct used to schedule virtio bottom half handling.
112 * @dd - Virtio device descriptor.
113 * @dc - Virtio device control fields.
114 * @list - List of Virtio devices.
115 * @virtio_db - The doorbell used by the card to interrupt the host.
116 * @virtio_cookie - The cookie returned while requesting interrupts.
117 * @vi: Transport information.
118 * @vdev_mutex: Mutex synchronizing virtio device injection,
119 * removal and data transfers.
120 * @destroy: Track if a virtio device is being destroyed.
121 * @deleted: The virtio device has been deleted.
125 wait_queue_head_t waitq
;
126 struct vop_device
*vpdev
;
128 unsigned long out_bytes
;
129 unsigned long in_bytes
;
130 unsigned long out_bytes_dma
;
131 unsigned long in_bytes_dma
;
132 unsigned long tx_len_unaligned
;
133 unsigned long tx_dst_unaligned
;
134 unsigned long rx_dst_unaligned
;
135 struct vop_vringh vvr
[MIC_MAX_VRINGS
];
136 struct work_struct virtio_bh_work
;
137 struct mic_device_desc
*dd
;
138 struct mic_device_ctrl
*dc
;
139 struct list_head list
;
141 struct mic_irq
*virtio_cookie
;
143 struct mutex vdev_mutex
;
144 struct completion destroy
;
148 /* Helper API to check if a virtio device is running */
149 static inline bool vop_vdevup(struct vop_vdev
*vdev
)
151 return !!vdev
->dd
->status
;
154 void vop_init_debugfs(struct vop_info
*vi
);
155 void vop_exit_debugfs(struct vop_info
*vi
);
156 int vop_host_init(struct vop_info
*vi
);
157 void vop_host_uninit(struct vop_info
*vi
);