Skip to content

Commit 5abfb22

Browse files
Shijith Thottonmstsirkin
authored andcommitted
vdpa/octeon_ep: read vendor-specific PCI capability
Added support to read the vendor-specific PCI capability to identify the type of device being emulated. Reviewed-by: Dan Carpenter <[email protected]> Acked-by: Jason Wang <[email protected]> Signed-off-by: Shijith Thotton <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 1629ee1 commit 5abfb22

File tree

3 files changed

+58
-2
lines changed

3 files changed

+58
-2
lines changed

drivers/vdpa/octeon_ep/octep_vdpa.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/pci_regs.h>
99
#include <linux/vdpa.h>
1010
#include <linux/virtio_pci_modern.h>
11+
#include <uapi/linux/virtio_crypto.h>
1112
#include <uapi/linux/virtio_net.h>
1213
#include <uapi/linux/virtio_blk.h>
1314
#include <uapi/linux/virtio_config.h>
@@ -52,6 +53,24 @@ struct octep_vring_info {
5253
phys_addr_t notify_pa;
5354
};
5455

56+
enum octep_pci_vndr_cfg_type {
57+
OCTEP_PCI_VNDR_CFG_TYPE_VIRTIO_ID,
58+
OCTEP_PCI_VNDR_CFG_TYPE_MAX,
59+
};
60+
61+
struct octep_pci_vndr_data {
62+
struct virtio_pci_vndr_data hdr;
63+
u8 id;
64+
u8 bar;
65+
union {
66+
u64 data;
67+
struct {
68+
u32 offset;
69+
u32 length;
70+
};
71+
};
72+
};
73+
5574
struct octep_hw {
5675
struct pci_dev *pdev;
5776
u8 __iomem *base[PCI_STD_NUM_BARS];
@@ -69,6 +88,7 @@ struct octep_hw {
6988
u32 config_size;
7089
int nb_irqs;
7190
int *irqs;
91+
u8 dev_id;
7292
};
7393

7494
u8 octep_hw_get_status(struct octep_hw *oct_hw);

drivers/vdpa/octeon_ep/octep_vdpa_hw.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* Copyright (C) 2024 Marvell. */
33

44
#include <linux/iopoll.h>
5+
#include <linux/build_bug.h>
56

67
#include "octep_vdpa.h"
78

@@ -358,7 +359,14 @@ u16 octep_get_vq_size(struct octep_hw *oct_hw)
358359

359360
static u32 octep_get_config_size(struct octep_hw *oct_hw)
360361
{
361-
return sizeof(struct virtio_net_config);
362+
switch (oct_hw->dev_id) {
363+
case VIRTIO_ID_NET:
364+
return sizeof(struct virtio_net_config);
365+
case VIRTIO_ID_CRYPTO:
366+
return sizeof(struct virtio_crypto_config);
367+
default:
368+
return 0;
369+
}
362370
}
363371

364372
static void __iomem *octep_get_cap_addr(struct octep_hw *oct_hw, struct virtio_pci_cap *cap)
@@ -416,8 +424,25 @@ static int octep_pci_signature_verify(struct octep_hw *oct_hw)
416424
return 0;
417425
}
418426

427+
static void octep_vndr_data_process(struct octep_hw *oct_hw,
428+
struct octep_pci_vndr_data *vndr_data)
429+
{
430+
BUILD_BUG_ON(sizeof(struct octep_pci_vndr_data) % 4 != 0);
431+
432+
switch (vndr_data->id) {
433+
case OCTEP_PCI_VNDR_CFG_TYPE_VIRTIO_ID:
434+
oct_hw->dev_id = (u8)vndr_data->data;
435+
break;
436+
default:
437+
dev_err(&oct_hw->pdev->dev, "Invalid vendor data id %u\n",
438+
vndr_data->id);
439+
break;
440+
}
441+
}
442+
419443
int octep_hw_caps_read(struct octep_hw *oct_hw, struct pci_dev *pdev)
420444
{
445+
struct octep_pci_vndr_data vndr_data;
421446
struct octep_mbox __iomem *mbox;
422447
struct device *dev = &pdev->dev;
423448
struct virtio_pci_cap cap;
@@ -466,6 +491,15 @@ int octep_hw_caps_read(struct octep_hw *oct_hw, struct pci_dev *pdev)
466491
case VIRTIO_PCI_CAP_ISR_CFG:
467492
oct_hw->isr = octep_get_cap_addr(oct_hw, &cap);
468493
break;
494+
case VIRTIO_PCI_CAP_VENDOR_CFG:
495+
octep_pci_caps_read(oct_hw, &vndr_data, sizeof(vndr_data), pos);
496+
if (vndr_data.hdr.vendor_id != PCI_VENDOR_ID_CAVIUM) {
497+
dev_err(dev, "Invalid vendor data\n");
498+
return -EINVAL;
499+
}
500+
501+
octep_vndr_data_process(oct_hw, &vndr_data);
502+
break;
469503
}
470504

471505
pos = cap.cap_next;

drivers/vdpa/octeon_ep/octep_vdpa_main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,9 @@ static u32 octep_vdpa_get_generation(struct vdpa_device *vdpa_dev)
302302

303303
static u32 octep_vdpa_get_device_id(struct vdpa_device *vdpa_dev)
304304
{
305-
return VIRTIO_ID_NET;
305+
struct octep_hw *oct_hw = vdpa_to_octep_hw(vdpa_dev);
306+
307+
return oct_hw->dev_id;
306308
}
307309

308310
static u32 octep_vdpa_get_vendor_id(struct vdpa_device *vdpa_dev)

0 commit comments

Comments
 (0)