2 * Intel MIC Platform Software Stack (MPSS)
4 * Copyright(c) 2013 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 MIC Host driver.
24 #include <linux/virtio_config.h>
25 #include <linux/mic_ioctl.h>
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.
43 * struct mic_vringh - Virtio ring host information.
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(..).
54 struct mic_vring vring
;
56 struct vringh_kiov riov
;
57 struct vringh_kiov wiov
;
59 struct mutex vr_mutex
;
60 struct mic_vdev
*mvdev
;
64 * struct mic_vdev - Host information for a card Virtio device.
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.
82 wait_queue_head_t waitq
;
83 struct mic_device
*mdev
;
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
;
93 struct mic_irq
*virtio_cookie
;
96 void mic_virtio_uninit(struct mic_device
*mdev
);
97 int mic_virtio_add_device(struct mic_vdev
*mvdev
,
99 void mic_virtio_del_device(struct mic_vdev
*mvdev
);
100 int mic_virtio_config_change(struct mic_vdev
*mvdev
,
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
);
107 /* Helper API to obtain the MIC PCIe device */
108 static inline struct device
*mic_dev(struct mic_vdev
*mvdev
)
110 return mvdev
->mdev
->sdev
->parent
;
113 /* Helper API to check if a virtio device is initialized */
114 static inline int mic_vdev_inited(struct mic_vdev
*mvdev
)
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
);
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
);
133 /* Helper API to check if a virtio device is running */
134 static inline bool mic_vdevup(struct mic_vdev
*mvdev
)
136 return !!mvdev
->dd
->status
;