Skip to content

Commit d4ef098

Browse files
yshivakrishnagregkh
authored andcommitted
misc: mic: add dma support in host driver
This patch adds a dma device on the mic virtual bus and uses this dmaengine to transfer data for virtio devices Reviewed-by: Nikhil Rao <nikhil.rao@intel.com> Signed-off-by: Sudeep Dutt <sudeep.dutt@intel.com> Signed-off-by: Ashutosh Dixit <ashutosh.dixit@intel.com> Signed-off-by: Siva Yerramreddy <yshivakrishna@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b8e439f commit d4ef098

7 files changed

Lines changed: 281 additions & 41 deletions

File tree

‎drivers/misc/mic/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ comment "Intel MIC Host Driver"
1919

2020
config INTEL_MIC_HOST
2121
tristate "Intel MIC Host Driver"
22-
depends on 64BIT && PCI && X86
22+
depends on 64BIT && PCI && X86 && INTEL_MIC_BUS
2323
select VHOST_RING
2424
help
2525
This enables Host Driver support for the Intel Many Integrated

‎drivers/misc/mic/host/mic_boot.c‎

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,70 @@
2323
#include <linux/pci.h>
2424

2525
#include <linux/mic_common.h>
26+
#include <linux/mic_bus.h>
2627
#include "../common/mic_dev.h"
2728
#include "mic_device.h"
2829
#include "mic_smpt.h"
2930
#include "mic_virtio.h"
3031

32+
static inline struct mic_device *mbdev_to_mdev(struct mbus_device *mbdev)
33+
{
34+
return dev_get_drvdata(mbdev->dev.parent);
35+
}
36+
37+
static dma_addr_t
38+
mic_dma_map_page(struct device *dev, struct page *page,
39+
unsigned long offset, size_t size, enum dma_data_direction dir,
40+
struct dma_attrs *attrs)
41+
{
42+
void *va = phys_to_virt(page_to_phys(page)) + offset;
43+
struct mic_device *mdev = dev_get_drvdata(dev->parent);
44+
45+
return mic_map_single(mdev, va, size);
46+
}
47+
48+
static void
49+
mic_dma_unmap_page(struct device *dev, dma_addr_t dma_addr,
50+
size_t size, enum dma_data_direction dir,
51+
struct dma_attrs *attrs)
52+
{
53+
struct mic_device *mdev = dev_get_drvdata(dev->parent);
54+
mic_unmap_single(mdev, dma_addr, size);
55+
}
56+
57+
static struct dma_map_ops mic_dma_ops = {
58+
.map_page = mic_dma_map_page,
59+
.unmap_page = mic_dma_unmap_page,
60+
};
61+
62+
static struct mic_irq *
63+
_mic_request_threaded_irq(struct mbus_device *mbdev,
64+
irq_handler_t handler, irq_handler_t thread_fn,
65+
const char *name, void *data, int intr_src)
66+
{
67+
return mic_request_threaded_irq(mbdev_to_mdev(mbdev), handler,
68+
thread_fn, name, data,
69+
intr_src, MIC_INTR_DMA);
70+
}
71+
72+
static void _mic_free_irq(struct mbus_device *mbdev,
73+
struct mic_irq *cookie, void *data)
74+
{
75+
return mic_free_irq(mbdev_to_mdev(mbdev), cookie, data);
76+
}
77+
78+
static void _mic_ack_interrupt(struct mbus_device *mbdev, int num)
79+
{
80+
struct mic_device *mdev = mbdev_to_mdev(mbdev);
81+
mdev->ops->intr_workarounds(mdev);
82+
}
83+
84+
static struct mbus_hw_ops mbus_hw_ops = {
85+
.request_threaded_irq = _mic_request_threaded_irq,
86+
.free_irq = _mic_free_irq,
87+
.ack_interrupt = _mic_ack_interrupt,
88+
};
89+
3190
/**
3291
* mic_reset - Reset the MIC device.
3392
* @mdev: pointer to mic_device instance
@@ -95,16 +154,33 @@ int mic_start(struct mic_device *mdev, const char *buf)
95154
*/
96155
goto retry;
97156
}
157+
mdev->dma_mbdev = mbus_register_device(mdev->sdev->parent,
158+
MBUS_DEV_DMA_HOST, &mic_dma_ops,
159+
&mbus_hw_ops, mdev->mmio.va);
160+
if (IS_ERR(mdev->dma_mbdev)) {
161+
rc = PTR_ERR(mdev->dma_mbdev);
162+
goto unlock_ret;
163+
}
164+
mdev->dma_ch = mic_request_dma_chan(mdev);
165+
if (!mdev->dma_ch) {
166+
rc = -ENXIO;
167+
goto dma_remove;
168+
}
98169
rc = mdev->ops->load_mic_fw(mdev, buf);
99170
if (rc)
100-
goto unlock_ret;
171+
goto dma_release;
101172
mic_smpt_restore(mdev);
102173
mic_intr_restore(mdev);
103174
mdev->intr_ops->enable_interrupts(mdev);
104175
mdev->ops->write_spad(mdev, MIC_DPLO_SPAD, mdev->dp_dma_addr);
105176
mdev->ops->write_spad(mdev, MIC_DPHI_SPAD, mdev->dp_dma_addr >> 32);
106177
mdev->ops->send_firmware_intr(mdev);
107178
mic_set_state(mdev, MIC_ONLINE);
179+
goto unlock_ret;
180+
dma_release:
181+
dma_release_channel(mdev->dma_ch);
182+
dma_remove:
183+
mbus_unregister_device(mdev->dma_mbdev);
108184
unlock_ret:
109185
mutex_unlock(&mdev->mic_mutex);
110186
return rc;
@@ -122,6 +198,11 @@ void mic_stop(struct mic_device *mdev, bool force)
122198
mutex_lock(&mdev->mic_mutex);
123199
if (MIC_OFFLINE != mdev->state || force) {
124200
mic_virtio_reset_devices(mdev);
201+
if (mdev->dma_ch) {
202+
dma_release_channel(mdev->dma_ch);
203+
mdev->dma_ch = NULL;
204+
}
205+
mbus_unregister_device(mdev->dma_mbdev);
125206
mic_bootparam_init(mdev);
126207
mic_reset(mdev);
127208
if (MIC_RESET_FAILED == mdev->state)

‎drivers/misc/mic/host/mic_device.h‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <linux/idr.h>
2626
#include <linux/notifier.h>
2727
#include <linux/irqreturn.h>
28+
#include <linux/dmaengine.h>
29+
#include <linux/mic_bus.h>
2830

2931
#include "mic_intr.h"
3032

@@ -87,6 +89,8 @@ enum mic_stepping {
8789
* @cdev: Character device for MIC.
8890
* @vdev_list: list of virtio devices.
8991
* @pm_notifier: Handles PM notifications from the OS.
92+
* @dma_mbdev: MIC BUS DMA device.
93+
* @dma_ch: DMA channel reserved by this driver for use by virtio devices.
9094
*/
9195
struct mic_device {
9296
struct mic_mw mmio;
@@ -124,6 +128,8 @@ struct mic_device {
124128
struct cdev cdev;
125129
struct list_head vdev_list;
126130
struct notifier_block pm_notifier;
131+
struct mbus_device *dma_mbdev;
132+
struct dma_chan *dma_ch;
127133
};
128134

129135
/**
@@ -144,6 +150,7 @@ struct mic_device {
144150
* @load_mic_fw: Load firmware segments required to boot the card
145151
* into card memory. This includes the kernel, command line, ramdisk etc.
146152
* @get_postcode: Get post code status from firmware.
153+
* @dma_filter: DMA filter function to be used.
147154
*/
148155
struct mic_hw_ops {
149156
u8 aper_bar;
@@ -159,6 +166,7 @@ struct mic_hw_ops {
159166
void (*send_firmware_intr)(struct mic_device *mdev);
160167
int (*load_mic_fw)(struct mic_device *mdev, const char *buf);
161168
u32 (*get_postcode)(struct mic_device *mdev);
169+
bool (*dma_filter)(struct dma_chan *chan, void *param);
162170
};
163171

164172
/**
@@ -187,6 +195,22 @@ mic_mmio_write(struct mic_mw *mw, u32 val, u32 offset)
187195
iowrite32(val, mw->va + offset);
188196
}
189197

198+
static inline struct dma_chan *mic_request_dma_chan(struct mic_device *mdev)
199+
{
200+
dma_cap_mask_t mask;
201+
struct dma_chan *chan;
202+
203+
dma_cap_zero(mask);
204+
dma_cap_set(DMA_MEMCPY, mask);
205+
chan = dma_request_channel(mask, mdev->ops->dma_filter,
206+
mdev->sdev->parent);
207+
if (chan)
208+
return chan;
209+
dev_err(mdev->sdev->parent, "%s %d unable to acquire channel\n",
210+
__func__, __LINE__);
211+
return NULL;
212+
}
213+
190214
void mic_sysfs_init(struct mic_device *mdev);
191215
int mic_start(struct mic_device *mdev, const char *buf);
192216
void mic_stop(struct mic_device *mdev, bool force);

‎drivers/misc/mic/host/mic_intr.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@
2727
* The minimum number of msix vectors required for normal operation.
2828
* 3 for virtio network, console and block devices.
2929
* 1 for card shutdown notifications.
30+
* 4 for host owned DMA channels.
3031
*/
31-
#define MIC_MIN_MSIX 4
32+
#define MIC_MIN_MSIX 8
3233
#define MIC_NUM_OFFSETS 32
3334

3435
/**

0 commit comments

Comments
 (0)