Skip to content

Commit 16bb86b

Browse files
committed
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
Pull virtio updates from Michael Tsirkin: "A bunch of new drivers including vdpa support for block and virtio-vdpa. Beginning of vq kick (aka doorbell) mapping support. Misc fixes" * tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: (40 commits) virtio_pci_modern: correct sparse tags for notify virtio_pci_modern: __force cast the notify mapping vDPA/ifcvf: get_config_size should return dev specific config size vDPA/ifcvf: enable Intel C5000X-PL virtio-block for vDPA vDPA/ifcvf: deduce VIRTIO device ID when probe vdpa_sim_blk: add support for vdpa management tool vdpa_sim_blk: handle VIRTIO_BLK_T_GET_ID vdpa_sim_blk: implement ramdisk behaviour vdpa: add vdpa simulator for block device vhost/vdpa: Remove the restriction that only supports virtio-net devices vhost/vdpa: use get_config_size callback in vhost_vdpa_config_validate() vdpa: add get_config_size callback in vdpa_config_ops vdpa_sim: cleanup kiovs in vdpasim_free() vringh: add vringh_kiov_length() helper vringh: implement vringh_kiov_advance() vringh: explain more about cleaning riov and wiov vringh: reset kiov 'consumed' field in __vringh_iov() vringh: add 'iotlb_lock' to synchronize iotlb accesses vdpa_sim: use iova module to allocate IOVA addresses vDPA/ifcvf: deduce VIRTIO device ID from pdev ids ...
2 parents 57151b5 + d7bce85 commit 16bb86b

23 files changed

+1295
-172
lines changed

drivers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ obj-$(CONFIG_DMADEVICES) += dma/
4242
obj-y += soc/
4343

4444
obj-$(CONFIG_VIRTIO) += virtio/
45+
obj-$(CONFIG_VIRTIO_PCI_LIB) += virtio/
4546
obj-$(CONFIG_VDPA) += vdpa/
4647
obj-$(CONFIG_XEN) += xen/
4748

drivers/net/virtio_net.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,9 +2870,13 @@ static int virtnet_alloc_queues(struct virtnet_info *vi)
28702870
{
28712871
int i;
28722872

2873-
vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL);
2874-
if (!vi->ctrl)
2875-
goto err_ctrl;
2873+
if (vi->has_cvq) {
2874+
vi->ctrl = kzalloc(sizeof(*vi->ctrl), GFP_KERNEL);
2875+
if (!vi->ctrl)
2876+
goto err_ctrl;
2877+
} else {
2878+
vi->ctrl = NULL;
2879+
}
28762880
vi->sq = kcalloc(vi->max_queue_pairs, sizeof(*vi->sq), GFP_KERNEL);
28772881
if (!vi->sq)
28782882
goto err_sq;

drivers/vdpa/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ config VDPA_SIM
1414
depends on RUNTIME_TESTING_MENU && HAS_DMA
1515
select DMA_OPS
1616
select VHOST_RING
17+
select IOMMU_IOVA
1718
help
1819
Enable this module to support vDPA device simulators. These devices
1920
are used for testing, prototyping and development of vDPA.
@@ -25,6 +26,13 @@ config VDPA_SIM_NET
2526
help
2627
vDPA networking device simulator which loops TX traffic back to RX.
2728

29+
config VDPA_SIM_BLOCK
30+
tristate "vDPA simulator for block device"
31+
depends on VDPA_SIM
32+
help
33+
vDPA block device simulator which terminates IO request in a
34+
memory buffer.
35+
2836
config IFCVF
2937
tristate "Intel IFC VF vDPA driver"
3038
depends on PCI_MSI
@@ -52,4 +60,11 @@ config MLX5_VDPA_NET
5260
be executed by the hardware. It also supports a variety of stateless
5361
offloads depending on the actual device used and firmware version.
5462

63+
config VP_VDPA
64+
tristate "Virtio PCI bridge vDPA driver"
65+
select VIRTIO_PCI_LIB
66+
depends on PCI_MSI
67+
help
68+
This kernel module bridges virtio PCI device to vDPA bus.
69+
5570
endif # VDPA

drivers/vdpa/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ obj-$(CONFIG_VDPA) += vdpa.o
33
obj-$(CONFIG_VDPA_SIM) += vdpa_sim/
44
obj-$(CONFIG_IFCVF) += ifcvf/
55
obj-$(CONFIG_MLX5_VDPA) += mlx5/
6+
obj-$(CONFIG_VP_VDPA) += virtio_pci/

drivers/vdpa/ifcvf/ifcvf_base.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,38 @@ static void ifcvf_add_status(struct ifcvf_hw *hw, u8 status)
202202
ifcvf_get_status(hw);
203203
}
204204

205-
u64 ifcvf_get_features(struct ifcvf_hw *hw)
205+
u64 ifcvf_get_hw_features(struct ifcvf_hw *hw)
206206
{
207207
struct virtio_pci_common_cfg __iomem *cfg = hw->common_cfg;
208208
u32 features_lo, features_hi;
209+
u64 features;
209210

210211
ifc_iowrite32(0, &cfg->device_feature_select);
211212
features_lo = ifc_ioread32(&cfg->device_feature);
212213

213214
ifc_iowrite32(1, &cfg->device_feature_select);
214215
features_hi = ifc_ioread32(&cfg->device_feature);
215216

216-
return ((u64)features_hi << 32) | features_lo;
217+
features = ((u64)features_hi << 32) | features_lo;
218+
219+
return features;
220+
}
221+
222+
u64 ifcvf_get_features(struct ifcvf_hw *hw)
223+
{
224+
return hw->hw_features;
225+
}
226+
227+
int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features)
228+
{
229+
struct ifcvf_adapter *ifcvf = vf_to_adapter(hw);
230+
231+
if (!(features & BIT_ULL(VIRTIO_F_ACCESS_PLATFORM)) && features) {
232+
IFCVF_ERR(ifcvf->pdev, "VIRTIO_F_ACCESS_PLATFORM is not negotiated\n");
233+
return -EINVAL;
234+
}
235+
236+
return 0;
217237
}
218238

219239
void ifcvf_read_net_config(struct ifcvf_hw *hw, u64 offset,

drivers/vdpa/ifcvf/ifcvf_base.h

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,26 @@
1515
#include <linux/pci_regs.h>
1616
#include <linux/vdpa.h>
1717
#include <uapi/linux/virtio_net.h>
18+
#include <uapi/linux/virtio_blk.h>
1819
#include <uapi/linux/virtio_config.h>
1920
#include <uapi/linux/virtio_pci.h>
2021

21-
#define IFCVF_VENDOR_ID 0x1AF4
22-
#define IFCVF_DEVICE_ID 0x1041
23-
#define IFCVF_SUBSYS_VENDOR_ID 0x8086
24-
#define IFCVF_SUBSYS_DEVICE_ID 0x001A
22+
#define N3000_VENDOR_ID 0x1AF4
23+
#define N3000_DEVICE_ID 0x1041
24+
#define N3000_SUBSYS_VENDOR_ID 0x8086
25+
#define N3000_SUBSYS_DEVICE_ID 0x001A
2526

26-
#define IFCVF_SUPPORTED_FEATURES \
27+
#define C5000X_PL_VENDOR_ID 0x1AF4
28+
#define C5000X_PL_DEVICE_ID 0x1000
29+
#define C5000X_PL_SUBSYS_VENDOR_ID 0x8086
30+
#define C5000X_PL_SUBSYS_DEVICE_ID 0x0001
31+
32+
#define C5000X_PL_BLK_VENDOR_ID 0x1AF4
33+
#define C5000X_PL_BLK_DEVICE_ID 0x1001
34+
#define C5000X_PL_BLK_SUBSYS_VENDOR_ID 0x8086
35+
#define C5000X_PL_BLK_SUBSYS_DEVICE_ID 0x0002
36+
37+
#define IFCVF_NET_SUPPORTED_FEATURES \
2738
((1ULL << VIRTIO_NET_F_MAC) | \
2839
(1ULL << VIRTIO_F_ANY_LAYOUT) | \
2940
(1ULL << VIRTIO_F_VERSION_1) | \
@@ -78,6 +89,8 @@ struct ifcvf_hw {
7889
void __iomem *notify_base;
7990
u32 notify_off_multiplier;
8091
u64 req_features;
92+
u64 hw_features;
93+
u32 dev_type;
8194
struct virtio_pci_common_cfg __iomem *common_cfg;
8295
void __iomem *net_cfg;
8396
struct vring_info vring[IFCVF_MAX_QUEUE_PAIRS * 2];
@@ -116,7 +129,10 @@ void ifcvf_set_status(struct ifcvf_hw *hw, u8 status);
116129
void io_write64_twopart(u64 val, u32 *lo, u32 *hi);
117130
void ifcvf_reset(struct ifcvf_hw *hw);
118131
u64 ifcvf_get_features(struct ifcvf_hw *hw);
132+
u64 ifcvf_get_hw_features(struct ifcvf_hw *hw);
133+
int ifcvf_verify_min_features(struct ifcvf_hw *hw, u64 features);
119134
u16 ifcvf_get_vq_state(struct ifcvf_hw *hw, u16 qid);
120135
int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num);
121136
struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw);
137+
int ifcvf_probed_virtio_net(struct ifcvf_hw *hw);
122138
#endif /* _IFCVF_H_ */

drivers/vdpa/ifcvf/ifcvf_main.c

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <linux/sysfs.h>
1515
#include "ifcvf_base.h"
1616

17-
#define VERSION_STRING "0.1"
1817
#define DRIVER_AUTHOR "Intel Corporation"
1918
#define IFCVF_DRIVER_NAME "ifcvf"
2019

@@ -169,17 +168,35 @@ static struct ifcvf_hw *vdpa_to_vf(struct vdpa_device *vdpa_dev)
169168

170169
static u64 ifcvf_vdpa_get_features(struct vdpa_device *vdpa_dev)
171170
{
171+
struct ifcvf_adapter *adapter = vdpa_to_adapter(vdpa_dev);
172172
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
173+
struct pci_dev *pdev = adapter->pdev;
174+
173175
u64 features;
174176

175-
features = ifcvf_get_features(vf) & IFCVF_SUPPORTED_FEATURES;
177+
switch (vf->dev_type) {
178+
case VIRTIO_ID_NET:
179+
features = ifcvf_get_features(vf) & IFCVF_NET_SUPPORTED_FEATURES;
180+
break;
181+
case VIRTIO_ID_BLOCK:
182+
features = ifcvf_get_features(vf);
183+
break;
184+
default:
185+
features = 0;
186+
IFCVF_ERR(pdev, "VIRTIO ID %u not supported\n", vf->dev_type);
187+
}
176188

177189
return features;
178190
}
179191

180192
static int ifcvf_vdpa_set_features(struct vdpa_device *vdpa_dev, u64 features)
181193
{
182194
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
195+
int ret;
196+
197+
ret = ifcvf_verify_min_features(vf, features);
198+
if (ret)
199+
return ret;
183200

184201
vf->req_features = features;
185202

@@ -319,19 +336,46 @@ static u32 ifcvf_vdpa_get_generation(struct vdpa_device *vdpa_dev)
319336

320337
static u32 ifcvf_vdpa_get_device_id(struct vdpa_device *vdpa_dev)
321338
{
322-
return VIRTIO_ID_NET;
339+
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
340+
341+
return vf->dev_type;
323342
}
324343

325344
static u32 ifcvf_vdpa_get_vendor_id(struct vdpa_device *vdpa_dev)
326345
{
327-
return IFCVF_SUBSYS_VENDOR_ID;
346+
struct ifcvf_adapter *adapter = vdpa_to_adapter(vdpa_dev);
347+
struct pci_dev *pdev = adapter->pdev;
348+
349+
return pdev->subsystem_vendor;
328350
}
329351

330352
static u32 ifcvf_vdpa_get_vq_align(struct vdpa_device *vdpa_dev)
331353
{
332354
return IFCVF_QUEUE_ALIGNMENT;
333355
}
334356

357+
static size_t ifcvf_vdpa_get_config_size(struct vdpa_device *vdpa_dev)
358+
{
359+
struct ifcvf_adapter *adapter = vdpa_to_adapter(vdpa_dev);
360+
struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
361+
struct pci_dev *pdev = adapter->pdev;
362+
size_t size;
363+
364+
switch (vf->dev_type) {
365+
case VIRTIO_ID_NET:
366+
size = sizeof(struct virtio_net_config);
367+
break;
368+
case VIRTIO_ID_BLOCK:
369+
size = sizeof(struct virtio_blk_config);
370+
break;
371+
default:
372+
size = 0;
373+
IFCVF_ERR(pdev, "VIRTIO ID %u not supported\n", vf->dev_type);
374+
}
375+
376+
return size;
377+
}
378+
335379
static void ifcvf_vdpa_get_config(struct vdpa_device *vdpa_dev,
336380
unsigned int offset,
337381
void *buf, unsigned int len)
@@ -392,6 +436,7 @@ static const struct vdpa_config_ops ifc_vdpa_ops = {
392436
.get_device_id = ifcvf_vdpa_get_device_id,
393437
.get_vendor_id = ifcvf_vdpa_get_vendor_id,
394438
.get_vq_align = ifcvf_vdpa_get_vq_align,
439+
.get_config_size = ifcvf_vdpa_get_config_size,
395440
.get_config = ifcvf_vdpa_get_config,
396441
.set_config = ifcvf_vdpa_set_config,
397442
.set_config_cb = ifcvf_vdpa_set_config_cb,
@@ -441,6 +486,19 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
441486
pci_set_drvdata(pdev, adapter);
442487

443488
vf = &adapter->vf;
489+
490+
/* This drirver drives both modern virtio devices and transitional
491+
* devices in modern mode.
492+
* vDPA requires feature bit VIRTIO_F_ACCESS_PLATFORM,
493+
* so legacy devices and transitional devices in legacy
494+
* mode will not work for vDPA, this driver will not
495+
* drive devices with legacy interface.
496+
*/
497+
if (pdev->device < 0x1040)
498+
vf->dev_type = pdev->subsystem_device;
499+
else
500+
vf->dev_type = pdev->device - 0x1040;
501+
444502
vf->base = pcim_iomap_table(pdev);
445503

446504
adapter->pdev = pdev;
@@ -455,6 +513,8 @@ static int ifcvf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
455513
for (i = 0; i < IFCVF_MAX_QUEUE_PAIRS * 2; i++)
456514
vf->vring[i].irq = -EINVAL;
457515

516+
vf->hw_features = ifcvf_get_hw_features(vf);
517+
458518
ret = vdpa_register_device(&adapter->vdpa, IFCVF_MAX_QUEUE_PAIRS * 2);
459519
if (ret) {
460520
IFCVF_ERR(pdev, "Failed to register ifcvf to vdpa bus");
@@ -476,10 +536,19 @@ static void ifcvf_remove(struct pci_dev *pdev)
476536
}
477537

478538
static struct pci_device_id ifcvf_pci_ids[] = {
479-
{ PCI_DEVICE_SUB(IFCVF_VENDOR_ID,
480-
IFCVF_DEVICE_ID,
481-
IFCVF_SUBSYS_VENDOR_ID,
482-
IFCVF_SUBSYS_DEVICE_ID) },
539+
{ PCI_DEVICE_SUB(N3000_VENDOR_ID,
540+
N3000_DEVICE_ID,
541+
N3000_SUBSYS_VENDOR_ID,
542+
N3000_SUBSYS_DEVICE_ID) },
543+
{ PCI_DEVICE_SUB(C5000X_PL_VENDOR_ID,
544+
C5000X_PL_DEVICE_ID,
545+
C5000X_PL_SUBSYS_VENDOR_ID,
546+
C5000X_PL_SUBSYS_DEVICE_ID) },
547+
{ PCI_DEVICE_SUB(C5000X_PL_BLK_VENDOR_ID,
548+
C5000X_PL_BLK_DEVICE_ID,
549+
C5000X_PL_BLK_SUBSYS_VENDOR_ID,
550+
C5000X_PL_BLK_SUBSYS_DEVICE_ID) },
551+
483552
{ 0 },
484553
};
485554
MODULE_DEVICE_TABLE(pci, ifcvf_pci_ids);
@@ -494,4 +563,3 @@ static struct pci_driver ifcvf_driver = {
494563
module_pci_driver(ifcvf_driver);
495564

496565
MODULE_LICENSE("GPL v2");
497-
MODULE_VERSION(VERSION_STRING);

0 commit comments

Comments
 (0)